2010年3月3日 星期三

C語言的Ternary Operator

C Variants

A GNU extension to C allows the second operand to be omitted,

and the first operand is implicitly used as the second as well:

a = x ? : y;

The expression is equivalent to

a = x ? x : y;

except that if x is an expression, it is evaluated only once.

The difference is significant if evaluating the expression has side effects.

沒有留言:

張貼留言