I have one doubt if i declared global variable with static.
static int a=5;
main()
{
func();
}
can it be access in another file2.c using extern ?
func()
{
extern int a;
printf(a);
}
or only global variable declared without static can be access using extern?
No!static
limits the scope of the variable to same translation unit.static
gives 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 static
keyword.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With