1、Compilation
C is a compiled language.
C compilers map C programs into architecture-
specific machine code (string of 0s and 1s)
-
Unlike Java, which converts to architecture-independent bytecode (run by JVM)
-
Unlike python, which directly interprets the code
-
Main difference is when your program is mapped to low-level machine instructions
ps:C 程序是在CPU上加载并且执行的,所以速度很快


2、Typed Variables in C
- Integer sizes are machine dependant!
- Common size is 4 or 8 bytes (32/64-bit), but can’t ever assume this
- Can add“unsigned” before int or char
Characters
ASCII standard defines 128 different characters and their numeric encodings
A char takes up 1 byte of space
- 7 bits is enough to store a char (2 ^ 7 = 128), but we add a bit to round up to 1 byte since computers usually deal with multiples of bytes
Typecasting in C

Structs Alignment and Padding in C

Unions in C

联合体与结构体之间的区别是:结构体的各个成员会占用不同的内存,相互之间无影响。而联合体的所有成员公用一段内存,修改一个成员会影响其余所有成员。
结构体占用的内存大于等于所有成员占用的内存的总和(成员之间可能会存在缝隙),联合体占用的内存等于最长的成员占用的内存。
联合体使用了内存覆盖技术,同一时刻只能保存一个成员的值,如果对新的成员赋值,就会把原来成员的值覆盖掉。
C 和 java的区别

特别注意,c中要自己手动管理内存。
3. C Syntax and Control Flow

C Syntax:main

main Example

打印argv[3],结果是 null 或者 zero
C Syntax: Variable Declarations
如果某个变量被申明了但是没进行初始化,那么之后你直接引用它的话会得到垃圾值
c语言中是没有布尔类型的
Has there been an update to ANSI C?

4. Pointers — Address vs. Value
A pointer is a variable that contains an address
- An address refers to a particular memory location,usually also associated with a variable name
- Name comes from the fact that you can say that it points to a memory location

Pointer Syntax

Pointers in C

Pointer Bugs

Summary

637

被折叠的 条评论
为什么被折叠?



