// The purpose of this example is to show how scope of a variable is affected // by the block of code { } where the variable is declared. // The extra block is shown for illustrative purposes only. Normally blocks are defined // for conditional statements, loops, and functions. But this example shows that // they can be created by themselves. #include using namespace std; int main() { int a = 5, b = 10; int x = 15; { double a = 1.5; b = -2; int x = 20; int y = 25; cout << "a = " << a << ", b = " << b << ", x = " << x << ", y = " << y << endl; } cout << "a = " << a << ", b = " << b << ", x = " << x << endl; system("pause"); }