Question 10
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int count = 100;
void tick(void) {
static int count = 0;
count++;
printf("%d ", count);
}
int main(void) {
tick();
tick();
printf("%d\n", count);
return 0;
}
- A 1 2 100 Correct
- B 101 102 102
- C 1 2 2
- D 101 102 100
Correct Answer: Option A
Inside tick(), the static local count shadows the global, so only the local goes 1, 2. main() sees the global, which is still 100.
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!