ProgrammingModerate
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?
- A. 6
- B. 9
- C. 4
- D. 15
Correct answer: A. 6
m[i][j] = i + j, so m[3][3] = 3 + 3 = 6 (index 3 is the last row and column of a 4 x 4 array). 9 multiplies the indices, 4 treats them as 1-based (2 + 2), and 15 is the flat position 3 * 4 + 3 rather than the stored value.
More C Programming questions
- 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?
- int d[2][3] = {1, 2, 3, 4, 5, 6}; printf("%d", d[1][0]); What is printed?
- 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"…
- int m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int t = 0; for (int i = 0; i < 3; i++) t += m[i][i] m[i][2 - i]; printf("%d", t); What is…