It might be helpful to try a sample program consisting of one source file:
Code:
#include <stdio.h>
void foo(void);
int x;
static int y;
int main(void)
{
x = 10;
y = 100;
printf("x=%d; y=%d\n", x, y);
foo();
printf("x=%d; y=%d\n", x, y);
return 0;
}
and another source file:
Code:
extern int x;
static int y;
void foo(void)
{
x = 20;
y = 200;
}
If you compile and link them to build an executable, then run it, you'll get output like this:
Code:
x=10; y=100
x=20; y=100
So, the global variable named x has what we call external linkage, hence my use of the extern keyword to explicitly specify this in its declaration in the second source file: the name x (unless shadowed by a more local declaration of the name x) refers to the same object across translations units (i.e., across different source files + their respective included headers). The file scope variable named y that is declared static has what we call internal linkage: the name y refers to the same object in the same translation unit. That's why we see that the value of x has changed but the value of y remained the same: the x that foo() modified is the same x that the main function referred to, whereas the y that foo() modified is a different variable that also happens to be a file scope variable named y.