1

I was reading about const_cast, as it is supposed to remove the constantness of the variable,

const int c1 = 100;
int *c2 = const_cast <int *>(&c1); // removing the constantness
*c2 = 200; // hence now i can edit it
cout << *c2 << endl; // reflect the changed value = 200
cout << c1 << endl; // still old value = 100

constantness is removed and variable i can edit, it is same like passing it to some function, which receives "int *" datatype,

but why same pointed space is showing two values?

Is const_cast is creating some other temporary space?

Vishwadeep Singh
  • 1,043
  • 1
  • 13
  • 38

0 Answers0