c++ const_cast

Why the statement below print one address and two values:

#include <iostream>
using namespace std;

int main() {
const int i = 2147483646;
int *j = const_cast<int*>(&i); // Preferred
*j = 2147483647;
cout << i <<endl<<*j <<endl<<endl;
cout <<&i <<endl<<j <<endl;
}

Thank's whom will answer.
All the best
Last edited on
Undefined behaviour.

Except that any class member declared mutable can be modified,
any attempt to modify a const object during its lifetime results in undefined behaviour. - IS


undefined behaviour: Renders the entire program meaningless http://en.cppreference.com/w/cpp/language/ub
Thank you very much!
Topic archived. No new replies allowed.