a2 has a local scope. When main() returns, a2 ceases to exist. So that local scope is associated with the main() function. Some people describe this as "function scope"
a2 has a local scope. When main() returns, a2 ceases to exist. So that local scope is associated with the main() function. Some people describe this as "function scope"
Pardon if I'm missing the answer in that, but my question is which one is true:
orIt is very true.So is this untrue then? [...]A local variable by definition has local scope, a non-local variable by definition cannot have local scope.
a = a + 2; //This uses a2; it is nonlocal to this block, but it has local scope and is currently the only a in scope
They are both true, although personally I would not have used quite the wordings that tabstop did.
a2 is within the scope associated with the function main(), and hides a1 (at file scope). The body of the while loop within main() defines a new scope, That new scope is within the scope associated with main(), so can access a2 - another a (called a3) is introduced within that scope.