C++ Operators
C++ provides arithmetic (`+ - * / %`), assignment (`= += -=`), comparison (`== != < >`) and logical (`&& || !`) operators. Operator precedence follows mathematical convention, and parentheses can force evaluation order.
Increment/decrement operators `++`/`--` are heavily used in loops, and come in prefix (`++i`) and postfix (`i++`) forms with subtly different behaviour.
Arithmetic and assignment
`%` gives the remainder of integer division. Compound assignment like `x += 5` is shorthand for `x = x + 5`.
Comparison and logical
Comparisons return a bool. `&&` (AND), `||` (OR) and `!` (NOT) combine boolean expressions, and short-circuit evaluation skips unnecessary checks.
int a = 7, b = 2;
std::cout << a % b << " " << (a > b);1 17 % 2 is 1 (remainder); a > b is true (1).
int i = 5;
std::cout << i++ << " " << i;5 6Postfix i++ returns the old value, then increments.
Key points
- Arithmetic: + - * / %; assignment: = += -= *= /=.
- Comparison operators return bool.
- && and || short-circuit evaluation.
- Prefix ++i increments then returns; postfix i++ returns then increments.
