I have one doubt if i declared global variable with static.
file1.c
static int a=5;
main()
{
func();
}
can it be access in another file2.c using extern ?
file2.c
func()
{
extern int a;
printf(a);
}
or only global variable declared without static can be access using extern?
No!
staticlimits the scope of the variable to same translation unit.staticgives the variable an Internal Linkage and this variable cannot be accessed beyond the translation unit in which was created.If you need to access a variable accross different files just drop the
statickeyword.