I Need Help

In Quiz 3 there is a question:

Question 2:
What would the following expression evaluate to? (((true || false) && true) || false)

Answer: True
Verify with cout << boolalpha << (((true || false) && true) || false);

Could someone explain the logic to me? I know the || means OR and the && means AND.
I just can’t figure out how it turns out to be true. Is it because of the pair of () the true is in?

If you break it down into its parts you would get
(true || false) = T
(true && true) = T
(true || false) = T

If I’m not mistaken its just like algebra where you have to do the inner most parentheses first and work your way out. Since with OR only 1 condition has to be true for it to become T, its always T unless its double false.

Also, http://kias.dyndns.org/comath/21.html is a very good and pretty simple site that I came across while trying to understand logic tables and it helps quite a bit.

2 Likes

Thank you Bryan, I hit this one in the quiz as well and was confused. It was confusing initially to remember that ‘true’ and ‘false’ represent placeholders for something evaluating as either. This cleared it up.

Privacy & Terms