如果声明?并且:

前端之家收集整理的这篇文章主要介绍了如果声明?并且:前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > What does the question mark and the colon (?: ternary operator) mean in objective-c?13个
我听说过哪种if语句使用?并且:在C中
我不知道如何使用它,我无法找到任何相关的东西.
我需要使用它来缩短我的代码
任何帮助,将不胜感激.

解决方法

?:在C中是 ternary operator(也称为条件运算符).你可以缩短你的代码
if(condition)
    expr1;
else
    expr2;

condition ? expr1 : expr2;

看看它怎么运作:

C11:6.5.15条件运算符:

The first operand is evaluated; there is a sequence point between its evaluation and the
evaluation of the second or third operand (whichever is evaluated). The second operand
is evaluated only if the first compares unequal to 0; the third operand is evaluated only if the first compares equal to 0; the result is the value of the second or third operand (whichever is evaluated),

原文链接:https://www.f2er.com/c/117678.html

猜你在找的C&C++相关文章