《C程序设计语言》第二版 Exercise1-1

用一个最原始的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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值