ProgrammingVery hard
Which statement about passing a 2D array to a function is correct in C99?
- A. The inner dimension can be left empty, as in int m[][], because the compiler infers it
- B. The inner dimension must be given (or be a VLA size declared earlier), because the compiler needs the row length to compute addresses
- C. A 2D array decays to int ** automatically
- D. The function receives a copy of every element, so the size does not matter
Correct answer: B. The inner dimension must be given (or be a VLA size declared earlier), because the compiler needs the row length to compute addresses
C needs the row length to compute offsets, so a parameter like int m[][4] or int m[][n] with n declared earlier is required. int ** is a different type.
More C Programming questions
- 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…
- int m[2][3] = {{1, 2, 3}, {4, 5, 6}}; int p = m[1]; printf("%d %d", p[0], (p + 2)); What is printed?