Written version of Logical Operators in C++
In this tutorial, you are going to learn about the keywords that can be used in place of logical operators. So let’s discuss the all logical operators one by one and how to implement it in C++.
1. And Operator
Symbol – &&
Keyword – and
Code:-
#include<iostream> using namespace std; int main(){ int x=1, y=0,res; res = x and y; cout << res; return 0; }
Output:-
0
2. Or Operator
Symbol – ||
Keyword – or
Code:-
#include<iostream> using namespace std; int main(){ int x=1, y=0,res; res = x or y; cout << res; return 0; }
Output:-
1
3. Not Operator
Symbol – !
Keyword – not
Code:-
#include<iostream> using namespace std; int main(){ int x=1,res; res = not x; cout << res; return 0; }
Output:-
0
4. Not equal to Operator
Symbol – !=
Keyword – not_eq
Code:-
#include<iostream> using namespace std; int main(){ int x=1, y=0,res; res = x not_eq y; cout << res; return 0; }
Output:-
1
5. Bitwise and Operator
Symbol – &
Keyword – bitand
Code:-
#include<iostream> using namespace std; int main(){ int x=1, y=0,res; res = x bitand y; cout << res; return 0; }
Output:-
0
6. Bitwise Or Operator
Symbol – |
Keyword – bitor
Code:-
#include<iostream> using namespace std; int main(){ int x=1, y=0,res; res = x bitor y; cout << res; return 0; }
Output:-
1
7. Bitwise XOR Operator
Symbol – ^
Keyword – Keyword is not available.
8. And equal to Operator
Symbol – &=
Keyword – and_eq
Code:-
#include<iostream> using namespace std; int main(){ int x=1, y=0,res; res = x and_eq y; cout << res; return 0; }
Output:-
0
9. Or equal to Operator
Symbol – !=
Keyword – or_eq
Code:-
#include<iostream> using namespace std; int main(){ int x=1, y=0,res; res = x or_eq y; cout << res; return 0; }
Output:-
1
10. XOR equal to Operator
Symbol – ^=
Keyword – Keyword is not available.
Conclusion
By now you might have gained the knowledge of how to use keywords of logical operators instead of their symbols. You might have also noticed that there is no specific keyword for operators “Bitwise XOR” and “XOR equal to”.
Leave a Reply