ProgrammingHardGATE CS · Infosys

What is printed?

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

Correct answer: B. 6

A 3 by 3 array is contiguous row by row, so flat index 5 is m[1][2], which holds 1 * 3 + 2 + 1 = 6.

More C Programming questions

Exams that ask this topic