Script started on Sun Sep 26 14:30:17 1999 strauss[2:30pm] [~/Class/cisc181/deitel-files/examples/ch03/]> CC -compat fig3_1 2.cpp strauss[2:30pm] [~/Class/cisc181/deitel-files/examples/ch03/]> cat fig3_12.cpp // A scoping example #include void a(void); // function prototype void b(void); // function prototype void c(void); // function prototype int x = 1; // global variable main() { int x = 5; // local variable to main cout << "local x in outer scope of main is " << x << endl; { // start new scope int x = 7; cout << "local x in inner scope of main is " << x << endl; } // end new scope cout << "local x in outer scope of main is " << x << endl; a(); // a has automatic local x b(); // b has static local x c(); // c uses global x a(); // a reinitializes automatic local x b(); // static local x retains its previous value c(); // global x also retains its value cout << "local x in main is " << x << endl; return 0; } void a(void) { int x = 25; // initialized each time a is called cout << endl << "local x in a is " << x << " after entering a" << endl; ++x; cout << "local x in a is " << x << " before exiting a" << endl; } void b(void) { static int x = 50; // Static initialization only // first time b is called. cout << endl << "local static x is " << x << " on entering b" << endl; ++x; cout << "local static x is " << x << " on exiting b" << endl; } void c(void) { cout << endl << "global x is " << x << " on entering c" << endl; x *= 10; cout << "global x is " << x << " on exiting c" << endl; } strauss[2:30pm] [~/Class/cisc181/deitel-files/examples/ch03/]> CC -compat fig3_1 2.cpp strauss[2:30pm] [~/Class/cisc181/deitel-files/examples/ch03/]> a.out local x in outer scope of main is 5 local x in inner scope of main is 7 local x in outer scope of main is 5 local x in a is 25 after entering a local x in a is 26 before exiting a local static x is 50 on entering b local static x is 51 on exiting b global x is 1 on entering c global x is 10 on exiting c local x in a is 25 after entering a local x in a is 26 before exiting a local static x is 51 on entering b local static x is 52 on exiting b global x is 10 on entering c global x is 100 on exiting c local x in main is 5 strauss[2:30pm] [~/Class/cisc181/deitel-files/examples/ch03/]> exit strauss[2:30pm] [~/Class/cisc181/deitel-files/examples/ch03/]> exit script done on Sun Sep 26 14:30:58 1999