SlideShare a Scribd company logo
Lecture 10Lecture 10
Version 1.0Version 1.0
More on FunctionsMore on Functions
Scope RulesScope Rules
Math Library FunctionsMath Library Functions
2Rushdi Shams, Dept of CSE, KUET, Bangladesh
More Knowledge on FunctionsMore Knowledge on Functions
Actual Arguments
Formal Arguments
3Rushdi Shams, Dept of CSE, KUET, Bangladesh
More Knowledge on FunctionsMore Knowledge on Functions
 Instead of using different variable namesInstead of using different variable names xx,, yy
andand zz, we could have used the same variable, we could have used the same variable
namesnames aa,, bb andand cc
 compiler would still treat them as differentcompiler would still treat them as different
variables since they are in different functionsvariables since they are in different functions
4Rushdi Shams, Dept of CSE, KUET, Bangladesh
More Knowledge on FunctionsMore Knowledge on Functions
 There is no restriction on the number ofThere is no restriction on the number of returnreturn
statements that may be present in a functionstatements that may be present in a function
 returnreturn statement need not always be present at the endstatement need not always be present at the end
of the called functionof the called function
5Rushdi Shams, Dept of CSE, KUET, Bangladesh
More Knowledge on FunctionsMore Knowledge on Functions
 All the following are validAll the following are valid returnreturn statementsstatements
 In the last statement a garbage value is returned to theIn the last statement a garbage value is returned to the
calling function since we are not returning any specificcalling function since we are not returning any specific
valuevalue
 Note that in this case the parentheses afterNote that in this case the parentheses after returnreturn areare
droppeddropped
6Rushdi Shams, Dept of CSE, KUET, Bangladesh
More Knowledge on FunctionsMore Knowledge on Functions
 A function can return only one value at a timeA function can return only one value at a time
 the following statements are invalidthe following statements are invalid
7Rushdi Shams, Dept of CSE, KUET, Bangladesh
More Knowledge on FunctionsMore Knowledge on Functions
 If the value of a formal argument is changed in theIf the value of a formal argument is changed in the
called function, the corresponding change does not takecalled function, the corresponding change does not take
place in the calling functionplace in the calling function
8Rushdi Shams, Dept of CSE, KUET, Bangladesh
More Knowledge on FunctionsMore Knowledge on Functions
9Rushdi Shams, Dept of CSE, KUET, Bangladesh
Calling ConventionsCalling Conventions
 Calling convention indicates the order inCalling convention indicates the order in
which arguments are passed to a functionwhich arguments are passed to a function
when a function call is encounteredwhen a function call is encountered
 There are two possibilities here:There are two possibilities here:
1.1. Arguments might be passed from left to right.Arguments might be passed from left to right.
2.2. Arguments might be passed from right to left.Arguments might be passed from right to left.
 C language follows the second orderC language follows the second order
10Rushdi Shams, Dept of CSE, KUET, Bangladesh
Calling ConventionsCalling Conventions
 In this call it doesn’t matter whether the argumentsIn this call it doesn’t matter whether the arguments
are passed from left to right or from right to leftare passed from left to right or from right to left
 However, in some function call the order of passingHowever, in some function call the order of passing
arguments becomes an important considerationarguments becomes an important consideration
11Rushdi Shams, Dept of CSE, KUET, Bangladesh
Calling ConventionsCalling Conventions
12Rushdi Shams, Dept of CSE, KUET, Bangladesh
Scope RulesScope Rules
 The scope of an identifier is the portion of theThe scope of an identifier is the portion of the
program in which an identifier is referencedprogram in which an identifier is referenced
 When we declare a local variable in a block, itWhen we declare a local variable in a block, it
can be referenced only in that block or in blockscan be referenced only in that block or in blocks
nested within that blocknested within that block
13Rushdi Shams, Dept of CSE, KUET, Bangladesh
14Rushdi Shams, Dept of CSE, KUET, Bangladesh
Math Library FunctionsMath Library Functions
 Math library functions allow the programmer toMath library functions allow the programmer to
perform certain common mathematical calculationsperform certain common mathematical calculations
 A programmer desiring to calculate and print the squareA programmer desiring to calculate and print the square
root of 900.0 can write-root of 900.0 can write-
15Rushdi Shams, Dept of CSE, KUET, Bangladesh
Math Library FunctionsMath Library Functions
 When the statement is executed, sqrt() is called toWhen the statement is executed, sqrt() is called to
calculate the square root of the number contained incalculate the square root of the number contained in
the parenthesis (900.0)the parenthesis (900.0)
 The number 900.0 is the argument of sqrt() functionThe number 900.0 is the argument of sqrt() function
 The statement will print 30.00The statement will print 30.00
 sqrt() function takes an argument of type double andsqrt() function takes an argument of type double and
returns a result of type doublereturns a result of type double
 All math library functions return the data type doubleAll math library functions return the data type double
16Rushdi Shams, Dept of CSE, KUET, Bangladesh
Math Library FunctionsMath Library Functions
 If c1=13.0, d=3.0 and f=4.0, then the line would printIf c1=13.0, d=3.0 and f=4.0, then the line would print
5.005.00
17Rushdi Shams, Dept of CSE, KUET, Bangladesh
Other Useful Math FunctionsOther Useful Math Functions

More Related Content

Similar to Lec 10. Functions (Part II)

Lec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesLec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesRushdi Shams
 
Lec 07. Do-While Loop / Switch
Lec 07. Do-While Loop / SwitchLec 07. Do-While Loop / Switch
Lec 07. Do-While Loop / SwitchRushdi Shams
 
Vb script
Vb scriptVb script
Vb script
mcatahir947
 
379008-rc217-functionalprogramming
379008-rc217-functionalprogramming379008-rc217-functionalprogramming
379008-rc217-functionalprogrammingLuis Atencio
 
WORKING WITH FUNCTIONS
WORKING WITH FUNCTIONSWORKING WITH FUNCTIONS
WORKING WITH FUNCTIONS
PihuJha1
 
Computer science notes of functions chapter
Computer science notes of functions chapterComputer science notes of functions chapter
Computer science notes of functions chapter
Godzilla33
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
Vikash Dhal
 
Lec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory ConceptLec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory ConceptRushdi Shams
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3
Isham Rashik
 
QTP VB Script Trainings
QTP VB Script TrainingsQTP VB Script Trainings
QTP VB Script Trainings
Ali Imran
 
Data services-functions
Data services-functionsData services-functions
Data services-functions
Durga Venkatesh
 
Informatica interview questions by H2kInfosys
Informatica interview questions by H2kInfosysInformatica interview questions by H2kInfosys
Informatica interview questions by H2kInfosys
H2kInfosys
 
Cocoa heads 09112017
Cocoa heads 09112017Cocoa heads 09112017
Cocoa heads 09112017
Vincent Pradeilles
 
System Verilog Functional Coverage
System Verilog Functional CoverageSystem Verilog Functional Coverage
System Verilog Functional Coverage
rraimi
 
solidity programming solidity programming
solidity programming solidity programmingsolidity programming solidity programming
solidity programming solidity programming
Mohan Kumar Ch
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
Jagan Mohan Bishoyi
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
lavparmar007
 
PythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdfPythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdf
data2businessinsight
 
Library management system
Library management systemLibrary management system
Library management system
SHARDA SHARAN
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variablesSaurav Kumar
 

Similar to Lec 10. Functions (Part II) (20)

Lec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesLec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by Values
 
Lec 07. Do-While Loop / Switch
Lec 07. Do-While Loop / SwitchLec 07. Do-While Loop / Switch
Lec 07. Do-While Loop / Switch
 
Vb script
Vb scriptVb script
Vb script
 
379008-rc217-functionalprogramming
379008-rc217-functionalprogramming379008-rc217-functionalprogramming
379008-rc217-functionalprogramming
 
WORKING WITH FUNCTIONS
WORKING WITH FUNCTIONSWORKING WITH FUNCTIONS
WORKING WITH FUNCTIONS
 
Computer science notes of functions chapter
Computer science notes of functions chapterComputer science notes of functions chapter
Computer science notes of functions chapter
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
Lec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory ConceptLec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory Concept
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3
 
QTP VB Script Trainings
QTP VB Script TrainingsQTP VB Script Trainings
QTP VB Script Trainings
 
Data services-functions
Data services-functionsData services-functions
Data services-functions
 
Informatica interview questions by H2kInfosys
Informatica interview questions by H2kInfosysInformatica interview questions by H2kInfosys
Informatica interview questions by H2kInfosys
 
Cocoa heads 09112017
Cocoa heads 09112017Cocoa heads 09112017
Cocoa heads 09112017
 
System Verilog Functional Coverage
System Verilog Functional CoverageSystem Verilog Functional Coverage
System Verilog Functional Coverage
 
solidity programming solidity programming
solidity programming solidity programmingsolidity programming solidity programming
solidity programming solidity programming
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
PythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdfPythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdf
 
Library management system
Library management systemLibrary management system
Library management system
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variables
 

More from Rushdi Shams

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
Rushdi Shams
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
Rushdi Shams
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
Rushdi Shams
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
Rushdi Shams
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
Rushdi Shams
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translationRushdi Shams
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translationRushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semanticsRushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logicRushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structureRushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representationRushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hackingRushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)Rushdi Shams
 

More from Rushdi Shams (20)

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L3 defense
L3  defenseL3  defense
L3 defense
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 

Recently uploaded

The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 

Recently uploaded (20)

The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 

Lec 10. Functions (Part II)

  • 1. Lecture 10Lecture 10 Version 1.0Version 1.0 More on FunctionsMore on Functions Scope RulesScope Rules Math Library FunctionsMath Library Functions
  • 2. 2Rushdi Shams, Dept of CSE, KUET, Bangladesh More Knowledge on FunctionsMore Knowledge on Functions Actual Arguments Formal Arguments
  • 3. 3Rushdi Shams, Dept of CSE, KUET, Bangladesh More Knowledge on FunctionsMore Knowledge on Functions  Instead of using different variable namesInstead of using different variable names xx,, yy andand zz, we could have used the same variable, we could have used the same variable namesnames aa,, bb andand cc  compiler would still treat them as differentcompiler would still treat them as different variables since they are in different functionsvariables since they are in different functions
  • 4. 4Rushdi Shams, Dept of CSE, KUET, Bangladesh More Knowledge on FunctionsMore Knowledge on Functions  There is no restriction on the number ofThere is no restriction on the number of returnreturn statements that may be present in a functionstatements that may be present in a function  returnreturn statement need not always be present at the endstatement need not always be present at the end of the called functionof the called function
  • 5. 5Rushdi Shams, Dept of CSE, KUET, Bangladesh More Knowledge on FunctionsMore Knowledge on Functions  All the following are validAll the following are valid returnreturn statementsstatements  In the last statement a garbage value is returned to theIn the last statement a garbage value is returned to the calling function since we are not returning any specificcalling function since we are not returning any specific valuevalue  Note that in this case the parentheses afterNote that in this case the parentheses after returnreturn areare droppeddropped
  • 6. 6Rushdi Shams, Dept of CSE, KUET, Bangladesh More Knowledge on FunctionsMore Knowledge on Functions  A function can return only one value at a timeA function can return only one value at a time  the following statements are invalidthe following statements are invalid
  • 7. 7Rushdi Shams, Dept of CSE, KUET, Bangladesh More Knowledge on FunctionsMore Knowledge on Functions  If the value of a formal argument is changed in theIf the value of a formal argument is changed in the called function, the corresponding change does not takecalled function, the corresponding change does not take place in the calling functionplace in the calling function
  • 8. 8Rushdi Shams, Dept of CSE, KUET, Bangladesh More Knowledge on FunctionsMore Knowledge on Functions
  • 9. 9Rushdi Shams, Dept of CSE, KUET, Bangladesh Calling ConventionsCalling Conventions  Calling convention indicates the order inCalling convention indicates the order in which arguments are passed to a functionwhich arguments are passed to a function when a function call is encounteredwhen a function call is encountered  There are two possibilities here:There are two possibilities here: 1.1. Arguments might be passed from left to right.Arguments might be passed from left to right. 2.2. Arguments might be passed from right to left.Arguments might be passed from right to left.  C language follows the second orderC language follows the second order
  • 10. 10Rushdi Shams, Dept of CSE, KUET, Bangladesh Calling ConventionsCalling Conventions  In this call it doesn’t matter whether the argumentsIn this call it doesn’t matter whether the arguments are passed from left to right or from right to leftare passed from left to right or from right to left  However, in some function call the order of passingHowever, in some function call the order of passing arguments becomes an important considerationarguments becomes an important consideration
  • 11. 11Rushdi Shams, Dept of CSE, KUET, Bangladesh Calling ConventionsCalling Conventions
  • 12. 12Rushdi Shams, Dept of CSE, KUET, Bangladesh Scope RulesScope Rules  The scope of an identifier is the portion of theThe scope of an identifier is the portion of the program in which an identifier is referencedprogram in which an identifier is referenced  When we declare a local variable in a block, itWhen we declare a local variable in a block, it can be referenced only in that block or in blockscan be referenced only in that block or in blocks nested within that blocknested within that block
  • 13. 13Rushdi Shams, Dept of CSE, KUET, Bangladesh
  • 14. 14Rushdi Shams, Dept of CSE, KUET, Bangladesh Math Library FunctionsMath Library Functions  Math library functions allow the programmer toMath library functions allow the programmer to perform certain common mathematical calculationsperform certain common mathematical calculations  A programmer desiring to calculate and print the squareA programmer desiring to calculate and print the square root of 900.0 can write-root of 900.0 can write-
  • 15. 15Rushdi Shams, Dept of CSE, KUET, Bangladesh Math Library FunctionsMath Library Functions  When the statement is executed, sqrt() is called toWhen the statement is executed, sqrt() is called to calculate the square root of the number contained incalculate the square root of the number contained in the parenthesis (900.0)the parenthesis (900.0)  The number 900.0 is the argument of sqrt() functionThe number 900.0 is the argument of sqrt() function  The statement will print 30.00The statement will print 30.00  sqrt() function takes an argument of type double andsqrt() function takes an argument of type double and returns a result of type doublereturns a result of type double  All math library functions return the data type doubleAll math library functions return the data type double
  • 16. 16Rushdi Shams, Dept of CSE, KUET, Bangladesh Math Library FunctionsMath Library Functions  If c1=13.0, d=3.0 and f=4.0, then the line would printIf c1=13.0, d=3.0 and f=4.0, then the line would print 5.005.00
  • 17. 17Rushdi Shams, Dept of CSE, KUET, Bangladesh Other Useful Math FunctionsOther Useful Math Functions