0% found this document useful (0 votes)
32 views2 pages

Operators Precedence in C

The document discusses operator precedence in C, explaining that certain operators like multiplication have higher precedence than others like addition. It provides a table of operator precedence categories and examples to demonstrate how precedence works in expressions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Operators Precedence in C

The document discusses operator precedence in C, explaining that certain operators like multiplication have higher precedence than others like addition. It provides a table of operator precedence categories and examples to demonstrate how precedence works in expressions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

8/10/2016

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

Copyright 2016. All Rights Reserved.


Enter email for newsletter

http://www.tutorialspoint.com/cprogramming/c_operators_precedence.htm

go

2/2

You might also like