104k views
5 votes
If a programming language does not use short-circuit evaluation, what is the output of the following code fragment if the value of myInt is 0? int other = 3, myInt; if(myInt != 0 && other % myInt != 0) printf("other is odd\\"); else printf("other is even\\");

User EAW
by
8.3k points

1 Answer

3 votes

Answer:

other is even.

Explanation:

Since the value of myInt variable is assumed to be 0 and we have other =3. In the if condition the expression is true only when the myInt is not equal to zero and and the remainder of other/myInt is not equal to zero (%modulus operator provides the remainder). myInt is 0 hence the expression returns false and the else block is executed so it prints other is even.

User KuKu
by
7.8k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.