Codecademy will be down from 00:00 to 02:00 ET on November 15, 2019 for scheduled database maintenance. This will affect the website, learning environment, forums, and mobile app. We will provide updates as necessary.
Cheat Sheets are in BETA. Give us your feedback.


A variable refers to a storage location in the computer’s memory that one can set aside to save, retrieve, and manipulate data.

Variables are denoted by a name.

// declare a variable int score; // initialize a variable score = 0;

int Data Type

In C++, int is a type for storing integer (whole) numbers.

int age = 28;

double Data Type

In C++, double is a type for storing floating point (decimal) numbers.

double price = 8.99;

Arithmetic Operators

C++ supports arithmetic operators for:

  • + addition
  • - subtraction
  • * multiplication
  • / division
  • % modulo (yields the remainder)
int x = 0; x = 4 + 2; // x is now 6 x = 4 - 2; // x is now 2 x = 4 * 2; // x is now 8 x = 4 / 2; // x is now 2 x = 4 % 2; // x is now 0

User Input

In C++, std::cin, which stands for “character input”, can read user input from the keyboard.

Here, the user can enter a number, press enter, and that number gets stored in the variable tip.

int tip = 0; std::cout << "Enter amount: "; std::cin >> tip;

Chaining the Output

In C++, std::cout can output multiple values by chaining them using the output operator <<.

Here, the output would be I'm 28.

int age = 28; std::cout << "I'm " << age << ".\n";

char Data Type

In C++, char is a type for storing individual characters. Characters are wrapped in single quotes.

char grade = 'A';

string Data Type

In C++, std::string is a type for storing text strings. Strings are wrapped in double quotes.

std::string message = "good nite";

bool Data Type

In C++, bool is a type for storing true or false boolean values.

bool late_to_work = true;