DamnSchool
Logical Operators are useful in combining one or more conditions. C allows usage of three logical operators namely " &&, ||, ! ".

Logical Operators

  Operator   Meaning
&&   Logical AND  
|| Logical OR
! Logical NOT

Truth Table of Logical Operator

In the following table
if True(T) means value is one.
If False(F) means valuse is Zero.
  X     Y     !X     !Y     X && Y     X || Y  
F F T T F F
F T T F F T
T F F T F T
T T F F T T
Consider the statement
a=5,b=7;c=5;
  Expression     Interpretation     Value  
(a>=5)&&(a<b) True 1
!(a==c) False 0
(a!=5)||(b>c) True 1
!(a==b) True 1

Codings for the above Example:
#include <stdio.h>
void main() {
int a = 5;
int b = 20;
if ( a && b ) {
printf("Line 1 - Condition is true\n" );
}

if ( a || b ) {
printf("Line 2 - Condition is true\n" );
}
}

Run Example >

< Previous Next >

Privacy Policy Terms of Service About
Creative Commons License
This work is licensed under a Creative Commons Attribution-NoDerivatives 4.0 International License.