Logical Operators in C

The logical operators are used to perform the logical operation on two operands or variables. e.g. AND operation, OR operation, NOT operation.

Logical AND ( && ): True, only if all operands / conditions are true, otherwise false.

suppose x = 10, and y = 0, then

x && y will return FALSE.

if all operands are non-zero, then it will returns TRUE.

Logical OR ( || ): True, if one or more operands/conditions are true, otherwise False.

suppose x = 10, and y = 0, then

x || y will return TRUE.

If all operands are zero, then it will returns FALSE.

Logical NOT ( ! ): True, only if operand is 0.

suppose y = 0, then

!y will return TRUE.

If operand is non-zero, it will returns FALSE.

Here is a C program to demonstrate logical operators

/**
* To demonstrate logical operator in C
*/
#include<stdio.h>
int main ( int argc, char **argv )
{
int x = 10;
int y = 0;
int z = 15;
/* Logical AND */
if ( x && y )
{
printf("Logical AND : TRUE\n");
}
else
{
printf ("logical AND : FALSE\n");
}
/* Logical OR */
if ( x || y )
{
printf("Logical OR : TRUE\n");
}
else
{
printf ("logical OR : FALSE\n");
}
/* Logical NOT */
if ( !y )
{
printf("Logical NOT : TRUE\n");
}
else
{
printf ("logical NOT : FALSE\n");
}
return 0;
}

Hope, it would be helpful !!

To contribute :

” If you like Advance Computing and would like to contribute, you can  mail your article to “computingadvance@gmail.com”. You will get credit as your name , email id, designation with article on this blog. “

Leave a Reply