ProgrammingVery hardProduct company OA

What is printed?

What is printed?
int m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
        int t = m[i][j]; m[i][j] = m[j][i]; m[j][i] = t;
    }
printf("%d %d", m[0][1], m[2][0]);
  1. A. 2 3
  2. B. 2 7
  3. C. 4 3
  4. D. 4 7

Correct answer: B. 2 7

Both loops run over the full matrix, so every off-diagonal pair is swapped twice, once at (i, j) and again at (j, i), which puts it back. The matrix ends unchanged. An in-place transpose must loop j from i + 1 only.

More C Programming questions

Exams that ask this topic