Why does return 0 or break not work with the comma operator?
I can write the code if(1) x++, y++; instead of if(1) {x++; y++;}, but in some cases it does not work (see below). It would be nice if you tell me about this. int x = 5, y = 10; if (x == 5) x++, y++; // It works if (x == 5) x++, return 0; // It shows an error The same applies to for loops: for (int i = 0; i < 1; i++) y++, y += 5; // It works for (int i = 0; i < 1; i++) y++, break; // Does not work That's because return and break are statements, not expressions. As such, you cannot use it in another expression in any way. if and the others are similarly also statements. What you can do however is rewrite your expression (for return) so that it's not nested in an expression - not that I recommend writing code like that: return x++, 0; You can't do that for break because it doesn't accept an expression. The comma operator is for expressions. The return statement and other pure statements are not expressions. The comma operator is a binary operator ...