Core Module
12 min forge

C++ Operators

Arithmetic, relational, logical, and bitwise operators in C++.

C++ Operators

πŸ“˜ What is it

Operators are symbols used to perform operations on variables and values. C++ supports arithmetic ($+, -, *, /, %$), relational ($==, !=, >, <$), logical ($&&, ||, !$), and bitwise ($&, |, \sim, \wedge, <<, >>$) operators.

⚑ When to use

For calculations, comparisons, and boolean logic in conditional statements.

🧠 Time complexity

  • Basic arithmetic/logical: $O(1)$
  • Bitwise: $O(1)$

πŸ’» Code example

cpp Standard
int a = 10, b = 20; bool result = (a < b) && (b > 15); // Logical AND int bitwise = (a << 1); // Left shift (multiplies by 2)

❌ Common mistakes

  • Confusing = (assignment) with == (comparison).
  • Integer division: 5 / 2 is 2, not 2.5. Use 5.0 / 2 for floating point results.
  • Operator precedence: Not using parentheses () to clarify complex expressions.