Question 2
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int n = 5;
void bump(void) { n++; }
int main(void) {
int n = 1;
bump();
bump();
{
extern int n;
printf("%d ", n);
}
printf("%d\n", n);
return 0;
}
- A 7 1 Correct
- B 1 1
- C 7 7
- D 5 1
Correct Answer: Option A
bump() changes the global n, so it is 7. Inside the inner block, extern int n; re-declares the file-scope n, so it prints 7; after the block, the local n (1) is visible again.
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!