0% found this document useful (0 votes)
12 views20 pages

Functions Part1 Tut

Uploaded by

adham0n10ashraf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views20 pages

Functions Part1 Tut

Uploaded by

adham0n10ashraf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

▪ A function groups a number of program

statements into a unit and gives it a


name. This unit can then be invoked
from other parts of the program.

1
▪ The most important reason to use functions is to aid in the conceptual organization
of a program.

▪ Another reason to use functions (and the reason they were invented, long ago) is to
reduce program size.

2
Declaration

Call

Definition

3
Declaration

Definition

Call

4
▪ Passing Constants

5
▪ Passing Variables

6
▪ Passing Variables by Value

▪ the function creates new variables to


hold the values of these variable
arguments.

7
▪ Passing Variables by Reference

▪ Passing arguments by reference uses a


different mechanism. Instead of a
value being passed to the function a
reference to the original variable in
the calling program is passed.
▪ An important advantage of passing by
reference is that the function can
access the actual variables in the
calling program. Among other benefits
this provides a mechanism for passing
more than one value from the
function back to the calling program.

8
9
▪ We can only use return to return one
variable only

10
1. A function’s single most important role is to:
a. give a name to a block of code.
b. reduce program size.
c. accept arguments and provide a return value.
d. help organize a program into conceptual units.
A function argument is :
a. variable in the function that receives a value from the
calling program.
b. way that functions resist accepting the calling program’s
values.
c. value sent to the function by the calling program.
d. value returned by the function to the calling program.
11. Which of the following can legitimately be passed to a
function?
a. A constant
b. A variable
c. A structure
d. A header file
A default argument has a value that
a. may be supplied by the calling program.
b. may be supplied by the function.
c. must have a constant value.
d. must have a variable value.
11
12
13
14
15

You might also like