Multiple choice

What will be the output of the following question?

main() { extern int out; printf(“%d”,out); } int out=100;

  1. 0

  2. Garbage value

  3. 100

  4. None of these

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The extern keyword tells the compiler that the variable 'out' is defined elsewhere. Even though the actual definition of 'out' appears after the main function, the linker will correctly resolve the reference to the global variable and print 100.