Search code examples
cif-statementevaluation

Evaluation of this statement


I am reading a C book and don't understand this statement it is asking me to evaluate:

!(1 && !(0 || 1))

I can understand some things here... This is what I have so far, not(1 and not(0 or 1))

So is it not 1 and not 0 or 1? Or is it not 1 and 0 or 1? Do those two ! cancel each other out like a double negative? The answer is true but I expected false.

What is the explanation?


Solution

    1. (0 || 1) == 1
    2. !1 == 0
    3. 1 && 0 == 0
    4. !0 == 1 also known as true :)

    Keep in mind that || and && are short circuit operators, but in this case you still have to evaluate the right side because the operators do not short circuit