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.



Inside the variable.cpp file, you have declared an int variable named year.

Let’s give the variable a value of 2019.


Type the following commands in the terminal and press enter:


g++ variable.cpp



Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?