#include<iostream.h> main() { const int i=10; int *p=const_cast<int *>(&i); *p=100; cout<<i<<endl<<*p; } |
100 100 |
10 100 |
i
is const
so you can't change its value.int *p=const_cast<int *>(&i); |
yeah i is a const ...but as we can see the output the value pointed by pointer p is equal to 100 and by i , it is equal to 10 .But at the same time pointer p is holding the memory location of i.so how can the same memory location can have two different values.. |
It is that many of us would think that value of const is stored in the sysmbol table in C++ ...but here we are taking the address of const so forcing it to store in the memory by the lne number 5 |