Your understanding is correct.
The postfix increment operator ++
evaluates to the current value of its operand, and as a side effect increments its operand. The effect of the increment is guaranteed to be visible at the next sequence point.
A sequence point occurs after each statement, but it could occur within an expression based on the operator. Examples of operators that create a sequence point are the logical AND operator &&
, the logical OR operator ||
, the comma operator ,
, and as in your case the ternary operator ?:
.
Breaking down the single line statement, the condition a[left] <= a[right]
is evaluated first. There is now a sequence point in this stage of the evaluation. Based on the result of this condition, either a[left++]
or a[right++]
is evaluated, and whichever is evaluated is assigned to b[bIdx++]
. There is a sequence point here at the end of the statement, at which point bIdx
is incremented and either left
or right
is incremented.
The above is reflected in the multiple statement version of the code. The condition is evaluated first, then b[bIdx]
is assigned either a[left]
or a[right]
, then either left
or right
are incremented, then bIdx
is incremented.