Q: Why can I access an out-of-scope C++ var? A: So you rent a hotel room...
I'll probably get downvoted, but I think elaborate real-life analogies like this are more likely to confuse novices than help them.<p>A better explanation in my opinion is to draw a diagram of a stack and showing that returning from a function just decreases a pointer. C++ programs don't scrub the top of the stack once you finish a function because it is a waste of time.<p>If another function was called before the 2nd call to foo(), then the variable on the stack would be overwritten.