Sunday, 7 August 2016

LOGICAL OPERATORS IN C ( && , || , ! )



#include <stdio.h>
void main()
{
 int a = 5;
 int b = 20;
 int c ;
/* if the value of condition in ' if ' is zero, condition is false
   if the value of condition in ' if ' is non-zero, condition is true */
 if ( a && b )
 { printf("Line 1 - Condition is true\n" ); }
 else
 { printf("Line 1 - Condition is not true\n" ); }

 if ( a || b )
 {printf("Line 2 - Condition is true\n" ); }
 else
 { printf("Line 2 - Condition is not true\n" ); }
/* lets change the value of a and b */
 a = 0;
 b = 10;

 if ( a && b )
 { printf("Line 3 - Condition is true\n" ); }
 else
 { printf("Line 3 - Condition is not true\n" ); }
 if ( !(a && b) )
 { printf("Line 4 - Condition is true\n" ); }
 else
 { printf("Line 4 - Condition is not true\n" ); }
}

output :
Line 1 - Condition is true
Line 2 - Condition is true
Line 3 - Condition is not true
Line 4 - Condition is true

No comments:

Post a Comment

smhjifrivly@gmail.com