Demonstrates the logical operators by producing their truth tables. - C++ Operator

C++ examples for Operator:Logical Operator

Description

Demonstrates the logical operators by producing their truth tables.

Demo Code

#include <iostream>

int main(int argc, const char *argv[]) {
    // create truth table for && (logical AND) operator
    std::cout << std::boolalpha << "Logical AND (&&)"
              << "\nfalse && false : " << (false && false)
              << "\nfalse && true  : " << (false && true)
              << "\ntrue  && false : " << (true && false)
              << "\ntrue  && true  : " << (true && true) << "\n\n";

    // create truth table for || (logical OR) operator
    std::cout << "Logical OR (||)"
              << "\nfalse || false : " << (false || false)
              << "\nfalse || true  : " << (false || true)
              << "\ntrue  || false : " << (true || false)
              << "\ntrue  || true  : " << (true || true) << "\n\n";

    // create truth table for ! (logical negation) operator
    std::cout << "Logical NOT (!)"
              << "\n!false : " << (!false) << "\n!true  : " << (!true)
              << std::endl;//from   w  ww.  ja va2  s. c  om
    return 0;
}

Result


Related Tutorials