100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C++

Data Types in C++

Learn the fundamental data types in C++ — int, float, double, char, bool, and void — with sizes, ranges, and examples.

BasicsBeginner7 min readJul 7, 2026
Analogies

1. Intro

A data type tells the compiler what kind of value a variable will hold and how much memory to set aside for it. C++ is a statically typed language, so every variable's data type must be known before the program runs. Data types are broadly grouped into fundamental (built-in) types, derived types (arrays, pointers, functions), and user-defined types (classes, structs, enums).

🏏

Cricket analogy: A data type is like a team roster slot pre-declared as 'bowler', 'batsman' or 'all-rounder' before the squad is even announced — C++ similarly demands every variable's role be fixed before the match runs, grouped into basic roles, combo roles (derived types), and specialist categories (user-defined types).

2. Syntax

cpp
data_type variable_name;

3. Explanation

The fundamental data types built directly into C++ are:

🏏

Cricket analogy: Just as a scorecard has a fixed set of built-in categories — runs, wickets, overs — C++ comes with its own fixed set of fundamental data types built directly into the language.

  • int — stores whole numbers (e.g. 10, -42)
  • float — stores single-precision decimal numbers (e.g. 3.14f)
  • double — stores double-precision decimal numbers, more precise than float
  • char — stores a single character (e.g. 'A')
  • bool — stores true or false
  • void — represents "no value", commonly used as a function return type

The exact size in bytes for each type is implementation-defined by the compiler and target platform rather than fixed by the C++ standard — but on most common modern compilers, int is typically 4 bytes, char is 1 byte, float is 4 bytes, and double is 8 bytes. You can always check the size on your own system using the sizeof operator.

🏏

Cricket analogy: Just as boundary rope distances vary slightly ground to ground even though roughly '70 yards' is typical, C++ type sizes like int (typically 4 bytes) aren't fixed by the standard but by the compiler and platform — you check the actual value with sizeof, like measuring the actual rope at your specific stadium.

Pro Tip

use sizeof(type) to check exactly how many bytes a data type occupies on your specific compiler and platform, instead of assuming a fixed size.

4. Example

cpp
#include <iostream>
using namespace std;

int main() {
    int quantity = 25;
    float price = 19.99f;
    double preciseValue = 3.14159265;
    char grade = 'B';
    bool inStock = true;

    cout << "Quantity: " << quantity << " (size: " << sizeof(quantity) << " bytes)" << endl;
    cout << "Price: " << price << endl;
    cout << "Precise value: " << preciseValue << endl;
    cout << "Grade: " << grade << endl;
    cout << "In stock: " << inStock << endl;

    return 0;
}

5. Output

text
Quantity: 25 (size: 4 bytes)
Price: 19.99
Precise value: 3.14159
Grade: B
In stock: 1

6. Key Takeaways

  • A data type defines what kind of value a variable can hold and how much memory it uses.
  • The core fundamental types are int, float, double, char, bool, and void.
  • Exact type sizes are implementation-defined — use sizeof() to check them on your platform.
  • C++ also supports derived types (arrays, pointers) and user-defined types (class, struct, enum).

Practice what you learned

Was this page helpful?

Topics covered

#CStudyNotes#Programming#DataTypesInC#Data#Types#Syntax#Explanation#StudyNotes#SkillVeris#ExamPrep