Declaring variables with const


In this lesson we work with const.

What do you think const does when we use this keyword in a variable declaration?


My guess is that it forces the identifier to keep the same value even if attempted to change elsewhere, possibly throwing an error if a change is attempted.


I think const means constant but I don’t know how it affects our code.


My guess is that const would most likely stand for constant, therefore the value of “const int a = 4;” would remain at 4 because we have declared “a” to have a fixed value of 4.


I think const means “constant” so it would imply that the variable value can’t be changed?


const would prevent you from changing that variable’s value. I guess it would be useful if you dont want to accidentally change a value.


I think "const " means constant, I think what it does is that you can not change the value of the variables once initialized. I think in the code this is used to do operations with variables but we can not change their value, this could serve to avoid loss of information.


const declares a constant whose value remains the same throughout the entire program execution, it cannot be assigned a new value.


Const stands for “Constant” and makes it so that the value of a declared variable can not be altered by other lines in the program.


const I believe stands for constant. When you have a variable that is constant it is no longer changing. You can do things to the variable however it won’t let you change it.


It locks the variable once it has been assigned a value. The compiler throws out an error code attesting to the fact that the variable cannot be changed.


const means constant. What this does is prevent us from changing the variable later in our code. We would have to change the constant variable, where it’s declared, if we wanted to make changes to that variable.


I think it keeps the value the same (constant), so it stops being a variable?
when I initialised a different number it said it could not do this if the number was const


I think const means constant and that the variable will remain constant throughout the whole program and never change, but I’m not sure.


Const makes a variable into a constant, meaning that it is unchangeable. If one were to try to reassign a value to a const variable, the compiler would throw an error.


I think const means that the variable remains constant and can not be changed


if we put const keyword before the variable name the variable will become constant and never can’t change its value.


Hey there,

I think that if you put the keyword const infront of the variable decleration that you can’t change its value afterwards. So the value is set for the whole program.

Kind regards


I believe const keeps the variable consistent with the variable you set it to in the code. If it is changed somewhere else in the code it will return an error.


When using const in a variable declaration causes a variable to remain constant no matter what until the variable in question is manually change on the const line. If not then an error will occurred letting you know that you can’t assign a variable to a const.