What is precedence of operators?


When number of operators occurs in an expression the operator which is to be evaluated first is judged by applying priority of operators. The arithmetic operators available in C are


+ used for Addition

-  used for Subtraction

* used for Multiplication

/ used for Division

% used for Modulus operation. In other words operator used to remainder after division  


When all this is used in an expression in a C program then the operator priority is applied in the following order namely


* followed by

/ followed by

% followed by

+ and this followed by –


Example to understand the concept of priority of operators is

main()

{

int a;

a=5 + 7 – 8 * 10 / 5 % 10;

printf(“a=%d”,a);

}


The output of the above program is a=6 , This occurs as follows:

a=5 + 6 – 80 / 5 % 10 (since * is operated first)

a=5 + 6 – 16 % 10 (/ is operated)

a= 5 + 7 - 6 (% is calculated)

a= 12 - 6 (+ is operated)

a=6


Questions by GeekAdmin   answers by GeekAdmin

Showing Answers 1 - 3 of 3 Answers

chandan kumar jena

  • Sep 1st, 2007
 

From my point of view, It is nothing but the sequence of operation that means which operator should insert into the stack first. According to the compiler design principle they the parser first choose the operators and manipulate it with the specified operand.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions