Return type of ‘?:’ (ternary conditional operator)

Why does the first return a reference?

int x = 1;
int y = 2;
(x > y ? x : y) = 100;

While the second does not?

int x = 1;
long y = 2;
(x > y ? x : y) = 100;

Actually, the second did not compile at all – “not lvalue left of assignment”.

4 Answers
4

Leave a Comment