Home > Backend Development > C++ > Why does the conditional operator handle lvalues differently in C and C ?

Why does the conditional operator handle lvalues differently in C and C ?

Patricia Arquette
Release: 2024-11-07 16:45:02
Original
293 people have browsed it

Why does the conditional operator handle lvalues differently in C and C  ?

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template