Thursday, June 23, 2011

c++ - Local variable's memory can be accessed outside its scope?! - Stack Overflow

c++ - Local variable's memory can be accessed outside its scope?! - Stack Overflow: "How can it be? Isn't the memory of a local variable inaccessible outside its function?

You rent a hotel room. You put a book in the top drawer of the bedside table and go to sleep. You check out the next morning, but 'forget' to give back your key. You steal the key!

A week later, you return to the hotel, do not check in, sneak into your old room with your stolen key, and look in the drawer. Your book is still there. Astonishing!

How can that be? Isn't the contents of a hotel room drawer inaccessible if you haven't rented the room?"