Most programming languages have a table of precedence and associativity for binary operators. Associativity matters in some cases e.g. (a - b) - c
!= a - (b - c)
.
However, for an associative operator like &&
it would seem not to matter, yet most languages list this as left associative.
Are there any situations where there is actually a difference between (a && b) && c
and a && (b && c)
?
a
,b
andc
are functions that have side-effects. – Fadoa() && b()
thena()
is called first if&&
is left-associative. If it's right-associative thenb()
is called first. That's why associativeness matters. – Fado&&
... but there's nothing technically wrong with that. My point was only that they don't make a difference in the evaluation order. – Annaleeannaliese