ProgrammingVery hardProduct company OA

What is printed?

What is printed?
/* LP64: 4-byte int, 8-byte pointers */
void f(int m[][4], int n) {
    printf("%zu %zu %td ", sizeof m, sizeof m[0], (char *)(m + n) - (char *)m);
}
int main(void) {
    int a[3][4] = {0};
    f(a, 2);
    printf("%zu", sizeof a);
}
  1. A. 48 16 32 48
  2. B. 8 16 2 48
  3. C. 8 16 32 48
  4. D. 8 4 32 48

Correct answer: C. 8 16 32 48

A parameter declared int m[][4] is adjusted to int (*m)[4], a pointer to a row, so sizeof m is 8. m[0] is a whole row of 4 ints: 16 bytes. m + n advances by n rows, i.e. 2 × 16 = 32 bytes (a plain 2 would be the difference in rows, not bytes). In main, a is a real array: 3 × 4 × 4 = 48.

More C Programming questions

Exams that ask this topic