Because the variable is external to the file; it is defined in another file, and you just tell that file that it exists, but it won't find it there. Then it's the job of the linker to solve that.
Example:
// a.c
int x = 7;
a.c has the variable defined
// a.h
extern int x;
a.h has knowledge that the variable exists, but it doesn't know where. Any file that includes a.h will gain that knowledge
// b.c
#include "a.h"
b.c, because it has included a.h, now has knowledge that the variable x exists, but doesn't know where.
The linker will resolve those different usages of the same variable x. They better be the same, or there will be problems.
You could lie to a.h, and write a float
instead of int
, and only the linker may notice that, because the compiler literally has no knowledge about a.c (well, a.c should include a.h, so it will notice, but you could lie to it if you don't include it)
In the whole project there must be one and only one non-extern definition of each variable. 0 or 2 or more, and the linker will report an error.