The reason this is undefined behavior is that a truly const object may well end up in read-only memory on some (for example, embedded) systems! This is not the case on a "normal computer" though; the const object exists in memory (because its address has been taken) and that memory is perfectly writable. The reason for the discrepancy you see between the contents of that memory location and what the compiler substitutes for
cValue
is that the compiler is free to assume that the value of cValue
(a const object, after all!) never changes. The compiler probably simply inserts 16 there.