Does the following sequence produce a division by zero Expla
Does the following sequence produce a division by zero? Explain your answer. Assume the code is correct. if ((j e) && (1/ (j-1) 10)) cout
Solution
1. No, it will not generate the error division by 0. As the initial value of j=-1. The if condition has two conditions with && operator. Here the first condition (j>0) is false. As we know true and false is false, the code will not attempt to check the second condition (1/(j+1)>10).
2. The output is
other is even
In this code if has two conditions with && operator. If any of the one condition is false, the control will go to else part.
Here the first condition (myInt !=0) is false ad the value of myInt is 0. Thus the else part gets evaluated.
