M
marsarden
here is the code:
int main()
{
const int a = 1;
int *p = const_cast<int*>(&a);
*p = 2;
cout << "value a=" << a << endl;
cout << "value *p=" <<*p << endl;
cout << "address a="<<&a << endl;
cout << "address p="<<p << endl;
}
the result like:
value a=1
value *p=2
address a=0012FED4
address p=0012FED4
why the same memory address has different value?
int main()
{
const int a = 1;
int *p = const_cast<int*>(&a);
*p = 2;
cout << "value a=" << a << endl;
cout << "value *p=" <<*p << endl;
cout << "address a="<<&a << endl;
cout << "address p="<<p << endl;
}
the result like:
value a=1
value *p=2
address a=0012FED4
address p=0012FED4
why the same memory address has different value?