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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -