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?
- A. 0
- B. 1
- C. 2
- 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
- int a[4][4] = {0}; for (int i = 0; i < 4; i++) a[i][i] = a[i][3 - i] = 1; int c = 0; for (int i = 0; i < 4; i++) for (int j = 0; j < 4…
- A 5 x 5 grid is stored as an int matrix. Which expression gives the number of cells on its main diagonal?
- int n = 4; int m[n][n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) m[i][j] = i + j; printf("%d", m[3][3]); What is printed?
- Which statement about passing a 2D array to a function is correct in C99?
- int a[3][3]; printf("%zu", sizeof a[0][0] 3 3); What is printed with 4-byte int?
- A 2D grid of 1000 x 1000 is stored as int g[1000][1000] global. Roughly how many bytes does it take with 4-byte int?