Ds 101
Ds 101
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…