Question 10
Back to Exercise
How do you test that exactly one of two int flags a and b (which may hold any value) is true?
- A a ^ b
- B !a != !b Correct
- C a != b
- D a || b
Correct Answer: Option B
C has no logical XOR. !a and !b are 0 or 1, so !a != !b is true exactly when one flag is set. a ^ b fails for a = 2, b = 4 (result 6, "true", though both are set), and a != b fails for 2 and 4 too.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!