// Example 1
{
int a = 2;
a = a + 1; // ok, a is recognized
{
int b = a; // ok, a is still in scope
}
a = b; // error, b is out of scope and is undefined
}
a = a + 1; // error, a is out of scope// Example 2int a = 2;
{
int a = 3; // inner a (a=3) masks the outer a (a=2)int b = a; // b is assigned the value 3
}
// inner a is out of scope and outer a is no longer maskedint c = a; // c is assigned the value of the outer a (a=2) int d = b; // error: b is no longer in scope// Example 3int a = 42; // global variableintmain(){
int a = 13; // local variableint b = a + 1; // 14int c = ::a + 1; // 43return0;
}