如下所示,当C语言main函数,返回值是void时,有提醒:return type of ‘main’ is not ‘int’ [-Wmain]
- #include <stdio.h>
- //warnning:return type of ‘main’ is not ‘int’ [-Wmain]
- void main(){
- printf(”hello world!”);
- return 0;
#include <stdio.h>
//warnning:return type of 'main' is not 'int' [-Wmain]
void main(){
printf("hello world!");
return 0;
- }
}
正确写法如下:
- #include <stdio.h>
- int main(){
- printf(”hello,c!”);
- return 0;
- }
#include <stdio.h>
int main(){
printf("hello,c!");
return 0;
}
虽然能运行,但是看着不爽我就去查了下。发现c标准里规定main返回值必须为int。
以下是stackoverflow的一些回答:
What should main() return in C and C++?
Hello.c: In function ‘main’: Hello.c:13: warning: return type of ‘main’ is not ‘int’? [duplicate]