I found a weird problem of same address with different values after change const_cast ptr/ref object value.
#include <iostream>
using namespace std;
int main(void){
const auto i=123;
auto &ref2i=i; auto ptr2i=&i;
auto pp=const_cast<int*>(ptr2i); *pp=456;
cout<<&i<<" with value "<<i<<endl;
cout<<pp<<" with value "<<*pp<<endl;
cout<<ptr2i<<" with value "<<*ptr2i<<endl;
auto &rr=const_cast<int&>(ref2i); rr=789;
cout<<i<<endl;
cout<<ref2i<<endl;
cout<<rr<<endl;
}
what the hell is going on?
https://paiza.io/projects/HyLGbHxD2khynpclDWJnvA?language=cpp
Output:
0x7ffc1b0e8b54 with value 123
0x7ffc1b0e8b54 with value 456
0x7ffc1b0e8b54 with value 456
123
789
789