Question

I have the following code :

const int k=1;
    int *p=const_cast<int *>( &k);
    cout<<"k before="<<*p<<endl;
    *p=10;
    *const_cast<int *>( &k)=12;
    cout<<"k after="<<k<<endl;

the output was :

k before=1
k after=1

why doesn't const cast work here ?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top