C++ Operators

An operator may be a symbol that tells the compiler to perform specific mathematical or logical manipulations

C++ divides the operators into the subsequent groups:
  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators

Arithmetic Operators

There are following arithmetic operators supported by C++ language −

Let Say, A = 10 and B = 20, then -

OperatorsDescriptionExampleOutput
+Add Two OperandsA + B30
-Substract Two OperandsA - B-10
*Multiplies Two OperandsA * B200
/Divides Two OperandsB / A2
%Modulus Two OperandsB % A0
++Increase Value By OneA++11
--Increase Value By OneA--9

Relational Operators

There are following relational operators supported by C++ language −

Let Say, A = 10 and B = 20, then -

OperatorsDescriptionExampleOutput
==Checks if the values of two operands are equal or not.if the value are same then condition becomes true.A == BNot True
!=Checks if the values of two operands are equal or not.if the value are not same then condition becomes trueA == BTrue
>Checks if the worth of left operand is bigger than the worth of right operand, if yes then condition becomes true. A > BNot True
<Checks if the worth of left operand is a smaller amount than the worth of right operand, if yes then condition becomes true A < BTrue
>=Checks if the worth of left operand is bigger than or adequate to the worth of right operand, if yes then condition becomes true.A >= BNot True
<=Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.A <= BTrue

Logical Operators

There are following logical operators supported by C++ language.

Let Say, A = 1 and B = 0, then -

OperatorsDescriptionExampleOutput
&&Called Logical AND operator. If both the operands are non-zero, then condition becomes true.A && BFalse
||Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true.A || BTrue
!Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true, then Logical NOT operator will make false.!(A && B)True

Bitwise Operators

Bitwise operator works on bits and perform bit-by-bit operation.

The truth tables for &, |, and ^ are as follows −
pqp & qp | qp ^ q
00000
01011
11110
10011