// // Filename: pgm3_4c.cpp // // Description: Demo program, Scope #3, Static // // ENSC 104: Digital Computer Programming // // Instructor: Dr. Walsh // // Section: 2 // // Date Created: 03/17/98 // Last Modified: 03/17/98 // // Name: N/A // #include void sub0( void ); void sub1( void ); void sub2( void ); int x = 1; // global variable, it can be seen in other files. static int y = -1; // global to this file, can NOT be seen in other files. main() { cout << "X = " << x << ", Y = " << y << endl; int x = 5; // local variable to main cout << "X = " << x << ", Y = " << y << endl; { // Block A int x = 10; cout << "X = " << x << ", Y = " << y << endl; } // End Block A sub0(); sub0(); sub0(); cout << endl; sub1(); sub1(); sub1(); cout << endl; sub2(); sub2(); sub2(); return 0; } void sub0( void ) { static int x = 25; cout << "sub0(): X = " << x << ", Y = " << y << endl; ++x; cout << "sub0(): X = " << x << ", Y = " << y << endl; } void sub1( void ) { static int x = 50; cout << "sub1(): X = " << x << ", Y = " << y << endl; ++x; cout << "sub1(): X = " << x << ", Y = " << y << endl; } void sub2( void ) { static int y = 100; cout << "sub2(): X = " << x << ", Y = " << y << endl; y++; x *= 10; cout << "sub2(): X = " << x << ", Y = " << y << endl; }