/* scope.c * Demonstrate different scopes in C. C has file scope, function (local) scope, for loop scope, and block scope */ #include int file = 0; void func1( ) { int local = 5; printf( "local to func1 %d\n", local ); if (local > 0) { int b = 5; // b has block scope printf( "b is %d\n", b ); } for (int i =0; i < 3; i++) { int i = 4; // this definition of i shadows the one at the for loop level printf( "i is %d\n", i ); } } int main( int argc, char* argv[] ) { func1(); printf( "Here is file: %d\n", file ); file = 7; printf( "Here is file now: %d\n", file ); // printf( "local to func1 %d\n", local ); return 0; }