撰寫完函數的原型宣告以及定義
接下來
就要在程式裡面呼叫函數
呼叫格式:
- 傳回值指定給變數
- 直接呼叫函數,不需要傳回值
Ex:
[code language=”cpp”]
#include <iostream>
using namespace std;
#include <iostream>
using namespace std;
void show(int);
int plus1(int);
int main(){
int a=10,b;
show(a); //呼叫函數,傳入a變數
b=plus1(10); //呼叫函數,並把傳回值指定給b變數
cout << "b=" << b << endl;
}
void show(int n){
cout << n << endl;
}
int plus1(int n){
return (n+10);
}
[/code]