Bird
0
0

Given two boolean variables p and q, which expression correctly checks if exactly one is true?

hard📝 Application Q9 of 15
C - Operators and Expressions
Given two boolean variables p and q, which expression correctly checks if exactly one is true?
A!(p || q)
Bp && q
Cp || q
D(p && !q) || (!p && q)
Step-by-Step Solution
Solution:
  1. Step 1: Understand exclusive OR logic

    Exactly one true means p true and q false OR p false and q true.
  2. Step 2: Match expression

    (p && !q) || (!p && q) matches this logic.
  3. Final Answer:

    (p && !q) || (!p && q) -> Option D
  4. Quick Check:

    Exclusive OR = (p && !q) || (!p && q) [OK]
Quick Trick: Exactly one true = (p && !q) || (!p && q) [OK]
Common Mistakes:
  • Using p && q (both true)
  • Using p || q (any true)
  • Negating OR incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes