logic - C++ logical operator Q -
this question might seem noobish question this: these 2 statements logically same?
int a; int b; int c; if (!a && !b && !c) //do if (!(a || b || c)) //do
a truth table useful understanding logics.
#include <iostream> using std::cout; using std::endl; int main(void) { int a; int b; int c; bool differ = false; cout << "a b c x y\n"; (a = 0; <= 1; a++) { (b = 0; b <= 1; b++) { (c = 0; c <= 1; c++) { bool x = (!a && !b && !c); bool y = (!(a || b || c)); differ = differ || (x != y); cout << << " " << b << " " << c << " " << x << " " << y << "\n"; } } } if (differ) { cout << "they differ" << endl; } else { cout << "they same" << endl; } return 0; }
actually same de morgan's laws:
!a && !b && !c = !(a || b) && !c = !((a || b) || c) = !(a || b || c)
(=
here not c++ assignment operator)
Comments
Post a Comment