-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbackup.pug
300 lines (236 loc) · 6.25 KB
/
backup.pug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
section
h1 What is "Program"?
hr
br
p.fragment A program is an <em>abstract</em> <u>state machine</u>.
br
p.fragment A <u>behavior</u> of a state machine is a sequence of states.
br
p.fragment A <u>state</u> is an assignment of all variables.
br
p.fragment A <u>variable</u> is an <u>object</u> in computer memory.
section
h1 State Machines
hr
br
img(src = "./0-intro/figs/button-state-machine.jpg",
alt = "State Machine for Buttons",
width = 400, height = auto)
section
h1 State Machines
hr
br
img(src = "./0-intro/figs/vending-state-machine.png",
alt = "State Machine for Beverage Vending Machine",
width = 500, height = auto)
section
p C is a <span class="hl">imperative</span> programming language.
p (Imperative: 命令式的)
//- Why C?
section
h2 Why C?
hr
br
img(src = "./0-intro/figs/pl.jpg" alt = "PL"
width = 700 height = auto)
p Hundreds of programming languages
section
h2 C is General-Purpose
hr
br
<div class="row">
<div class="column">
img(src = "./0-intro/figs/linux-c.png" alt = "Linux in C"
width = 600 height = auto)
</div>
<div class="column">
img(src = "./0-intro/figs/honor-of-kings.jpg", alt = "Honor of Kings",
width = 600, height = auto)
</div>
</div>
p In principle, you can do whatever you want using C.
section
h2 C is (still) Popular
hr
img(src = "./0-intro/figs/PL-IEEE.png" alt = "PL IEEE"
width = 500 height = auto)
section
h2 "Spirit of C"
hr
br
p(class = "r-fit-text") "Keep the language small and simple."
br
br
p.fragment What you see <em>is</em> what you get.   (<code>a + b</code>)
section
h2 "Spirit of C"
hr
br
p "Don't prevent the programmer from doing what needs to be done."
br
br
p.fragment ???
section
h2 "Spirit of C"
hr
br
p "Make it <mark>fast</mark>, even if it is not guaranteed to be <mark>portable</mark>."
//- How to learn?
section
h2 How to Learn?
hr
img(src = "./0-intro/figs/keep-calm-dont-panic.jpg" alt = "Keep Calm and Don't Panic"
width = 400 height = auto)
p Beginners are welcome!
section
h2 How to Learn?
hr
br
p 20% theory + 80% coding
img(src = "./0-intro/figs/theory-practice.jpeg" alt = "Theory vs. Practice"
width = 500, height = auto)
p(class = "r-fit-text") I can teach you theory; but I cannot write code for you.
section
h2 How to Learn?
hr
br
img(src = "./0-intro/figs/step-by-step.jpg" alt = "Step by Step"
width = 500 height = auto)
p Don't expect to learn everything at once.
p (<code>pointers: *</code>)
section
h2 Dev-C++
hr
p Open Source C/C++ IDE for Windows
img(src = "./0-intro/figs/DevC++.jpg" alt = "The C Programming Language"
width = 600 height = auto)
p
a(class='button' href='https://www.bilibili.com/video/BV1sP4y1p7n5') <small>Wins-DevC++ @ bilibili</small>
section
h2 Hello World
hr
pre
code(class="lang-c")
script(type="text/template").
#include <stdio.h>
int main() {
printf("Hello World");
return 0;
}
section
h2 Comments
hr
img(src = "./0-intro/figs/less-comments.jpeg" alt = "Less Comments"
width = 400 height = auto)
p Replace verbose comments with clear code.
section
h2 How to Learn?
hr
br
img(src = "./0-intro/figs/gates-programming.jpeg" alt = "Bill Gates on Programming",
width = 800 height = auto)
//- section
//- h2 Xiaobo Wang (王小波)
//- hr
//- br
//- img(src = "./1-io/figs/Wang.jpeg" alt = "Xiaobo Wang"
//- width = 500 height = auto)
//- p Xiaobo Wang ($5\text{-}13\text{-}1952 \sim 4\text{-}11\text{-}1997$)
//- section
//- h2(style="font-variant: small-caps") Recommend
//- img(src = "./1-io/figs/5-stars.png" alt = "Recommend"
//- width = 300, height = auto)
//- hr
//- br
//- p <code>int number = 100;</code>
//- br
//- p <code>number</code> has also been <em>initialized</em>.
tr
td %o
td unsigned int
td unsigned octal (dddd)
tr
td %u
td unsigned int
td unsigned decimal (dddd)
tr
td %x, %X
td unsigned int
td unsigned hexadecimal (dddd)
section
h2 Program
hr
br
<div class="row">
<div class="column">
img(src = "./1-io/figs/program-wirth.png" alt = "Book by Wirth"
width = 400 height = auto)
p 程序 = 数据 + 操作
</div>
<div class="column">
img(src = "./1-io/figs/Wirth.jpg" alt = "Wirth"
width = 450 height = auto)
p Niklaus Wirth ($1934 \sim$)
p <small> Turing Award ($1984$) for developing a sequence of innovative computer languages</small>
</div>
</div>
section
h2 Hello World (Standard C)
hr
br
pre
code(class="lang-c")
script(type="text/template").
#include <stdio.h>
int main() {
printf("Hello World\n");
return 0;
}
br
p <code>main</code> (主) 函数是程序的入口
section
h2 Game: Guess the Number
hr
img(src = "./0-intro/figs/guess-the-number.png",
alt = "Guess the Number",
width = 500, height = auto)
p
a(class = "button" href = "https://www.abcya.com/games/guess_the_number") Guess the Number
section
h2 Declarations, Expressions, and Statements (Informal)
hr
br
p <code>double circumference = <mark>0</mark>;</code>
p <code>circumference = <mark>2 * PI * radius</mark>;</code>
br
p.fragment Declarations declare <em>variables</em>.
p.fragment Expressions express <em>values</em>.
p.fragment Statements state <em>actions</em>.
section
h2 Expressions (Formal)
hr
br
p <code>circumference = <mark>2 * PI * radius</mark>;</code>
br
ul
li Variables are expressions;
li Constants are expressions;
li If $E_{1}$ and $E_{2}$ are expressions, then $E_{1} \circ E_{2}$ is an expression.
ul
li ($\circ$ is an operator)
section
h2 Statements (Formal)
hr
br
ul
li Assignment statements
li If statements
li For statements
li $\ldots$
section
h2 Compound Statements (Blocks)
hr
p Declarations and statements surrounded by <code>{}</code>.
img(src = "./2-if-for-array/figs/compound-statement.png" alt = "Compound Statement"
width = 350 height = auto)
h3 Always use <code>{}</code>.