Help with Logical Operators.

Ok, so I am learning c++ as a hobby and using an online tutorial and I have come to a section about logical operators !, &&, and ||. So I understand that ! is the inverse of a variable, && means both have to be true or it is false and || means only one has to be true. So it explained that but it gave these problems to solve.
Evaluate the following:
1) (true && true) || false
2) (false && true) || true
3) (false && true) || false || true
4) (5 > 6 || 4 > 3) && (7 > 8)
5) !(7 > 6 || 3 > 4)

And it gives these answers to check your work:
1)
(true && true) || false == true || false == true

2)
(false && true) || true == false || true == true

3)
(false && true) || false || true == false || false || true == false || true == true

4)
(5 > 6 || 4 > 3) && (7 > 8) == (false || true) && false == true && false == false

5)
!(7 > 6 || 3 > 4) == !(true || false) == !true == false

Please explain how they got these answers, and why do the answers seem like they are too long? Please help me out, Im just learning this on my own so I have no teacher or anyone to ask. Thanks!
Those anwers look partially expanded, and while some are technically correct, they're wrong. What exactly was the goal?

I'm pretty sure these are the correct answers:
1. true
2. true
3. true
4. false
5. false
Last edited on
The answers are long because they have included all the steps. It's like when you have a complicated math expression, you often do many small steps until you find the final answer.
Last edited on
The "steps" you describe seem all mushed together, unless the OP hand-copied them wrong.
It's unfortunate the == was used to seperate them. If you replace all occurrences of == with -> it becomes more clear.

1)
(true && true) || false -> true || false -> true

2)
(false && true) || true -> false || true -> true

3)
(false && true) || false || true -> false || false || true -> false || true -> true

4)
(5 > 6 || 4 > 3) && (7 > 8) -> (false || true) && false -> true && false -> false

5)
!(7 > 6 || 3 > 4) -> !(true || false) -> !true -> false
Hmmm, the concept for these operators seemed extremely simple until I got to these problems. Take number 4 for example. I understand 5 IS NOT greater than 6 so its false, 4 IS greater than 3 so it's true and 7 IS NOT greater so its false so of the answer I understand (false || true) && false this much, but what does this part == true && false == false mean?? Heres a link to the exact page so you can look over and see how it's written:
http://www.learncpp.com/cpp-tutorial/36-logical-operators/
By the way is my question making sense? Hope so, everything else I've learned I understand but Ive been struggling with this part for a couple hours and cant make sense of it.
(false || true) is true so you can replace (false || true) with true in (false || true) && false to get true && false.
Topic archived. No new replies allowed.