Primitive Data Types
A free lesson from Swipe Coding · C++, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
Every variable in C++ needs a type, and the primitive (or "fundamental") types are the most basic kinds of data a variable can hold. They store a simple value directly in memory, which makes them fast and memory-efficient.
int quantity = 10; double price = 4.99; bool inStock = true; char grade = 'A';
int stores whole numbers (no decimal point) and is the default choice for counting things. double stores decimal numbers and is the default choice for anything with a fractional part, like prices or measurements. bool can only ever be true or false, which makes it perfect for yes/no conditions. char stores exactly one character, written in single quotes like 'A' — never double quotes, which are reserved for std::string.
To store a single character like 'A', you use the ____ type, written with single quotes.
C++ also has smaller and larger whole-number types for when int isn't the right fit: short saves memory for small numbers, while long and long long are used for whole numbers bigger than int can reliably hold. float is a smaller, less precise alternative to double, using less memory but storing fewer accurate decimal digits.
long long population = 8000000000; short smallNumber = 120; float approxPi = 3.14f;
One quirk of C++: the exact size (in bytes) of a type like int or long is not fixed by the language the same way it is in some other languages — it can vary slightly between compilers and platforms, though int is virtually always at least 4 bytes on modern systems. If you ever need to be certain, the sizeof operator tells you the exact size in bytes on your current setup.
std::cout << sizeof(int) << std::endl; // commonly prints 4
In C++, a local variable's exact byte size for a type like int is guaranteed to be identical on every computer and compiler in existence.
Which primitive type would you use to store whether a light switch is on or off?
Variables & Primitive Types
10 questions · pass with 60% — just like in the app.
What is a variable in C++?
The general pattern for declaring and initializing a variable in C++ is ____.
If you declare a local variable in C++ without giving it a value, C++ automatically sets it to a safe default like 0.
Which of these is NOT a valid C++ variable name?
By convention, this course writes variable names in ____, such as totalScore.
Which primitive type would you use to store whether a light switch is on or off?
To store a single character like 'A', you use the ____ type, written with single quotes.
double is the default choice when you need to store a number with a fractional part, such as a price.
Which type would you reach for to store a whole number far larger than an int can reliably hold?
In C++, a type like int is guaranteed to occupy exactly the same number of bytes on every computer and compiler.
Keep your streak going in Swipe Coding
Swipe through every level of C++ on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →