What is a return data type?
By the end of function,
if you have a "return" statement,
which kind of data
type you return to the caller has to be
listed in
the beginning of function header.
When a function does not return any value
to the calling program (Caller)
or return more than one value,
you must use the keyword void as the
return class.
Examples:
| Return more than one information
The information is passed back by parameters. |
Return nothing.
main() calls print() doing the job. print() prints information on the screen and print() does not return any information to caller, main(). |
| #include <iostream.h>
void getData(int &x, int &y); void
main ()
void
getData(int &x, int &y)
|
#include <iostream.h>
void print(int x, int y); void
main ()
void
print(int x, int y)
|
| Return the maximum number which is an integer. | Return the average of two integers which may be a decimal. |
| #include <iostream.h>
int getMax(int x, int y); void
main ()
int
getMax(int x, int y)
|
#include <iostream.h>
float getAverage(int x, int y); void
main ()
float
getAverage(int x, int y)
T = x +
y;
|
| Call more than one function. Please see the interface between functions. |
| #include <iostream.h>
void getData(int &x, int &y); int getMax(int x, int y); float getAverage(int x, int y); void print(int x, int y, int LargeOne, float avg); void
main ()
void
getData(int &x, int &y)
T = x +
y;
|