Question 3
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
static int counts[5];
counts[2] += 3;
printf("%d %d\n", counts[2], counts[4]);
return 0;
}
- A 3 0 Correct
- B 3 garbage
- C garbage garbage
- D 0 0
Correct Answer: Option A
A static array has static storage duration, so every element starts at 0 – even without an initializer. Without static, all five elements would be indeterminate.
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!