Operators Precedence in C
Operators Precedence in C
OperatorsPrecedenceinC
We are hiring
OperatorsPrecedenceinC
Advertisements
PreviousPage
NextPage
Operatorprecedencedeterminesthegroupingoftermsinanexpressionanddecideshowanexpressionisevaluated.Certainoperators
havehigherprecedencethanothersforexample,themultiplicationoperatorhasahigherprecedencethantheadditionoperator.
Forexample,x=7+3*2here,xisassigned13,not20becauseoperator*hasahigherprecedencethan+,soitfirstgetsmultiplied
with3*2andthenaddsinto7.
Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an
expression,higherprecedenceoperatorswillbeevaluatedfirst.
Category
Operator
Associativity
Postfix
()[]>.++
Lefttoright
Unary
+!~++(type)*&sizeof
Righttoleft
Multiplicative
*/%
Lefttoright
Additive
Lefttoright
Shift
<<>>
Lefttoright
Relational
<<=>>=
Lefttoright
Equality
==!=
Lefttoright
BitwiseAND
&
Lefttoright
BitwiseXOR
Lefttoright
BitwiseOR
Lefttoright
LogicalAND
&&
Lefttoright
LogicalOR
||
Lefttoright
Conditional
?:
Righttoleft
Assignment
=+==*=/=%=>>=<<=&=^=|=
Righttoleft
Comma
Lefttoright
Example
TrythefollowingexampletounderstandoperatorprecedenceinC
#include<stdio.h>
main(){
inta=20;
intb=10;
intc=15;
intd=5;
inte;
e=(a+b)*c/d;//(30*15)/5
printf("Valueof(a+b)*c/dis:%d\n",e);
e=((a+b)*c)/d;//(30*15)/5
printf("Valueof((a+b)*c)/dis:%d\n",e);
e=(a+b)*(c/d);//(30)*(15/5)
printf("Valueof(a+b)*(c/d)is:%d\n",e);
e=a+(b*c)/d;//20+(150/5)
printf("Valueofa+(b*c)/dis:%d\n",e);
return0;
}
http://www.tutorialspoint.com/cprogramming/c_operators_precedence.htm
1/2
8/10/2016
OperatorsPrecedenceinC
Whenyoucompileandexecutetheaboveprogram,itproducesthefollowingresult
Valueof(a+b)*c/dis:90
Valueof((a+b)*c)/dis:90
Valueof(a+b)*(c/d)is:90
Valueofa+(b*c)/dis:50
PreviousPage
NextPage
Advertisements
Write for us
FAQ's
Helping
Contact
http://www.tutorialspoint.com/cprogramming/c_operators_precedence.htm
go
2/2