Declaring variables with const

from what i remember from the other languages i breafly learnt, it will turn our variables into constants, thus forbidding the change of the value that is assigned while declarating the constant.

I suppose const assign a constant value to a variable so even though we attempt to change it the variable will have the same value no matter what.

After inputting const, any changes that we make to the variables will not be applied. Const most likely is short for constant meaning that the compiler will always keep the variables the same value as the ones that were first declared.

“const” will fixed whatever the value of a variable.
Eg. const a = 20;
a is now always equal to 20 and cannot change.

after using const, all later values we apply to the variable will be ignored?

I think const will make the variable constant. In other words, you can’t change the value once its been declared.

Const means constant variable. When we assign some value to constant variable, it cannot be changed later in code. It’s useful when you want that value to stay same all the time and prevent it from changing.

i think it makes the variable a constant, “so const int a = 3;” will make a = 3 even if somewhere else a is declared to = 7

My guess is that “Const” stands for constant, so that means that the integer could not be changed

I’m gonna guess that const is short for constant and has keeps the variable at a set value throughout the rest of the code. Now, whether or not you would be able to change a const variable later in the code, I am not sure.

If const is anything like other languages that use the same keyword it’s kind of like a lock that prevents the variables from being changed by reassignment operations.

I think const is going to make sure that the variable keeps its initial value even if attempted to be changed.

Hello,

I believe that const means that the variable that it is prefixing is a constant variable. Meaning that it cannot be changed it is no long an editable variable but a constant throughout the code function.

Jib

i found it, when i use const makes this variable unchangable with new decleration after first declare :crazy_face:

i think const is a fixed integer. the value will stay the same. the advantage of using const in the program is code readability?

Const = constant in this case the integer is constant and can’t be changed.

const makes the value constant

So it seems that nothing has changed in terms of addition and multiplication. So it means that we assing each variable as constant value and it won’t change after adding new variable value.

const likely stands for constant - the variable does not change - it is not variable :wink:

const may stand for constant. Even after I wrote the code and tried to change the variable the compiler told me that you cannot assign to a variable that is const.

Privacy & Terms