用一个最原始的hello, world程序让初学者了解各个程序片段分别都有什么用。
但由于是本书的第一个程序,main函数写的不规范,没有返回类型,参数和返回值,所以编译过程中不可避免的会遇见以下错误:
warning: return type defaults to ‘int’ [-Wimplicit-int]
3 | main() {
| ^~~~
第一章后面几小节的程序也会有此类报错,不必过多在意。进入后面的章节之后作者会恢复到标准的main函数写法,这个warning就不会再出现了。
对于hello, world函数中其他片段丢失后编译器的反馈请参考下面的代码最后的注释部分:
#include <stdio.h>
main() {
printf("hello, world\n");
}
/*
1. Whitout #include <stdio.h> :
ERROR/WARNING message:
----------------------------------------------------------------
Exercise1_1.c:3:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
3 | main() {
| ^~~~
Exercise1_1.c: In function ‘main’:
Exercise1_1.c:4:5: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
4 | printf("hello, world\n");
| ^~~~~~
Exercise1