Const variables

Not sure I follow. The type of var 1 is known: it is an integer, in this case. It can change. In my example, var2 is of type integer as well (i.e., the same type as var1. But as was already mentioned, after compilation, I could change the type of either variable, and the compiler must allow for that, thus decreasing efficiency.

The word const is really a misnomer. It is not that the variable is constant. It is the variable type that is constant, which is quite different. If I write

const a = 3::Int64

I am allowed to change the value of a without impacting the efficiency of the compiler, but I cannot change the type of a.

I thank you all for deepening my understanding. I will mark this problem solved, but please continue to write!

1 Like