函数的四种基本样式:无参无返、无参有返、有参无返、有参有返

#include<iostream>
using namespace std;
//01无参无返
void test01()
{
    cout << " This is test01 " << endl;
    cout << "test01输出的语句为:用我熟练的刀法,把坏人全部讨伐" << endl;
    cout << endl;
}

//02无参有返
int test02()
{
    cout << " This is test02 " << endl;
    return 99;
}

//03有参无返
void test03(int num1)
{
    cout << " This is test03 " << endl;
    cout << "test03=" << num1 << endl;
    cout << endl;
}

//04有参有反返
int test04(int num1,int  num2)
{
    cout << " This is test04 " << endl;
    int sum = num1 + num2;
    return sum;
}
int main()
{
    //调用01函数
    test01();

    //调用02函数
    int ret = test02();
    cout << "test02=" << ret << endl;
    cout << endl;

    //调用03函数
    int a = 100;
    test03(a);

    //调用04函数
    int b = 500;
    int c = 20;
    int sum = test04(b, c);
    cout << "test04的结果为:" << sum << endl;
    cout << endl;

    system("pause");
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值