Normally; const to non-const assignments are forbidden for referance and pointer variables but here I force to do it.
const int a = 5;
int* ap = (int*)&a;
*ap = 123;
cout << &a << " " << a << endl;
cout << ap << " " << *ap << endl;
the output surprises me because, although ap and &a has the same memory location they have different data stored.
0x7ffc9ab219fc 5
0x7ffc9ab219fc 123
What's going on here?
Aucun commentaire:
Enregistrer un commentaire