ProgrammingHardGATE CS · TCS NQT

What is printed?

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

Correct answer: C. 6

t is the transpose of m, so t[2][1] = m[1][2], which is 6. Using m[1][1] gives 5, one of the usual index mix-ups.

More C Programming questions

Exams that ask this topic