GCGrowCarrer

Variables and Primitive Types

Available

Lesson 1 of 25 · Syntax · Easy

Mastery0% of 85%
1

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.
Key words (tap to learn):
2

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.

3

Quick check

Which line creates a whole-number variable named age set to 20 in C++?

4

Your challenge

2 sample tests, 1 hidden

Inside main(), create a whole-number variable named x set to 5 (type int x = 5;).

Stuck? Get a hint (free)
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.

Mastery0%

Learn this first

Nothing needed - you can start here.