Get to know && (Boolean operator and) Operator - C Operator

C examples for Operator:Logic Operator

Introduction

The && operator implements the Boolean operator and.

Both sides of the operator must evaluate to true before the entire expression becomes true.

True table For And Operator

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

The following two code blocks demonstrate C's && operator.

Demo Code

#include <stdio.h>

int main()/*from  w w  w . ja va 2 s.  c om*/
{
    if ( 3 > 1 && 5 < 10 ) 
       printf("The entire expression is true\n"); 
    return 0;
}

Result

The next compound if condition results in false.

Demo Code

#include <stdio.h>

int main(){/*www  .j a v a 2 s .  c om*/
    if ( 3 > 5 && 5 < 5 ) 
       printf("The entire expression is false\n"); 
    else
       printf("else\n"); 
    return 0;
}

Result


Related Tutorials