ProgrammingVery hardGATE CS

With 4-byte int, what is printed?

With 4-byte int, what is printed?
int a[2][3][4];
printf("%zu %zu %td", sizeof a[1], sizeof a[1][2],
       (char *)&a[1][2][3] - (char *)a);
  1. A. 48 16 23
  2. B. 48 16 96
  3. C. 48 16 92
  4. D. 12 4 92

Correct answer: C. 48 16 92

a[1] is a 3 × 4 block of ints (48 bytes) and a[1][2] is a row of 4 ints (16 bytes). Element [1][2][3] is at index 1·12 + 2·4 + 3 = 23 in row-major order, and as a char-pointer difference that is 23 × 4 = 92 bytes. '23' forgets the char casts.

More C Programming questions

Exams that ask this topic