// // Filename: pgm3_4b.cpp // // Description: Demo program, Scope #2: Local variables // // 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 a( void ); void b( void ); void c( void ); int x = 1; // global variable main() { cout << "X = " << x << endl; int x = 5; // local variable to main cout << "X = " << x << endl; { // Block A int x = 7; cout << "X = " << x << endl; } // Block B a(); b(); c(); a(); b(); c(); c(); c(); cout << "X = " << x << endl; return 0; } void a( void ) { int x = 25; // Local to a, Initialized each time a is called cout << "a(): X = " << x << endl; x -= 5; cout << "a(): X = " << x << endl << endl; } void b( void ) { int x = 50; // Local to b, initialized each time b is called cout << "b(): X = " << x << endl; ++x; cout << "b(): X = " << x << endl << endl;; } void c( void ) { cout << "c(): X = " << x << endl; // Using the global variable x *= 10; // Using the global variable cout << "c(): X = " << x << endl << endl; // Using the global variable }