You mean since this kind of behavior (i.e., changing the value of a constant) is not defined inside the compiler, the consequence of this kind of action could be anything, and there is no way to judge what is "correct" or "incorrect". In this sense, any outcome of x could be said "correct" or "incorrect".
Since you declared x as "const", the compiler is allowed to assume that the value of x will not change. That said,
the compiler is free to replace memory accesses of x with the actual value, and in fact, not even allocate memory
However, as soon as you take the address of a variable, the compiler can no longer optimize it into a register --
it has to allocate memory for it. So you've got two different things going on. First, the compiler optimized the
line cout << x << endl; into cout << 0 << endl;. Second, line 11 caused the compiler
to allocate memory for x so it could take its address. References to x via pointer will now read the memory location.
Hence your two different answers.
Moral to the story: const_cast is very dangerous. In fact, the result of modifying a value which has had its constness
casted away with const_cast is undefined behavior according to the standard. const_cast<> really was only intended
to allow integration with legacy C functions that aren't const correct.