0% found this document useful (0 votes)
2 views18 pages

Programming Week 10

The document provides an overview of logical operators in programming, including AND, OR, and NOT, along with their usage and examples. It also summarizes operator precedence, detailing the hierarchy of unary, arithmetic, relational, logical, conditional, and assignment operators. Additionally, it covers control statements such as BREAK and CONTINUE, with examples demonstrating their functionality.

Uploaded by

mrtamangnood2205
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views18 pages

Programming Week 10

The document provides an overview of logical operators in programming, including AND, OR, and NOT, along with their usage and examples. It also summarizes operator precedence, detailing the hierarchy of unary, arithmetic, relational, logical, conditional, and assignment operators. Additionally, it covers control statements such as BREAK and CONTINUE, with examples demonstrating their functionality.

Uploaded by

mrtamangnood2205
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

1.

Logical Operators
2. Precedence Summary
3. Other Control Statements
Logical Operators:

• Programming is all about logics. Logical


operators form important block in software
development.
Logical Operators
Three Logical Operators

1. && (Logical AND)


2. | | (Logical OR)
3. ! (Logical NOT)
&& (Logical AND)
• In this operator, the condition is true if both
conditions are true.

if ( gender == 1 && age >= 65 )


senior++;
Example Program
Example
| | (Logical OR)
• 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“);
Example Program
Example

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

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
Example

Use the NOT operator on the bit pattern


10011000.
Example Program
SUMMARY OF PRECEDENCE

Operator Operators Precedence


type
Unary !, ++, - -, -, + Highest

Arithmetic +, - , * , / , %

Relational <, >, >=, <=, ==, !=

Logical &&, ||, !

Conditional ?:

Assignment = , - = , +=, /= , %= Lowest


Unary Operators

++ Increament Operator Increaments the value of an operand by 1


-- Decreament Operator Decreaments the value of an operand by 1
Relational
Operators
Operator Meaning
X == Y X equal to Y
X != Y X not equal to Y
X < Y X less than Y
X > Y X greater than Y
X <= Y X less than or equal to Y
X >= Y X greater than or equal to Y
OTHER CONTROL STATEMENTS
BREAK STATEMENT CONTINUE STATEMENT
• Continue The Loop From Beginning
• Break The Loop
• Example
• Example
include<stdio.h>
include<stdio.h> Int main(){
Int I = 0;
Int main(){
Do{
Int I = 0;
i++;
Do{ printf(“before continue”);
i++; continue;
printf(“before continue”); printf(“After continue”);
break; }while(i<3);
printf(“After continue”); }
}while(i<3);
}

You might also like