加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

这在c中如何工作?

发布时间:2020-12-16 09:49:49 所属栏目:百科 来源:网络整理
导读:参见英文答案 How does the Comma Operator work????????????????????????????????????9个 我遇到了这样的情况: if(true,false){ cout"A";}else{ cout"B";} 实际上它写出了B.这个陈述是如何起作用的?根据我的观察,始终将最后一个值计算在内.但那有什么意义
参见英文答案 > How does the Comma Operator work????????????????????????????????????9个
我遇到了这样的情况:

if(true,false)
{
    cout<<"A";
}
else
{
    cout<<"B";
}

实际上它写出了B.这个陈述是如何起作用的?根据我的观察,始终将最后一个值计算在内.但那有什么意义呢?

谢谢

解决方法

根据 http://www.cplusplus.com/doc/tutorial/operators/

The comma operator (,) is used to separate two or more expressions that are included where only one expression is expected. When the set of expressions has to be evaluated for a value,only the right-most expression is considered.

例如,请考虑以下事项:

int a,b;
a = (b=3,b+2);

b设置为3,但是equals运算符只关心下半部分,所以返回的实际值是5.至于有用性?这是有条件的:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读