联想考题: int i=(j=4,r=8,l=16,m=32); i值是多少? 哪位兄台指点一下!

hunters2000 2005-07-11 03:27:00
联想考题: int i=(j=4,r=8,l=16,m=32); i值是多少? 哪位兄台指点一下!偶实在是不懂
...全文
306 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
szws 2005-07-11
  • 打赏
  • 举报
回复
显然是32嘛
逗号操作符是从左往右的,最右边的值为整个表达式的值
K 2005-07-11
  • 打赏
  • 举报
回复
32
yangwuhan 2005-07-11
  • 打赏
  • 举报
回复
记错了
"C中只有四个运算符&&、||、?:和,指定了求值顺序。逗号操作符运算顺序是从左往右。"

结果是32
Kernall 2005-07-11
  • 打赏
  • 举报
回复
是32

A.7.18 Comma Operator
expression:
assignment-expression
expression , assignment-expression
A pair of expressions separated by a comma is evaluated left-to-right, and the value of the left expression is discarded. The type and value of the result are the type and value of the right operand. All side effects from the evaluation of the left-operand are completed before beginning the evaluation of the right operand. In contexts where comma is given a special meaning, for example in lists of function arguments (Par.A.7.3.2) and lists of initializers (Par.A.8.7), the required syntactic unit is an assignment expression, so the comma operator appears only in a parenthetical grouping, for example,

f(a, (t=3, t+2), c)

has three arguments, the second of which has the value 5.
yangwuhan 2005-07-11
  • 打赏
  • 举报
回复
32?
cy2005abc 2005-07-11
  • 打赏
  • 举报
回复
32,最右的值
Maconel 2005-07-11
  • 打赏
  • 举报
回复
()中的“,”叫做逗号操作符。楼主可以参考一下c++的语法书籍。
Maconel 2005-07-11
  • 打赏
  • 举报
回复
不同的编译器可能不一样,不过一般来说,应该是32,也就是()中的最后一个表达式的值。
foochow 2005-07-11
  • 打赏
  • 举报
回复
32??
yangwuhan 2005-07-11
  • 打赏
  • 举报
回复
,运算符的求值顺序是从右向左
所以(j=4,r=8,l=16,m=32)的值就是4
yangwuhan 2005-07-11
  • 打赏
  • 举报
回复
4
sf

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧