3 ms·
The important part that makes the parens in the second operation unnecessary is that addition is associative, not that it's commutative. And concatentation is a
by tsimionescu 3y ago
The important part that makes the parens in the second operation unnecessary is that addition is associative, not that it's commutative. And concatentation is also associative, so even if those were strings, the parens would still be unnecessary.
That is, (a+b)+c == a+(b+c).
Interestingly, C integer addition is not actually associative, since (1+INT_MAX) + (-1) is UB, but 1+(INT_MAX+(-1)) should in principle be defined as INT_MAX.
- xigoi 3y agoAnd floating-point addition is not associative in any language: