在调用函数时,可以不用或使用部分参数调用,不指定的值为函数默认值
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <fstream>
#include <shappmgr.h>
#include <stdio.h>
#include <cmath>
using namespace std;
int add(int a = 2, int b = 4, int c = 6) {
return a + b + c;
}
int main() {
int x=add();//全部使用默认参数
cout << x << endl;
int y = add(1, 3);//C的值使用默认参数
cout << y << endl;
int z=add(1, 3, 5);//全部不使用默认值
cout << z << endl;
cin.get();
}
原文:https://www.cnblogs.com/fuRyZ/p/8909171.html