#include <iostream>
usingnamespace std;
int main()
{
constfloat pi = 3.14;
constfloat *pointer1 = π
float *pointer2;
pointer2 = (float*)pointer1;
*pointer2 = 6.28;
if(pointer1 == pointer2)
cout << "hehe, pointer1 points to the same spot as the pointer2\n";
cout << *pointer2 << ' ' << *pointer1 << ' ' << pi;
return 0;
}
The output I get is:
hehe, pointer1 points to the same spot as the pointer2
6.28 6.28 3.14
Why does the changed value pointed by "pointer1" print (6.28), but when I try to access the original variable, I still get the unchanged value (3.14)?
Shouldn't "*pointer1" and "pi" print out the same value, because they access the same part of the memory? I'm confused.