Difference between revisions of "cpp/keyword/and"
From cppreference.com
m (→Example: ~) |
(Added link to cpp/language/operator_logical) |
||
Line 3: | Line 3: | ||
===Usage=== | ===Usage=== | ||
− | * [[cpp/language/operator alternative | alternative operators]]: as an alternative for {{tt|&&}} | + | * [[cpp/language/operator alternative | alternative operators]]: as an alternative for {{tt|&&}} {{lt|cpp/language/operator_logical|(Logical AND operator)}} |
===Example=== | ===Example=== |
Revision as of 06:40, 24 May 2022
Usage
- alternative operators: as an alternative for
&&
(Logical AND operator)
Example
Run this code
#include <iostream> #include <string> void truth_table_entry(bool const x, bool const y) { const std::string s[] = {"false ", "true ", "and ", " "}; const std::string x_and_y = s[x] + s[2] + s[y]; const std::string r = s[x and y] + s[3]; if (x + y == 0) std::cout << "┌──────────────────┬─────────┐\n"; if (x + y <= 2) std::cout << "│ " << x_and_y <<" │ "<<r<<" │\n"; if (x + y == 2) std::cout << "└──────────────────┴─────────┘\n"; } int main() { truth_table_entry(false, false); truth_table_entry(false, true ); truth_table_entry(true , false); truth_table_entry(true , true ); }
Output:
┌──────────────────┬─────────┐ │ false and false │ false │ │ false and true │ false │ │ true and false │ false │ │ true and true │ true │ └──────────────────┴─────────┘