什么?和:在C ++中的意思? [英] What does ? and : mean in C++?
问题描述
例如我有这个语句
return ( m > n ? m : n );
问号在 m> n 和
m:n
?
code>意味着?
What does the question mark mean between m > n
and m : n
?
What does the colon in m : n
mean?
推荐答案
它的技术名称是条件运算符, if / then; else 。
Its technical name is the conditional operator, and it's shorthand for if-then;else
.
if m > n
then m
else n
p>
or in actual C++ syntax:
if(m > n)
{
return m;
}
else
{
return n;
}
问号是什么意思m> n和m:
在m:n中的冒号是什么意思?
What does the question mark mean between m > n and m : n? What does the colon in m : n mean?
?
和:
是条件运算符语法的一部分。 ?
表示左表达式应该是布尔值 true
或 false
。 :
描述了 true
和 false
结果。如果表达式的计算结果为 true
,而<$ c>的右侧为:
$ c>:是结果,如果表达式 false
The ?
and :
are part of the conditional operators syntax. The ?
indicates that the left expression should be a boolean evaluation true
or false
. The :
delineates the true
and false
results. The left-hand of :
is the result if the expression evaluates to true
and the right-hand of :
is the result if the expression is false
这篇关于什么?和:在C ++中的意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!