The Basic Types
C++ has four basic types you'll use constantly: int (whole numbers), double (decimals), string (text, via #include <string>), and bool (true/false).
int age = 20;
double gpa = 4.5;
string name = "Ada";
bool passed = true;
Arithmetic operators
cout << 7 + 3 << endl; // 10
cout << 7 - 3 << endl; // 4
cout << 7 * 3 << endl; // 21
cout << 7 / 3 << endl; // 2 -- int / int truncates
cout << 7.0 / 3 << endl; // 2.33333 -- a double operand makes it a real division
cout << 7 % 3 << endl; // 1 -- % is the remainder
Comparison and logical operators
cout << (5 == 5) << endl; // 1 (true)
cout << (5 != 3) << endl; // 1 (true)
cout << (5 > 3 && 2 < 4) << endl; // 1 (true)
cout << (5 > 3 || 2 > 4) << endl; // 1 (true)
cout << (!true) << endl; // 0 (false)
Why This Matters for Your Exams
int / int truncates to a whole number in C++ -- 7 / 3 is 2, not 2.33. At least one operand must be a double (e.g. 7.0 / 3) to get a real division. Mixing this up silently produces a wrong, truncated answer instead of a compile error -- the single most common source of "off by a fraction" bugs.
Try it yourself
lock
Real-time practice is a paid add-on
Reading units and the practice quiz are free. Pay once to unlock running real code for CPP.

