+ 3
Mystery of const_cast
const int t = 9; const int *p = &t; *const_cast<int*>(p) = 999999; cout << p << " " << *p << endl; cout << &t << " " << t << endl; Why isn't "*p" the same value with "t"??
9 Respostas
+ 3
hello.
+ 3
give me some time I will explain you.
+ 2
hellooo
+ 2
Ok thank you!
+ 2
const_cast is safe to use only with reference/pointer that point to not-const variables else result is undefined... I think that result is dependent from compiler internals and optimizations
+ 1
what's going on.
+ 1
I wanna know why the values of the '*p' and 't' are different!
+ 1
Thank you. I am happy to know the reason!
+ 1
👍👍👍