This question already has an answer here:
const int* pc = new const int(3); // note the const int* p = const_cast<int*>(pc); *p = 4; // undefined behavior?
In particular, can the compiler ever optimize away the heap-allocated
If not, does an attempt to modify
p still constitute undefined behavior - and if so, why?