ProgrammingModerate
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?
- A. About 1 MB
- B. About 40 MB
- C. About 4 GB
- D. About 4 MB, that is 4 000 000 bytes
Correct answer: D. About 4 MB, that is 4 000 000 bytes
1000 x 1000 = 10^6 ints of 4 bytes each, which is about 4 MB.
More C Programming questions
- 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?
- A rectangular table with R rows and C columns is traversed in a loop that touches each cell once in row-major order. Which total cost is…