Logical operators in c language are the operators which combine two or more conditions and evaluate the result (i.e true or false).
For Example
Lets consider same example in relational operators ie b1( i.e basket 1) has 40 balls and b2 has 30 balls.I will now write the statement of logical operator in our language.
b1 is equal to 40 and b2 is less than 40 then i want to sum b1 and b2 Here and is used to compare the two conditions
1) b1 is equal to 40
2) b2 is less than 40
and is a logical operator in c language which runs the first condition if it finds it valid then it goes on to the next condition.If both of them is true then it gives us the result true and if it finds the first condition false then it does not go to the another condition and results in false.
There are three logical operators in c language
1) And Operator in C language ‘&&’ :-
The syntax of and operator in c languge is double ampersand symbol ‘&&’.
In c languges it is used in between conditions to combine them .
And operator in c language utilizes all conditions if all of the condition are true the result will be true and as in c language number 1 is used as true and if any one of them is false the result will be false and as you know that c languge uses 0 as false so the result will be 0.
C languge Code:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a=32,b=54;
clrscr();
printf(“%d”,(a > 1) && (a < b) );
getch();
}
Here in source code there are two conditions in c languge printf function.
a>1 since a is 34 it is obviously greater than 1 so the first condition is valid.
a<b since b is 54 and a is 34 so this condition is also true.
Since both conditions are true the result will also be true and in c languge the result is 1.
2) Or operator in C language ”
The syntax of or operator in c languge is double line symbol ” .You will use shift + backslash to get this symbol.
In c languges it is used in between conditions to combine them .
Or operator in c language is the opposite of and operator in c languge.It utilizes all conditions if any one of the condition is true the result will be true and as in c language number 1 is used as true and is false only when all of the conditions are false and as you know that c languge uses 0 as false so the result will be 0.
C Language Code:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a=32,b=54;
clrscr();
printf(“%d”,(a<1) (b<a) );
getch();
}
Here there are two conditions in printf function of c languge.
a < 1 This condition is false since a in 32 how could a be less than 1.
b < a This condition is also false be b is 54 and a is 32 so b is greater than a not less than
Since both conditions are false so the result is false and the c languge uses 0 for false so the result is 0.
3) Not operator in c languge ‘ ! ‘
The syntax of not operator in c languge is exclaimation mark symbol ‘ ! ‘ .
In c languges it is used before the codition.
Not operator in c language utilizes all conditions if the result is false it converts the result to true and as in c language number 1 is used as true and if the result is true it converts it to false and as you know that c languge uses 0 as false so the result will be 0.
C Language Code:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a=32,b=54;
clrscr();
printf(“%d”,(a<1) !(b<a) );
getch();
}
Here there are two conditions in printf function of c language .
a < 1 this condition is false because a is greater than 1 .
!(b < a) this condition is also false because b is greater than a but since not operator is applied here it converts the false result to true .
Since or operator is used here so the result will be true and c languge uses 1 for true so the result will be true.