The condition num! =65 cannot be replaced by

2022

The condition num! =65 cannot be replaced by

  1. A.

    num >65 || num <65

  2. B.

    !( num ==65)

  3. C.

    num −65

  4. D.

    !(num−65)

Attempted by 990 students.

Show answer & explanation

Correct answer: D

Goal: determine which expression cannot replace the condition num != 65.

Key insight: an expression can replace num != 65 only if it evaluates to true exactly when num is not equal to 65.

  • num > 65 || num < 65: This checks whether num is either greater than or less than 65, which precisely means num ≠ 65. Hence, it is equivalent.

  • !(num == 65): Negating the equality condition gives true when num is not 65. Hence, it is equivalent.

  • num - 65: In languages like C/C++, nonzero values are treated as true and zero as false. This expression becomes zero only when num == 65, so it behaves like num != 65. However, in strongly typed languages (like Java), this is invalid as a boolean condition.

  • !(num - 65): This becomes true only when num - 65 == 0, i.e., when num == 65. Hence, it represents num == 65, which is the opposite of num != 65.

Conclusion: The expression !(num - 65) cannot replace num != 65 because it evaluates to true when num equals 65, not when it is different.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Mppsc Assistant Professor