// h_mingcheng.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void func(int a=666)
{
cout << "a=" << a << endl;
}
//求立方体体积
void get(int len, int w, int h=10)
{
cout << len << " " << w << " " << h << endl;
cout << len * w*h << endl;
}
int main()
{
int value = 110;
func();//得到的结果 打印是666
int len = 1;
int w = 2;
int h = 3;
//get(len, w, h);
//默认参数是从右向左,如果len有默认参数,那么w和h也要有
get(len, w);
return 0;
}
占位参数
// h_mingcheng.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void func(int a=666)
{
cout << "a=" << a << endl;
}
//求立方体体积
void get(int len, int w, int h=10)
{
cout << len << " " << w << " " << h << endl;
cout << len * w*h << endl;
}
void fun(int x,int)//占位参数
{
cout << "x=" << x << endl;
}
void fun1(int x, int = 0)
{
cout << "x=" << x << endl;
}
int main()
{
int value = 110;
func();//得到的结果 打印是666
int len = 1;
int w = 2;
int h = 3;
//get(len, w, h);
//默认参数是从右向左,如果len有默认参数,那么w和h也要有
get(len, w);
fun(10, 20);
fun1(10);
return 0;
}