I've declared variables and their values before but I've never done this on a single line before.
If I write
A, B = 0.0, 2;
Does this mean
A = 0
and
B = 2?
I've declared variables and their values before but I've never done this on a single line before.
If I write
A, B = 0.0, 2;
Does this mean
A = 0
and
B = 2?
This expression
A, B = 0.0, 2;
is an expression with the comma operator (here are two comma operators). It can be presented like
( A ), ( B = 0.0 ), ( 2 );
As result the variable B
will get the value 0.0. The variable A
will be unchanged.
From the C Standard (6.5.17 Comma operator)
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
So the value of the above expression is 2
and the type is int
. The value of the expression is not used. So the only its side effect is assigning the value 0.0
to the variable B
.