Primitive Data Types

What Are the 7 Types of Data?

The seven basic data types many C++ tutorials list: bool, char, wchar_t, int, float, double and void, with what each one holds and how it is used.

On this page
  1. The seven basic types
  2. How big is each type?
  3. Are these all the types?
  4. Which ones do you use most?

Many C++ tutorials group the basic data types into seven: bool, char, wchar_t, int, float, double and void. The number is a convention, not an official count from the C++ standard, which defines more types than these. Still, these seven are the building blocks that most programs use.

The seven basic types

  • bool holds true or false. It is used for yes-or-no conditions.
  • char holds one character, written in single quotes like 'A'. Under the hood, it stores a small number.
  • wchar_t is a wide character type for text that needs more room than char gives. Its size depends on the platform.
  • int holds a whole number, such as 42.
  • float holds a decimal number with about 6 to 7 significant digits.
  • double holds a decimal number with about 15 to 16 significant digits. A decimal literal such as 3.14 is a double unless you add an f suffix.
  • void means no value. It is the return type of a function that returns nothing.

Here they are in a short program:

#include <iostream>

bool isValid = true;
char initial = 'J';
wchar_t wideInitial = L'J';
int count = 42;
float ratio = 0.5f;
double distance = 12.75;

void sayHello() {
    std::cout << "Hello\n";
}

int main() {
    sayHello();
    return 0;
}

How big is each type?

Sizes depend on your system. On a typical 64-bit desktop, int is 4 bytes and double is 8 bytes. Is int 2 or 4 bytes in C? On most desktops it is 4, but the standard only sets minimum ranges, so use sizeof to check your own system when the size matters.

Are these all the types?

No. C++ has more built-in types and variations. char16_t, char32_t and char8_t are for different character encodings. The modifiers short, long, long long, signed and unsigned change the range of the integer types.

Which ones do you use most?

Most programs rely on int, double, bool and char. For text, use std::string rather than working with char directly. Use wchar_t when an API you are calling needs wide characters, such as some Windows APIs.

If you remember these seven, you will recognize most of the basic types in C++ code. For the ranges and pitfalls of each, see the full guide to primitive data types in C++.

The complete guide to primitive data types

Primitive Data Types in C++
Read the guide

Keep exploring

Guides from other topics

All topics →

stringstream in C++

stringstream in C++ explained: how the <sstream> classes read and write text in memory, convert strings and numbers, split text, and avoid common mistakes.

stringstream 4 min read