0% found this document useful (0 votes)
122 views10 pages

08 - Operator Precedence Associativity

The document discusses C operators including arithmetic, unary, relational, logical, bitwise, and assignment operators. It explains that operator precedence determines the order of operations in an expression with multiple operators, with higher precedence operators performed first. Associativity determines the order of operations within the same precedence group from left to right. The document provides examples of operator precedence and associativity as well as short-circuit evaluation in logical expressions.

Uploaded by

Chiku Rohit
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)
122 views10 pages

08 - Operator Precedence Associativity

The document discusses C operators including arithmetic, unary, relational, logical, bitwise, and assignment operators. It explains that operator precedence determines the order of operations in an expression with multiple operators, with higher precedence operators performed first. Associativity determines the order of operations within the same precedence group from left to right. The document provides examples of operator precedence and associativity as well as short-circuit evaluation in logical expressions.

Uploaded by

Chiku Rohit
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/ 10

Computer Programming

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.

•Operations with a higher precedence are carried out before


operations having a lower precedence

Eg: 10 + 20 * 30
is calculated as 10 + (20 * 30)

and not as (10 + 20) * 30


Associativity
• Associativity is used to determine the order in which consecutive
operations within the same precedence group are carried out.

For example: 100 / 10 * 10

- ‘*’ and ‘/’ have same precedence


- Associativity is Left to Right,

100 / 10 * 10 is treated as (100 / 10) * 10


Precedence and Associativity
Operator category Operators Associativity
- ++ -- sizeof cast !
* / %
+ -
< <= > >=
== !=
&&
||
?:
= += -= *= /= %=
Operator Precedence and Associativity

* / %
+ -
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.

You might also like