However, I expected the parentheses to have
b1
incremented before its value is assigned toa1
You should not have expected that: placing parentheses around an increment expression does not alter the application of its side effects.
Side effects (in this case, it means writing 11 into b1
) get applied some time after retrieving the current value of b1
. This could happen before or after the full assignment expression is evaluated completely. That is why a post-increment will remain a post-increment, with or without parentheses around it. If you wanted a pre-increment, place ++
before the variable:
a1 = ++b1;