最近又想回过头来好好看看C语言,以前虽然就会点,但发现其实不太懂,遂拿起《C程序设计语言(第2版·新版)》边看边练习。
编译的预处理阶段将对程序文本进行宏替换,包含其他源文件以及进行条件编译。
C语言不提供直接处理诸如字符串,集合,列表或数组等复合对象的操作。虽然可以将整个结构作为一个单元进行拷贝,但C语言没有处理整个数组或字符串的操作。除了由函数的局部变量提供的静态定义和堆栈外,C语言没有定义任何存储器分配工具,也不提供堆和无用内存回收工具。最后,C语言本身没有提供输入/输出功能,没有READ或WRITE语句,有没有内置的文件访问方法。所有这些高层的机制必须由显式调用的函数提供。C语言的大部分实现已合理地包含了这些函数的标准集合。
C语言保持了其初始的设计思想,即程序员了解他们在做什么,惟一的要求是程序员要明确地表达他们的意图。
标准库提供了一个与操作系统交互的公用接口,使用这个库执行输入,输出或其他访问操作系统的操作的程序可以不加修改地运行在不同的机器上。
学习一门新的程序设计语言的惟一途径就是使用它编写程序。
类似于/n的转义字符序列为表示无法输入的字符或不可见字符提供了一种通用的可扩充的机制。
我们建议每行只书写一条语句,并在运算符两边各加上一个空格字符。
P8 练习1-3,1-4
代码 练习1-3
代码 练习1-4
在允许使用某种类型变量值的任何场合,都可以使用该类型的更复杂的表达式
P9 练习1-5
代码 练习1-5
符号常量: #define 名字 替换文本
符号常量名通常用大写字母拼写,这样可以很容易与用小写字母拼写的变量名相区别。注意:#define指令行末尾没有分号。
文件结束符EOF(end of file)定义在头文件<stdio.h>中,是一个整型数,其具体数值时什么并不重要,只要它与任何char类型的值都不同即可。
P11 练习1-7 编写一个打印EOF值的程序
代码 练习1-7(虽然打印的结果是-1,但使用终端时,EOF在类Unix和Windows上分别用Ctrl+D,Ctrl+Z来表示)
单引号中的字符表示一个整型值,该值等于此字符在机器字符集中对应的数值,称之为字符常量
P13 练习1-8 1-9 1-10
代码 练习1-8
代码 练习1-9
代码 练习1-10(疑问:回退符无法再终端输入)
由&&或||连接的表达式由左至右求值,并保证在求值过程中只要能够判断最终的结果为真或假,求值就立即终止。
P15 练习1-12
代码 练习1-12
P17 练习1-13 1-14
代码 练习1-13
代码 练习1-14