< previous page page_339 next page >

Page 339
within the function itself. And because local variables are destroyed when the function returns, you cannot use them to store values between calls to the function.
The following code segment illustrates each of the parts of the function declaration and calling mechanism that we have discussed.
#include <iostream.h>

void TryThis( int, int, float );      // Function prototype

int main()                            // Function definition
{
    int   int1;                       // Variables local to main
    int   int2;
    float someFloat;
    .
    .
    .

    TryThis(intl, int2, someFloat);   // Function call with three
                                      //   actual parameters
    .
    .
    .
}

void TryThis( int   param1,           // Function definition with
              int   param2,           //   three formal parameters
              float param3 )
{
    int   i;                          // Variables local to TryThis
    float x;
    .
    .
    .
}
The Return Statement
The main function uses the statement
return 0;
to return the value 0 (or 1 or some other value) to its caller, the operating system. Every value-returning function must return its function value this way.
A void function does not return a function value. Control returns from the function when it falls off the end of the bodythat is, after the final statement has executed. As you saw in the NewWelcome program, the PrintLines function simply prints some lines of asterisks and then returns.

 
< previous page page_339 next page >