Given this code (from my last post here):
const int j = 5; // constant object
const int *p = &j; // `p` is a const access path to `j`
int *q = const_cast<int *>(p); // `q` is a non-const access path to `j`
*q = 10;
cout << *q << endl;
The output is : 10
Is it suppose to be this way ? I thought that this code was supposed to lead to
an undefined behavior , since j
is a const . Am I wrong ?
Thanks