Page 264 - Computer_Science_F5
P. 264
Logical NOT operator “!” involves only one value. It performs the Boolean operation
by reversing the value of the expression to be operated. If the value of the expression
is true, it changes that value to false. Otherwise, if the expression is false, it changes
that value to true. Logical OR operator “| |”is used to conclude a set of the conditions.
If either of the condition is true, then the statements are executed. Logical AND Chapter Four: Object oriented programming with C++
FOR ONLINE READING ONLY
operator “&&” is used to make a conclusion from the conditions where the execution
takes place when all conditions are true. The following C++ Program Example 4.19
demonstrates the operation of logical operators. The output is shown in Figure 4.35.
Program Example 4.19:
Use of relational operators
#include <iostream>
using namespace std;
int main()
{
bool answer;
cout<<”Condition : Return value”<<endl;
answer = ((9>2)&&(17>2));
cout<<”(9>2)&&(17>2)”<<” : “<< answer<<endl;
answer = ((8>13)||(5!=3));
cout<<”(8>13)||(5!=3)”<<” : “<< answer<<endl;
answer = ((15!=20)&&(27>30));
cout<<”(15!=20)&&(27>30)”<<” : “<< answer<<endl;
return 0;
}
Output:
Figure 4.35: Output of the program
255
Student’s Book Form Five
Computer Science Form 5.indd 255 23/07/2024 12:33

