ProgrammingHardIBM · Deloitte pattern

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int a[2][3] = {{1, 2, 3}, {4, 5, 6}};
    int (*p)[3] = a;
    printf("%d %d", (*(p + 1))[2], *(*(p + 1) + 1));
}
  1. A. 3 2
  2. B. 6 4
  3. C. 6 5
  4. D. 5 6

Correct answer: C. 6 5

p is a pointer to a 3-int row. p+1 points to row a[1] = {4,5,6}. (*(p+1))[2] is a[1][2]=6, and *(*(p+1)+1) is a[1][1]=5.

More C Programming questions

Exams that ask this topic