ProgrammingHard

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

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

Correct answer: B. 1

grid[i][2 - i] visits the anti-diagonal, which holds 0, 0 and 1 in this identity-like matrix. The sum is 1.

More C Programming questions

Exams that ask this topic