ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
/* LP64: 4-byte int, 8-byte pointers */
int a[2][3] = {{1, 2, 3}, {4, 5, 6}};
int (*p)[3] = a;
printf("%d %d %zu %zu", p[1][2], **(p + 1), sizeof(*p), sizeof(p));
  1. A. 6 4 12 8
  2. B. 6 2 12 8
  3. C. 6 4 4 8
  4. D. 6 4 12 12

Correct answer: A. 6 4 12 8

p is a pointer to an array of 3 ints, so p + 1 skips a whole row. p[1][2] is a[1][2] = 6, and **(p + 1) is the first element of row 1, 4 (2 would come from treating p as a plain int pointer). *p is an entire row: sizeof is 3 × 4 = 12. p itself is just a pointer: 8 bytes.

More C Programming questions

Exams that ask this topic