In C++ Language
if a value is zero, it can be used as the logical value false.
if a value is not zero, it can be used as the logical value true.
There is three type of logical operator
1. Not operator ( ! )
This unary operator convert true to false and false to true.
2. And ( && )
The result of This Binary operator is true only when
both operator is true; it is false in all other case.
3. Or ( || )
The result is false if both oprands are false; its true all other case.
Demonstrates the result of logical operator
Input:
Output:
if a value is zero, it can be used as the logical value false.
if a value is not zero, it can be used as the logical value true.
There is three type of logical operator
1. Not operator ( ! )
This unary operator convert true to false and false to true.
2. And ( && )
The result of This Binary operator is true only when
both operator is true; it is false in all other case.
3. Or ( || )
The result is false if both oprands are false; its true all other case.
Demonstrates the result of logical operator
Input:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <iostream.h> #include <conio.h> int main() { cout <<" 5 && - 3 is: " << ( 5 && - 3)<< endl; cout <<" 5 && 0 is: " << ( 5 && 0)<< endl; cout <<" 0 && 5 is: " << ( 0 && 5)<< endl; cout <<" 5 || 0 is: " << ( 5 || 0)<< endl; cout <<" 0 || 5 is: " << ( 0 || 5)<< endl; cout <<" 0 || 0 is: " << ( 0 || 0)<< endl; cout <<" !5 && !0 is: " << (!5 || !0)<< endl; cout <<" !5 || !0 is: " << (!5 || !0)<< endl; cout <<" !5 || 0 is: " << (!5 || 0)<< endl; cout <<" 5 || !0 is: " << ( 5 || !0)<< endl; getch(); return 0; } // main |
Output:
5 && - 3 is: 1 5 && 0 is: 0 0 && 5 is: 0 5 || 0 is: 1 0 || 5 is: 1 0 || 0 is: 0 !5 && !0 is: 0 !5 || !0 is: 0 !5 || 0 is: 05 || !0 is: 1
No comments:
Post a Comment