- : Logical Operator :-
Operators are those symbols which are used between operands to perform Mathematical and Logical operations.
Logical Operators are those operators which are used to perform logical operations between two or more given statements or conditions to make sense that the given conditions are true or not.
these operators gives us boolean (true or false) value as Output. if given condition is true, the displayed output will be 1 where if given condition is not true (means false), so the output will be 0.
where, 1 means True
0 means False.
Logical Operators includes following Symbols -
[&&(logical And) , ||(logical Or) , !(logical Not)]
in &&(logical and) operator, if given all the condition are true, then output will be true And if anyone in given conditions becomes false, then output will be false.
Condition1. & & Condition2. Output
true true true
true false false
false true false
false false false
in ll(logical or) operator, either anyone or all the given conditions are true, then output will be true. if anything in the conditions is not true then output will be false.
Condition1. ll Condition2. Output
true true true
true false true
false true true
false false false
in !(logical not), if given conditions are "true" , the displayed output will be "false". if given conditions are "false" , the output will be "true".
!(Condition) Output
true false
false true
_________________________________________________________
A Program to understand logical operators
#include<iostream>
using namespace std ;
int main() {
int a=5, b=4, c=7, d=9;
cout<<(a>b)&&(c>d) <<endl;
cout<<(a>b)||(c>d) <<endl;
cout<<!(a>b) ;
return 0;
}
_________________________________________________________
Output :-
0
1
0
_________________________________________________________
let's understand what happened above
initially we passed two conditions, where condition-1 is (a>b) which is "true" and condition-2 is (c>b), which is false.
(1)using LOGICAL AND operator,
true & & false = false
(2)using LOGICAL OR operator,
true || false = true
(3)using LOGICAL NOT operator,
!(true) = false
where, true = 1
false = 0
_________________________________________________________
Must Read(click on the link below) :-
What is Operator in Programming Language
What is Arithmetic Operator in Programming Language
What is Relational Operator in C, C++ programming languages
What is Logical Operator in C, C++ Language (Hindi Explanation)
what is Bitwise Operator in C, C++
No comments:
Post a Comment