demo_function_default_parameter.cpp

来自「对于一个初涉VC++的人来书」· C++ 代码 · 共 30 行

CPP
30
字号

#include <iostream.h>
#include <iomanip.h>

int get_volume(int length, int width=2, int height=3);

int main()
{
	int x = 10, y = 12, z = 15;

	cout << "Some box data is " ;
	cout << get_volume(x, y, z) << endl;
	cout << "Some box data is " ;
	cout << get_volume(x, y) << endl;
	cout << "Some box data is " ;
	cout << get_volume(x) << endl;
	cout << "Some box data is ";
	cout << get_volume(x, 7) << endl;
	cout << "Some box data is ";
	cout << get_volume(5, 5, 5) << endl;

	return 0;
}

int get_volume(int length, int width, int height)
{
	cout<<setw(5)<<length<<setw(5)<<width<<setw(5)<<height<<' ';
	return length * width * height;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?