Declaring variables with const

I think the compiler won’t let you change the value of the variable.

Let’s see!

const variable means constant variable… so when we add this to a variable it fixes it’s value.

We cannot change the value of the variable after initializing the variable by using the const keyword.

1 Like

const possibly does not allow change of the value stored in it.

So what I assumed it would do would basically clamp the value of whatever variable at whatever the value you assigned to it was and it wouldn’t allow you to assign it a new value later in the code.

I gave it a quick test after and tried to assign a new value to “a” that had the const int and it threw an error and wouldn’t allow me to reassign.

I guess const makes the variable constant, so it prevents it from being changed later on in the code, if you try to change it, I guess the compiler would give you an error.

const is short for constant that keeps the initialized variable value the same and unchangeable

1 Like

I think const prevents any changes to the assigned variable.

1 Like

i think const is short for constant and it means that the variables value can no longer be changed after initialization, is this right?

Const from my knowledge would make the ''int" variable a constant variable that cannot be changed?
Wild guess

I think const means constant, but I don’t know why the value can’t change.