#include<iostream>
using namespace std;
/***************************************
语法:返回值数据类型 函数名(参数=默认值){}
***************************************/
int func(int a, int b, int c)
{
return a + b + c;
}
int func1(int a, int b=30, int c=30)
{
return a + b + c;
}
int main()
{
int f = func(10,20,30);
cout << f << endl;//f=60
int f1 = func1(10,20,30);
cout << f1 << endl;//f1=60,有参数优先参数,没参数用默认值
int f2 = func1(10, 40);
cout << f2 << endl;//f2=80,有参数优先参数
//1.如果参数某个位置有默认值,那么从这个参数开始,之后的参数必须有默认值,
//否则报错 int fun(int a,int b=20,int c),这是错误的
//2.函数声明有默认参数,函数实现的时候不能有默认参数,二者选一
//int fun(int a=10,int b=20,int c=30); int fun(int a,int b,int c){}
system("pause");
return 0;
}