In this tutorial, you will learn about the Logical operations in C and their usage and examples.
Logical Operations in C with Examples
The table below illustrates the Logical Operators in C, a brief description, and simple examples.
Operator | Description | Example |
---|---|---|
&& (logical AND) | It returns true if both conditions are true | (x>5)&&(y<5) |
|| (logical OR) | It returns true if at-least one of the condition is true | (x>=10)||(y>=10) |
! (logical NOT) | It reverses the state of the operand “((x>5) && (y<5))” | !((x>5)&&(y<5)) |
Example of Logical Operators in C
#include <stdio.h> main() { int x = 5; int y = 10; int z ; if ( x && y ) { printf("x && y is true\n" ); } if ( x || y ) { printf("x || y is true\n" ); } }
Result
x && y is true x || y is true