C++ Operators

An operator is a symbol which tells compiler to take an action on operands and yield a value. The Value on which operator operates is called as operands. C++ supports wide verity of operators. Supported operators are listed below -

OperatorExplanation
Arithmetic OperatorsUsed for arithmetic operations
Relational OperatorsUsed for specifying relation between two operands
Logical OperatorsUsed for identifying the truth value of the expression
Bitwise OperatorsUsed for shifting the bits
Assignment OperatorsUsed for assigning the value to the variable
Misc Operators-

Arithmetic Operators :

Consider that we have A = 20 and B = 10

OperatorDescriptionExample
+Adds two operands or variablesA + B = 30
-Subtracts second operand from the firstA - B = 10
*Multiplies both operandsA * B = 200
/Divides numerator by denominatorA / B = 2
%After dividing the numberator by denominator remainder will be returned after divisionA % B = 0
++Increment operator will increases integer value by one A++ = 21
#8211; -Decrement operator will decreases integer value by one A- #8211; = 19

Relational Operators:

Consider that A = 40 and B = 20

SymbolMeaningExample
>Greater thanA > B returns true
<Less thanA < B returns false
>=Greater than equal toA >= B returns false
<=Less than equal toA <= B returns false
==Equal toA == B returns false
!=Not equal toA != B returns true

Logical Operators :

Consider that, A = 0 and B = 0

OperatorDescriptionExample
Logical AND (&&)If both the operands are non-zero then only condition becomes true(A && B) is false.
Logical OR (||)If both the operands are zero then only condition becomes false(A || B) is true.
Logical NOT (!)It will reverses the state of its operand i.e true will become false(!A) is true.