ProgrammingHardGATE CS · Infosys

What is printed?

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

Correct answer: D. 13

The array is row major with rows of five ints, so flat index 13 is m[2][3], which holds 2 * 5 + 3 = 13.

More C Programming questions

Exams that ask this topic