0
点赞
收藏
分享

微信扫一扫

C++:函数默认形参,指定顺序示例

爱做梦的老巫婆 2022-05-03 阅读 119
c++
// moren_xingcan2.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#include<iostream>
using namespace std;

void f(int a, int b = 2, int c = 3, int d = 4);		//声明,默认形参

int _tmain(int argc, _TCHAR* argv[])
{
	f(1);		
	f(5, 10);
	f(11, 12, 13);
	f(20, 30, 40,50);
	getchar();
	return 0;
}

void f(int a, int b, int c , int d)		//函数实现
{
	cout << a << " " << b << " " <<  c  << " " << d << endl;
}

运行结果:

 

举报

相关推荐

0 条评论