ProgrammingHardIBM · Deloitte pattern

What is printed?

What is printed?
int **p = malloc(3 * sizeof(int*));
for (int i = 0; i < 3; i++) p[i] = malloc(3 * sizeof(int));
for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++)
        p[i][j] = i * 3 + j;
printf("%d %d", *(p[1] + 2), *(*(p + 2) + 0));
  1. A. 5 5
  2. B. 5 6
  3. C. 6 5
  4. D. 2 6

Correct answer: B. 5 6

p[1][2] = 1*3+2 = 5. *(p+2) is p[2], so *(*(p+2)+0) is p[2][0] = 2*3+0 = 6.

More C Programming questions

Exams that ask this topic