The C++Course provides a general introduction to programming in C++. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details.


Definitions and Uses

Pulling together all the code fragments from the previous section, the whole program looks like this:

#include <iostream.h>

void newLine ()
{
  cout << endl;
}

void threeLine ()
{
  newLine ();  newLine ();  newLine ();
}

void main ()
{
  cout << "First Line." << endl;
  threeLine ();
  cout << "Second Line." << endl;
}

This program contains three function definitions: newLine, threeLine, and main.

Inside the definition of main, there is a statement that uses or calls threeLine. Similarly, threeLine calls newLine three times. Notice that the definition of each function appears above the place where it is used.

This is necessary in C++; the definition of a function must appear before (above) the first use of the function. You should try compiling this program with the functions in a different order and see what error messages you get.


Last Update: 2005-12-05