Converting && (logical and) operator into || (logical or) operator

c

Solution

Yes, they are equivalent, because of De Morgan's laws:

!(a && b) == !a || !b

hence

 (a && b) == !(!a || !b)

However, at any decent company, one would get fired quickly if one wrote code like this.

if (<condition>)
    return true;
else
    return false;

is redundant, and it's more readable to write

return <condition>;

instead. (maybe `return <condition> != 0` if you need to always ensure a 0 or 1 result, but this is already the case in your code, since `&&` and `||` are guaranteed to yield 0 or 1.)

Problem

bool a, b; ``` A) if (a && b) return true; else return false; B) if (!a || !b) return false; else return true; ``` I am little bit confused. Are A & B equivalent??

Original source