因為我們要向編譯器宣告一個還沒定義
即將會用到的函數
所以要把函數原型宣告
放在主函數(int main)前面
如果我們直接將函數定義放在主函數前
該函數的定義就具備宣告跟定義的功能
就不必再宣告函數原型
Ex:
[code language=”cpp”]
#include <iostream>
using namespace std;
//將定義寫在前面,就可以不用再撰寫函數宣告
void print(void){
cout << "Bello!" << endl;
}
int main(){
print();
}
[/code]