Types of Operators in C++

Operators in C++:

An expression consists of variables and constants separated by Operators in C++. There are mainly 8 types of Operators in C++ are given as follows:

Types of Operators in C++:

1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Increment and decrement operators
5. Pointer Operators
6. Assignment Operators
7. Bitwise Operators
8. Misc Operators

Arithmetic Operators: Arithmetic Operators are used to perform arithmetic operations.

Relational Operators: Relational Operators are used to compare the values of operands to produce a logical value. It is a type of bool so, a logical is either true or false.

Logical Operators: Logical Operators combine two or more relational operators or expressions and produce a logical value or results.

Example:


x>y && x==5
x==5 || y==7

Increment and decrement operators: Increment operator (++) is used to increase the value of an integer or char variable by 1. The decrement operator (- -) is used to reduce the value of an integer or char variable by 1

x = 15;
x++ or ++x will produce the result x = 16
x = 15;
x- – or – -x will produce the result x = 14

Pointer Operators: Pointer Operators produce address values.


Example:


&a
ptr
ptr+1
"ABC"

where

a

 is a variable and

ptr

 is a pointer.

Assignment Operators: In C++, there are three types of Assignment Operators given below:

(i) Chained Operators: A chained operator is used for instance variable at the time of declaration. It can’t be used to initialize variables.

a=(b=5);
or
a=b=5;

(ii) Embedded Operators :

a=(b=10)+5;

(b=10) is an assignment operator that is known as an Embedded Operator,
Here the value 10 is assigned to b and then the result 10+5=15 is assigned to a.

(iii) Compound Operators: In C++, the compound operator is a combination of the assignment operator with a binary arithmetic operator.

a+=5;
or
a=a+5;

The operator += is known as the Compound Assignment Operator.

Bitwise Operators: Bitwise Operators are used to manipulate data at the bit level. They are used for testing or shifting bits.
Example:

a<<4 b>> 2