Question: > 
> **Possible Duplicate:**  
> 
> [C/C++ changing the value of a const](https://stackoverflow.com/questions/583076/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 !!!

Answer: 
The compiler will substitute a literal value when it is assigned to a `const int`. Effectively your program looks like:

```
        cout<<10<<endl;
        cout<<*p<<endl;

```
well， it is interesting question.
when you remove the const prefix of x you will get the result as you wish.

```
int main()       
{               
 int x = 10;               
 int * p = (int *)&x;               
 *p = 12;              
 cout<<x<<endl;              
 cout<<*p<<endl;               
 return 0;      
}

```

I think it is the const mark prevent the change of the value of x.