Hi .. I still have some doubt. I have added few printouts in my code as below.
#include<iostream>
using namespace std;
int main() {
const int i = 0;
int *j;
j = const_cast<int*>(&i);
*j=2; // De- referencing the Const variable
cout << "i = " << i << endl;
cout << "Address of i = " <<&i << endl;
cout << "*&i =" << *&i << endl;
cout << "Address Pointed by j = " << j << endl;
cout << "Value of Address pointed by J = " << *j << endl;
}
Here is the output
i = 0
Address of i = 0x7fff3d83e75c
*&i =0
Address Pointed by j = 0x7fff3d83e75c
Value of Address pointed by J = 2
My question is , If compiler is forced to allocate address due to casting. Then *&i and *p should have same value right. How can a address have two values ?