I can\'t understand output of this program:
#include
using namespace std;
int main()
{
int x = 1 , y = 1, z = 1;
cout << ( ++x || +
Let's put the excess parantheses in:
( ++x || (++y && ++z ))
Then it's easy to see that (++y && ++z )
will only be evaluated if ++x
is 0. So you can see that irrespective of operator precedence, the short-circutting nature of ||
means that the right hand side is only evaluated if the left hand side is 0.
(If the right hand side is evaluted, then note that ++z
will only be evaluated if ++y
is not 0.)