ProgrammingHardGATE CS · Infosys

What is printed?

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

Correct answer: D. 5

A 2D array is stored row by row, so flat index 4 is element m[1][1] = 5. Index 4 is not the end of a row, so the answer is not 6.

More C Programming questions

Exams that ask this topic