C++ data types: int, double, char, bool

Short answer: a type tells the compiler how many bytes a value needs and what those bytes mean. The four you'll live in as a beginner: int (whole numbers), double (decimals), char (one character — which is secretly a small number), bool (true/false, printed as 1/0).

All four, in one program

#include <iostream>
using namespace std;

int main() {
    int    age   = 25;     // whole numbers
    double price = 9.99;   // decimals
    char   grade = 'A';    // ONE character, single quotes
    bool   ok    = true;   // true or false

    cout << age << " " << price << " " << grade << " " << ok << endl;
    return 0;
}

Two things to notice: grade uses single quotes ('A', not "A" — that's a string, and mixing them is a classic compiler error), and ok prints as 1, not true — cout shows bools as numbers unless you ask for boolalpha.

The four types, one paragraph each

TypeStoresTypical sizeWatch out for
intWhole numbers4 bytesOverflow past ≈ ±2.1 billion; 7/2 is 3
doubleDecimals8 bytes0.1 + 0.2 ≠ exactly 0.3 (floating-point fuzz)
charOne character1 byte'a' vs "a"; it's secretly a number
booltrue / false1 bytePrints as 1/0; any nonzero number converts to true

Sizes are "typical" because the C++ standard sets minimums, not exact values — on your desktop compiler, sizeof(int) prints the real answer for your machine.

char is a number wearing a costume

Every character is stored as an integer code (ASCII): 'A' is 65, 'a' is 97, '0' is 48. That's why you can do arithmetic on characters:

#include <iostream>
using namespace std;

int main() {
    char c = 'A';
    cout << c << " is code " << (int)c << endl;
    cout << "next letter: " << (char)(c + 1) << endl;
    cout << "digit '7' as number: " << '7' - '0' << endl;
    return 0;
}

The last line — '7' - '0' — is a genuine interview-grade idiom: it converts a digit character into its numeric value. '7' has code 55 and '0' has code 48, so the subtraction leaves exactly 7 — and it works for every digit, no lookup table needed.

How each type breaks

Choosing between int and double — the beginner decision tree

  1. Can the value ever have a fraction? (average, price, percentage) → double.
  2. Is it a count, index, year, score? → int.
  3. Do you need bigger than ±2.1 billion? → long long on a desktop compiler (our playground covers the teaching core; see the compiler setup guide).
  4. Money? → integer cents. Seriously.

Interview questions on types

  1. "What does cout print for a bool?" — 1 or 0; cout << boolalpha switches to true/false.
  2. "Why is 7 / 2 equal to 3?" — both operands are ints, so the division is integer division (full guide: here).
  3. "What's the difference between 'A' and "A"?" — a char (one byte, code 65) vs a string (an array ending in '\0').
  4. "What happens on int overflow?" — signed overflow is undefined behavior: no exception, no reliable wrap; the compiler may assume it never happens.
  5. "Why is char arithmetic useful?" — digit conversion ('7' - '0'), case conversion (c - 'a' + 'A'), and it's the basis of how text processing works at all.

Practice

Related: integer division, pass by value vs pointer vs reference, 15 beginner interview questions.