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.



In your program, declare and initialize an int variable named year and initialize its value as 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?