"Applying the specifier static to a global variable instructs the compiler to create a global variable known only to the file in which it is declared. This means that even though the variable is global, routines in other files have no knowledge of it and cannot alter its contents directly, keeping it from side effects." - C: The Complete Reference, by Herbert Schildt.

Contents of "staticgl.c"

#include <stdio.h>
#include "static.h"
int main()
{
int i;
startat(10);
for (i=0; i<5; i++)
printf("%d %d\n", counter++, nextnumber()); /*How could it possible.*/
return 0;
}

Contents of "static.h", Header file used in "staticgl.c".

static int counter;

void startat(int);
int nextnumber(void);

void startat(int x)
{
counter=x;
}

int nextnumber(void)
{
counter++;
return counter;
}

Output:

11 11
13 13
15 15
17 17
19 19
19 19


How the main() function in another file can access the 'counter' variable? I am using Turbo C 2.0 compiler.