C++ provides standard arithmetic operators to perform basic math operations:
+ Addition- Subtraction* Multiplication/ Division% Modulus (remainder)Assignment operators are used to update the value of a variable based on its current value:
= assigns a value+= adds and assigns-= subtracts and assigns*= multiplies and assigns/= divides and assigns%= modulus and assignsComparison operators are used to compare two values and return a boolean result:
== → equal to!= → not equal to> → greater than< → less than>= → greater than or equal to<= → less than or equal toUsed with bool types or conditions:
bool a = true, b = false;
cout << (a && b) << endl; // false
cout << (a || b) << endl; // true
cout << (!a) << endl; // falseint x = 5;
x++; // 6
++x; // 7
x--; // 6
--x; // 5++x is pre-increment, x++ is post-increment.
--x is pre-decrement, x-- is post-decrement.
Bitwise operators work at the binary level and perform operations on individual bits:
& → AND| → OR^ → XOR (exclusive OR)~ → NOT (bitwise complement)<< → Left shift>> → Right shiftThese are especially useful in low-level programming, flags, and performance-critical code.
Ask the AI if you need help understanding or want to dive deeper in any topic