How can we modify a constant variable?
suppose
const int x=12;
How can we change its value????
Please tell me.
Printable View
How can we modify a constant variable?
suppose
const int x=12;
How can we change its value????
Please tell me.
Specify a pointer to the variable that you want to change. That should do the trick. :)
You can only assign an address of a constant to a pointer to a constant so that wouldn't work. You can cast though -Quote:
Specify a pointer to the variable that you want to change
const int a = 10;
const int* ptr = &a;
*(int *)ptr=20;
Why make it const if you are going to want to change it? You are better off just being careful not too fool with it too much.