Back to Curriculum

2. Variables

What are Variables?

Variables are like containers that store data in your program. Think of them as labeled boxes where you can put different types of information.

In C++, you need to tell the computer what type of data you want to store. Here are the most common types:

  • int - for whole numbers (like 1, 42, -7)
  • double - for decimal numbers (like 3.14, 2.5)
  • std::string - for text (like "Hello", "Player Name")

To create a variable, you write: type name = value;

int age = 25;
double price = 19.99;
std::string name = "Alex";

Your First Task

Declare an integer variable named playerHealth and initialize it with a value of 100.

🎉

Lesson Complete!

Excellent! You now know how to work with different types of variables in C++.

Continue to Lesson 3: Const
main.cpp
Output
Click "Check Answer" to run your code.