Logical Operators
Logical Operators
- AND,OR operators are used when we want to use two or more Conditions.
Types Of Logical Operators
- && Logical AND
- || Logical OR
- ! Logical NOT
Logical And (&&) Operator
Logical And Operator Definition
If both the operations are successful, then the condition becomes true.
Logical And Operator Syntax
expr1 && expr2
Logical And Operator Syntax Example
if( (a>10) && (a<20) )
printf(?A is in-between of 10 and 20?);
Logical And Operator Example Program
/* Example Program For Logical And operator In C Programming Language
little drops @ thiyagaraaj.com
Coded By:THIYAGARAAJ MP */
// Header Files
#include<stdio.h>
#include<conio.h>
//Main Function
int main()
{
// Variable Declaration
int num1 = 30;
int num2 = 40;
if(num1>=40 && num2>=40){
printf("Example of Logical And operator");
}
// Wait For Output Screen
getch();
//Main Function return Statement
return 0;
}
Sample Output:
Example of Logical And operator
Logical OR (||) Operator
Logical OR Operator Definition
If any one of the operations are successful, then the condition becomes true
Logical OR Operator Syntax
expr1 || expr2
Logical OR Operator Syntax Example
if( (a>10) || (a<20) )
printf(?A is greater than 10 or less than 20?);
Logical OR Operator Example Program
/* Example Program For Logical Or (||) operator In C Programming Language
little drops @ thiyagaraaj.com
Coded By:THIYAGARAAJ MP */
// Header Files
#include<stdio.h>
#include<conio.h>
//Main Function
int main()
{
// Variable Declaration
int num1 = 30;
int num2 = 40;
if(num1>=40 || num2>=40){
printf("Example of Logical Or operator");
}
// Wait For Output Screen
getch();
//Main Function return Statement
return 0;
}
Sample Output
Example of Logical OR operator
Logical NOT (!) Operator
Logical NOT Operator Definition
It is used to reverse the condition of result. That is, if a condition is true, Logical NOT operator reverses the result and produces output as false.
Logical NOT Operator Syntax
!expression
Logical NOT Operator Syntax Example
if( !(a>10)
printf(?A is less than 10 ?);
Logical Not Operator Example Program
/* Example Program For Logical Not (!) operator In C Programming Language
little drops @ thiyagaraaj.com
Coded By:THIYAGARAAJ MP */
// Header Files
#include<stdio.h>
#include<conio.h>
//Main Function
int main()
{
int number;
printf("Please enter an integer value: ");
scanf("%d", &number);
if(!(number>40)){
printf("Input check greater than 40 - TRUE");
}else{
printf("Input check greater than 40 - FALSE");
}
// Wait For Output Screen
getch();
//Main Function return Statement
return 0;
}
Sample Output
Please enter an integer value: 35
Input check greater than 40 - FALSE
Read More Articles
- Use of getch(),getche() and getchar() in C
- Switch Case Statement Example Program In C Programming Language
- C Character Set
- Convert a Floating-point value to an Integer in C
- Data Input and Output gets and puts Example Program In C
- Special Operators In C
- Pointer Representation and Pointer Example Programs
- C Data Input and Data Output
- Simple While Loop Example Program In C Programming Language
- Data Output printf and putchar Example Program In C
- C Introduction
- C Operators
- Storage Classes In C
- C Pointers
- File Management
- C Identifiers
- Loop Control Statements
- Hello World - Simple C Program
- C Array
- Single Character Output Function : putchar()
- C Reserve Words
- C Specific Properties and Implementation
- If else Statement Example Program In C Programming Language
- If Statement Example Program In C Programming Language
- Confusing Array in C ( Array Representation and Initialization )