Possible Duplicate:
How can I access a shadowed global variable in C?
how to access global variable in C , if there is local variable with same name?
int m=20 ;
void main()
{
int m=30;
}
In C, you can. Of course this is just trivia, you should never do so in real life.
Declaring something extern
can be done anywhere, and always links the declared variable to the global of that name.
#include <stdio.h>
int i = 3;
int main( int argc, char **argv ) {
int i = 6;
printf( "%d\n", i );
{ // need to introduce a new scope
extern int i; // shadowing is allowed here.
printf( "%d\n", i );
}
return 0;
}
In C++, the global is always available as ::i
.
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