DeMorgan's & related Laws
Given a Conditional Expression, When its NOT true Given a Conditional Expression, apply the NOT operator !(cond)
How are these laws useful? if (cond) // do this when cond is true else // do this when !cond is true
if (cond) { } else // !cond Useful else comment if (cond) { } else // !cond
Useful else comment if (a < 0) cout << "negative"; else // a >= 0 cout << "zero or positive";
< >= > <= == != Relational Operators Operator "Not of" the Operator < >= > <= == !=
|| && ! Logical Operators Operator "Not of" the Operator ! ! cond is cond
if ((a <= 3) ||(b != 0)) { } else { // ((a > 3) && (b == 0)) Example 1 if ((a <= 3) ||(b != 0)) { } else { // ((a > 3) && (b == 0))
if ((a > 3) &&(b == 0)) { } else { // ((a <= 3) || (b != 0)) Example 2 if ((a > 3) &&(b == 0)) { } else { // ((a <= 3) || (b != 0))
Example 3 if ((a >=0) && (a<=9)) cout << "single digit number"; else // (a < 0) || (a > 9) cout << "notsingle digit num";
if (!(a > 3)) { } else { // (a > 3) is !!(a>3) Example 4 if (!(a > 3)) { } else { // (a > 3) is !!(a>3)