Logical Operators:OR Operator || - C Operator

C examples for Operator:Logic Operator

Introduction

If either or both operands of the || operator are true, the result is true.

The result is false only when both operands are false.

Demo Code

#include <stdio.h> 

int main(void) { 

   int a = 6;/*from  w ww.  ja  v a2 s  . co m*/
   int b = 12;
   int c = 123;
   
   if(a < 10 || b > c || c > 50)
      printf("At least one of the conditions is true.");


  return 0; 
} 

Result

You can use the && and || logical operators in combination.

Demo Code

#include <stdio.h> 

int main(void) { 

   int age = 6;/*from  ww w .  ja v  a 2 s .  co m*/

   int grade = 10;
   
   if((age > 12 && age < 20) || grade > 5)
     printf ("a teenager, or in school.");

  return 0; 
} 

Result


Related Tutorials