Contrary to popular belief, pointers are not just numbers and you are inviting weird behaviour by trying to do things with a dangling pointer, not limited to dereferencing them.
Your reading of a pointer's value involves an "lvalue-to-rvalue conversion" and the standard has this to say about your antics:
Otherwise, if the object to which the glvalue refers contains an invalid pointer value ([basic.stc.dynamic.deallocation], [basic.stc.dynamic.safety]), the behavior is implementation-defined. [7.3.1/3])
This means that your assumption/premise is incorrect. Although we wouldn't expect nice simple variables like int
s to change on their own, life is not that simple for all value types. The pointer is not a number; it is a pointer. You are asking your computer to tell you the address of an object that no longer exists. Per the passage above, it's pretty much allowed to do whatever it likes under those conditions.
Apparently your compiler has decided to take advantage of this rule to apply some optimisation and you've ended up with a "weird" result (or its delete
implementation deliberately modified its argument to aid in diagnostics (or... (or... (or...)))).
I will say though that I've never personally witnessed this behaviour. Then again, I don't make a habit of observing dead pointers. :)
Rule of thumb: null it out immediately and never speak of it again.