Here, the program discusses the logical operators in C++.
Logical operators in C++ can be defined as the operators or the symbols which help to expressions and to make the resultant expression. The value of the resultant will only depend on the input expression and the logical operator's meaning. Common logical operators include AND, OR, and NOT. it is mainly used to check the validity of comparative operations and in decision-making.
Declare a Boolean-type variable to store the status of the logical operations.
Explanation of logical operator program
Step 1: Call the header file iostream
.
Step 2: Use the namespace std
.
Step 3: Open the integer type main function; int main();
Step 4: Declare a boolean type variable result.
Step 5: check (3 != 5) && (3 < 5); call step 13
Step 6: check (3 == 5) && (3 < 5); call step 13
Step 7: Check (3 == 5) && (3 > 5); call step 13
Step 8: Check (3 != 5) || (3 < 5); call step 13
Step 9: Check (3 != 5) || (3 > 5); call step 13
Step 10: Check (3 == 5) || (3 > 5); call step 13
Step 11: Check !(5 == 2); call step 13
;
Step 12: Check !(5 == 5); call step 13
Step 13: Print the value of the variable result.
Step 14: Exit;
#include <iostream>
using namespace std;
int main() {
bool result;
result = (3 != 5) && (3 < 5); // true
cout << "(3 != 5) && (3 < 5) is " << result << endl;
result = (3 == 5) && (3 < 5); // false
cout << "(3 == 5) && (3 < 5) is " << result << endl;
result = (3 == 5) && (3 > 5); // false
cout << "(3 == 5) && (3 > 5) is " << result << endl;
result = (3 != 5) || (3 < 5); // true
cout << "(3 != 5) || (3 < 5) is " << result << endl;
result = (3 != 5) || (3 > 5); // true
cout << "(3 != 5) || (3 > 5) is " << result << endl;
result = (3 == 5) || (3 > 5); // false
cout << "(3 == 5) || (3 > 5) is " << result << endl;
result = !(5 == 2); // true
cout << "!(5 == 2) is " << result << endl;
result = !(5 == 5); // false
cout << "!(5 == 5) is " << result << endl;
return 0;
}
(3 != 5) && (3 < 5) is 1 (3 == 5) && (3 < 5) is 0 (3 == 5) && (3 > 5) is 0 (3 != 5) || (3 < 5) is 1 (3 != 5) || (3 > 5) is 1 (3 == 5) || (3 > 5) is 0 !(5 == 2) is 1 !(5 == 5) is 0