c++函数参数相关的扩展

#include <iostream>
using namespace std;

void myPrint(int x = 3)
{
	cout<<"x"<<x<<endl;
}

//1 若 你填写参数,使用你填写的,不填写默认
//2 在默认参数规则 ,如果默认参数出现,那么右边的都必须有默认参数
void myPrint2( int m, int n, int x = 3, int y = 4)
//void myPrint2( int m, int n, int x = 3, int y )
{
	cout<<"x"<<x<<endl;
}

void main_默认参数()
{
	
	myPrint(4);
	myPrint(); 

	//
	cout<<"hello..."<<endl;
	system("pause");
	return ;
}

//函数占位参数 函数调用是,必须写够参数

void func1(int a, int b, int)
{
	cout<<"a"<<a<<" b"<<b<<endl;
}

void main_占位参数()
{
	
	//func1(1, 2); //err调用不起来
	func1(1, 2, 3);

	cout<<"hello..."<<endl;
	system("pause");
	return ;
}

//默认参数和占位参数

void  func2(int a, int b, int =0)
{
	cout<<"a="<<a<<";b="<<b<<endl;
}

void main()
{
	func2(1, 2); //0k
	func2(1, 2, 3); //ok
	
	cout<<"hello..."<<endl;
	system("pause");
	return ;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值