用括号括起来的用逗号分隔的值列表在C中意味着什么? a =(1,2,3); [英] What does a comma separated list of values, enclosed in parenthesis mean in C? a = (1, 2, 3);

查看:101
本文介绍了用括号括起来的用逗号分隔的值列表在C中意味着什么? a =(1,2,3);的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚遇到的代码基本上执行以下操作:

I've just come across code that essentially does the following:

int a = (1, 2, 3);

我以前从未见过这种表示法。是什么意思?

I've never seen this notation before. What does it mean?

推荐答案

这是逗号运算符:对 a,b 的求值首先导致 a ,然后是 b ,结果是 b

This is the comma operator: evaluation of a, b first causes a to be evaluated, then b, and the result is that of b.

int a =(1、2、3); 首先计算 1 ,然后 2 ,最后是 3 ,并使用最后一个 3 来初始化 a 。在这里是没有用的,但是当的左操作数有副作用(通常:当它是函数调用)时,它很有用。

int a = (1, 2, 3); first evaluates 1, then 2, finally 3, and uses that last 3 to initialise a. It is useless here, but it can be useful when the left operand of , has side effects (usually: when it's a function call).

这篇关于用括号括起来的用逗号分隔的值列表在C中意味着什么? a =(1,2,3);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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