不要省略返回值的类型

不要省略返回值的类型。

C 语言中,凡不加类型说明的函数,一律自动按整型处理。这样做不会有什么好处, 却容易被误解为 void 类型。

C++语言有很严格的类型安全检查,不允许上述情况发生。由于 C++程序可以调用 C 函数,为了避免混乱,规定任何 C++/ C 函数都必须有类型。

如果函数没有返回值,那么 应声明为 void 类型。

 

 1 #include <iostream>
 2 #include <stdlib.h>
 3 #include <math.h>
 4 #define PI 3.1415926535
 5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 6 
 7 using namespace std;
 8 int main(int argc, char** argv) {
 9         int i;
10     double x=PI/180;
11     cout<<"X\tSIN(X)\t\tCOS(X)"<<endl;
12     cout<<"---------------------------------------"<<endl;
13     for (i=0;i<=360;i=i+30) {
14         cout<<i<<"\t";
15         cout.precision(2);
16         cout<<sin(i*x)<<"\t\t";
17         cout<<cos(i*x)<<endl;
18     }
19     return 0;
20 }

 

posted @ 2018-08-03 13:08  borter  阅读(600)  评论(0编辑  收藏  举报