C examples for Operator:Logic Operator
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 |
&& | And | true || true |
#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); }