Consider the code:
#include
int x;
int main (void)
{ }
The value of x
is 0
inside main>
x is a global variable, it has space allocated for it when the program starts and is initialized to 0 (generally, however you should have an explicit initializer).
The 'static' keyword has two different meanings.
1)
static int x; int main() { }
This limits the scope of x to the single file. Although it is still a global variable, the linker will not be able to connect references to x from other files.
2)
int main() { static int x; }
This effectively turns x into a global variable. Although the scope is still within the main function, space is allocated for it globally, and it's value will be retained between calls to main().