Use the logical operators && and || to help the if command make multiple decisions in one statement: - C Operator

C examples for Operator:Logic Operator

Introduction

The && is the logical AND operator.

The || is the logical OR operator.

Logical Operators Used in if Comparisons

Operator Meaning"True" Examples
|| Or true || true
|| Or true || false
|| Or false || true
&& Andtrue || true

Demo Code

#include <stdio.h>
int main()//w w w  .j  a v a  2 s .co  m
{
   char c,d;
   printf("Enter the character code for self-destruct?");
   c=getchar();
   fflush(stdin);                 /* use fpurge(stdin) in unix */
   printf("Input number code to confirm self-destruct?");
   d=getchar();
   if(c=='G' && d=='0')
   {
      printf("Bye!\n");
   }
   else{
      printf("Whew!\n");
   }
   return(0);
}

Result


Related Tutorials