逗号运算符是什么意思?

What does the comma operator mean?

我以前声明过变量及其值,但我以前从未在一行中这样做过。

如果我写

A, B = 0.0, 2;

这是否意味着

A = 0 

B = 2? 

这个表达式

A, B = 0.0, 2;

是带逗号运算符的表达式(这里有两个逗号运算符)。可以这样呈现

( A ), ( B = 0.0 ), ( 2 );

因此,变量 B 将获得值 0.0。变量 A 将保持不变。

来自 C 标准(6.5.17 逗号运算符)

2 The left operand of a comma operator is evaluated as a void expression; there is a sequence point between its evaluation and that of the right operand. Then the right operand is evaluated; the result has its type and value

所以上面表达式的值为2,类型为int。不使用表达式的值。所以它唯一的副作用是将值 0.0 分配给变量 B.