Learn C++
#include "variablesdatatypes/fundamental_types.hpp"

Fundamental Data Types in C++

//concept

C++ builds everything from a small set of fundamental types: int for whole numbers, double for decimals, char for single characters, bool for true/false, and void for nothing (used in function returns). Their exact sizes are platform-dependent — int is at least 16 bits but 32 on virtually every modern system — which is why portable code uses fixed-width aliases like int32_t when exact size matters.

Choosing correctly is mostly about range and intent: double is the default floating type (float exists but halves precision for little gain), char is really a tiny integer that happens to print as a character, and bool makes conditions self-documenting instead of hiding them inside ints.

//how it works
1

int: the workhorse

Whole numbers, typically 32 bits (about +-2 billion). The default choice for counts, indexes, and IDs.

2

double: the default decimal

64-bit floating point with ~15 reliable decimal digits. Prefer it over float unless memory profiling says otherwise.

3

char: a tiny integer

Usually 8 bits holding a character code. 'A' is just the number 65 in a char-sized slot — arithmetic on chars is legal.

4

bool and void

bool holds true or false for conditions; void means no value and appears mainly as a function return type.

//example
#include <iostream>
 
int main() {
int n = 1000000;
double pi = 3.14159;
char grade = 'A';
bool passed = true;
std::cout << n << ", " << pi << ", " << grade << ", " << passed << std::endl;
return 0;
}
Output
1e+06, 3.14159, A, 1
1Each variable declares its type up front — int, double, char, bool — locking in size and allowed operations.
2cout prints a bool as 1 or 0 by default (use std::boolalpha to get true/false words), and large doubles may print in scientific notation.
3grade prints as the character A even though underneath it is stored as the integer 65.
//use cases
Picking double over float for any calculation where precision matters
Using bool return values to make function contracts obvious (isValid(), hasData())
Reaching for int32_t/int64_t from <cstdint> when file formats or protocols demand exact sizes
Remembering char arithmetic (grade + 1) is integer math, useful in ciphers and parsers

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in C++ yourself — building beats watching.