Logical operator
Logical operator are three types these are -
1.)Logical AND (&&)
2.)Logical OR (||)
3.)Logical NOT(!)
Logical AND (&&)
Logical AND operator works on the two operand .According to logical AND operator if both
operands are true value then value return true(1) otherwise false(0) values suppose two operands x and Y and see table :-
X
|
Y
|
X&&Y
|
1
|
1
|
1
|
1
|
0
|
0
|
0
|
1
|
0
|
0
|
0
|
0
|
Program example:-
Notes:- Zero is taken false value otherwise greater value value than Zero is taken always
true.
Logical OR (||)
This operator works on two operands. According to logical OR operator if one from both
operands are true then value return true(1) an also true when both operators true then
returns the true(1) value otherwise false.Suppose x and two operands :-
X
|
Y
|
X||Y
|
1
|
1
|
1
|
1
|
0
|
1
|
0
|
1
|
1
|
0
|
0
|
0
|
1.) #include<stdio.h>
int main()
{
printf("%d",4||6);
return 0;
}
Output : 1
2.) #include<stdio.h>
int main()
{
printf("%d",6||0);
return 0;
}
Output : 1
Logical NOT (!)
The logical NOT operator works only on the single operands if operand is true then it returns false. If operand is false then it returns true.Suppose X an operands :-
X
|
!X
|
1
|
0
|
0
|
1
|
1.) #include<stdio.h>
int main()
{
printf("%d",!6);
return 0;
}
Output :- 0
Equality operators
Basically equality operator are two types these are -
1.) (==) equal to operator
2.) (!=) not equal to operator
Equality operator have low precedence than relational operator(<,>,<=,>=) and assignment operator.equal to(==) operator return true(1) if both side of equal to operator same value
otherwise return false(0). And not equal to returns true if both side are not equal to(!=)
otherwise return false(0).
Example programs -
1.) #include<stdio.h>
int main()
{
printf("%d",2==2);
return 0;
}
Output : 1
2.) #include<stdio.h>
int main()
{
printf("%d",2==3);
return 0;
}
Output : 0
3.) #include<stdio.h>
int main()
{
printf("%d",2!=3);
return 0;
}
Output : 1
4.) #include<stdio.h>
int main()
{
printf("%d",5!=5);
return 0;
}
Output:- 0
Relational operators
Relational operator are operator that compare the value.It gives the true(1) value if condition
condition is true otherwise false(0). these operators are:-
Operator
|
Meaning of operator
|
>
|
greater than
|
<
|
less than
|
>=
|
greater or equal to
|
<=
|
less or equal to
|
Notes - Having low precedence than equality operator
Relational operator check condition if correct than value returns true(1) otherwise false(0). Examples :- )5<6 gives 1
1. 6>5 gives 1 true
2. 7>9 gives 0 false
3. 6<5 gives 0 false
4. 5<=8 gives 1 true
5. 8<=5 gives 0 false
6. 9>=7 gives 1 true
7. 7>=9 gives 0 false
Program example -
#include<stdio.h>
int main()
{
printf("%d",5>7);
return 0;
}
Output : 0
By the following rule give your answer of these question
1.) #include<stdio.h>
int main()
{
printf("%d",8&&0);
return 0;
}
2.) #include<stdio.h>
int main()
{
printf("%d",100||1);
return 0;
}
3.) #include<stdio.h>
int main()
{
printf("%d",!0);
return 0;
}
4.) #include<stdio.h>
int main()
{
printf("%d",56&&12);
return 0;
}
5.) #include<stdio.h>
int main()
{
printf("%d",!3||44);
return 0;
}
0 Comments
Any query comment in comment box thank you
Emoji