Curriculum / C++ / Lesson 03

Data Types in C++

C++ includes all of C's basic types (int, float, double, char) and adds a proper boolean type, bool, which can only be true or false..

3 of 10
beginner 📖 5 min read 🎯 1 question

Data Types

C++ includes all of C's basic types (int, float, double, char) and adds a proper boolean type, bool, which can only be true or false.

💡 Key insight Unlike plain C, C++'s bool type genuinely stores true/false — it's not just an int convention.

Syntax

syntax
int wholeNumber;
double decimalNumber;
char singleCharacter;
bool trueOrFalse;

Example

When printed with cout, bool values show as 1 (true) or 0 (false) by default.

cpp
#include <iostream>
using namespace std;

int main() {
    int age = 20;
    double gpa = 8.9;
    bool isEnrolled = true;
    cout << age << " " << gpa << " " << isEnrolled << endl;
    return 0;
}
output20 8.9 1

Try it yourself

Copy this example into the C++ compiler and run it — try changing a value and see what happens.

Quick Quiz

1. What are the only two values a bool can hold in C++?

Back to curriculum