【发布时间】:2014-03-23 02:14:55
【问题描述】:
我正在查看一个计算 3 个数字的平均值的程序并遇到了
#define EXIT_SUCCESS 0
使return EXIT_SUCCESS; 正常工作(在包含标题下方)。使用#define EXIT_SUCCESS 0 和return EXIT_SUCCESS; 的目的是什么,还有其他选择吗?是不是像return 0;?感谢您的宝贵时间。
这是我正在查看的程序的代码:
#include <iostream>
#define EXIT_SUCCESS 0
using namespace std;
int main()
{
// prototypes:
float add_and_div(float, float, float);
// variables:
float x, y, z;
float result;
cout << "Enter three floats: ";
cin >> x >> y >> z;
// continue the program here
result = add_and_div( x, y, z );
cout<< "Average is \n" << result;
return EXIT_SUCCESS;
}
// function definition:
float add_and_div(float n1, float n2, float n3)
{
// continue the program here
return ( n1 + n2 + n3 ) / 3;
}
【问题讨论】:
-
这太可怕了。只需
#include <cstdlib>。 -
这太可怕了。只是
return 0;:-) -
这太可怕了。只是从
main()的末尾掉下来,因为return 0;是隐含的。
标签: c++ function function-prototypes