Look at the priority of the operator.
Without explicit () your code behaves like
( a >= 5 ? b = 100 : b ) = 200;
The result of the expression ?: not a mutable value of l [#] and, therefore, we cannot assign any values ββto it.
Also worth mentioning, according to the c syntax rule,
never allowed to appear on the right side of a conditional statement
Background: Priority Table C.
OTOH, In the case of c++ , well,
the conditional statement has the same priority as the assignment.
and grouped from right to left, essentially making your code the same as
a >= 5 ? (b = 100) : ( b = 200 );
So your code works fine in case of c++
[#] - according to chapter 6.5.15, footnote (12), C99 standard,
The conditional expression does not give an lvalue.
source share