#include using namespace std ; int main() { int x1 = 10; const int* ptr1 = &x1 ; //Can't do because ptr points to a constant //*ptr1 = 20 ; int* ptr2 = const_cast( ptr1 ); // Casting away constness *ptr2 = 20 ; cout << "x1:" << x1 << endl ; const int x3 = 10; int* ptr3 = const_cast( &x3 ) ; *ptr3 = 22 ; //Doesn't change the original x3 . Undefined //behavior. Not recommended cout << "x3:" << x3 << endl ; int x4 = 10; const int& constRef = x4 ; // Attempting to modify value through constRef directly will result in a compiler error // constRef = 20; // Error: assignment of read-only reference // Use const_cast to remove constness from the reference int& nonConstRef = const_cast(constRef); nonConstRef = 20; cout << "x4: " << x4 << endl; // Output: Value: 20 return 0; }