ProgrammingHard

int m[2][2] = {{1, 2}, {3, 4}}; int t[2][2]; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) t[j][i] = m[i][j]; printf("%d", t[0][1]); What is printed?

  1. A. 2
  2. B. 3
  3. C. 1
  4. D. 4

Correct answer: B. 3

The loop stores m[i][j] into t[j][i], so t is the transpose and t[0][1] = m[1][0] = 3. 2 is m[0][1], which is what you get if you forget the swap of indices.

More C Programming questions

Exams that ask this topic