x += '|' + b, x;
This compiles because the comma here is acting as an operator (instead of a separator) where the right-hand operand has no effect.
From Wikipedia:
In the C and C++ programming languages, the comma operator (represented by the token ,) is a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value (and type).
...
The comma operator has the lowest precedence of any C operator...
In x += '|' + b, x;
, operator +=
has a higher precedence than ,
and operator +
has a higher precedence than +=
, meaning that it's equivalent to (x += ('|' + b)), x
;
Additionally, if you compile your code with warnings on, you will likely receive a warning similar to this:
warning: right-hand operand of comma has no effect