what will be the value of z and how pls help !!!! | SoloLearn: Learn to code for FREE!


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);

c++ c

6/3/2020 5:20:22 PM


4 Answers

New Answer


oh now i get it you were a great help thanks


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.




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.