Question 4
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
int main(void) {
int scores[3] = {90, 85, 70, 60};
printf("%d\n", scores[0]);
return 0;
}
- A scores must be global
- B The list has 4 values for a 3-element array – excess initializers are not allowed Correct
- C The extra value is ignored silently, so there is no bug
- D Array sizes must be even
Correct Answer: Option B
An initializer list may be shorter than the array (the rest is zeroed) but never longer. Enlarge the array, or omit the size – int scores[] = {90, 85, 70, 60}; – and let the compiler count.
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!