How could the same memory location hold different values in the following program? I am using g++ compiler.
code:
#include<iostream>
using namespace std;
int main()
{
const int i=100;
int *j = const_cast<int*>(&i);
*j=1;
cout<<"The value of i is:"<<i<<endl;
cout<<"The value j holds:"<<*j<<endl;
cout<<"The address of i is:"<<&i<<endl;
cout<<"The address of j is:"< <j<<endl;
}
output:
The value of i is:100
The value j holds:1
The address of i is:0xbffbe79c
The address of j is:0xbffbe79c