1.定义
2.分类
1.全缺省参数
//定义函数Func
void Func(int a = 10,int b = 20,int c = 30)
{
cout <<<< "a = " << a << endl;
cout << "b = " << b << endl;
cout << "c = " << c << endl;
cout << endl;
}
int main()
{
Func();
Func(1);
Func(1, 2);
Func(1, 2, 3);
return 0;
}
运行结果:
2.半缺省参数
//定义函数Func
void Func(int a,int b = 20,int c = 30)//参数的值只能从右向左给出
{
cout <<<< "a = " << a << endl;
cout << "b = " << b << endl;
cout << "c = " << c << endl;
cout << endl;
}