99
Comments:
There is just one object x
,
which is referred to in all three files.
When the executable program is loaded into memory, there is just one x
,
which holds an 8.
The main()
function starts running and calls foo()
which
changes x
to 99.
x
continues to hold 99 when control returns to main()
.
Contrast this to the previous two puzzles where the x
in foo()
is a local variable with no linkage.
/* --- fileA.c --- */ int x = 8;
/* --- fileB.c --- */ void foo() { extern int x; x = 99; }
/* --- fileC.c --- */ #include <stdio.h> void foo(); extern int x; void main() { foo(); printf("%d\n", x ); }