Data Types and Variables in C++
In C++, data types specify the type and size of data that a variable can store. Because C++ is a strongly-typed and statically-typed language, every variable must have a declared data type before it can be used, and this type cannot change during runtime.
Understanding how data types map to memory allocation is foundational to writing optimized, high-performance C++ applications.
Video Explanation

1. Declaring and Initializing Variables
A variable is a named storage location in memory. To use a variable, you must first declare it. You can also optionally initialize it (assign an initial value) at the same time.
Declaration
Specifies the type and the identifier (name) of the variable. This tells the compiler how much memory to reserve.
int age; // Reserves memory for an integer
double salary; // Reserves memory for a double-precision float
char grade; // Reserves memory for a single character
Initialization
Assigns a literal value to the allocated memory location.
int age = 25;
double salary = 45000.50;
char grade = 'A';
2. Primitive Data Types Summary
The table below summarizes the core primitive data types in C++ (assuming a standard 64-bit architecture):
| Data Type | Keyword | Size (Bytes) | Typical Value Range |
|---|---|---|---|
| Integer | int | 4 bytes | to |
| Floating-Point | float | 4 bytes | 6-7 decimal digits of precision |
| Double Floating-Point | double | 8 bytes | 15 decimal digits of precision |
| Character | char | 1 byte | ASCII characters (e.g., 'A', '9', '\n') |
| Boolean | bool | 1 byte | true (1) or false (0) |
3. Deep Dive: Primitive & Standard Types
A. Integer Types (int)
Used for storing whole numbers without decimals.
int executionCount = 150;
int temperature = -12;