牛骨文教育服务平台(让学习变的简单)

将前面章节所有的代码片段集中到一起后,整个程序如下:

#include <iostream.h>
void newLine ()
{
  cout << endl;
}
void threeLine ()
{
  newLine (); newLine (); newLine ();
}
void main ()
{
    cout << "First Line." << endl;
    threeLine ();
    cout << "Second Line." << endl;
}

这段程序包含3个函数定义:newLine、threeLine和main。

main函数内有一条语句使用(调用)了threeLine。同样的,threeLine调用了三次newLine。请注意,每个函数定义都出现在调用之前。

在C++中这是必需的:函数的定义必须出现在第一次使用之前(之上)。你可以把函数顺序调换一下,然后尝试编译程序,看得到什么错误信息。