C examples for Operator:Logic Operator
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 |
---|---|---|
true | true | true |
true | false | false |
false | true | false |
false | false | false |
The following two code blocks demonstrate C's && operator.
#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; }
The next compound if condition results in false.
#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; }