More on Functions - PowerPoint PPT Presentation

About This Presentation
Title:

More on Functions

Description:

BR. 3. Function Prototype ... BR. 6. Function Parameter. This help customize a ... BR. 9. Summary. Functions provide basic construct to modularize you solution. ... – PowerPoint PPT presentation

Number of Views:11
Avg rating:3.0/5.0
Slides: 10
Provided by: bina1
Learn more at: https://cse.buffalo.edu
Category:

less

Transcript and Presenter's Notes

Title: More on Functions


1
More on Functions
  • B. Ramamurthy
  • Chapter 5

2
Introduction
  • 1. Function Prototype
  • 2. Function Definition
  • 3. Function Call
  • 4. Function parameters
  • 5. Function Usage
  • 6. Function execution trace

3
Function Prototype
  • Function prototype specifies the format
    (signature) for calling a function.
  • Function prototype is declared at the top of your
    program before the main function.
  • It is same as the function header but with a
    semicolon at the end.
  • Example Here is the prototype for factoiral
    function
  • int factorial (int n)

4
Function Definition
  • int factorial (int n)
  • int product 1
  • for (int j 1 jlt n j)
  • product product j
  • return product

5
Function Invocation ( or call)
  • ..
  • int main()
  • int n 7
  • int x
  • x factorial (n)
  • x factorial (9)

6
Function Parameter
  • This help customize a function.
  • Parameters are specified at the header of a
    definition as place holders
  • Actual value of the parameters are passed in at
    the time of function invocation.

7
Function Parameters
  • Write a function for rectangle code
  • Parameterize the function add length and width
    as parameters to the function
  • Call/Invoke function with different parameters.

8
Function Execution
  • When a function is called control is transferred
    into the function
  • Parameters are assigned
  • Execution begin at the first statement inside the
    function.
  • It continues until the end of the function.
  • Then control is transferred back to invoking
    method.

9
Summary
  • Functions provide basic construct to modularize
    you solution.
  • Practice writing functions.
  • Read Chapter 5.
Write a Comment
User Comments (0)
About PowerShow.com