#include <iostream>
usingnamespace std;
int main() {
constint a = 2;
constint& b = a;
const_cast<int&>(b) = 3;
cout << b << endl << a;
return 0;
}
hello,
is there any chance to change the value of variable a as it is now?
I know it's possible if a is used as pointer, but I wanna change it like it is now in this example, how would I go to do that?
LOL, sorry for double posting...
I've just found a way to do that:
1 2 3 4 5 6 7 8
#include <iostream>
usingnamespace std;
int main() {
volatileconstint a = 2;
const_cast<int&>(a) = 3;
cout << a; //LOL now a is 3 instead of 2
return 0;
}