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.
