Originally posted by newt
hmmm......
Just one more thing then:
The address stored in the pointer and the address of the
constant is the same, so how can two values reside in the same
location
Well whenever the compiler creates a constant in the non-writable area,
we have a direct substituion for that constant-reference to value...
hence does not reach out to the RAM
Code:
const int i = 10; // this could be completely optimized
Having said that if you have created the constant in such a way
that it can't just stop there.. but has to allocate memory, then it
does allocate the same too. The pointers that point to this const,
get that address
Code:
const int i = 10;
int *p = const_cast<int *>(&i);
// since u r taking the address of i,
//it has no choice but to allocate memory
*p = 30; // will change the value at the memory allocated for i,
cout << i; // gives u 10
// but still everywhere u use i, it would be an assembly level
//direct substitution and hence it does not go to the location to
//fecth the value