Question 6
Back to Exercise
The program below has a problem. Which statement correctly describes it?
#include <stdio.h>
int corner(int m[][], int rows) {
return m[rows - 1][0];
}
int main(void) {
int m[2][3] = {{1, 2, 3}, {4, 5, 6}};
printf("%d\n", corner(m, 2));
return 0;
}
- A rows must be the first parameter
- B int m[][] – the number of columns must be given, e.g. int m[][3] Correct
- C There is no error; it prints 4
- D m must be passed as &m
Correct Answer: Option B
To find m[i][j] the compiler needs the row length, so only the first dimension can be left empty: int corner(int m[][3], int rows), or as a VLA parameter int corner(int rows, int cols, int m[rows][cols]).
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!