Associativity of operators (#23217)

When two or more operators of the same precedence occur in an expression, associativity determines the order in which they must be evaluated.
This commit is contained in:
wolfwhocodes
2018-11-22 14:40:27 +05:30
committed by Manish Giri
parent a930ebce53
commit 281a6f4fb8

View File

@ -201,9 +201,13 @@ sizeof() Returns the size of a variable. size
? : Conditional Expression. If Condition is true ? then value X : otherwise value Y ? : Conditional Expression. If Condition is true ? then value X : otherwise value Y
## 6. Operator precedence in C ## 6. Operator precedence and associativity in C
Operators with the highest precedence appear at the top of the list. Within an expression, operators Operators with the highest precedence appear at the top of the list. Within an expression, operators
with higher precedence will be evaluated first. with higher precedence will be evaluated first. When two or more operators of the same precedence is
present in an expression, then the associativity of the operator tells us the order in which the operators
must be evaluated. The associativity in the given list is from left to right i.e, operators in the left are
evaluated first.
- Postfix `() [] -> . ++ --` - Postfix `() [] -> . ++ --`
- Unary `+ - ! ~ ++ -- (type)* & sizeof` - Unary `+ - ! ~ ++ -- (type)* & sizeof`
- Multiplicative `* / %` - Multiplicative `* / %`