Learn
We can both declare and assign a value to a variable in a single initialization statement.
Suppose we have these two lines:
// Declare a variable int score; // Initialize a variable score = 0;
We can actually combine these two lines into a single line of code:
int score = 0;
This means we are declaring an integer called score
and setting it equal to 0.

Note: We only need to declare a variable one time! And it is highly suggested to initialize a variable before using it later.
Instructions
1.
In your program, declare and initialize an int
variable named year
and initialize its value as 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.