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_SUCCESS或EXIT_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语言 函数的参数传递示例