int a=1,3,15;
is not allowed:
prog.c: In function ‘main’:
prog.c:2:13: error: expected identifier or ‘(’ before numeric constant
int a=1,3,15;
This is because it is parsed as a list of declarations, the items being a=1
, 3
, and 15
(and 3
is not a valid variable name).
If you write
int a;
a = 1,3,15;
that is parsed as (a = 1), 3, 15;
because =
binds tighter than ,
.
On the other hand,
int b=(1,2,4);
declares a single variable b
initialized from the expression (1,2,4)
. The parens are simply for grouping.
,
(comma) is an operator that evaluates (and throws away the result of) its left operand, then evaluates and returns its right operand. So b
ends up being 4
(and some compilers will warn about ignoring the values of 1
and 2
).