Hey there, Do you know? What is an operator in c? If not, then let me explain you the concept of an operator in c with operator priority and associativity

Contents

## What is an operator?

Declaration gives the list of variables with a different type of values to be used, the operator is something which tells what to be done to the declared variables.

### Every operator in c has

- Priority
- Associativity

### Why 6/5 gives 1 not 1.2 in C program?

Do you know, if we calculate 6/5 gives 1 not 1.2 in C

Similarly, 4/8 gives 1 not 0.5

Do you know why? Because both values are integers then C evaluate result also int not float but when one value is int and another value is float then it evaluates result also as float, so 6.5/5.5 gives 1.1818 which is obvious.

**Still confused! **Have you ever checked the arthimatic in c, if not, then check now

**#include <stdio.h>**

**int main()**

**{**

**
int k;**

**
k=66/30;**

**
printf(“%d”,k);**

**
return 0;**

**}**

**Arithmetic in c result **

K=12/18 0

K=20/42 0

K=72/20 3

K=88/48 1

K=44/66 0

K=88/25 3

K=66/30 2

**normal Arithmetic result**

K=12/18 0.666

K=20/42 0.4761

K=72/20 3.6

K=88/48 1.833

K=44/66 0.666

K=88/25 3.52

K=66/30 2.2

Observe the results carefully you will notice, arithmetic in C is different than the normal arithmetic because when both values are integers then C evaluate result as int not float

So, when ever you do any arithmetic operation in C some problems may crop up.

## Leave a Reply