Conditional Operator Discrepancies Between C and C
The conditional operator (?) offers varying behaviors in C and C . Specifically, this concerns its ability to return an lvalue.
In C , the operator can return an lvalue, allowing expressions like:
However, C restricts this functionality, necessitating the use of if/else or direct references:
Additionally, C grants equal precedence to the ?: and = operators, grouping them right to left. This means the following is syntactically correct in C :
In contrast, C requires parentheses to resolve such expressions:
The above is the detailed content of Why does the conditional operator handle lvalues differently in C and C ?. For more information, please follow other related articles on the PHP Chinese website!