Home > Back-end >  Built-in types const_cast after modification
Built-in types const_cast after modification

Time:09-16

 
Const int ci=90;
Const int * PI=& amp; Ci;
Int * pi2=const_cast & lt; Int * & gt; (PI);
* pi2=120;//undefined behavior
Cout & lt; Cout & lt; <* PI & lt; Cout & lt; <* pi2 & lt;
Q:
Check memory as you can see the ci value within the corresponding address is 120 by changes, ci, PI, pi2 is indeed is the same address
Print the ci, you get 90 is get the compiler optimizations to replace?
Is substituted for: cout & lt; <90 & lt; CodePudding user response:

Yes, the behavior of the compilation phase
  • Related