ProgrammingHardGATE CS · Campus placements

void f(int *a) { size_t n = sizeof a / sizeof a[0]; ... } is called as f(arr) where int arr[4]. What is true about n?

  1. A. It equals 4 for any array passed in
  2. B. It equals sizeof(int *) / sizeof(int), which is not the length of arr
  3. C. It is a compile-time error
  4. D. It is always 0

Correct answer: B. It equals sizeof(int *) / sizeof(int), which is not the length of arr

The parameter is a pointer, so sizeof a is the pointer size and the division measures the pointer, not the array. The length must be passed as a separate argument.

More C Programming questions

Exams that ask this topic