ProgrammingVery hardGATE CS

What is printed? Assume int is 4 bytes and the array is a 2-D array object of automatic storage.

What is printed? Assume int is 4 bytes and the array is a 2-D array object of automatic storage.
#include <stdio.h>
int main(void) {
    int a[3][4];
    printf("%td %td %zu", (char *)&a[2][1] - (char *)&a[0][0],
           &a[2][1] - &a[0][0], sizeof(a[1]));
    return 0;
}
  1. A. 9 36 16
  2. B. 36 9 16
  3. C. 9 9 16
  4. D. 36 9 4

Correct answer: B. 36 9 16

Element a[2][1] is 2 x 4 + 1 = 9 ints after a[0][0], so the int-pointer difference is 9 and the byte difference is 36. a[1] is a row of 4 ints: 16 bytes.

More C Programming questions

Exams that ask this topic