position: fixed; top: auto !important; margin-left: 112px;

Operators in C

Operators are used to perform operations on variables . Common operations includes addition, subtraction, multiplication, division etc.

There are various types of operators in C :-
Operators Description
* / % + - Arithmetic Operators
!= > < >= <= ==/td> Relational Operators
&& || ! Logical Operators
&, |, ^, ~, >> << Bitwise Operators
+=, -=, *=,= Assignment Operators
conditional, comma, sizeof, address, redirecton Other Operators

Hierarchy of Operations

There are various scenarios where compiler has to know which operation should it performs first. What do you think this expression will be evaluated according to compiler ?

`2 * x - 3 * y `

Now,

There are two ways to solve this equation

```1)  (2x)-(3y)
2)  2(x-3y)
```

We engineers know how to solve these problems because we know multiplication is solved first then minus operation should be applied. But how does compiler know how to solve this ? So Hierarchy of Operations helps compiler to understand these kind of equations.

Following table list the operators according to priorities :-

Priority Operators Description
1st */% multiplication, division, modular division
3rd = assignment

What this table signifies ?

* will be always solved first then division (/) operator . + will be solved before - operator but * will be solved first then + operator.

Example

`a = 2*3/4+4/4`

As * has max priority than '/' So it will be evaluated first. So,

`6/4+4/4`

Now '/' has max priority than '+' so

`1 + 4/4`

Now '/' has max priority than '+' so

`1 + 1`

Result is 2

Solve the Quiz of Article

1) What do you think '/' has max priority than '+'?
Yes
No

2) Both the operators in this equation have same priorities 100 / 10 *10. So what do you think / will be solved before *?
Yes
No

codzify.com

Largest collection of up-to-date tutorials to learn programming languages. We are focused on easy learning. Massive collection of interview questions one may need for preparation.