// Author: Keith A. Shomper // Date: 2/23/2004 // Purpose: To demonstrate variable scope #include using namespace std; char i = 'A'; print() { cout << "print scope: " << i << endl; } main () { int i = 1; int j = 2; int k = 3; cout << "main scope: " << i << " " << j << " " << k << endl; { int i, j = 10, k = 20; cout << "main (first block): " << i << " " << j << " " << k << endl; } cout << "main scope: " << i << " " << j << " " << k << endl; print(); while (k >= 0) { int i = k * 5; cout << "main (while block): " << i << " " << j << " " << k << endl; k--; } cout << "main scope: " << i << " " << j << " " << k << endl; return 0; }