In C you can. Of course, these are just trifles; you should never do this in real life.
Declaring something extern can be done anywhere and always associates a declared variable with a global 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 .
source share