# Operator in c++ and Operator precedence so, let’s starts with the operator

## What is Operator in C++ programming?

An operator in a C++ programming language is a symbol that tells the compiler or interpreter to perform the specific mathematical, relational, or logical operations and produce the final result.

## Types of Operator

• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Bitwise operators

## Arithmetic Operators

Arithmetic operators are used to perform common mathematical operations.

In the example below, we will use the arithmetic `+` operator to add together two values:

`int x = 100 + 50;`

## Assignment operators

Assignment operators are used to assign values to variables.

In the example below, we use the assignment operator (`=`) to assign the value 10 to a variable called x:

`int x = 100 + 50;`

Although the `+` operator is often used to add together two values, like in the example above, it can also be used to add together a variable and a value, or a variable and another variable:

A list of all assignment operators:

## Comparison Operator

Comparison operators are used to compare two values.

Note: The return value of a comparison is either true (`1`) or false (`0`).

In the following example, we use the greater than operator (`>`) to find out if 5 is greater than 3:

```int x = 5;
int y = 3;
cout << (x > y); // returns 1 (true) because 5 is greater than 3```

A list of all comparison operators:

## Logical Operator

Logical operators are used to determining the logic between variables or values:

Below is the example of logical operator.

```#include <iostream>
using namespace std;

int main() {
int x = 5;
int y = 3;
cout << (x > 3 && x < 10); // returns true (1) because 5 is greater than 3 AND 5 is less than 10
return 0;
}
```

## Bitwise Operator

In C++, bitwise operators perform operations on integer data at the individual bit-level. These operations include testing, setting, or shifting the actual bits.

Here is a list of 6 bitwise operators included in C++.

Below is the example of bitwise And operator

```#include <iostream>
using namespace std;

int main() {
// declare variables
int a = 12, b = 25;

cout << "a = " << a << endl;
cout << "b = " << b << endl;
cout << "a & b = " << (a & b) << endl;

return 0;
}```

## What is operator precedence in c++?

Operator precedence determines the grouping of terms in an expression and decides how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator.

For example x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher precedence than +, so it first gets multiplied with 3*2 and then adds into 7.

Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedence operators will be evaluated first.

5 1 vote
Article Rating 