Computer Science, asked by arshadraza7292, 8 hours ago

If I want to print 1, which expres Consider value of num1 = 20 should I use from the options below? O printf("%d",num1 >=20 && num1 < 35 && num1=22); O printf("%s",num1 35 && num1!=22); O printf("%d",num1 >=20 && num1 < 35 && num1!=22); 47​

Answers

Answered by divus14
21

Answer:

The third expression will give you desired output.

Explanation:

Let's eliminate expression 2 as it is will give segmentation error due to incorrect formatting used in printf statement.

Here we need to consider the the logical operator && in getting the solution

  1. In first expression num1>=20 && num1<35 && num1==22 : num1>=20 is 1, num1<35 is 1 and num1==22 is 0. So logically evaluating the result would be (1 && 1 && 0) = 0. The statement will print 0.
  2. In third expression num1>=20 && num1<35 && num1!=22: num1>=20 is 1,num1<35 is 1 and num1!=22 is 1. So logically evaluating the result would be (1 && 1 && 1) = 1. The statement will print 1.

Hope this helps,

Similar questions