After I put the const on declaration, I can no longer assign a new value to the variable, except the first assignment.
Declaring variable as āconstā means that we give āpromiseā to compiler not to change this variable after its initialization. If we try to do this, compiler will alert us.
I agree with most of the students here; I believe the variable is declared to remain the same value disallowing it from being changed. I donāt think an error will be thrown, though, if our code attempts to change it.
Makes it immutable.
The compiler should throw an error.
This error should indicate that an attempt was made trying to modify a variable that cannot be changed. Hopefully, it will also include the file, the line, and maybe even the column of said error.
Additionally, the VSCode, hopefully, should also highlight/underline the corresponding line where the attempt was made to modify the value of this variable.
My guess is that const applys a constant to the variable, which in turn will force it to remain constant. even if changed at a seperate location within the code.
It makes a constant, which is like a variable but never changes in value. Although, iām not too sure what use this would have. Instead, couldnāt you justā¦ not assign the variable a new value?
I think when assigning const to a variable the variable is unable to change. For example if const int a = 4 then a is always going to be 4.
Const is sort for constant and which means the variable stays constant and isnt changeable within the code
I think it makes the variable stable and if you change it later on like if you did
const int a = 4;
and then after that you write
a = 7;
and then compiled it and ran it would stay as the variable 4 and wouldnāt change?
āconstā makes the variable read-only. You can look at it, but it cannot be modified outside of where it is declared and initialized.
I think const makes the value of the variable constant, that is it canāt be changed, and if we try to change the value of a āconst variableā after its initialized it may either, not change the value or it may throw up a error.
My best guess would be that const means constant, and will prevent any changes to that variable throughout the rest of the code.
My guess is that const
prevents any change of variableās value
So I already know what āconstā means, and will just go ahead and explain it in case anyone needs it.
Const stands for constant and it creates a variable that is constantly one value.
This means you can never change itās value. Const should only be used for variables that will only ever have one value for the duration of the program.
In games, this can be the running speed of a player if there is not sprint or walk, the number of strikes in a baseball game, or anything else that will never change.
In TripleX, it looks like this will be used for the number of tries the player has to guess.
I think it means that the variable wonāt. It means that an value canāt be assigned to the variable.
The line āconst int a = 4;ā declares and initializes the variable a to be equal to 4. Later in the code if you try to change the value of a with āa = 5;ā you get an error. You cannot change the value of a const variable.
Const means constant.
const = constant (guessing) that will keep the integer constant
I assume const means constant and makes it so the identifier has a fixed value
I think that the const
variable keeps a variable from changing. A.K.A. by keeping it constant.