Machine-translated by Google. Questions are authored in English.
Top

Discussion

In C, if you pass an array as an argument to a function, what actually gets passed?

  • A.Value of elements in array
  • B.First element of the array
  • C.Base address of the array
  • D.Address of the last element of array

Answer: C

Correct answer: Base address of the array

An array argument decays to a pointer to its first element, so what the function receives is the base address, not a copy of the elements. This is why passing a large array costs nothing extra, why the function can modify the caller’s data, and why sizeof inside the function returns the size of a pointer rather than of the array.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.