What are C++ operators?

C++ operators are symbols that perform operations on variables and values. For example, + is an operator used for addition, while - is an operator used for subtraction. C++ Operators can be classified into 6 types:

  1. Arithmetic Operators
  2. Assignment Operators
  3. Relational Operators
  4. Logical Operators
  5. Bitwise Operators
  6. Other Operators

Arithmetic Operators

There are the following arithmetic operators supported by the C++ language:

Operator Description
+ Adds two operands
Subtracts second operand from the first
* Multiplies both operands
/ Divides numerator by de-numerator
% Modulus Operator and the remainder of after an integer division
++ Increment operator increases integer value by one
Decrement operator decreases integer value by one

Relational Operators

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

Operator Description
== Checks if the values of two operands are equal or not, if yes then the condition becomes true.
!= Checks if the values of two operands are equal or not, if values are not equal then the condition becomes true.
> If the value of the left operand is greater than the value of the right operand, if yes then the condition becomes true.
< Checks if the value of the left operand is less than the value of the right operand, if yes then the condition becomes true.
>= Checks if the value of the left operand is greater than or equal to the value of the right operand, if yes then the condition becomes true.
<= Inspect if the value of the left operand is less than or equal to the value of the right operand, if yes then the condition becomes true.

Logical Operators

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

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

Bitwise Operators

Operator Description
& Binary AND Operator copies a bit to the result if it exists in both operands.
| Binary OR Operator copies a bit if it exists in either operand.
^ Binary XOR Operator copies the bit if it is set in one operand but not both.
~ Binary Ones Complement Operator is unary and has the effect of ‘flipping’ bits.
<< Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.
>> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.

Assignment Operators

There are the following assignment operators supported by the C++ language.

Operator Description
= Simple assignment operator, Assigns values from right side operands to left side operand.
+= Add AND assignment operator, It adds the right operand to the left operand and assigns the result to the left operand.
-= Subtract AND assignment operator, It subtracts the right operand from the left operand and assigns the result to the left operand.
*= Multiply AND assignment operator multiplies the right operand with the left operand and assigns the result to the left operand.
/= Divide AND assignment operator, It divides left operand with the right operand and assigns the result to the left operand.
%= Modulus AND assignment operator, It takes modulus using two operands and assigns the result to the left operand.
<<= Left shift AND assignment operator.
>>= Right shift AND assignment operator.
&= Bitwise AND assignment operator.
^= Bitwise exclusive OR and assignment operator.
|= Bitwise inclusive OR and assignment operator.

C++ Operators

Leave a Reply

Your email address will not be published. Required fields are marked *