条件/三元运算符如何工作?C ++ [英] How does the conditional/ternary operator work? C++
本文介绍了条件/三元运算符如何工作?C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码的文字翻译是什么?另外,请解释它的含义以及使用此运算符的不同方式.
What would be the literal translation for the following code. Also, please explain what it meaning and the different ways of using this operator.
int i = 1, j = 2;
cout << ( i > j ? i : j ) << " is greater." << endl;
有关三元运算符的任何其他有用或附加信息,将帮助我更好地理解它.
Any other useful or additional information about the ternary operator that will help me understand it better would be much appreciated.
推荐答案
( i > j ? i : j )
基本上是指:
如果(i> j)为真
,则返回 i
,否则返回 j
if (i > j) is true
return i
, else return j
附带说明:这与MS Excel的if-formula非常相似
Side note: This is very similar to MS Excel's if-formula
这篇关于条件/三元运算符如何工作?C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文