+ 1
what will be the value of z and how pls help !!!!
int x=1, y=0, z=5; int a = x && y || z++ ; printf("%d",z);
4 Antworten
+ 2
oh now i get it
you were a great help thanks
+ 1
x && y is executed first because && has higher precedence than ||.
1 && 0 -> false or 0
0 || z -> true or 1 since z is not 0.
Since z was 5 and is incremented.
The output when printing will be 6.
Put y=1 and you can see the z++ is never reached and you will get 5 as output.
+ 1
thanks
0
Because for an && expression to be true, both the conditions on the either side of the && operator has to be true. If the one on left is false then it will not even check the one on the right. Do you get it? Because it is obvious that it will return false.
So since 1 && 0 is false.
Then false && z++ is also false so z++ is again not executed.
But in || operator any one condition in either side has to be true. So if the one on left is true then it will not check the right one. Just like I mentioned previously.