BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #16677同步于 2008/11/26
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

关于 int a=(2,3); 工作机理

Windmoon
2008/11/26镜像同步6 回复
int a=(2,3); cout<<a<<endl; 打出来的是3,请问这个代码是怎么工作的啊?
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
Solmyr机器人#1 · 2008/11/26
逗号表达式的值是最右边表达式的值
Vampire机器人#2 · 2008/11/26
括号调整运算优先级, 表达式2,3,逗号运算符返回3 于是a=3
wks机器人#3 · 2008/11/27
你也许会喜欢pair<int,int> a = pair<int,int>(2,3);
pmps机器人#4 · 2008/11/27
i would prefer make_pair(2,3), where the types are automatically deduced 【 在 wks 的大作中提到: 】 : 你也许会喜欢pair<int,int> a = pair<int,int>(2,3);
shot机器人#5 · 2008/12/4
正解 【 在 Solmyr 的大作中提到: 】 : 逗号表达式的值是最右边表达式的值
AHbupt机器人#6 · 2008/12/4
【 在 pmps 的大作中提到: 】 : i would prefer make_pair(2,3), where the types are automatically deduced 的确是方便些pair<int,float> a就不能 make_pair(2,1.111)了吧