If you are using more then one operator for an expression, then it is good to know the precedence and associative of the operator. The operator precedence defines the priority of the operators that means precedence indicates which operator applied first on the given expression. The higher precedence operator is evaluated before the low precedence operator.

But the problem occurs when an expression has two or more than two operators with the same precedence, so to resolve this problem a new term is introduced by the C standard, it is called associativity. The associativity defines the order in which operators of the same precedence are evaluated, that means evaluated from right to left or left to right.

#### Table of Operators with Precedence and Associativity in C

**Note:** In below table Precedence of operators decreases from top to bottom.

**Let see some examples to understand the precedence and associativity,**

**Example 1,**

What is the output of below program?

1 2 3 4 5 6 7 8 9 10 11 12 13 | #include<stdio.h> int main() { int a = 5, b = 10; int c; c = a * 2 + b; printf("\n output = %d", c); return 0; } |

Using the precedence table, we can calculate the output of the above described code. According the precedence table multiplication operator ( * ) has higher precedence than addition operator ( + ) and assignment operator ( = ) so multiplication will be evaluated first.

**c = a* 2 + b;**

**c = 5* 2 + 10;**

**c = 10 + 10;**

**c = 40;**

**Example 2,**

What is the output of below program?

1 2 3 4 5 6 7 8 9 10 11 12 13 | #include<stdio.h> int main() { int a = 5, b = 10; int c; c = a * 2 + b/2; printf("\n output = %d", c); return 0; } |

In above example, two operator ( * and / ) has the same precedence, in that situation we need to check the precedence and associativity table. According to table * and / has the associativity from the left to right multiplication will be evaluated first.

**c = a* 2 + b / 2 ;**

**c = 5 * 2 + 10 / 2 ;**

**c = 10 + 10 / 2 ;**

**c = 10 + 5;**

**c = 15;**

**Note:** You should always use the parentheses where more than one operator are used with expression. It prevents from the undesired behavior. See the below example,

1 2 3 4 5 6 7 8 9 10 11 12 13 | #include<stdio.h> int main() { int a = 5, b = 10; int c; c = ((a*2)+(b/2)); printf("\n output = %d", c); return 0; } |