Code:
Precisely. That's why I said "do this INSTEAD". i.e. don't change the const variable with a pointer, cos you won't get the desired result. This way you DO get the desired result, i.e. the output 10 20, and just to be certain (in VS2008 at least)
If you need to print 10 20 or for that matter any value this is quite obvious that don't try to change the value of const variable coz than there is no use of defining a variable as const.
But my point is that if you wish to change the value of const even though it should remain constant by definition still there is a a way around it by using pointers you can modify it maybe not on VS2008.I tried it on gcc and it allows ayou to get around const.So that is my point but yeah if you want to do something as trival as printing values than please don't try changing the value of const.
Code:
So the net effect is that if you "need" to change the value of a const, don't bother, because the compiler will thwart your attempts
Well this would depend on compiler some like gcc would simply throw a warning and modify the value.
Code:
If you need to change the value of a const, then you need for it not to be const, so take the const off and everything will work
Exactly coz by definition const is something whose value remains constant but there is way around it so that's all I'm trying to say.