As mentioned in the comments, you have a problem with operator precedence. Your code is interpreted as follows:
((a > 1) ? b = 10 : b) = 50;
The code above is invalid for the same reason that the entry (b = 10) = 50 invalid.
The code can be more clearly written as:
b = a > 1 ? 10 : 50;
And how is it different from if ... else ...?
The conditional operator only works with expressions as operands. The if may contain instructions in the body.
A conditional statement can always be replaced by an equivalent if . But the converse is not true - there are expressions that cannot be replaced by an equivalent conditional operator expression.
source share