in reply to Operator precedence
There's no such thing as priority, and neither precedence nor associativity define the order in which stuff is evaluated. They determine what is an operand of what operator.
apple && (banana || cherry) apple: LHS operand of && banana || cherry: RHS operand of && banana: LHS operand of || cherry: LHS operand of || (apple && banana) || cherry apple && banana: LHS operand of || apple: LHS operand of && banana: RHS operand of && cherry: RHS operand of ||
Operand evaluation order is what controls the order in which stuff is evaluated.
In order to provide short-circuiting, && evaluates its LHS operand before its RHS. Same goes for ||.
Given
apple && (banana || cherry) apple: LHS operand of && banana || cherry: RHS operand of && banana: LHS operand of || cherry: LHS operand of ||
apple must be evaluated before banana || cherry
banana must be evaluated before cherry
So we get:
Given
(apple && banana) || cherry apple && banana: LHS operand of || apple: LHS operand of && banana: RHS operand of && cherry: RHS operand of ||
apple && banana must be evaluated before cherry
apple must be evaluated before banana
So we get:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Operator precedence
by muba (Priest) on Jan 18, 2013 at 22:43 UTC |