//默认参数
void myPrint(int a=3)
{
cout<<“a”<<a<<endl;
}
void main()
{
myPrint(4);//若你填写参数则为你填写的,不填写则为默认
myPrint();
}
//注意:只有在参数列表后面的参数才可提供默认参数值(int a,int b,int c=1,int d=2;)
//占位参数
void func(int a,int b,int)
{
cout<<“a”<<a<<endl;
}
void main()
{
func(1,2);//错误的!
func(1,2,3);//正确的!
}
//默认参数和占位参数的共用
void func(int a,int b,int=3)
{
}
void main()
{
func(1,2,3);//正确
func(1,2);//正确
}
//作用:为以后的扩展留下线索
879

被折叠的 条评论
为什么被折叠?



