This is due to the operator precedence and the order of evaluation. =
binds harder than ,
and from that we can figure out that the below two expressions are the same:
i = 1,2,3,4,5 /* <- same as -> */ (i = 1),(2),(3),(4),(5)
side-note: the comma operator is the "weakest" operator of them all
Why does the comma operator yield the last value of our list?
To put it simple this operator evaluate the first operand only to discard it and move on to the next one, it binds left-to-right which means that it will start from the left, and continue walking towards the right.
Where can I read more about this topic?
- cppreference.com - C++ Operator Precedence
- swansontec.com - C Language Operator Precedence