Logical Operators | Operators in C | C Language



Logical Operators

Following table shows all the logical operators supported by C language. Assume variable A holds 1 and variable B holds 0, then −


Operator Description Example
&& Called Logical AND operator. If both the operands are non-zero, then the condition becomes true. (A && B) is false.
|| Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true. (A || B) is true.
! Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false.

Example




#include <stdio.h>

main() {

   int a = 5;
   int b = 20;
   int c ;

   if ( a && b ) {
      printf("Line 1 - Condition is true\n" );
   }
 
   if ( a || b ) {
      printf("Line 2 - Condition is 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" );
   }
 
}

Output


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

Learn from tutorials https://www.youtube.com/channel/UCf_rYynEasdwiY7q0v1q6ZQ 

C Language Tutorials https://www.youtube.com/playlist?list=PLz5NJMw6aXU6pvSzre8YKHMh6NG6Y6jze


Thanks for Reading Please Follow and Share and Comment if You Like it !!!
If this POST contains Any Wrong Information Feel free to comment it i will FIX the Problem !!! or You can contact me at given links below




Follow the Blog for more new post http://rajeevchaudhary-youtuber.blogspot.com/
 
 
 
 



Share:

No comments:

Post a Comment

Facebook

Popular

Recent Posts

Unordered List

  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  • Aliquam tincidunt mauris eu risus.
  • Vestibulum auctor dapibus neque.

Contact Form

Name

Email *

Message *