Hey guys, what is up. In this particular post, we will be talking about what are operators in c++ and types of operators with examples.

Updated on 29/9/2021

## OPERATORS IN C++

Operators in c++ are the symbols that triggers an action on variables and values to perform mathematical or logical operations. These are of 6 types:

1. Arithmetic operator
2. Increment/decrement operator
3. Relational operator
4. Logical operator
5. Assignment operator
6. Misc operator

## Arithmetic operators in c++

It is the most important operator. It takes numerical values in the form of input and then produces a single numerical value after operating.

Example: A=4, B=2. If we want to perform addition and subtraction using these variables: A+B=6 & A-B=2. Here “+” and “–” are arithmetic

## Increment/decrement operators in c++

The increment operator (++) adds the value of a operand by 1.

Types of increment operators:

• Pre – increment: It increases the value of the operand and then stores the new value of the operand.
• Post – increment: It first stores the value of the operand and then increases the value of the operand.

The decrement operator (–) drops the value of the variable by 1.

Types of decrement operators:

• Pre – decrement: it first decreases the value of the operand and then stores the new value of the operand.
• Post – decrement: it first stores the value of the operand and then decreases the value of the operand.

EXAMPLE 1:

OUTPUT:

EXAMPLE 2:

OUTPUT:

## Relational operators

Relational operators in c++ are used in defining the relationship between 2 operators. These operators compare the value and return true or false in the form of binary value.

Let us understand this with an example taking A=8, B=9

## Logical operators

Whenever one or more than one expressions need to be combined then we use logical operators. We have 3 fundamental logical operators: ! (Not), && (And), || (Or).

Not (!): It is a unary operator. It reverses the value of the variable/operand.

And (&&): It is a binary operator which operates with 2 operands. Gives true if both the variables are non-zero. In simple words, it can be explained as the multiplication of values of both operands.

Or (||): It is also a binary operator which operates with 2 operands. Gives result as true when at least one of the operands is non-zero. In simple words, it is the addition of values of both operands.

Example:

1. ( 5<3 && 6!=4)                   Answer= False
3. (4<6 || 7>3 && 5!=6)          Answer= True

## Assignment operators

Assignment operators are used to assigning the value to the variable.

## Precedence of operators:

In the upcoming post, you will be getting information related to big data analytics technology and Nesting of loops in c++. If you haven’t read about what are loops in C++ then go and read this. You can read previous posts by scrolling downwards. Also, stay tuned for the upcoming post.

Categories: CODING