Possible Duplicate:
C/C++ changing the value of a const
The following program:
int main()
{
const int x = 10;
int * p = (int *)&x;
*p = 12;
cout<<x<<endl;
cout<<*p<<endl;
return 0;
}
Gives an output of:
10
12
What is the effect of casting &x to (int *) and why is the value of x still 10 ? I expected it to be 12.
Another doubt
Why cant we cast say int ** to int const ** ? Rather this operation is valid
void f(int const ** p);
void g(int const * const * p);
int main()
{
int ** p = /*....*/
f(p); //Error
g(p); //OK
}
Please help me understanding this with suitable example Thanks !!!