Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/keyword/and"

From cppreference.com
< cpp‎ | keyword
m (Example: ~)
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

 
 
C++ language
General topics
Flow control
Conditional execution statements
if
Iteration statements (loops)
for
range-for (C++11)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications (until C++17*)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
const/volatile
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
explicit (C++11)
static

Special member functions
Templates
Miscellaneous
 
 

Usage

Example

#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    │
└──────────────────┴─────────┘