+ 3

Why this prints 3?

#include <stdio.h> int main() { int a = (1,2,3); printf ("%d", a); return 0; }

30th Jan 2019, 4:54 AM
Mihai C
Mihai C - avatar
3 Réponses
+ 6
Because it evaluates the last expression and returns it. So the last expression here is "3"
30th Jan 2019, 4:57 AM
Chriptus13
Chriptus13 - avatar
+ 5
A different behaviour found for C++ assignment operator, without the parentheses, the first value will be taken instead. (Edit) Apparently the same behaviour in C language. https://code.sololearn.com/c3hQ2573ECgC/?ref=app
30th Jan 2019, 5:29 AM
Ipang
+ 4
https://www.sololearn.com/discuss/1672605/?ref=app
30th Jan 2019, 4:57 AM
Chriptus13
Chriptus13 - avatar