+ 1
Why does the following code print 2 instead 5?
A part of Code: int x; x = 2, 3, 4, 5; printf("%d", x);
1 Réponse
+ 4
You can string up several operations with commas, but then you can't control in which order they're executed, so normally you'd use semicolons instead.
Also, you can just write any literal for a value into your code, like 42, without anything else - it just won't do anything.
So this is somewhat like:
x = 2;
3;
4;
5;
Lines 2 to 4 become meaningless statements.
If you do it like this, you'll get a warning for ineffective statements though.