ProgrammingHard

A 2D array is passed to a function that needs the number of rows. Which argument can it NOT rely on?

  1. A. An explicit rows argument passed by the caller
  2. B. A sentinel value stored in the last row
  3. C. sizeof of the parameter, since the parameter is a pointer and sizeof gives the pointer size
  4. D. A global constant set by the caller

Correct answer: C. sizeof of the parameter, since the parameter is a pointer and sizeof gives the pointer size

An array parameter adjusts to a pointer, so sizeof gives the pointer's size and cannot give the row count. The caller must pass the count.

More C Programming questions

Exams that ask this topic