Learn
After we declare a variable, we can give it a value!
Suppose that we have declared an int
variable called score
, to set it to 0, we can simply write:
score = 0;
- The
score
is the name of the variable. - The
=
indicates assignment. - The
0
is the value you want to store inside the variable.
Note: In C++, a single equal sign =
does not really mean “equal”. It means “assign”. In the code above, we are assigning the score
variable a value of 0.
Instructions
1.
Inside the variable.cpp file, you have declared an int
variable named year
.
Let’s give the variable a value of 2019.
2.
Type the following commands in the terminal and press enter:
Compile:
g++ variable.cpp
Execute:
./a.out
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.