Get to know || Operator - C Operator

C examples for Operator:Logic Operator

Introduction

For || Boolean operator, if either side of the condition is true, the whole expression results in true.

Truth Table for or Operator

x y Result
truetrue true
truefalse true
false true true
false false false

Checking for a Range of Values

Demo Code

#include <stdio.h> 
int main()/*ww  w.  j  a v  a2 s. c o  m*/
{ 
   int iResponse = 0; 
   printf("Enter a number from 1 to 10: "); 
   scanf("%d", &iResponse); 

   if ( iResponse < 1 || iResponse > 10 ) 
      printf("\nNumber not in range\n"); 
   else 
      printf("\nThank you\n"); 
}

Result


Related Tutorials