Tag: operation cannot arithmetic condition style description size Pre Union
A?b:c
This is a conditional expression, which means that if a is true, the expression value is B, and if A is false, the expression value is C
The conditional expression is specified as follows
Conditional statements:
if (a>b) max=A; else max=b;
An available conditional expression is written as
max= (a>b) a:b;
The semantics for executing the statement are: If A>b is true, assign a to max, otherwise assign B to max.
When you use conditional expressions, you should also be aware of the following points:
1) The operator precedence of the conditional operator is lower than the relational operator and the arithmetic operator, but above the assignment.
So
max= (a>b)? a:b
You can remove parentheses and write as
Max=a>b?a:b
2) The conditional operator? And: is a pair of operators and cannot be used separately.
3) The binding direction of the conditional operator is from right to left.
For example:
A>b?a:c>d?c:d
Should be understood as
A>b?a: (C>D?C:D)
This is the case where conditional expressions are nested, where expression 3 is another conditional expression.
C # Conditional expression max= (a>b)? a:b; meaning