ProgrammingHard

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

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

Correct answer: D. 3

Assigning u[j][i] = t[i][j] turns the 1 x 3 row into a 3 x 1 column, so u[2][0] = t[0][2] = 3. 1 reads t[0][0], and 0 wrongly assumes that cell of u was never written.

More C Programming questions

Exams that ask this topic