C++ Operators — Arithmetic, Logical, Bitwise
Types of Operators
| Category | Operators |
|---|---|
| Arithmetic | + - * / % ++ -- |
| Relational | == != < > <= >= |
| Logical | && || ! |
| Assignment | = += -= *= /= %= &= |= ^= <<= >>= |
| Bitwise | & | ^ ~ << >> |
| Ternary | condition ? val1 : val2 |
| sizeof | sizeof(type) |
| Scope resolution | :: |
| Member access | . -> |
#include <iostream>
using namespace std;
int main() {
int a = 10, b = 3;
// Arithmetic
cout << "a + b = " << (a + b) << endl; // 13
cout << "a - b = " << (a - b) << endl; // 7
cout << "a * b = " << (a * b) << endl; // 30
cout << "a / b = " << (a / b) << endl; // 3 (integer division)
cout << "a % b = " << (a % b) << endl; // 1 (remainder)
// Increment / Decrement
int x = 5;
cout << "x++: " << x++ << endl; // 5 (post: use then increment)
cout << "x: " << x << endl; // 6
cout << "++x: " << ++x << endl; // 7 (pre: increment then use)
// Assignment operators
int n = 10;
n += 5; cout << "n += 5: " << n << endl; // 15
n -= 3; cout << "n -= 3: " << n << endl; // 12
n *= 2; cout << "n *= 2: " << n << endl; // 24
n /= 4; cout << "n /= 4: " << n << endl; // 6
n %= 4; cout << "n %= 4: " << n << endl; // 2
return 0;
}
#include <iostream>
using namespace std;
int main() {
int a = 5, b = 10;
// Relational - return bool
cout << boolalpha;
cout << "a == b: " << (a == b) << endl; // false
cout << "a != b: " << (a != b) << endl; // true
cout << "a < b: " << (a < b) << endl; // true
cout << "a >= b: " << (a >= b) << endl; // false
// Logical
bool x = true, y = false;
cout << "x && y: " << (x && y) << endl; // false (AND)
cout << "x || y: " << (x || y) << endl; // true (OR)
cout << "!x: " << (!x) << endl; // false (NOT)
// Ternary: condition ? if_true : if_false
int age = 20;
string status = (age >= 18) ? "Adult" : "Minor";
cout << "Status: " << status << endl; // Adult
// Spaceship operator (C++20) - three-way comparison
// auto result = a <=> b; // negative if a < b
return 0;
}
Level Up Your C plus plus Skills
Master C plus plus with these hand-picked resources
10,000+ learners
Free forever
Updated 2026
Related C++ Topics