# Operators in C++8 min read

An operator is a symbol that performs a specific mathematical or logical operation on operands.
Example: Addition : `2 + 3`, where 2 and 3 are the operands and + is the operator.

We can say that operators are the foundation of any programming language, the program is incomplete without the operators as we use them in all of our programs.

Following are the types of Operators in C++.

• Arithmetic Operators
• Increment and Decrement Operators
• Assignment Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Other Operators

### C++ Arithmetic Operators

These are used to perform mathematical operations on operands such as addition, subtraction, multiplication, division etc.

### C++ Increment and Decrement Operators

These are the Unary Operators as they operate on a single operand. They are `++` and `--` operators. ++ is used to increase the value by 1 and — is used to decrease the value by 1. There are two kinds of Increment and Decrement Operators.

• Post-Increment or Post-Decrement:
First, the value is used for operation and then incremented or decremented. Represented as a++ or a–.
• Pre-Increment Pre-Decrement:
Here First the value is incremented or decremented then used for the operation. Represented as ++a or –a.

### C++ Assignment Operators

Assignment operators are used in a program to assign a value of the right-hand side to the left-hand side as shown below.

These are the short version formed by combining the two operators. For example Instead of writing, `int a = a+5`, we can write `a += 5`.

Following are the list of assignment operators used in C++.

### C++ Relational Operators

These operators are used to compare two values and return Boolean results. For example: it checks if the operand is equal to another operand or not or an operand is greater than the other operand or not or checks less than between two values, etc.

List of relational operators in C++:

### C++ Logical Operators

Logical Operators are used in conditional statements and loops for evaluating a condition with binary values. They are used to combine two different expressions together.

The following are the C++ Logical Operators. Assume X holds the value 1 and Y holds 0

### C++ Bitwise Operators

Bitwise operators are used to perform a bit-level operation on operands. They are used in testing, setting, or shifting the actual bits in a program.

You can see the truth table below.

Below are the list of Bitwise operators:

### Other Operators

Apart from the above operators, there are various other operators used in C++ programming. They are listed below.

## Operators Precedence in C++

In a program, there may be an expression that uses more than one operator, in such case operator precedence determines which is to be evaluated first and next.

Let us take an example:

The output of the above expression is 60 because the precedence of multiplication is higher than the addition. So first (5 * 10) is evaluated and then 10 is added to the result.

The following shows the precedence and associativity of C++ operators:

Associativity refers to the direction of the operators to be evaluated first and next. It may be right to left or left to right.

### C Program to search an element in an array using Pointers

A separate function( search_function()) will be created where the array pointer will be declared and the searched element along with the size of an array …

### C Program to find the sum of the digits of a number using recursion function

This C program calculates the sum of digits of a given number using recursion. Here’s a concise explanation: Function Definition: sumDigits(int n) This function calculates …

### C program to find factorial of a numberĀ using Ternary operator with Recursion

Recursion refers to the function calling itself directly or in a cycle. Before we begin, you should have the knowledge of following in C Programming: …

### C Program to Add Two Numbers Using Call by Reference

The program takes the two numbers from the user and passes the reference to the function where the sum is calculated. You may go through …

### Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …

### String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …