|
|
|
|
|
|
|
void Print2Lines() // Function heading
{
cout << *************** << endl;
cout << *************** << endl;
} |
|
|
|
|
|
|
|
|
This segment is a function definition. A function definition is the code that extends from the function heading to the end of the block that is the body of the function. The function heading begins with the word void, signalling the compiler that this is not a value-returning function. The body of the function executes some ordinary statements and does not finish with a return statement to return a function value. |
|
|
|
|
|
|
|
|
Now look again at the function heading. Just like any other identifier in C++, the name of a function is not allowed to include blanks, even though our paper-and-pencil module names do. Following the function name is an empty parameter listthat is, there is nothing between the parentheses. Later we'll see what goes inside the parentheses if a function uses parameters. Now let's put main and the other two functions together to form a complete program. |
|
|
|
|
|
|
|
|
//******************************************************************
// Welcome program
// This program prints a Welcome Home message
//******************************************************************
#include <iostream.h>
void Print2Lines(); // Function prototypes
void Print4Lines();
int main()
{
Print2Lines(); // Function call
cout << Welcome Home! << endl;
Print4Lines(); // Function call
return 0;
}
//******************************************************************
void Print2Lines() // Function heading
// This function prints two lines of asterisks
|
|
|
|
|
|