Modifying a const through a non-const pointer

As I said in my comment, once you modified the const value you are in undefined behaviour land, so it doesn’t make much sense to talk about what is happening. But what the hell..

cout << *w << endl;            // (3) outputs 5
cout << e << endl;             // (4) outputs 2

At a guess, *w is being evaluated at runtime, but e is being treated as a compile time constant

Leave a Comment