Logical Operators in C++
What are the Logical Operators in C++?
What is AND, NOT, OR in operators?
The logical operators
are used to logically combine, compare Boolean conditions or expressions.
The following table lists the operators.
|Operator ||Action |
|! ||NOT |
|&& ||AND |
||| ||OR |
using namespace std;
cout << "Enter the Date::";
cin >> date;
if ((date!=0)&&(date>10 && date<20) )
cout << "Date is in the Middle of the Month" ;
else if (date<1 || date>31)
cout << "Enter a valid DATE";
cout << "Date is either the start or end of the Month";
Enter the Date:: 12
Date is in the Middle of the Month
In the above example the "&&" operator is used to combine two conditions that specifies the date range between 10 and 20. The "!" is used to check if the date is not equal to "0". The "||" operator is used to check if the the date enter is between the range "1-31".
This is how, logical operators used in C++.