C++ COUT with arguments? (a, b, c) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

C++ COUT with arguments? (a, b, c)

I come along with c++ code using cout with some kind of arguments in parentheses, but only last one was printed out, can somebody please explain why? Thanks. cout << (1,2,3); Output: 3. https://code.sololearn.com/ccCiIoexxXe8/?ref=app

4th Mar 2018, 11:08 AM
Miroslav M
Miroslav M - avatar
3 Answers
+ 5
Nice question. I got the results when I googled about it. This is because of comma operator. Visit the given link for description. https://stackoverflow.com/questions/28326062/what-is-the-output-of-cout-a-b-and-why
4th Mar 2018, 11:27 AM
Hrishikesh Kulkarni
Hrishikesh Kulkarni - avatar
+ 1
Updated code. all expressions are processed but not used in cout, only the last one. https://code.sololearn.com/ccCiIoexxXe8/?ref=app
4th Mar 2018, 1:06 PM
Miroslav M
Miroslav M - avatar
0
Thanks HK. I tried to google this, but was not sure how to define the question. So I see now, the comma operator is the key. It evaluates all the comma separated value, but result is not used, only the last one.
4th Mar 2018, 12:24 PM
Miroslav M
Miroslav M - avatar