8. In this operator , the program is executed if any one
of the two conditions is true.
if (semesterAvg >= 90 || finalExam >=90 )
printf("Student grade is A“);
| | (Logical OR)
9. Operand 1 Operand 2 Result
x y x | | y
0 0 0
0 Non-Zero 1
Non-Zero 0 1
Non-Zero Non-Zero 1
Table of Logical OR
10. Use the OR operator on the bit patterns 10011001
and 00101110.
Example
13. If a condition is true then Logical NOT operator will
make false and vice versa.
if ( !( grade == 20 ) )
printf(“hello world“);
Alternative:
if ( grade != 20 )
printf(“hello world“);
! (Logical NOT)
14. Operand 1 Operand 2 Result Result
x y !x !y
0 0 1 1
0 Non-Zero 1 0
Non-Zero 0 0 1
Non-Zero Non-Zero 0 0
Table of Logical NOT
15. Use the NOT operator on the bit pattern 10011000.
Example
17. Ternary operator are used to
reduce the code the in a short
form.
Conditional
Operator
18. General form is,
(expression 1 ? expression 2 : expression 3);
Conditional operators ? and : are sometimes called
ternary operators
if expression 1 is true, then the value returned will be
expression 2, otherwise the value returned will be
expression 3
Syntax