"extern" means:
"this variable will come from some other place. It is not being declared here; this statement just provides notice that it is a valid name."
So in essence this code is:
extern int x;
// This is a valid name, but the variable will be defined "externally", eg, somewhere else.
[...]
int x=0;
// OH! Here is where the definition is. Now we know where that "extern" variable came from.
// And we know that it starts with value 0.
It is somewhat unusual for and extern
and definition to appear in the same file.
More typically, the definition is in one .C
file, and the extern
is in a different .C
that will get linked together during the build process.