什么?和:在C ++中的意思? [英] What does ? and : mean in C++?

查看:221
本文介绍了什么?和:在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆