Because =
has a higher precedence than ,
(which has the lowest), the first is the same as
(i = 1),2,3,4,5;
which assigns 1
to i
(i = 1
) then evaluating the expressions 2
, 3
, 4
, and 5
through the comma operators (the whole expression actually results in 5
, which is not used). In the second one,
(1,2,3,4,5)
is parenthesized, therefore it will be first evaluated before =
. It results in 5
(the right-most expression; this is the behavior of the comma operator) which is then assigned to i
.
i = (1,2,3,4,5);
| |
\---------\--- results in 5 then is assigned to i
See operator precedence Wikipedia article.