Variables and Primitive Types
AvailableLesson 1 of 25 · Syntax · Easy
The big idea
A variable stores a value so your C++ program can remember it. In C++, you write the type first, then the name, an equals sign =, the value, and a semicolon ; at the end: Every C++ program starts running inside int main() { ...
Think of it like this: Think of a C++ variable like a labeled box with a size tag: `int` says it holds a whole number, `x` is the name, and `5` goes inside.
Read the lesson
A variable stores a value so your C++ program can remember it.
In C++, you write the type first, then the name, an equals sign =, the value, and a semicolon ; at the end:
int age = 20; // a whole number
double price = 9.99; // a decimal number
bool ok = true; // true or false
Every C++ program starts running inside int main() { ... }. We already added that wrapper for you — just type your variable line inside the curly braces.
Quick check
Which line creates a whole-number variable named age set to 20 in C++?
Your challenge
Inside main(), create a whole-number variable named x set to 5 (type int x = 5;).
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to python.variables-types (85% overlap). Variables & primitive types: compare let/const (JS), auto/int (C++), := (Go), let mut (Rust), and column types (SQL).
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Variables and Primitive Types.
Learn this first
Nothing needed - you can start here.