Nested Blocks
The scope of a variable includes nested blocks, i.e., blocks that appear within the block in which the variable is declared.
{
int a = readInt();
int b = readInt();
if (a > b)
{
int temp = a;
a = b;
b = temp;
}
. . .
}
Thus, a and b are meaningful within the inner block, but temp is not meaningful in the outer block.
Previous slide
Next slide
Back to first slide
View graphic version