int main()
{
const int ia = 10;
int *pia = const_cast<int*>(&ia);
*pia = 5;
std::cout << &ia << "\t" << pia <<endl;
std::cout << ia << "\t" << *pia <<endl;
return 0;
}
The output is:
0x28fef4 0x28fef4
10 5
*pia
and ia
have the same address, but they have different values. My purpose is to use const_cast
to modify a constant value, but as the result shows that it does not work.
Does anyone know why?