Question 4
Back to Exercise
What is the output of the following C program on a 64-bit system?
#include <stdio.h>
extern int n;
int twice(void) { return n * 2; }
int n = 21;
int main(void) {
printf("%d\n", twice());
return 0;
}
- A 42 Correct
- B 0
- C Compilation error
- D Garbage
Correct Answer: Option A
The extern declaration lets twice() use n before its definition appears. The definition initialises n to 21 before the program starts, so the result is 42.
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!