1、最标准的写法
#include <stdio.h>
int main()
{
printf("Hello World! ");
return 0;
}
2、把int 换成void
#include <stdio.h>
void main()
{
printf("Hello World! ");
return 0;
}
3、不写int
#include <stdio.h>
main()
{
printf("Hello World! ");
return 0;
}
4、不写return
#include <stdio.h>
int main()
{
printf("Hello World! ");
}
以上四种写法均成功运行。
多种写法不报错的原因
- C语言最早的时候只是一种规范和标准(例如C89, C11等)
- 标准的推行需要各大厂商的支持和实施
- 而在支持的实施的时候由于各大厂商利益、理解等问题,导致了实施的标准不同,发生了变化
- Turbo C
- Visual C(VC)
- GNU C(GCC)
- 所以大家才会看到不同的书上书写的格式有所不同, 有的返回int,有的返回void,有的甚至没有返回值