Question 5
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
const int SIZE = 10;
int buffer[SIZE];
int main(void) {
buffer[0] = 1;
printf("%d\n", buffer[0]);
return 0;
}
- A buffer must be static
- B In C, a const int is not a constant expression, so it cannot size a file-scope array (that would be a VLA, which is not allowed there) Correct
- C SIZE must be unsigned
- D There is no bug
Correct Answer: Option B
This compiles in C++, but not in C. Use enum { SIZE = 10 };, #define SIZE 10, or C23 constexpr int SIZE = 10;.
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!