Declaring a variable whose value cannot be changed

const x=1 then variable x's value can be changed if a variable of the same type is reassigned. Is it possible to declare a variable so its value will NOT be changed by any assignment?

Related: Does declaring a variable to be constant do anything at all?

2 Likes

That thread does not seem to answer this question. const is the way to declare a variable to not be assignable again. Assignment of same type is allowed only for debugging convience since it has a lower risk of crashing. Nevertheless, doing that is basically undefined behavior and you should not ignore warning raised when you do that.

4 Likes