ProgrammingHardGATE CS · Product company OA

With 4-byte int, what is printed?

With 4-byte int, what is printed?
int a[3][4] = {0};
int (*p)[4] = a;
int *q = &a[0][0];
printf("%td %td %td", (p + 2) - p, (char *)(p + 1) - (char *)p, &a[2][1] - q);
  1. A. 2 16 9
  2. B. 8 16 9
  3. C. 2 4 9
  4. D. 2 16 6

Correct answer: A. 2 16 9

p points to a whole row (4 ints = 16 bytes), so (p + 2) − p is 2 rows and p + 1 is 16 bytes past p. &a[2][1] is element 2·4 + 1 = 9 counted from &a[0][0]. '4' treats p as an int pointer; '6' uses 3 columns instead of 4.

More C Programming questions

Exams that ask this topic