C++DAY8 函数·函数的常见样式

函数的常见样式有四种:

1、无参无返

2、无参有返

3、有参无返

4、有参有返

#include<iostream>
using namespace std;


//1、无参无返
void aaa1()
{
	cout << "thiis is aaa1" << endl;
}

//2、无参有返
int aaa2()
{
	cout << "this is aaa2" << endl;

	return 1;
}

//3、有参无返
void aaa3(int a=1,int aa=2)
{
	cout << "this is aaa3" << endl;
	int b = a + aa;
}

//4、有参有返
int aaa4(int a1 = 10, int a2 = 20)
{
	cout << "this is aaa4" << endl;

	return 100;
}
int main()
{
	//1、无参无返的调用
	aaa1();
	//2、无参有返的调用
	int aaa = aaa2();
	//3、有参无返的调用
	int shu1 = 10;
	int shu2 = 10;
	aaa3(shu1, shu2);
	//4、有参有返的调用
	int shu3 = 10;
	int shu4 = 10;
	int shu5 = aaa4();

	system("pause");

	return 0;
}

所以有参的函数在调用时要使用量,无参则不需要量的引用,可直接使用;而有返的函数可以为变量赋值(它返回的值就是给变量赋的值),无返则赋不了值。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值