Show toolbar

2014年7月14日 星期一

Default Argument

標題:函式預設引數
VC++ (defaultArgument.cpp):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//Chapter 3 - Default Argument
#include <iostream>
using namespace std;
double circumference(double, double = 3.14);
int main(void)
{
//scientific使用科學記號輸出
cout << scientific << circumference(1) << endl;
cout << scientific << circumference(1, acos(-1.0)) << endl;
system("pause");
return 0;
}
double circumference(double d, double pi) {
return d * pi;
}
範例結果:


說明:
基礎的函式預設引數範例。

沒有留言:

張貼留言