Have a look at the operator precedence.
Without an explicit ()
your code behaves like
( a >= 5 ? b = 100 : b ) = 200;
The result of a ?:
expression is not a modifiable lvalue [#] and hence we cannot assign any values to it.
Also, worthy to mention, as per the c
syntax rule,
assignment is never allowed to appear on the right hand side of a conditional operator
Relared Reference : C precedence table.
OTOH, In case of c++
, well,
the conditional operator has the same precedence as assignment.
and are grouped right-to-left, essentially making your code behave like
a >= 5 ? (b = 100) : ( b = 200 );
So, your code works fine in case of c++
[ # ] -- As per chapter 6.5.15, footnote (12), C99
standard,
A conditional expression does not yield an lvalue.