SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Topic:
Logical Operators and
Conditional Operator
Presented by:
Abdul Rehman (BSSE09151014)
Three Logical Operators
1. && (Logical AND)
2. | | (Logical OR)
3. ! (Logical NOT)
Logical Operators
 In this operator, the condition is true if both
conditions are true.
if ( gender == 1 && age >= 65 )
senior++;
&& (Logical AND)
Table of Logical AND
Operand 1 Operand 2 Results
x y x&&y
0 0 0
0 Non-Zero 0
Non-Zero 0 0
Non-Zero Non-Zero 1
• Use the AND operator on the bit patterns 10011000 and 00101010.
Example
Example Program
Example
 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)
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
Use the OR operator on the bit patterns 10011001
and 00101110.
Example
Example Program
Int x,y,z;
if (x<y | | x<z)
printf(“x is small”);
Example
 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)
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
Use the NOT operator on the bit pattern 10011000.
Example
Example Program
Ternary operator are used to
reduce the code the in a short
form.
Conditional
Operator
 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
Nested conditional operator
(expression 1 ? expression 2 : expression 3);
Single
condition or
compound
condition
(expression 1 ? expression 2 : expression 3);
(expression 1 ? expression 2 : expression 3);
Example program
main( )
{
float sal ;
printf ("Enter the salary" ) ;
scanf ( "%f", &sal ) ;
( (sal < 40000 && sal > 25000) ? printf ( "Manager" ) :
(( sal < 25000 && sal > 15000 ) ? printf ( "Accountant") :
printf ( "Clerk" ) ));
}
Any Question???

Weitere ähnliche Inhalte

Was ist angesagt?

Branching statements
Branching statementsBranching statements
Branching statements
ArunMK17
 

Was ist angesagt? (20)

Operators
OperatorsOperators
Operators
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming Expression and Operartor In C Programming
Expression and Operartor In C Programming
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Data types
Data typesData types
Data types
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Data types in C
Data types in CData types in C
Data types in C
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Variables in python
Variables in pythonVariables in python
Variables in python
 
Presentation on C Switch Case Statements
Presentation on C Switch Case StatementsPresentation on C Switch Case Statements
Presentation on C Switch Case Statements
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
Branching statements
Branching statementsBranching statements
Branching statements
 
C if else
C if elseC if else
C if else
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Array in c
Array in cArray in c
Array in c
 

Andere mochten auch

Programming course slides c++ (Prof Mansoor Bhatti)
Programming course slides c++ (Prof Mansoor Bhatti)Programming course slides c++ (Prof Mansoor Bhatti)
Programming course slides c++ (Prof Mansoor Bhatti)
Syed Arslan Rizvi
 
Logical expression and logical operators
Logical expression and logical operatorsLogical expression and logical operators
Logical expression and logical operators
Suneel Dogra
 

Andere mochten auch (20)

Explore new possibilities with paperless medical documentation
Explore new possibilities with paperless medical documentationExplore new possibilities with paperless medical documentation
Explore new possibilities with paperless medical documentation
 
Programming course slides c++ (Prof Mansoor Bhatti)
Programming course slides c++ (Prof Mansoor Bhatti)Programming course slides c++ (Prof Mansoor Bhatti)
Programming course slides c++ (Prof Mansoor Bhatti)
 
Lecture 6 operators
Lecture 6   operatorsLecture 6   operators
Lecture 6 operators
 
Abuttal of Pakistan
Abuttal of PakistanAbuttal of Pakistan
Abuttal of Pakistan
 
Boolean Algebra and Logic Smiplification
Boolean Algebra and Logic SmiplificationBoolean Algebra and Logic Smiplification
Boolean Algebra and Logic Smiplification
 
Digital logic mohammed salim ch4
Digital logic mohammed salim ch4Digital logic mohammed salim ch4
Digital logic mohammed salim ch4
 
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
 
Logical expression and logical operators
Logical expression and logical operatorsLogical expression and logical operators
Logical expression and logical operators
 
gujju
gujjugujju
gujju
 
presentation
presentationpresentation
presentation
 
Boolean algebra
Boolean algebraBoolean algebra
Boolean algebra
 
Introduction to digital logic
Introduction to digital logicIntroduction to digital logic
Introduction to digital logic
 
Introduction To Biometrics
Introduction To BiometricsIntroduction To Biometrics
Introduction To Biometrics
 
Water Level Indicator Project Presentation
Water Level Indicator Project PresentationWater Level Indicator Project Presentation
Water Level Indicator Project Presentation
 
Normalization 1
Normalization 1Normalization 1
Normalization 1
 
Difference between Rural and urban life
Difference between Rural and urban lifeDifference between Rural and urban life
Difference between Rural and urban life
 
Chap 10(structure and unions)
Chap 10(structure and unions)Chap 10(structure and unions)
Chap 10(structure and unions)
 
IS 151 Lecture 3
IS 151 Lecture 3IS 151 Lecture 3
IS 151 Lecture 3
 
IS 139 Lecture 7
IS 139 Lecture 7IS 139 Lecture 7
IS 139 Lecture 7
 
IS 151 - Lecture 3
IS 151 - Lecture 3IS 151 - Lecture 3
IS 151 - Lecture 3
 

Ähnlich wie Logical and Conditional Operator In C language

02 iec t1_s1_oo_ps_session_02
02 iec t1_s1_oo_ps_session_0202 iec t1_s1_oo_ps_session_02
02 iec t1_s1_oo_ps_session_02
Pooja Gupta
 

Ähnlich wie Logical and Conditional Operator In C language (20)

Java unit 3
Java unit 3Java unit 3
Java unit 3
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
4. operators in c programming by digital wave
4. operators in  c programming by digital wave4. operators in  c programming by digital wave
4. operators in c programming by digital wave
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
6 operators-in-c
6 operators-in-c6 operators-in-c
6 operators-in-c
 
6 operators-in-c
6 operators-in-c6 operators-in-c
6 operators-in-c
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
02 iec t1_s1_oo_ps_session_02
02 iec t1_s1_oo_ps_session_0202 iec t1_s1_oo_ps_session_02
02 iec t1_s1_oo_ps_session_02
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
C PRESENTATION.pptx
C PRESENTATION.pptxC PRESENTATION.pptx
C PRESENTATION.pptx
 
Presentation on logical_operators
Presentation on logical_operatorsPresentation on logical_operators
Presentation on logical_operators
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Java - Operators
Java - OperatorsJava - Operators
Java - Operators
 
Java 2
Java 2Java 2
Java 2
 
Operators
OperatorsOperators
Operators
 
Class_IX_Operators.pptx
Class_IX_Operators.pptxClass_IX_Operators.pptx
Class_IX_Operators.pptx
 

Kürzlich hochgeladen

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Kürzlich hochgeladen (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

Logical and Conditional Operator In C language

  • 1. Topic: Logical Operators and Conditional Operator Presented by: Abdul Rehman (BSSE09151014)
  • 2. Three Logical Operators 1. && (Logical AND) 2. | | (Logical OR) 3. ! (Logical NOT) Logical Operators
  • 3.  In this operator, the condition is true if both conditions are true. if ( gender == 1 && age >= 65 ) senior++; && (Logical AND)
  • 4. Table of Logical AND Operand 1 Operand 2 Results x y x&&y 0 0 0 0 Non-Zero 0 Non-Zero 0 0 Non-Zero Non-Zero 1
  • 5. • Use the AND operator on the bit patterns 10011000 and 00101010. Example
  • 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
  • 12. Int x,y,z; if (x<y | | x<z) printf(“x is small”); 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
  • 19.
  • 20. Nested conditional operator (expression 1 ? expression 2 : expression 3); Single condition or compound condition (expression 1 ? expression 2 : expression 3); (expression 1 ? expression 2 : expression 3);
  • 21. Example program main( ) { float sal ; printf ("Enter the salary" ) ; scanf ( "%f", &sal ) ; ( (sal < 40000 && sal > 25000) ? printf ( "Manager" ) : (( sal < 25000 && sal > 15000 ) ? printf ( "Accountant") : printf ( "Clerk" ) )); }