ProgrammingVery hardProduct company OA

What is printed?

What is printed?
int a[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};
int *p = (int *)a;
printf("%d %d %d", *(p + 5), *(*(a + 1) + 2), *(a[2] + 1));
  1. A. 6 7 11
  2. B. 5 7 10
  3. C. 6 6 10
  4. D. 6 7 10

Correct answer: D. 6 7 10

Treating a as flat memory, p+5 is the 6th int = 6. *(a+1) decays the row a[1] to a pointer, +2 gives a[1][2]=7. a[2]+1 points to a[2][1]=10.

More C Programming questions

Exams that ask this topic