Operators
C++ has the same core operator families as C — arithmetic, relational, logical, and assignment — plus a powerful extra feature: operator overloading, which lets you redefine what operators like + do for your own classes.
💡 Key insight
Operator overloading is unique to C++ among the four languages here — it's why you can write custom_object1 + custom_object2.
Syntax
syntax
a + b a - b a * b a / b a % b
a == b a != b a > b a < b
a && b a || b !aExample
Comparison operators like a > b evaluate to a bool in C++.
cpp
#include <iostream>
using namespace std;
int main() {
int a = 10, b = 3;
cout << "Sum: " << (a + b) << endl;
cout << "Remainder: " << (a % b) << endl;
cout << "Greater: " << (a > b) << endl;
return 0;
}outputSum: 13
Remainder: 1
Greater: 1
Try it yourself
Copy this example into the C++ compiler and run it — try changing a value and see what happens.
