《The C Programming Language》学习笔记

最近又想回过头来好好看看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

The C programming Language By Brian W. Kernighan and Dennis M. Ritchie. Published by Prentice-Hall in 1988 ISBN 0-13-110362-8 (paperback) ISBN 0-13-110370-9 目录结构: Contents Preface Preface to the first edition Introduction Chapter 1: A Tutorial Introduction Getting Started Variables and Arithmetic Expressions The for statement Symbolic Constants Character Input and Output File Copying Character Counting Line Counting Word Counting Arrays Functions Arguments - Call by Value Character Arrays External Variables and Scope Chapter 2: Types, Operators and Expressions Variable Names Data Types and Sizes Constants Declarations Arithmetic Operators Relational and Logical Operators Type Conversions Increment and Decrement Operators Bitwise Operators Assignment Operators and Expressions Conditional Expressions Precedence and Order of Evaluation Chapter 3: Control Flow Statements and Blocks If-Else Else-If Switch Loops - While and For Loops - Do-While Break and Continue Goto and labels Chapter 4: Functions and Program Structure Basics of Functions Functions Returning Non-integers External Variables Scope Rules Header Files Static Variables Register Variables Block Structure Initialization Recursion The C Preprocessor File Inclusion Macro Substitution Conditional Inclusion Chapter 5: Pointers and Arrays Pointers and Addresses Pointers and Function Arguments Pointers and Arrays Address Arithmetic Character Pointers and Functions Pointer Arrays; Pointers to Pointers Multi-dimensional Arrays Initialization of Pointer Arrays Pointers vs. Multi-dimensional Arrays Command-line Arguments Pointers to Functions Complicated Declarations Chapter 6: Structures Basics of Structures Structures and Functions Arrays of Structures Pointers to Structures Self-referential Structures Table Lookup Typedef Unions Bit-fields Chapter 7: Input and Output Standard Input and Output Formatted Output - printf Variable-length Argument Lists Formatted Input - Scanf File Access Error Handling - Stderr and Exit Line Input and Output Miscellaneous Functions String Operations Character Class Testing and Conversion Ungetc Command Execution Storage Management Mathematical Functions Random Number generation Chapter 8: The UNIX System Interface File Descriptors Low Level I/O - Read and Write Open, Creat, Close, Unlink Random Access - Lseek Example - An implementation of Fopen and Getc Example - Listing Directories Example - A Storage Allocator Appendix A: Reference Manual Introduction Lexical Conventions Syntax Notation Meaning of Identifiers Objects and Lvalues Conversions Expressions Declarations Statements External Declarations Scope and Linkage Preprocessor Grammar Appendix B: Standard Library Input and Output: <stdio.h> File Operations Formatted Output Formatted Input Character Input and Output Functions Direct Input and Output Functions File Positioning Functions Error Functions Character Class Tests: <ctype.h> String Functions: <string.h> Mathematical Functions: <math.h> Utility Functions: <stdlib.h> Diagnostics: <assert.h> Variable Argument Lists: <stdarg.h> Non-local Jumps: <setjmp.h> Signals: <signal.h> Date and Time Functions: <time.h> Implementation-defined Limits: <limits.h> and <float.h> Appendix C: Summary of Changes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值