Variable Scope
Local variables
Variables that are declared within the body of a function definition are said to be local to that function or to have that function as their scope. If a variable is local to a function, then you can have another variable (or other kind of item) with the same name that is declared in another function definition; these will be two different variables, even though they have the same name. (In particular, this is true even if one of the functions is the main function.)
Blocks
A block is some C++ code enclosed in braces. The variables declared in a block are local to the block, and so the variable names can be used outside the block for something else (such as being reused as the names for different variables).
Scope Rule for nested blocks
If an identifier is declared as a variable in each of two blocks, one within the other, then these are two different variables with the same name. One variable exists only within the inner block and cannot be accessed outside of the inner block. The other variable exists only in the outer block and cannot be accessed in the inner block. The two varibles are distinct, so changes made to one of these variables will have no effect on the other of these two variables.
Variables declared in a for loop
A variable may be declread in the heading of a for statement. That variable is local to the body of the loop.
