SlideShare ist ein Scribd-Unternehmen logo
1 von 60
A First Book of ANSI C Fourth Edition Chapter 7 Modularity Using Functions: Part II
Objectives ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Variable Scope ,[object Object],[object Object]
Variable Scope (continued)
Variable Scope (continued) ,[object Object],[object Object]
Variable Scope (continued)
Variable Scope (continued)
Variable Scope (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Variable Scope (continued) ,[object Object],[object Object]
Variable Scope (continued)
When to Use Global Declarations ,[object Object],[object Object],[object Object],[object Object]
Misuse of Global Variables ,[object Object],[object Object],[object Object],[object Object]
Variable Storage Class ,[object Object],[object Object],[object Object],[object Object]
Variable Storage Class (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Local Variable Storage Classes ,[object Object],[object Object],[object Object],[object Object],[object Object]
Output is: The value of the automatic variable num is 0 The value of the automatic variable num is 0 The value of the automatic variable num is 0 Local Variable Storage Classes (continued)
Local Variable Storage Classes (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object]
Output is: The value of the static variable num is now 0 The value of the static variable num is now 1 The value of the static variable num is now 2 Local Variable Storage Classes (continued)
Local Variable Storage Classes (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object]
Global Variable Storage Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Global Variable Storage Classes (continued)
Global Variable Storage Classes (continued)
Global Variable Storage Classes (continued) ,[object Object],[object Object],[object Object],[object Object]
Pass by Reference ,[object Object],[object Object],[object Object]
Passing Addresses to a Function ,[object Object],[object Object],[object Object]
Storing Addresses ,[object Object],[object Object]
Storing Addresses (continued)
Storing Addresses (continued)
Using Addresses ,[object Object],[object Object],[object Object],[object Object]
Using Addresses (continued)
Declaring and Using Pointers ,[object Object],[object Object],[object Object]
Output is: The address stored in milesAddr is 1244872 The value pointed to by milesAddr is 22 The value in miles is now 158 Declaring and Using Pointers (continued)
Declaring and Using Pointers (continued)
Passing Addresses to a Function
Passing Addresses to a Function (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object]
Passing Addresses to a Function (continued)
Add 20.2 to the value of the variable pointed to by  xnum Passing Addresses to a Function (continued)
Returns multiple values Passing Addresses to a Function (continued)
Case Study: Swapping Values ,[object Object],[object Object]
Requirements Specification ,[object Object],[object Object]
Analyze the Problem ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Analyze the Problem (continued)
Analyze the Problem (continued)
Code the Function
Code the Function (continued)
Code the Function (continued)
Code the Function (continued)
Test and Debug the Program ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Recursion ,[object Object],[object Object],[object Object]
Mathematical Recursion ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Mathematical Recursion (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Mathematical Recursion (continued)
How the Computation is Performed
How the Computation is Performed (continued)
How the Computation is Performed (continued)
Recursion versus Iteration ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Common Programming Errors ,[object Object],[object Object],[object Object],[object Object]
Common Compiler Errors
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object]
Summary (continued) ,[object Object],[object Object],[object Object],[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

Class 4: Making Procedures
Class 4: Making ProceduresClass 4: Making Procedures
Class 4: Making ProceduresDavid Evans
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
Functions in c language1
Functions in c language1Functions in c language1
Functions in c language1sirikeshava
 
lazy evaluation
lazy evaluationlazy evaluation
lazy evaluationRajendran
 
Intro To Scala
Intro To ScalaIntro To Scala
Intro To Scalachambeda
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppteShikshak
 
Implicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingImplicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingVIKASH MAINANWAL
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and typesimtiazalijoono
 
Command line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialCommand line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialKuntal Bhowmick
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignmentAhmad Kamal
 
Command Line Arguments in C#
Command Line Arguments in C#Command Line Arguments in C#
Command Line Arguments in C#Ali Hassan
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c languagetanmaymodi4
 
Notes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and FunctionsNotes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and FunctionsJay Baxi
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 

Was ist angesagt? (20)

Functions
FunctionsFunctions
Functions
 
Class 4: Making Procedures
Class 4: Making ProceduresClass 4: Making Procedures
Class 4: Making Procedures
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
9 subprograms
9 subprograms9 subprograms
9 subprograms
 
Functions in c language1
Functions in c language1Functions in c language1
Functions in c language1
 
lazy evaluation
lazy evaluationlazy evaluation
lazy evaluation
 
Oop lec 1
Oop lec 1Oop lec 1
Oop lec 1
 
Intro To Scala
Intro To ScalaIntro To Scala
Intro To Scala
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppt
 
Implicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingImplicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handling
 
Mule expression
Mule expressionMule expression
Mule expression
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
Command line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialCommand line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorial
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignment
 
Command Line Arguments in C#
Command Line Arguments in C#Command Line Arguments in C#
Command Line Arguments in C#
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
Function in C++
Function in C++Function in C++
Function in C++
 
Notes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and FunctionsNotes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and Functions
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 

Andere mochten auch (10)

8. semiconductors.rr
8. semiconductors.rr8. semiconductors.rr
8. semiconductors.rr
 
Superconductor
SuperconductorSuperconductor
Superconductor
 
Copper and its alloys
Copper and its alloysCopper and its alloys
Copper and its alloys
 
Crystalography
CrystalographyCrystalography
Crystalography
 
An Introduction to Crystallography
An Introduction to CrystallographyAn Introduction to Crystallography
An Introduction to Crystallography
 
Super Conductors
Super ConductorsSuper Conductors
Super Conductors
 
Crystal structures
Crystal structuresCrystal structures
Crystal structures
 
Magnetic material
Magnetic materialMagnetic material
Magnetic material
 
Polymer ppt
Polymer pptPolymer ppt
Polymer ppt
 
Polymers
PolymersPolymers
Polymers
 

Ähnlich wie Ch07 (20)

04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
 
Functions in C++.pdf
Functions in C++.pdfFunctions in C++.pdf
Functions in C++.pdf
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
Storage class
Storage classStorage class
Storage class
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdf
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdf
 
What is storage class
What is storage classWhat is storage class
What is storage class
 
C language presentation
C language presentationC language presentation
C language presentation
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
 
Storage classes
Storage classesStorage classes
Storage classes
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variables
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
 
Introduction to Visual Basic
Introduction to Visual Basic Introduction to Visual Basic
Introduction to Visual Basic
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
 
Csc1100 lecture06 ch06_pt2
Csc1100 lecture06 ch06_pt2Csc1100 lecture06 ch06_pt2
Csc1100 lecture06 ch06_pt2
 
Advanced C Programming Notes
Advanced C Programming NotesAdvanced C Programming Notes
Advanced C Programming Notes
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
 

Mehr von Arriz San Juan (18)

Session 6 merchandising1
Session 6 merchandising1Session 6 merchandising1
Session 6 merchandising1
 
9. logic gates._rr
9. logic gates._rr9. logic gates._rr
9. logic gates._rr
 
7. kirchhoff s_rules
7. kirchhoff s_rules7. kirchhoff s_rules
7. kirchhoff s_rules
 
9. transistors.rr
9. transistors.rr9. transistors.rr
9. transistors.rr
 
12 exception handling
12 exception handling12 exception handling
12 exception handling
 
12 exception handling
12 exception handling12 exception handling
12 exception handling
 
Chap 17 controlling
Chap 17 controllingChap 17 controlling
Chap 17 controlling
 
11 advance inheritance_concepts
11 advance inheritance_concepts11 advance inheritance_concepts
11 advance inheritance_concepts
 
9. transistors.rr
9. transistors.rr9. transistors.rr
9. transistors.rr
 
7. kirchhoff s_rules
7. kirchhoff s_rules7. kirchhoff s_rules
7. kirchhoff s_rules
 
Ch13
Ch13Ch13
Ch13
 
Ch06
Ch06Ch06
Ch06
 
Ch05
Ch05Ch05
Ch05
 
Ch04
Ch04Ch04
Ch04
 
Ch03
Ch03Ch03
Ch03
 
Ch02
Ch02Ch02
Ch02
 
Ch09
Ch09Ch09
Ch09
 
Ch08
Ch08Ch08
Ch08
 

Ch07