Written version of Logical operators in C++

C++Server Side ProgrammingProgramming

In c++ programming language, there are keywords that can be used in place of logical operators. The keywords are initially used in c when the keyboards didn’t support symbols like &&, !, ||, etc. Now, here are some written version of logical operators in c++.

Operators and their written versions are −

OperatorSymbolsWritten version
And operator&&and
Or operator||or
Not operator!not
Not equal to operator!=not_eq
Bitwise and operator&bitand
Bitwise or operator|bitor
Bitwise XOR operator^
And equal to operator&=and_eq
Or equal to operator|=or_eq
XOR equal to operator^=

Program to show the implementation of our program


 Live Demo

using namespace std;
int main(){
   int x=1, y=0;
   cout<<"Written logical operators are :\n";
   cout<<x<<" and "<<y<<" = "<<(x and y)<<endl;
   cout<<x<<" or "<<y<<" = "<<(x or y)<<endl;
   cout<<x<<" bitwise and "<<y<<" = "<<(x bitand y)<<endl;
   cout<<x<<" not equal to "<<y<<" = "<<(x not_eq y)<<endl;
   return 0;


Written logical operators are :
1 and 0 = 0
1 or 0 = 1
1 bitwise and 0 = 0
1 not equal to 0 = 1

Pros and cons of using written operators −

Pro − improves the readability of the code.

Pro − it is useful when used with the keyboard that does not support characters like |, &, !, etc.

Cons − using written keywords in a statement, needs space between operators and operands otherwise error might occur.

Published on 17-Apr-2020 12:36:37