Declaring variables with const

6_tx_uc2
#1

In this lesson we work with const.

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

#2

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.

#3

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

#4

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.

#5

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

#6

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.

#7

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.

#8

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

#9

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.

#10

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.

#11

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.

#12

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.

#13

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

#14

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

#15

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.

#16

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

#17

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

#18

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
Daniel

#19

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.

#20

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.