ProgrammingModerate
int a[3][3]; printf("%zu", sizeof a[0][0] * 3 * 3); What is printed with 4-byte int?
- A. 9
- B. 12
- C. 36
- D. 4
Correct answer: C. 36
sizeof binds only to its operand a[0][0], one int of 4 bytes, so the expression is 4 * 3 * 3 = 36. 9 counts elements instead of bytes, and 12 is the size of one row.
More C Programming questions
- 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…
- int m[2][3] = {{1, 2, 3}, {4, 5, 6}}; int p = m[1]; printf("%d %d", p[0], (p + 2)); What is printed?
- int m[2][3]; int p = &m[0][0]; for (int i = 0; i < 6; i++) p[i] = i i; printf("%d", m[1][2]); What is printed?