I can't understand output of this program:
#include<iostream>
using namespace std;
int main()
{
int x = 1 , y = 1, z = 1;
cout << ( ++x || ++y && ++z ) << endl; //outputs 1;
cout << x << " " << y << " " << z ; //x = 2 , y = 1 , z = 1;
return 0;
}
Output:
1
2 1 1
If ||
is evaluated first then this output is fine, however this article says that &&
has a higher precedence than ||
, and thus it must be evaluated first. If this is the case then according to me output should be:
1
1 2 2
as ++y && ++z
would evaluate to true
and thus ++x
won't be evaluated.