[go: up one dir, main page]

0% found this document useful (0 votes)
14 views8 pages

Ds 101

The document explains operator precedence and associativity in C programming, highlighting how they determine the order of operations in expressions. It provides examples to illustrate the concepts, such as the evaluation of '10 + 20 * 30' and '100 / 10 * 10'. Additionally, it includes a table outlining the precedence and associativity of various operators.

Uploaded by

trjmeitei
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)
14 views8 pages

Ds 101

The document explains operator precedence and associativity in C programming, highlighting how they determine the order of operations in expressions. It provides examples to illustrate the concepts, such as the evaluation of '10 + 20 * 30' and '100 / 10 * 10'. Additionally, it includes a table outlining the precedence and associativity of various operators.

Uploaded by

trjmeitei
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/ 8

Operator Precedence and

Associativity in C
PROGRAMMING METHODOLOGY
BCA101
PRESENTER-DAISY SHARMAH
Operator precedence
• Operator precedence determines which operator
is performed first in an expression with more than
one operators with different precedence.
• Operator precedence determines the grouping of
terms in an expression and decides how an
expression is evaluated.
• Certain operators have higher precedence than
others; for example, the multiplication operator
has a higher precedence than the addition
operator.
Example
• Solve 10 + 20 * 30
Operators Associativity
• Operators Associativity is used when two
operators of same precedence appear in an
expression.
• Associativity can be either Left to Right
or Right to Left.
Example
• Solve 100/10*10
• ‘*’ and ‘/’ have same precedence and their
associativity is Left to Right, so the expression
“100 / 10 * 10” is treated as “(100 / 10) * 10”.
Table of Precedence & associativity
Category Operator Associativity
Postfix () [] -> . ++ - - Left to right
Unary + - ! ~ ++ - - (type)* & Right to left
sizeof
Multiplicative */% Left to right
Additive +- Left to right
Shift << >> Left to right
Relational < <= > >= Left to right
Equality == != Left to right
Bitwise AND & Left to right
Bitwise XOR ^ Left to right
Bitwise OR | Left to right
Logical AND && Left to right
Table of Precedence & associativity
Category Operator Associativity
Logical OR || Left to right
Conditional ?: Right to left
Assignment = += -= *= /= %=>>= <<= &= Right to left
^= |=
Comma , Left to right
• ANY QUERIES…

You might also like