ProgrammingHardProduct company OA

Assume C99 or later. What is printed?

Assume C99 or later. What is printed?
void f(int n, int a[][n]) { printf("%zu", sizeof a[0] / sizeof a[0][0]); }
int main(void) { int m[2][5]; f(5, m); }
  1. A. 2
  2. B. 10
  3. C. 5
  4. D. 1

Correct answer: C. 5

a is a pointer to a variable-length row of n ints, so a[0] is a whole row whose size is computed at run time: 5 ints. That is how C99 lets functions take 2-D arrays whose column count is not fixed at compile time.

More C Programming questions

Exams that ask this topic