The comma operator has the lowest precedence, so this is actually
( someValue ? ++x, ++y : --x ) , --y;
Try the program and make sure someValue is true, it'll only increment I not j :/ so
You think it's going to be 16 because your brain is assuming this:
|
someValue ? (++x, ++y) : (--x, --y);
|
But it's actually as Cubbi describes.
Last edited on
btw:
someValue ? ++x, ++y : --x, --y;
is a horrible line of code :)
No I meant this, see the picture.
http://postimg.org/image/4xvq0h72l/
Only x is incremented, why is y not incremented?
OH lol, just relised but what I dont get is would the ?: not need a Semi colon to end it?
Last edited on
A semicolon only ends statements. With the comma operator, you can have infinitely many expressions in a statement.