Last Updated:
Thursday 26th January 2006, 7:52 PT, AHD
Chapter 4
Functions For All Subtasks
By Anne Dawson
4.1 void-Functions
4.2 Call-by
Reference Parameters
4.3 Using
Procedural Abstraction
4.4 Testing and
Debugging Functions
4.1 void Functions
In
C++ a function must either return a single value or no value at all.
A function
that returns no value is known as a void function.
The return statement
The return
statement in a non-void statement:
Void-functions and
functions which return a value can have return statements.
In the case of a function which returns a
value, the return statement specifies the value being returned.
The return statement in a void
statement:
In a
void-function, the return statement simply ends the function.
You can have more than one return
statement in a function!
Because a void-function returns nothing, it does not need
a return statement. The function
ends at the last line in the function. But, if a void-function does contain one
or more return statements, execution of the function ends when the first return
is encountered.
A void
function: 04-02.cpp
http://www.annedawson.com/04-02.cpp
(Text book references can be seen at the end of this
presentation.)
Use of return in a void function:
04-03.cpp
http://www.annedawson.com/04-03.cpp
(Text book
references can be seen at the end of this presentation.)
4.2 Call-by-reference Parameters
Call by
Value: funcs08.cpp
http://www.annedawson.com/funcs08.cpp
Call by Reference: funcs09.cpp
http://www.annedawson.com/funcs09.cpp
Program Development using function stubs: funcs10.cpp
http://www.annedawson.com/funcs10.cpp
4.3 Using Procedural
Abstraction
Using Procedural Abstraction:
p212_01.cpp -
p212_05.cpp
4.4 Testing and Debugging Functions
See textbook
This Presentation
uses the following files:
5th Ed 4th Ed 3rd Ed 2nd Ed
04-02.cpp p160 p180 p178 p172
04-03.cpp p162 p182 p180 p174
funcs08.cpp ---- ---- ---- ----
funcs09.cpp ---- ---- ---- ----
funcs10.cpp ---- ---- ---- ----
p212_01.cpp ---- ---- ---- ----
p212_02.cpp ---- ---- ---- ----
p212_03.cpp ---- ---- ---- ----
p212_04.cpp ---- ---- ---- ----
p212_05.cpp ---- ---- ---- ----