C++ Operators

Arithmetic Operators

C++ provides standard arithmetic operators to perform basic math operations:

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • % Modulus (remainder)
Loading...
Output:

Assignment Operators

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 assigns
Loading...
Output:

Comparison Operators

Comparison 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 to
Loading...
Output:

Logical Operators

Used with bool types or conditions:

bool a = true, b = false;

cout << (a && b) << endl; // false
cout << (a || b) << endl; // true
cout << (!a) << endl;     // false

Increment/Decrement

int 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

Bitwise operators work at the binary level and perform operations on individual bits:

  • & → AND
  • | → OR
  • ^ → XOR (exclusive OR)
  • ~ → NOT (bitwise complement)
  • << → Left shift
  • >> → Right shift

These are especially useful in low-level programming, flags, and performance-critical code.

Loading...
Output:

Need Help?

Ask the AI if you need help understanding or want to dive deeper in any topic