SlideShare a Scribd company logo
1 of 6
Download to read offline
FUNCTIONS Lecture 2.1
Prepared by: Mian Saeed Akbar
FUNCTIONS
Functions
Programs use new and “prepackaged” functions
o New: programmer-defined functions, classes
o Prepackaged: from the standard library
Functions invoked by function call
 Function name and information (arguments) it needs
Function definitions
 Only written once
 Hidden from other functions
Function
A Block of code that
perform a specific task
Functions
 Modularize a program
 Software reusability
 Call function multiple times
Local variables
 Known only in the function in which they are defined
 All variables declared in function definitions are local variables
Parameters
 Local variables passed to function when called
 Provide outside information
FUNCTIONS
Function prototype
 Tells compiler argument type and return type of function
 Function takes an int and returns an int
Calling/invoking a function
 Write function name with argument as variable, expression or value.
Format for function definition
return-value-type function-name( parameter-list )
{
declarations and statements
}
Prototype must match function definition
 Function prototype
double maximum( double, double, double );
 Definition
double maximum( double x, double y, double z )
{
…
}
int square( int );
square( x );
int square( int x ){
return x*x;
}
FUNCTIONS
FUNCTIONS
return keyword
o Returns data, and control goes to function’s caller
• If no data to return, use return;
o Function ends when reaches right brace
• Control goes to caller
Functions cannot be defined inside other functions
Function signature
o Part of prototype with name and parameters
• double maximum( double, double, double );
Function signature
Thank you
Please subscribe my channel for more videos
and courses

More Related Content

Similar to Lecture 2.1 Functions.pdf

D-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptxD-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptx
VedantSahane
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
Jeevan Raj
 

Similar to Lecture 2.1 Functions.pdf (20)

Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
D-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptxD-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptx
 
Ch07.pdf
Ch07.pdfCh07.pdf
Ch07.pdf
 
functions.pptx
functions.pptxfunctions.pptx
functions.pptx
 
C FUNCTIONS
C FUNCTIONSC FUNCTIONS
C FUNCTIONS
 
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 R PROGRAMMING.pptx
FUNCTIONS IN R PROGRAMMING.pptxFUNCTIONS IN R PROGRAMMING.pptx
FUNCTIONS IN R PROGRAMMING.pptx
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
 
Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
 
functions in c language_functions in c language.pptx
functions in c language_functions in c language.pptxfunctions in c language_functions in c language.pptx
functions in c language_functions in c language.pptx
 
C functions
C functionsC functions
C functions
 
functions new.pptx
functions new.pptxfunctions new.pptx
functions new.pptx
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
Python Programming - Functions and Modules
Python Programming - Functions and ModulesPython Programming - Functions and Modules
Python Programming - Functions and Modules
 
Function-Definition, Need, Declaration, Definition, Arguments, Return Value
Function-Definition, Need, Declaration, Definition, Arguments, Return ValueFunction-Definition, Need, Declaration, Definition, Arguments, Return Value
Function-Definition, Need, Declaration, Definition, Arguments, Return Value
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
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
 

More from MianSaeedAkbar1

More from MianSaeedAkbar1 (20)

Lecture 1.3 A Simple Program to Print a Line of Text.pdf
Lecture 1.3 A Simple Program to Print a Line of Text.pdfLecture 1.3 A Simple Program to Print a Line of Text.pdf
Lecture 1.3 A Simple Program to Print a Line of Text.pdf
 
Lecture 2.8 Arrays.pdf
Lecture 2.8 Arrays.pdfLecture 2.8 Arrays.pdf
Lecture 2.8 Arrays.pdf
 
Lecture 2.2 Default Arguments.pdf
Lecture 2.2 Default Arguments.pdfLecture 2.2 Default Arguments.pdf
Lecture 2.2 Default Arguments.pdf
 
Lecture 2.6 Function Templates.pdf
Lecture 2.6 Function Templates.pdfLecture 2.6 Function Templates.pdf
Lecture 2.6 Function Templates.pdf
 
Lecture 2.4 Recursion.pdf
Lecture 2.4 Recursion.pdfLecture 2.4 Recursion.pdf
Lecture 2.4 Recursion.pdf
 
Lecture 3 Structures in C++.pdf
Lecture 3 Structures in C++.pdfLecture 3 Structures in C++.pdf
Lecture 3 Structures in C++.pdf
 
Lecture 2.5 Function Overloading.pdf
Lecture 2.5 Function Overloading.pdfLecture 2.5 Function Overloading.pdf
Lecture 2.5 Function Overloading.pdf
 
Lecture 1.11 Break and Continue Statements.pdf
Lecture 1.11 Break and Continue Statements.pdfLecture 1.11 Break and Continue Statements.pdf
Lecture 1.11 Break and Continue Statements.pdf
 
Lecture 1.5 Variables.pdf
Lecture 1.5 Variables.pdfLecture 1.5 Variables.pdf
Lecture 1.5 Variables.pdf
 
Lecture 1.2 Basics of a typical C++ Environment.pdf
Lecture 1.2 Basics of a typical C++ Environment.pdfLecture 1.2 Basics of a typical C++ Environment.pdf
Lecture 1.2 Basics of a typical C++ Environment.pdf
 
Lecture 2.3 Inline Function.pdf
Lecture 2.3 Inline Function.pdfLecture 2.3 Inline Function.pdf
Lecture 2.3 Inline Function.pdf
 
Lecture 1.8 Conditional Structures.pdf
Lecture 1.8 Conditional Structures.pdfLecture 1.8 Conditional Structures.pdf
Lecture 1.8 Conditional Structures.pdf
 
Lecture 2.7 Type Conversion in C++.pdf
Lecture 2.7 Type Conversion in C++.pdfLecture 2.7 Type Conversion in C++.pdf
Lecture 2.7 Type Conversion in C++.pdf
 
Lecture 1.6 Arithmetic and Relational Operators.pdf
Lecture 1.6 Arithmetic and Relational Operators.pdfLecture 1.6 Arithmetic and Relational Operators.pdf
Lecture 1.6 Arithmetic and Relational Operators.pdf
 
Lecture 1.7 C++ Keywords.pdf
Lecture 1.7 C++ Keywords.pdfLecture 1.7 C++ Keywords.pdf
Lecture 1.7 C++ Keywords.pdf
 
Lecture 1.4 Escape Sequence.pdf
Lecture 1.4 Escape Sequence.pdfLecture 1.4 Escape Sequence.pdf
Lecture 1.4 Escape Sequence.pdf
 
Lecture 1.9 Switch Structure.pdf
Lecture 1.9 Switch Structure.pdfLecture 1.9 Switch Structure.pdf
Lecture 1.9 Switch Structure.pdf
 
Lecture 1.10 Repetition Structures.pdf
Lecture 1.10 Repetition Structures.pdfLecture 1.10 Repetition Structures.pdf
Lecture 1.10 Repetition Structures.pdf
 
Lecture 0 Object Oriented Programming.pdf
Lecture 0 Object Oriented Programming.pdfLecture 0 Object Oriented Programming.pdf
Lecture 0 Object Oriented Programming.pdf
 
Lecture 1.1 Introduction to Computer Languages.pdf
Lecture 1.1 Introduction to Computer Languages.pdfLecture 1.1 Introduction to Computer Languages.pdf
Lecture 1.1 Introduction to Computer Languages.pdf
 

Recently uploaded

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
 

Recently uploaded (20)

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
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
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
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
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
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...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
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
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 

Lecture 2.1 Functions.pdf

  • 1. FUNCTIONS Lecture 2.1 Prepared by: Mian Saeed Akbar
  • 2. FUNCTIONS Functions Programs use new and “prepackaged” functions o New: programmer-defined functions, classes o Prepackaged: from the standard library Functions invoked by function call  Function name and information (arguments) it needs Function definitions  Only written once  Hidden from other functions Function A Block of code that perform a specific task
  • 3. Functions  Modularize a program  Software reusability  Call function multiple times Local variables  Known only in the function in which they are defined  All variables declared in function definitions are local variables Parameters  Local variables passed to function when called  Provide outside information FUNCTIONS
  • 4. Function prototype  Tells compiler argument type and return type of function  Function takes an int and returns an int Calling/invoking a function  Write function name with argument as variable, expression or value. Format for function definition return-value-type function-name( parameter-list ) { declarations and statements } Prototype must match function definition  Function prototype double maximum( double, double, double );  Definition double maximum( double x, double y, double z ) { … } int square( int ); square( x ); int square( int x ){ return x*x; } FUNCTIONS
  • 5. FUNCTIONS return keyword o Returns data, and control goes to function’s caller • If no data to return, use return; o Function ends when reaches right brace • Control goes to caller Functions cannot be defined inside other functions Function signature o Part of prototype with name and parameters • double maximum( double, double, double ); Function signature
  • 6. Thank you Please subscribe my channel for more videos and courses