Can someone explain me this question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can someone explain me this question

What is output in this code: int a = (1,2,3,4); cout << a; I have answered 1,2,3,4 and the correct answer is 4. Why?

13th Dec 2018, 5:30 PM
Edin Hajdarevic
Edin Hajdarevic - avatar
4 Answers
+ 8
comma operator evaluates left values and discrads results then returns right value cout << (cout << 2, cout << 3, 4); Output: 234 https://stackoverflow.com/q/52550/9132046
13th Dec 2018, 5:43 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 1
Thanks
13th Dec 2018, 5:47 PM
Edin Hajdarevic
Edin Hajdarevic - avatar
+ 1
Its not correct syntax for array, I didn't get why they use simple brackets instead of curly braces
14th Dec 2018, 6:25 AM
Valeti Naveen
0
Valeti Naveen that's what confused me
16th Dec 2018, 10:44 AM
Edin Hajdarevic
Edin Hajdarevic - avatar