c语言 函数的参数传递示例_C ++中带有示例的exit()函数

c语言 函数的参数传递示例

C ++ exit()函数 (C++ exit() function)

exit() function is a library function of cstdlib header. It is used to terminate the calling process, it accepts a status code/value (EXIT_SUCCESS or EXIT_FAILURE) and terminates the process. For example – while working with the files, if we are opening a file and file does not exist – in this case, we can terminate the process by using the exit() function.

exit()函数cstdlib标头的库函数。 它用于终止调用过程,它接受状态码/值( EXIT_SUCCESSEXIT_FAILURE )并终止过程。 例如,在处理文件时,如果我们正在打开文件而文件不存在,在这种情况下,我们可以使用exit()函数终止该过程。

Syntax of exit() function:

exit()函数的语法:

C++11:

C ++ 11:

    void exit (int status);

Parameter(s):

参数:

  • status – represents the exit status code. 0 or EXIT_SUCCESS indicates the success i.e. the operation is successful, EXIT_FAILURE indicates the failure i.e. the operation is not successfully executed.

    status –表示退出状态代码。 0或EXIT_SUCCESS表示成功,即操作成功, EXIT_FAILURE表示失败,即操作未成功执行。

Return value:

返回值:

The return type of this function is void, It does not return anything.

该函数的返回类型为void ,它不返回任何内容。

Example:

例:

    Function call:
    exit(EXIT_FAILURE);
    //or
    exit(EXIT_SUCCESS);

C ++代码演示exit()函数的示例 (C++ code to demonstrate the example of exit() function)

// C++ code to demonstrate the example of
// exit() function

#include <iostream>
#include <cstdlib>
using namespace std;

// main() section
int main()
{
    float n; // numerator
    float d; // denominator
    float result;

    cout << "Enter the value of numerator  : ";
    cin >> n;
    cout << "Enter the value of denominator: ";
    cin >> d;

    if (d == 0) {
        cout << "Value of denominator should not be 0..." << endl;
        exit(EXIT_FAILURE);
    }

    cout << n << " / " << d << " = " << (n / d) << endl;

    return 0;
}

Output

输出量

RUN 1:
Enter the value of numerator  : 10
Enter the value of denominator: 0
Value of denominator should not be 0...

RUN 2:
Enter the value of numerator  : 10
Enter the value of denominator: 3
10 / 3 = 3.33333

Reference: C++ exit() function

参考: C ++ exit()函数

翻译自: https://www.includehelp.com/cpp-tutorial/exit-function-with-example.aspx

c语言 函数的参数传递示例

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值