i expect const_cast removes constness! , now points at which i have commented are the areas i have doubt on, i expect cout<<x to give 5Code:#include<iostream> using namespace std; int main() { const int x = 10; int *p=NULL; cout<<x; p = const_cast<int*>(&x); if(p) { *p = 5; if(p==&x) cout<<"same!"; // yes both point at same loc cout<<x; //gives 10 cout<<*p; //gives 5 } getchar(); return 0; }
However I also believe, how can i cast a const object to a non-const pointer!