ProgrammingHardGATE CS · Infosys

What is printed?

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

Correct answer: D. 2 7

Adding to a row pointer moves in whole rows, so (p + 2) - p is 2. Element a[1][3] holds 1 * 4 + 3 = 7.

More C Programming questions

Exams that ask this topic