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"

Right 98% of the time, and don't care about the other 3%.

If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

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.

Right 98% of the time, and don't care about the other 3%.

If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

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.

I don't like it either, but I was stuck with the nouns listed in the C++ standard.

I don't like it either, but I was stuck with the nouns listed in the C++ standard.

This is just one of those topics that are hard to express within the confines of the standard's grammer. Eh, I think the question has been answered, unless the OP has something else he is confused about.

Originally Posted by anduril462

Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....

Originally Posted by quzah

..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.

Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.