函数【默认参数】

做了一道选择题,让选择默认参数

int fun(int a, int b, int c);
1 int fun(int a = 0, int b = 1, int c = 1);
2 int fun(int a = 0, int b, int c = 1);//错误
3 int fun(int a, int b=0, int c = 1);//正确


如果某个参数是默认参数,那么它后面的参数必须都是默认参数

默认参数可以放在函数声明或者定义中,但只能放在二者之一

函数重载时谨慎使用默认参数值

参考:https://blog.csdn.net/baoendemao/article/details/40950379

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章