Programming Week 10
Programming Week 10
Logical Operators
2. Precedence Summary
3. Other Control Statements
Logical Operators:
Int x,y,z;
if (x<y | | x<z)
printf(“x is small”);
NOT Logical Operator
• It is unary operator as it has only one
operand
• If something is true, ! makes false; if it is
false,! Makes it true.
• For example
(x==7) is true if x is equal to 7,but !(x==7) is
true if x is not equal to 7.
• While(day != 0 && day !=1)
-> day is not weekend
! (Logical NOT)
• 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“);
Table of Logical NOT
Arithmetic +, - , * , / , %
Conditional ?: