An operator is a symbol used to perform operations on variables and values.
Used for mathematical calculations.
| Operator | Description | Example |
|---|---|---|
+ | Addition | a + b |
- | Subtraction | a - b |
* | Multiplication | a * b |
/ | Division | a / b |
% | Modulus (remainder) | a % b |
Used to compare values.
| Operator | Description | Example |
|---|---|---|
== | Equal to | a == b |
!= | Not equal to | a != b |
> | Greater than | a > b |
< | Less than | a < b> |
>= | Greater than or equal to | a >= b |
<= | Less than or equal to | a <= b |
Used to combine conditions.
| Operator | Description | Example |
|---|---|---|
&& | Logical AND | a > 0 && b > 0 |
| ` | ` | |
! | Logical NOT | !a |
Used to assign values.
| Operator | Description | Example |
|---|---|---|
= | Assign | a = 5 |
+= | Add and assign | a += 2 |
-= | Subtract and assign | a -= 2 |
*= | Multiply and assign | a *= 2 |
/= | Divide and assign | a /= 2 |
Used to increase or decrease a value by 1.
| Operator | Description | Example |
|---|---|---|
++ | Increment | a++ |
-- | Decrement | a-- |
Used for bit-level operations.
| Operator | Description | Example |
|---|---|---|
& | AND | a & b |
| ` | ` | OR |
^ | XOR | a ^ b |
~ | NOT | ~a |
<< | Left shift | a << 1> |
>> | Right shift | a >> 1 |
Used as a short form of if-else.
sizeof – returns size of a data type
, (comma) – evaluates multiple expressions
. – accesses class members
-> – accesses members using pointers
Operators perform operations on data
Different operators serve different purposes
Correct operator usage is essential for logic building
Operators are fundamental building blocks in C++ programs that allow computation, comparison, and decision-making.
Take quizzes related to this topic and see where you stand!
Start Quiz Now