Packaging Code in Functions 121
5
Q What are member functions?
AMember functions are special functions used in object-oriented languages such as
C#, C++, and Java. They are part of a class—which is a special type of structure
used in object-oriented languages. You’ll learn more about member functions in the
bonus week.
Workshop ............................................................................................................
The Workshop provides quiz questions to help you solidify your understanding of the
material covered and exercises to provide you with experience in using what you’ve
learned.
Quiz ..............................................................................................................
- Will you use structured programming when writing your C programs?
- How does structured programming work?
- How do C functions fit into structured programming?
- What must be the first line of a function definition, and what information does it
contain? - How many values can a function return?
- If a function doesn’t return a value, what type should it be declared?
- What’s the difference between a function definition and a function prototype?
- What is a local variable?
- How are local variables special?
- Where should the main()function be placed?
Exercises ........................................................................................................
- Write a header for a function named do_it()that takes three type chararguments
and returns a type floatto the calling program. - Write a header for a function named print_a_number()that takes a single type
intargument and doesn’t return anything to the calling program. - What type value do the following functions return?
a.int print_error( float err_nbr);
b.long read_record( int rec_nbr, int size );
4.BUG BUSTER:What’s wrong with the following listing?
#include <stdio.h>
09 448201x-CH05 8/13/02 11:15 AM Page 121