Professional Documents
Culture Documents
08 - Operator Precedence Associativity
08 - Operator Precedence Associativity
C – Operators
2021-’22 Winter B.Tech
Operators
Arithmetic operators
Unary operators
Relational operators
Logical operators
Bitwise operators
Assignment operators
Conditional operators
Operator Precedence
• Precedence determines which operator is performed first in an
expression with more than one operators with different precedence.
Eg: 10 + 20 * 30
is calculated as 10 + (20 * 30)
* / %
+ -
Operator Precedence and Associativity
* / %
+ -
< <= > >=
Operators
int x, a=10,b=5,c=6,d=7;
x=a>b||a<c&&c>d x=a>b||(a<c&&c>d)
x is 1
x=(a>b||a<c)&&c>d;
< <= > >=
x is 0 &&
||
Operators
• complex logical expression will not be evaluated in its entirety if its value
can be established from its constituent operands.
error=2, count=4;
If(error > 5 && count < 100)
{…}
• Since error > 5 is false, the second operand (i.e., count < 100) will not be
evaluated, because the entire expression will be considered false.
Operators
error=2; count=4;
If(error > 5 || count < 100)
{…}
• Here, error>5 is False. Hence the Truth value of OR depends
on the second expression, and hence the second half is
evaluated.