Notes / C++ / Data Types

Data Types in C++ — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 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..

Syntax

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

Example

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;
}

Output

output20 8.9 1

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview Know that cout << boolalpha << true; prints "true" instead of "1" — a nice detail to mention in interviews.
Back to notes Read full lesson →