We know that the conditional operator returns an lvalue if its Expr2 and Expr3 are lvalues of the same type otherwise it returns an rvalue:
int main(){
int a = 0, b = 0;
(a == 1 ? a : b) = 1; // C++ OK. C: error. lvalue needed
return 0;
}
- The code above compiles fines on C++ while it fails to compile on C.
Here is the output on C:
main.c: In function ‘main’:
main.c:8:20: error: lvalue required as left operand of assignment
(a == 1 ? a : b) = 1;
^