It is my understanding that the term j = i
will be executed before ++i
in the statement
j = i, ++i;
.
Does the C++ standard guarantee that j = i
will be executed before ++i
in the loop
for (auto i = std::next(begin), j = begin; i!= end; j= i, ++i)
?
The comma operator in c comes with the lowest precedence in the C language. The comma operator is basically a binary operator that initially operates the first available operand, discards the obtained result from it, evaluates the operands present after this, and then returns the result/value accordingly.
The commas you see in C for loops are not part of the syntax of the for loop specifically. They are just manifestations of the comma operator. Commas are major separators between arguments in function calls and between parameters in function declarations, but semicolons are not used.
You can use the comma operator when you want to include multiple expressions in a location that requires a single expression. The most common usage of this operator is to supply multiple parameters in a for loop.
The comma operator introduces a sequence point and, as such, this behavior is guaranteed by the C++ standard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With