+ 2

What syntax is this?

Why is the output the last element? What is this syntax and what does it mean? First time I saw this xD https://code.sololearn.com/c1T3Ez1B679t/?ref=app

30th Jan 2019, 4:03 AM
Chriptus13
Chriptus13 - avatar
2 Respuestas
+ 4
The comma operator does all the expressions in order and then returns the last one. You know, like in a = 4, b = 5; The above line also happens to return `5`. It's just code that is meant to look confusing.
30th Jan 2019, 4:20 AM
Schindlabua
Schindlabua - avatar
+ 2
Schindlabua oh yeah I get it now! Damn thats strange because this actually works: int main() { int a, b; int c = (a = 1, b = 2); printf("%d %d %d", a, b, c); return 0; } // Output: 1 2 2
30th Jan 2019, 4:45 AM
Chriptus13
Chriptus13 - avatar