+ 3

Can someone explain its output to me? Output: 1211

#include <iostream> using namespace std; int main() { int x=1, y=1, z=1; cout<<(++x||++y&&++z); cout<<x<<y<<z; return 0; } https://code.sololearn.com/cPcTxLyQDF8O/?ref=app

28th Apr 2019, 8:11 AM
Avinash Avi
Avinash Avi - avatar
4 Answers
+ 4
First cout is true, so it prints a '1'. To calculate the result of the first cout it only has to execute ++x. So x is now 2. Because ++y and ++z are never executed they remain 1. If you replace the || in the first cout by a &&, you get a different result.
28th Apr 2019, 8:41 AM
Paul
Paul - avatar
+ 4
Okay, I got it. Thank u for the answer
28th Apr 2019, 8:49 AM
Avinash Avi
Avinash Avi - avatar