**C++ Operators**

The operator represents an action. For example + is an operator that represents increments. An operator performs two or more tasks and produces the output. For example, 3 + 4 + 5 Here + the operator works on three tasks and produces 12 as output.

Type of C++ Operators

a) Arithmetic Operators

b) Assignment Operators

c) Auto-increment and Auto-decrement Operators

d) Logical Operators

e) Comparison (relational) operators

f) Bitwise Operators

g) Ternary Operator

## a) Arithmetic Operators in C++

C++ Arithmetic operators : +, -, *, /, %

2. – for subtraction.

3. * for multiplication.

4. / for division.

5. % for modulo.

## b) Assignment Operators in C++

C++ Assignments operators are: =, +=, -=, *=, /=, %=

**1. **num2+=num1 **2. **num2-=num1 **3.** num2*=num1 **4.** num2/=num1 **5.** num2%=num1

## c) Auto-increment and Auto-decrement Operators

## Auto-increment and Auto-decrement Operators are ++ and —

**1.** num++ is equal to num=num+1;**2.** num-- is equal to num=num-1;

**d) Logical Operator in C++**

## e) Relational operators in C++

## Relational operators are: ==, !=, >, <, >=, <=

1. == returns true if both the left side and right side are equal

2. != returns true if the left side is not equal to the right side of the operator.

3. > returns to the right if the left is greater than right.

4. < returns true if the left side is less than the right side.

5. >= returns true if the left side is greater than or equal to the right side.

6. <= returns true if the left side is less than or equal to the right side.

## f) Bitwise Operators in C++

Bitwise Operators are: &, |, ^, ~, <<, >>

**1.** num1 & num2 compare the same bits of num1 and num2 and produce 1 if the two bits are equal, otherwise, it returns 0. In our case, it will return 2 which is 00000010 because only the second last bits are found in the binary form of num1 and num2.**2.** num1 | num2 compares the same bits of moisture 1 and num2 and produces 1 if one is a little bit 1, otherwise, it returns 0. In our case, it will return 31 which is 00011111**3.** num1 ^ num2 compares the same bits of num1 and num2 and produces 1 if they are not equal, otherwise, it returns 0. In our example, this will return 29 which is equal to 00011101**4.** ~num1 is a finishing operator that only slightly changes from 0 to 1 and 1 to 0. In our example, it will come back to -12 which has 8-bit equivalent signatures equal to 11110100**5.** num1 << 2 is the left shutter operator that moves the bits to the left, gives a slight discount to the left, and sets a value of 0 to the right. In our case, the output is 44 which is equal to 00101100

**6. **num1 >> 2 is the right shift operator that moves bits to the right, subtracts slightly from the right, and assigns a value of 0 slightly to the left. In our case, the output is 2 which is equal to 00000010

**g) Ternary Operator in C++**

In C++, the ternary administrator (otherwise called the restrictive administrator) can be utilized to supplant if...else in specific situations. A ternary administrator assesses the test condition and executes a square of code dependent on the aftereffect of the condition. in case condition is valid, expression1 is executed. Furthermore, in case condition is bogus, expression2 is executed.