Relative Links: C Programming Language
The C Programming Language
Contents
- The C Programming Language
这是一本programmer写给programmer看的书
图书信息
http://book.douban.com/subject/1236999/
- 作者: Brian W. Kernighan / Dennis M. Ritchie
- 出版社: Prentice Hall
- 副标题: Second Edition
- 出版年: 1989-03-01
- 页数: 274
- 定价: $48.67
- 装帧: Paperback
- ISBN: 9780131103627
Contents
Chapter 1 - A Tutorial Introduction
Chapter 2 - Types, Operators and Expressions
2.1 Variable Names
2.2 Data Types and Sizes
c语言的类型(斜体是C99的类型)
整数: char/short/int/long/long long
浮点数:float/double/long double
逻辑:bool
- 指针
- 自定义类型
int/long/double
- 格式: %d/%ld/%lf
范围:char<short<int<float<double
- 长度:1byte ~ 16 byte
- 内存中的形式: 二进制数(补码)、编码
整数
- char: 1 byte(8 bit): -128~127
- short: 2 bytes: -32768~32767
- int: depend on compiler(cpu), usually 1 byte: %d
- long: same as above:
- long long: 8 byte: %ld
- unsigned: 后面加u或U: %u
- unsigned long long: %lu
- 16进制和8进制
浮点数
类型 |
字⻓ |
范围 |
有效数字 |
scanf |
printf |
float |
32 |
±(1.20E38 |
7 |
%f |
%f, %e |
double |
64 |
±(2.2E308 |
15 |
%lf |
%f, %e |
- 带小数点的字面量是double而不是float;
- float需要用f或F为后缀来表明身份;
- 如果没有特殊需要,只使用double;对于现代cpu,存储和计算double与float是一样的;
字符
- char是一种整数,也是一种特殊的类型:字符
- scanf和printf用%c来输入输出字符
逻辑类型
#include "stdbool.h" 之后就可以使用bool和true、false了
2.3 Constants
int/float/char/enum
2.6 Relational and Logical Operators
优先级: ! > && > ||
2.7 Type Conversions
automatic conversions: convert a "narrower" operand into a "wider" one without losing information
2.11 Conditional Expressions
- 当两个值的关系符合关系运算符的预期时,关系运算的结果为整数1;否则为整数0
2.12 Precedence and Order of Evaluation
关系运算符的优先级
- 所有的关系运算符的优先级比算数运算的低,但是比赋值运算的高;
- 判断是否相等的==和!=的优先级比其他的低,而连续的关系运算是从左到右进行的
Chapter 3 - Control Flow
3.4 Switch
3.5 Loops - While and For
The for statement
for (expr1; expr2; expr3 )
statement
is equivalent to
expr 1;
while (expr2) {
statement
expr3;
}
3.7 Break and Continue
- break: 跳出当前循环;
- continue: 跳过本轮循环剩下的语句,进入当前循环的下一轮
3.8 Goto and labels
Chapter 4 - Functions and Program Structure
Chapter 5 - Pointers and Arrays
Chapter 6 - Structures
Chapter 7 - Input and Output
Chapter 8 - The UNIX System Interface
The book
http://www.iups.org/media/meeting_minutes/C.pdf