Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Results of operator applied to std::cout <<

10 views
Skip to first unread message

Paul

unread,
Sep 15, 2018, 10:37:38 AM9/15/18
to
learncpp.com says:

(std::cout << (x > y)) ? x : y;
prints 1 (true) if x > y, or 0 (false) otherwise!

Experimentation on my computer shows that this is (unsurprisingly) correct.
However, I can't follow that logic.
std::cout << 0; returns std::cout in a healthy state
so std::cout << 0; should evaluate to true.
Also std::cout << 1; should evaluate to true;

So my expectation would be that (std::cout << (x > y)) ? x : y;
always prints 1

What am I missing?

Paul

Paul

unread,
Sep 15, 2018, 10:46:15 AM9/15/18
to
Sorry, I get it now -- the ternary operator always resolves to x for the
reasons I said.
But the text is only talking about the printout --- the printout is
just std::cout<< (x > y) which is what the text says.

Paul

0 new messages