diff --git a/programming/24fall/lec6/index.html b/programming/24fall/lec6/index.html index 90a10e7..0b07222 100644 --- a/programming/24fall/lec6/index.html +++ b/programming/24fall/lec6/index.html @@ -1184,16 +1184,16 @@

多级指针 printf("%d = %d = %d", a, *p, **var); 在上面的例子中,我们定义了一个 二级指针 var。二级指针可以理解为 “指针的指针“。一级指针可以用来存储一般变量或其他常量的地址,而一级指针同样是变量,我们可以使用二级指针来存储一级指针的地址。 -
-

[!warning] 注意 -在程序中,最好不要混用不同级的指针。

-
+
+

注意

+

在程序中,最好不要混用不同级的指针。

+

数组和指针

数组名实际上就是一个指针,数组表示 a[1] 和指针表示 &(a + 1) 实际上指的是同一个东西,两者也可以相互转化。 此外,二维数组的地址分布和我们的直观感受并不相同,其有下面的规律:

二维数组

-

int a[3][2]; +

int a[3][2]; 1. 首先需要知道,二维数组中的地址是线性分布的。也就是说,a[0][1] 的下一个就是 a[1][0] 2. 其次,二维数组是如何实现二维存储数据的呢?原因在于:a 是一个一维数组的指针。在上面的例子中,a 是一个长度为 2 int 数组的指针,所以 a[0] 指向第一个一维数组,a[1] 指向第二个一维数组。 3. 实际上,我们可以使用 *(*(a + i) + j) 来表示 a[i][j]。因为 *(a + i) 指向第 i 个数组(假设叫 b),而我们可以用 *(b + j) 来表示 b[j]。 @@ -1393,7 +1393,7 @@

结构体指针 '->' 符号而不是 '.' 符号。

内存分配与释放

-

在实际使用时,我们通常都需要让一个结构体指针指向一个实际有内存的结构体(也就是让 p 指向 A。在上面的例子中,我们是先定义了结构体 A,然后再设了一个结构体指针指向 A。那么能否有一个更简便的做法呢?\

+

在实际使用时,我们通常都需要让一个结构体指针指向一个实际有内存的结构体(也就是让 p 指向 A。在上面的例子中,我们是先定义了结构体 A,然后再设了一个结构体指针指向 A。那么能否有一个更简便的做法呢?

小心野指针

注意,千万不要定义一个结构体指针 p 后就直接进行相关赋值。因为此时我们还没有给指针 p 分配一个确定的空间,可以理解成 p 指向了一个虚无缥缈的地方,是一个 野指针

diff --git a/search/search_index.json b/search/search_index.json index fe98fe4..dbd26d9 100644 --- a/search/search_index.json +++ b/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"\u9996\u9875","text":"

\ud83d\ude09 \u4f60\u597d\uff0c\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u8ba1\u5212\u7f51\u7ad9~

\u8fd9\u91cc\u662f\u6d59\u6c5f\u5927\u5b66\u7afa\u53ef\u6862\u5b66\u9662\u5b66\u4e1a\u6307\u5bfc\u4e2d\u5fc3\u8f85\u5b66\u8ba1\u5212\u7684\u7ad9\u70b9\u3002\u8f85\u5b66\u8ba1\u5212\u4e3a\u5927\u4e00\u65b0\u751f\u63d0\u4f9b\u6570\u5b66\u5206\u6790\uff08H\uff09\u3001\u7ebf\u6027\u4ee3\u6570\uff08H\uff09\u3001\u5fae\u79ef\u5206\uff08H\uff09\u3001\u666e\u901a\u7269\u7406\u5b66\uff08H\uff09\u3001\u666e\u901a\u5316\u5b66\uff08H\uff09\u3001\u7a0b\u5e8f\u8bbe\u8ba1\uff08H\uff09\u7b49\u7afa\u9662\u8363\u8a89\u8bfe\u7a0b\u7684\u5b66\u4e60\u6307\u5bfc\u4e0e\u5e2e\u52a9\u3002

\u6211\u4eec\u670d\u52a1\u7684\u5bf9\u8c61\u4e3b\u8981\u662f\u7afa\u9662\u5b66\u5b50\uff0c\u4f46\u6211\u4eec\u540c\u6837\u6b22\u8fce\u9662\u5916\u540c\u5b66\u53c2\u4e0e\u6211\u4eec\u7684\u8f85\u5b66\u6d3b\u52a8\uff0c\u4e0d\u8bba\u662f\u542c\u8bb2\u3001\u7b54\u7591\u8fd8\u662f\u6388\u8bfe\u3002\u9662\u5185\u9662\u5916\u8bfe\u7a0b\u5185\u5bb9\u548c\u96be\u5ea6\u65b9\u9762\u53ef\u80fd\u5b58\u5728\u5dee\u5f02\uff0c\u8bf7\u81ea\u884c\u659f\u914c\u3002

\u4f60\u53ef\u4ee5\u901a\u8fc7\u7f51\u7ad9\u4e0a\u65b9\u6216\u5de6\u4fa7\u7684\u5bfc\u822a\u680f\u6d4f\u89c8\u6211\u4eec\u7684\u7f51\u7ad9\u3002\u4e0b\u9762\u662f\u6211\u4eec\u5f00\u8bbe\u7684\u5404\u8f85\u5b66\u8bfe\u7a0b\uff1a

\u5fae\u79ef\u5206 I/II\uff08H\uff09

23-24 \u8f85\u5b66\u7fa4\uff1a869733089

\u6570\u5b66\u5206\u6790 I/II\uff08H\uff09

23-24 \u8f85\u5b66\u7fa4\uff1a879217934

\u7ebf\u6027\u4ee3\u6570 I/II\uff08H\uff09

23-24 \u8f85\u5b66\u7fa4\uff1a148964020

\u7a0b\u5e8f\u8bbe\u8ba1\uff08H\uff09

23-24 \u8f85\u5b66\u7fa4\uff1a878442370

\u666e\u901a\u5316\u5b66\uff08H\uff09

23-24 \u8f85\u5b66\u7fa4\uff1a875585843

\u666e\u901a\u7269\u7406\u5b66 I\uff08H\uff09

23-24 \u8f85\u5b66\u7fa4\uff1a906774937

\u6211\u4eec\u8fd8\u5728\u5176\u4ed6\u8d44\u6e90\u4e2d\u6574\u7406\u4e86\u4e00\u4e9b\u6709\u7528\u7684\u8d44\u6599\uff0c\u4f46\u8fd9\u4e9b\u8d44\u6599\u5e76\u6ca1\u6709\u4e13\u4eba\u8d1f\u8d23\u7ef4\u62a4\u3002\u6211\u4eec\u6b22\u8fce\u5927\u5bb6\u7684\u8d21\u732e\uff5e

"},{"location":"#_2","title":"\u4ec0\u4e48\u662f\u8f85\u5b66\uff1f","text":""},{"location":"#_3","title":"\u5f55\u64ad/\u56de\u653e","text":"

\u81f4\u8c22\uff1a\u7afa\u53ef\u6862\u5b66\u9662\u5168\u5a92\u4f53\u5de5\u4f5c\u5ba4

\u5728\u7afa\u9662\u5168\u5a92\u4f53\u7684\u4eba\u5458\u548c\u8bbe\u5907\u652f\u6301\u4e0b\uff0c\u5927\u90e8\u5206\u8f85\u5b66\u6388\u8bfe\u90fd\u6709\u4e86\u4f18\u8d28\u7684\u5f55\u64ad\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\u5f55\u64ad\u90fd\u5c06\u4e0a\u4f20\u5230\u7afa\u9662\u5b66\u6307\u7684 Bilibili \u8d26\u53f7\u4e2d\uff0c\u70b9\u51fb\u5361\u7247\u5373\u53ef\u8df3\u8f6c\u5230 Bilibili \u9875\u9762\u3002

"},{"location":"#_4","title":"\u8d21\u732e","text":"

\u5982\u679c\u60a8\u613f\u610f\u53c2\u4e0e\u8be5\u7f51\u7ad9\u7684\u5efa\u8bbe\uff0c\u8bf7\u5230 GitHub \u4e2d\u672c\u9879\u76ee\u7684\u4ed3\u5e93\u8fdb\u884c\u8d21\u732e\u3002\u5411\u4ed3\u5e93\u63d0\u4ea4\u524d\uff0c\u8bf7\u67e5\u770b\u8d21\u732e\u9875\u9762\u3002

"},{"location":"#_5","title":"\u5927\u6587\u4ef6\u5b58\u653e\u5904","text":"

\u8d85\u8fc7 20MB \u7684\u5927\u6587\u4ef6\u90fd\u653e\u7f6e\u5728\u5b66\u4e1a\u6307\u5bfc\u4e2d\u5fc3\u516c\u5171\u7f51\u76d8\u7684\u5206\u4eab\u94fe\u63a5\u4e2d\uff0c\u540c\u5b66\u4eec\u53ef\u4ee5\u70b9\u51fb\u4e0b\u9762\u7684\u94fe\u63a5\u67e5\u770b\u3002\u5982\u679c\u6709\u9700\u8981\u653e\u7f6e\u7684\u5927\u6587\u4ef6\uff0c\u8bf7\u8054\u7cfb\u5b66\u4e1a\u6307\u5bfc\u4e2d\u5fc3\u7684\u540c\u5b66\u4e0a\u4f20\u3002

"},{"location":"#_6","title":"\u76f8\u5173\u7f51\u7ad9","text":""},{"location":"contribute/","title":"\u8d21\u732e","text":"

\u5728\u5411 ckc-agc \u4ed3\u5e93\u63d0\u4ea4 PR \u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u4f60\u5df2\u7ecf\u9605\u8bfb\u4e86\u672c\u6587\u6863\u3002

\u6bcf\u4e2a\u8f85\u5b66\u79d1\u76ee\u7684\u6587\u4ef6\u5939\u7ec4\u7ec7\u5982\u4e0b\uff1a

\u5176\u4e2d\u5b66\u671f\u4f7f\u7528\u5e74\u4efd + \u5b63\u8282\u547d\u540d\uff0c\u5982\uff1a23spring\u300124fall\u3002

\u6587\u6863\u7684\u9644\u4ef6\uff08\u5982\u56fe\u7247\u7b49\uff09\uff0c\u5e94\u5f53\u653e\u7f6e\u5728 \u6587\u6863\u540d.assets \u6587\u4ef6\u5939\u4e2d\uff0c\u4ee5\u4fbf\u4e8e\u7ba1\u7406\u3002

Example

\u7a0b\u8bbe\u7684\u6587\u4ef6\u5939\u7ed3\u6784\u5982\u4e0b\uff1a

programming\n\u251c\u2500\u2500 24fall\n\u2502   \u251c\u2500\u2500 index.md\n\u2502   \u251c\u2500\u2500 lec1.md\n\u2502   \u2514\u2500\u2500 ...\n\u251c\u2500\u2500 common\n\u2502   \u251c\u2500\u2500 exam\n\u2502   \u2502   \u251c\u2500\u2500 exam1.pdf\n\u2502   \u2502   \u2514\u2500\u2500 exam1_answer.pdf\n\u2502   \u2514\u2500\u2500 notes\n\u251c\u2500\u2500 archive\n\u2502   \u2514\u2500\u2500 23fall\n\u2502       \u251c\u2500\u2500 index.md\n\u2502       \u2514\u2500\u2500 lec1\n\u2502           \u251c\u2500\u2500 lec1.assets\n\u2502           \u2514\u2500\u2500 lec1.md\n\u2514\u2500\u2500 index.md\n

\u6211\u4eec\u4f7f\u7528 markdownlint\u3001autocorrect \u548c editorconfig \u63d2\u4ef6\u5bf9\u6587\u6863\u8fdb\u884c\u683c\u5f0f\u5316\u3002

"},{"location":"senior/","title":"\u8f85\u5b66\u5b66\u957f\u987b\u77e5","text":""},{"location":"senior/#_2","title":"\u7afa\u53ef\u6862\u5b66\u9662\u8f85\u5b66\u6388\u8bfe\u89c4\u8303\u5316\u610f\u89c1","text":""},{"location":"senior/#_3","title":"\u4e00\u3001\u52a8\u673a\u4e0e\u610f\u4e49","text":"

\u6388\u8bfe\u6d3b\u52a8\u662f\u7afa\u53ef\u6862\u5b66\u9662\u8f85\u5b66\u7684\u91cd\u8981\u73af\u8282\uff0c\u4e00\u65b9\u9762\u7ed9\u540c\u5b66\u4eec\u7684\u5b66\u4e60\u3001\u590d\u4e60\u5e26\u6765\u4fbf\u5229\uff0c\u53e6\u4e00\u65b9\u9762\u5728\u8f85\u5b66\u89c6\u9891\u4e0a\u7f51\u4e4b\u540e\uff0c\u4e5f\u662f\u63d0\u5347\u7afa\u9662\u8f85\u5b66\u54c1\u724c\u5f71\u54cd\u529b\u7684\u91cd\u8981\u9014\u5f84\u3002\u7136\u800c\uff0c\u76ee\u524d\u7684\u8f85\u5b66\u6388\u8bfe\u5b58\u5728\u4ee5\u4e0b\u95ee\u9898\uff1a

  1. \u6388\u8bfe\u5b89\u6392\u5e76\u4e0d\u5b8c\u5907\uff0c\u5b58\u5728\u591a\u6b21\u6388\u8bfe\u5185\u5bb9\u91cd\u53e0\uff0c\u6216\u65e0\u6cd5\u8986\u76d6\u6240\u6709\u91cd\u96be\u70b9\u7684\u60c5\u51b5\uff1b
  2. \u6388\u8bfe\u5b66\u957f\u98ce\u683c\u8fe5\u5f02\u3001\u504f\u597d\u4e0d\u540c\uff0c\u6bcf\u6b21\u6388\u8bfe\u4fa7\u91cd\u65b9\u5411\u3001\u96be\u5ea6\u7b49\u5dee\u5f02\u8f83\u5927\uff0c\u540c\u5b66\u8ddf\u7740\u8f85\u5b66\u6388\u8bfe\u8fdb\u884c\u5b66\u4e60\u5bb9\u6613\u4f53\u9a8c\u4e0d\u4f73\uff0c\u6478\u4e0d\u7740\u5934\u8111\uff1b
  3. \u6bcf\u5e74\u7684\u5907\u8bfe\u8d44\u6599\u5c3d\u7ba1\u4ece\u524d\u5e74\u5f00\u59cb\u6709\u6574\u7406\uff0c\u4f46\u4e0d\u540c\u5b66\u957f\u7684\u98ce\u683c\u5dee\u5f02\uff0c\u4ee5\u53ca\u6bcf\u5e74\u8bfe\u7a0b\u5b89\u6392\u7684\u5dee\u5f02\u7b49\uff0c\u5bfc\u81f4\u540c\u5b66\u4eec\u9762\u5bf9\u8fd9\u4e9b\u8d44\u6599\u4e5f\u53ea\u80fd\u65e0\u5934\u82cd\u8747\u4e00\u6837\u4e1c\u770b\u897f\u770b\uff0c\u6bd4\u8f83\u6df7\u4e71\uff0c\u5f88\u96be\u505a\u5230\u771f\u6b63\u7684\u8d44\u6599\u4f20\u627f\uff1b
  4. \u8f85\u5b66\u5b66\u957f\u867d\u7136\u5927\u90fd\u5177\u6709\u70ed\u60c5\uff0c\u4f46\u5f88\u591a\u65f6\u5019\u53ef\u80fd\u56e0\u4e3a\u81ea\u5df1\u592a\u5fd9\uff0c\u6216\u8005\u957f\u671f\u6ca1\u6709\u5b66\u4e60\u800c\u5fd8\u8bb0\u4e86\u4e00\u4e9b\u5185\u5bb9\u7b49\uff0c\u5bfc\u81f4\u5907\u8bfe\u3001\u6388\u8bfe\u8d28\u91cf\u4e0d\u9ad8\u3002\u5e76\u4e14\u76ee\u524d\u8f85\u5b66\u6574\u4f53\u6388\u8bfe\u7cfb\u7edf\u6027\u8f83\u5dee\uff0c\u5b8c\u5168\u4f9d\u8d56\u4e8e\u8f85\u5b66\u5b66\u957f\u7684\u4e2a\u4eba\u80fd\u529b\u548c\u7406\u89e3\uff0c\u5e76\u4e0d\u80fd\u5f88\u597d\u5730\u9762\u5411\u540c\u5b66\u89e3\u51b3\u540c\u5b66\u7684\u9700\u6c42\uff1b
  5. \u540c\u5b66\u7684\u53cd\u9988\u5728\u521d\u671f\u5f00\u5c55\u89c4\u8303\u5316\u6388\u8bfe\u65f6\u662f\u975e\u5e38\u91cd\u8981\u7684\uff0c\u56e0\u4e3a\u4ec5\u51ed\u501f\u51e0\u4e2a\u6388\u8bfe\u5b66\u957f\u7684\u8ba4\u8bc6\u5f88\u96be\u5168\u9762\u4e86\u89e3\u540c\u5b66\u4eec\u7684\u6838\u5fc3\u9700\u6c42\uff0c\u8bfe\u540e\u7684\u6539\u8fdb\u610f\u89c1\u4e5f\u5bf9\u4e8e\u8fdb\u4e00\u6b65\u63d0\u5347\u8f85\u5b66\u6559\u5b66\u8d28\u91cf\u5f88\u6709\u610f\u4e49\uff0c\u7136\u800c\u73b0\u5728\u7684\u8bfe\u524d\u8bfe\u540e\u53cd\u9988\u5747\u6d6e\u4e8e\u8868\u9762\uff0c\u6d41\u4e8e\u5f62\u5f0f\uff0c\u751a\u81f3\u8bfe\u540e\u53cd\u9988\u5f88\u5c11\u51fa\u73b0\u6709\u7528\u7684\u4fe1\u606f\u3002

\u56e0\u6b64\u6211\u4eec\u5e0c\u671b\u901a\u8fc7\u5c06\u7afa\u9662\u8f85\u5b66\u6388\u8bfe\u89c4\u8303\u5316\uff0c\u4ee5\u89e3\u51b3\u4e0a\u8ff0\u95ee\u9898\u3002\u6211\u4eec\u5c06\u5206\u522b\u4ece\u521d\u671f\u51c6\u5907\u3001\u5907\u8bfe\u6388\u8bfe\u8fc7\u7a0b\u4ee5\u53ca\u540e\u7eed\u5de5\u4f5c\u4e09\u4e2a\u65b9\u9762\u7ed9\u51fa\u6211\u4eec\u5bf9\u89c4\u8303\u5316\u7684\u610f\u89c1\u3002

"},{"location":"senior/#_4","title":"\u4e8c\u3001\u89c4\u8303\u5316\u7684\u51e0\u4e2a\u65b9\u9762","text":""},{"location":"senior/#1","title":"1.\u521d\u671f\u51c6\u5907\u5de5\u4f5c","text":"
  1. \u786e\u5b9a\u6388\u8bfe\u540d\u5355\u65f6\uff0c\u5e94\u5f53\u786e\u8ba4\u62a5\u540d\u5b66\u957f\u7684\u6388\u8bfe\u610f\u613f\uff0c\u7b80\u8981\u8bf4\u660e\u6388\u8bfe\u7684\u8981\u6c42\uff08\u53c2\u4e0e\u89c4\u8303\u5316\u5efa\u8bbe\uff09\uff0c\u8be2\u95ee\u662f\u5426\u613f\u610f\u5c06\u6388\u8bfe\u8d44\u6599\u4f20\u627f\u3001\u5f00\u6e90\uff08\u4e00\u822c\u90fd\u613f\u610f\uff09\uff1b
    1. \u4e0d\u786e\u5b9a\u8bd5\u8bfe\u662f\u5426\u6709\u5fc5\u8981\uff0c\u73b0\u5728\u62a5\u540d\u6388\u8bfe\u7684\u4eba\u6570\u90fd\u5f88\u6709\u9650\uff0c\u53ef\u80fd\u8981\u601d\u8003\u5982\u4f55\u6fc0\u52b1
  2. \u786e\u5b9a\u6388\u8bfe\u540d\u5355\u540e\uff0c\u5e94\u5f53\u7ed3\u5408\u5b66\u6821\u8bfe\u7a0b\u5927\u7eb2\u3001\u6388\u8bfe\u8fdb\u5ea6\u3001\u8003\u8bd5\u4e0e\u5c0f\u6d4b\u5b89\u6392\u7b49\uff0c\u786e\u5b9a\u8f85\u5b66\u7684\u5927\u81f4\u6388\u8bfe\u65f6\u95f4\u548c\u5185\u5bb9\u5b89\u6392\u3002\u7136\u540e\u5404\u8bfe\u7a0b\u7ec4\u5e94\u5f53\u7ec4\u7ec7\u7ebf\u4e0a\u6216\u7ebf\u4e0b\u7684\u4f1a\u8bae\uff0c\u4ecb\u7ecd\u521d\u6b65\u7684\u8ba1\u5212\uff0c\u7136\u540e\u8ba8\u8bba\u8be6\u7ec6\u7684\u6388\u8bfe\u5b89\u6392\u3001\u6388\u8bfe\u5927\u7eb2\uff08\u540e\u9762\u4f1a\u7ed9\u51fa\u793a\u4f8b\uff09\uff0c\u786e\u5b9a\u4e3b\u8981\u7684\u6559\u5b66\u53c2\u8003\u8d44\u6599\uff0c\u521d\u6b65\u786e\u5b9a\u6559\u5b66\u4fa7\u91cd\u70b9\u4ee5\u53ca\u96be\u5ea6\uff0c\u660e\u786e\u5206\u914d\u6388\u8bfe\u4efb\u52a1\uff0c\u9632\u6b62\u91cd\u53e0\u6216\u7f3a\u6f0f\u7b49\uff1b
    1. \u6559\u5b66\u53c2\u8003\u8d44\u6599\u662f\u5fc5\u8981\u7684\uff0c\u7279\u522b\u662f\u5fae\u79ef\u5206\u3001\u6570\u5b66\u5206\u6790\u8fd9\u79cd\u5e02\u9762\u4e0a\u5b58\u5728\u5e7f\u6cdb\u8d44\u6599\u7684\u79d1\u76ee\uff0c\u5e94\u5f53\u4ee5 2 \u672c\u5de6\u53f3\u7684\u7ecf\u5178\u6559\u6750\u6216\u8003\u7814\u6559\u8f85\u4e3a\u6838\u5fc3\u5c55\u5f00\uff0c\u63d0\u5347\u5907\u8bfe\u6548\u7387\u548c\u8d28\u91cf\uff0c\u56e0\u4e3a\u6211\u4eec\u76f8\u4fe1\u90a3\u4e9b\u6559\u6750\u548c\u6559\u8f85\u8d44\u6599\u505a\u4e86\u8fd9\u4e48\u591a\u5e74\u4e00\u5b9a\u662f\u6bd4\u5b66\u957f\u4eec\u81ea\u5df1\u7684\u8ba4\u77e5\u8981\u5b8c\u5907\u5f88\u591a\u7684\uff0c\u5e76\u4e14\u4e5f\u975e\u5e38\u6709\u903b\u8f91\uff0c\u9002\u5408\u8f85\u5b66\u6388\u8bfe\uff0c\u5f53\u7136\u4e5f\u9700\u8981\u7ed3\u5408\u5b66\u957f\u81ea\u5df1\u7684\u7406\u89e3\u4ee5\u53ca\u672c\u6821\u7684\u8003\u8bd5\u60c5\u51b5**\u4ece\u4e2d\u9009\u62e9\u5408\u9002\u7684\u5185\u5bb9\u8bb2\u89e3\uff1b
    2. \u5b89\u6392\u8bfe\u65f6\u53ef\u4ee5\u589e\u52a0\u7ebf\u4e0a\u8bfe\u65f6\uff0c\u56e0\u4e3a\u8f85\u5b66\u7ebf\u4e0b\u8bfe\u7a0b\u4e0d\u53ef\u80fd\u505a\u592a\u591a\u6b21\uff0c\u610f\u4e49\u4e0d\u5927\u5e76\u4e14\u540c\u5b66\u4eec\u65f6\u95f4\u4e5f\u6709\u9650\uff0c\u56e0\u6b64\u90e8\u5206\u4e0d\u90a3\u4e48\u91cd\u8981\u3001\u96be\u5ea6\u8f83\u5927\u6216\u8005\u7ebf\u4e0b\u6388\u8bfe\u96be\u4ee5\u5b89\u6392\u8bb2\u89e3\u7684\u5185\u5bb9\uff08\u4f8b\u5982\u7ebf\u6027\u4ee3\u6570\u4e2d\u7684\u884c\u5217\u5f0f\u8ba1\u7b97\u6280\u5de7\u91cd\u8981\u7a0b\u5ea6\u548c\u96be\u5ea6\u4e0d\u9002\u5408\u7ebf\u4e0b\u8bfe\u7a0b\uff0c\u7279\u5f81\u503c\u4e0e\u4e8c\u6b21\u578b\u90e8\u5206\u65f6\u95f4\u4e0a\u5f88\u96be\u5355\u72ec\u5b89\u6392\u8bfe\u7a0b\uff0c\u4e0e\u671f\u672b\u90bb\u8fd1\uff09\u53ef\u4ee5\u653e\u5728\u7ebf\u4e0a\u5f00\u8bfe\uff0c\u89c6\u9891\u4e0a\u4f20 B \u7ad9\u5373\u53ef\u3002\u7ebf\u4e0a\u5f00\u8bfe\u65f6\u957f\u3001\u5185\u5bb9\u90fd\u76f8\u8f83\u800c\u8a00\u66f4\u52a0\u81ea\u7531\uff1b
    3. \u786e\u5b9a\u6388\u8bfe\u5927\u7eb2\u65f6\uff0c\u5e94\u5f53\u660e\u786e\u5730\u5c06\u6240\u6709\u77e5\u8bc6\u70b9\u5217\u4e3e\uff08\u4f8b\u5982\u6839\u636e\u6559\u6750\uff0c\u7ed3\u5408\u4e00\u4e9b\u6559\u8f85\uff09\uff0c\u7136\u540e\u786e\u5b9a\u6bcf\u6b21\u7684\u6388\u8bfe\u5185\u5bb9\u3001\u6388\u8bfe\u91cd\u70b9\u4ee5\u53ca\u7ebf\u4e0a\u7ebf\u4e0b\u7684\u533a\u5206\uff0c\u9664\u6b64\u4e4b\u5916\uff0c\u6574\u4f53\u6388\u8bfe\u7684\u503e\u5411\u6027\u5e94\u5f53\u7edf\u4e00\uff0c\u4e0d\u5e94\u5f53\u51fa\u73b0\u4e00\u6b21\u6388\u8bfe\u5168\u662f\u4e60\u9898\uff0c\u4e00\u6b21\u6388\u8bfe\u5168\u662f\u57fa\u7840\u77e5\u8bc6\uff0c\u4e00\u6b21\u6388\u8bfe\u51fa\u73b0\u5f88\u591a\u8d85\u7eb2\u77e5\u8bc6\u7684\u60c5\u51b5\uff0c\u5e94\u5f53\u6709\u4e00\u4e2a\u57fa\u672c\u6807\u51c6\uff0c\u5728\u5176\u4e0a\u5404\u4e2a\u5b66\u957f\u53ef\u4ee5\u6309\u7167\u81ea\u5df1\u7684\u559c\u597d\u6dfb\u52a0\u5176\u4ed6\u5185\u5bb9\uff1b
    4. \u671f\u4e2d\u3001\u671f\u672b\u590d\u4e60\u6d89\u53ca\u7684\u77e5\u8bc6\u91cf\u53ef\u80fd\u8f83\u5927\uff0c\u53ef\u4ee5\u62c6\u5206\u6210\u4e24\u6b21\uff0c\u4e5f\u53ef\u4ee5\u7ebf\u4e0a\u7ebf\u4e0b\u7ed3\u5408\uff0c\u5f53\u7136\u5728\u73b0\u5728\u6574\u4f53\u6388\u8bfe\u89c4\u8303\u5316\u4e4b\u540e\uff0c\u590d\u4e60\u8bfe\u5e94\u8be5\u6bd4\u4ee5\u5f80\u66f4\u597d\u4e0a\uff0c\u56e0\u4e3a\u6709\u4e9b\u4e0d\u592a\u91cd\u70b9\u7684\u5185\u5bb9\u53ef\u4ee5\u76f4\u63a5 link \u5230\u4e4b\u524d\u7684\u8bfe\u7a0b\uff0c\u66f4\u52a0\u7a81\u51fa\u590d\u4e60\u91cd\u70b9\u3002
"},{"location":"senior/#2","title":"2.\u5907\u8bfe\u4e0e\u6388\u8bfe\u8fc7\u7a0b","text":"
  1. \u81f3\u5c11\u63d0\u524d\u4e00\u5468\u901a\u77e5\u6388\u8bfe\u5b66\u957f\u8fdb\u884c\u5907\u8bfe\uff0c\u5e76\u4e14\u8bb0\u4f4f\u501f\u6559\u5ba4\uff0c\u53ef\u4ee5\u6839\u636e\u5b66\u957f\u4f7f\u7528 PPT \u6216\u624b\u5199\u677f\u4e66\u7684\u9700\u6c42\u501f\u6559\u5ba4\uff08\u4e5f\u8bb8\u6709\u7684\u5b66\u957f\u4e0d\u559c\u6b22\u7c89\u7b14\uff0c\u6709\u7684\u5b66\u957f\u53d7\u4e0d\u4e86\u767d\u677f\u7b14\uff09\uff1b
  2. \u8bfe\u524d\u62a5\u540d\u901a\u77e5\u4ee5\u53ca\u62a5\u540d\u8868\u4e2d\uff0c\u5e94\u5f53\u6839\u636e\u6700\u540e\u7684\u8bfe\u7a0b\u5927\u7eb2\u793a\u4f8b\u660e\u786e\u5199\u51fa\u672c\u6b21\u6388\u8bfe\u7684\u6240\u6709\u4fe1\u606f\uff0c\u5e76\u4e14\u62a5\u540d\u8868\u4e2d\u5e94\u5f53\u6839\u636e\u6388\u8bfe\u5185\u5bb9\u8981\u6c42\u540c\u5b66\u4eec\u9009\u62e9\u6700\u5e0c\u671b\u542c\u5230\u7684\u5185\u5bb9\uff0c\u5199\u4e0b\u81ea\u5df1\u89c9\u5f97\u5b66\u4e60\u6bd4\u8f83\u56f0\u96be\u7684\u65b9\u9762\u7b49\uff1b
  3. \u5b66\u957f\u5907\u8bfe\u671f\u95f4\uff0c\u5efa\u8bae\u6839\u636e\u8bfe\u7a0b\u5927\u7eb2\u4e2d\u5199\u4e0b\u7684\u53c2\u8003\u8d44\u6599\u4ee5\u53ca\u4e4b\u524d\u8ba8\u8bba\u7684\u6574\u4f53\u5907\u8bfe\u98ce\u683c\u7b49\u7f16\u5199\u8bb2\u4e49\u6216 PPT\uff0c\u5e76\u7ed3\u5408\u540c\u5b66\u4eec\u7684\u542c\u8bfe\u610f\u613f\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u7ed3\u5408\u81ea\u5df1\u7684\u8ba4\u77e5\u548c\u98ce\u683c\u8fdb\u884c\u5907\u8bfe\uff0c\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879\u53ef\u4ee5\u53c2\u8003\u4e0b\u4e00\u8282\uff1b
  4. \u5907\u8bfe\u5b8c\u6210\u540e\uff0c\u5efa\u8bae\u63d0\u524d\u4e00\u5929\u5c06\u8bb2\u4e49\u516c\u5f00\u5728\u6388\u8bfe\u7fa4\uff08\u53ef\u4ee5\u4e0d\u662f\u6700\u7ec8\u7248\uff0c\u5927\u81f4\u5185\u5bb9\u5728\u5c31\u53ef\u4ee5\uff09\uff0c\u7136\u540e\u5ba1\u6838\u8bb2\u4e49\u3001PPT \u662f\u5426\u7b26\u5408\u57fa\u672c\u8981\u6c42\uff0c\u6700\u540e\u5c06\u6700\u7ec8\u7248\u53d1\u5e03\u5728\u8f85\u5b66\u7fa4\u3002
"},{"location":"senior/#3","title":"3.\u540e\u7eed\u5de5\u4f5c","text":"
  1. \u4e0b\u8bfe\u7b7e\u9000\u65f6\uff0c\u53ef\u4ee5\u8003\u8651\u628a\u7b7e\u9000\u7801\u548c\u53cd\u9988\u7801\u653e\u5728\u4e00\u8d77\uff0c\u8981\u6c42\u540c\u5b66\u586b\u5199\u3002\u8bfe\u540e\u53cd\u9988\u95ee\u5377\u5e94\u5f53\u5bf9\u8bfe\u7a0b\u8fdb\u5ea6\u3001\u96be\u5ea6\u3001\u6388\u8bfe\u8d28\u91cf\u3001\u4fa7\u91cd\u70b9\u7f3a\u5931\u7b49\u65b9\u9762\u8fdb\u884c\u5168\u9762\u7684\u8be2\u95ee\uff0c\u591a\u7528\u9009\u62e9\u9898\u53ef\u4ee5\u63d0\u5347\u95ee\u5377\u6548\u7387\uff1b
  2. \u5728\u5b66\u957f\u5141\u8bb8\u7684\u524d\u63d0\u4e0b\uff0c\u6240\u6709 PDF \u8d44\u6599\u5168\u90e8\u516c\u5f00\uff0c\u6e90\u6587\u4ef6\u4f5c\u4e3a\u5185\u90e8\u8d44\u6599\u8fdb\u884c\u5b58\u50a8\u4fdd\u7559\uff0c\u5982\u679c\u662f word\u3001PPT \u7b49\u53ef\u4ee5\u4fdd\u7559\u539f\u6587\u4ef6\uff0clatex\u3001markdown\u3001typst \u7b49\u53ef\u4ee5\u4fdd\u7559\u6e90\u7801\uff1b
  3. \u8865\u5145\u6388\u8bfe\u5927\u7eb2\u4e2d\u7684\u8bfe\u540e\u53cd\u9988\u680f\u76ee\uff0c\u4e3a\u4e0b\u4e00\u6b21\u5b66\u957f\u6388\u8bfe\u63d0\u4f9b\u610f\u89c1\u3002
"},{"location":"senior/#_5","title":"\u4e09\u3001\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879","text":"
  1. \u5404\u4e2a\u5b66\u79d1\u7684\u4e00\u4e9b\u9700\u8981\u6ce8\u610f\u7684\u7279\u70b9\uff08\u5f85\u8865\u5145\uff09\uff1a
    1. \u5fae\u79ef\u5206\uff1a
      1. \u4e2a\u4eba\u8ba4\u4e3a\u5fae\u79ef\u5206\u662f\u6700\u4e0d\u7f3a\u5e02\u9762\u4e0a\u8d44\u6599\u7684\u5b66\u79d1\uff0c\u56e0\u6b64\u5907\u8bfe\u7684\u65f6\u5019\u975e\u5e38\u6709\u5fc5\u8981\u6311\u9009\u597d\u7684\u8d44\u6599\uff0c\u53c2\u7167\u8fd9\u4e9b\u8d44\u6599\u5199\u51fa\u597d\u7684\u8bb2\u4e49\uff1b
      2. \u6743\u8861\u57fa\u7840\u77e5\u8bc6\u3001\u4e60\u9898\u5957\u8def\u3001\u62d3\u5c55\u5185\u5bb9\u3002
  2. \u6570\u5b66\u5206\u6790\uff1a
    1. \u6570\u5b66\u5206\u6790\u4e3b\u8981\u5c31\u662f\u4e24\u4e2a\u65b9\u9762\u7684\u95ee\u9898\uff0c\u4e00\u65b9\u9762\u662f\u6559\u6750\u5e76\u4e0d\u80fd\u628a\u57fa\u672c\u5185\u5bb9\u8bb2\u5f97\u5f88\u6e05\u695a\uff0c\u540c\u5b66\u4eec\u5206\u6790\u57fa\u7840\u8584\u5f31\uff0c\u53e6\u4e00\u65b9\u9762\u4e60\u9898\u4e0d\u591f\uff0c\u5e76\u4e14\u5bf9\u4e00\u4e9b\u57fa\u672c\u5957\u8def\u90fd\u4e0d\u719f\u6089\uff0c\u9762\u5411\u8003\u8bd5\u56f0\u96be\uff1b
    2. \u7b2c\u4e00\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u63a8\u8350\u9605\u8bfb\u5f20\u7b51\u751f\u8001\u5e08\u7684\u300a\u6570\u5b66\u5206\u6790\u65b0\u8bb2\u300b\uff0c\u7b2c\u4e8c\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u63a8\u8350\u4e00\u4e9b\u5e02\u9762\u4e0a\u5e38\u89c1\u7684\u6559\u8f85\uff0c\u4f8b\u5982\u9762\u5411\u8003\u7814\u7684......\uff0c\u751a\u81f3\u53ef\u4ee5\u53c2\u8003\u4e00\u4e9b\u5fae\u79ef\u5206\u7684\u53c2\u8003\u8d44\u6599\uff0c\u603b\u7ed3\u4e00\u4e9b\u5957\u8def\uff0c\u601d\u8def\u66f4\u6e05\u6670\u540c\u5b66\u4eec\u66f4\u5bb9\u6613\u63a5\u53d7\uff1b
    3. \u8f85\u5b66\u7684\u6388\u8bfe\u4e3b\u8981\u9762\u5411\u4e24\u4e2a\u95ee\u9898\uff0c\u5c06\u6211\u4eec\u89c9\u5f97\u6709\u5fc5\u8981\u8bb2\u4e00\u8bb2\u7684\u5185\u5bb9\u4ece\u8fd9\u4e9b\u53c2\u8003\u8d44\u6599\u4e2d\u9009\u51fa\u6765\u4ecb\u7ecd\uff0c\u56e0\u4e3a\u540c\u5b66\u4eec\u53ef\u80fd\u81ea\u5df1\u53bb\u770b\u7684\u52a8\u529b\u4e0d\u8db3\uff0c\u6216\u8005\u5f88\u96be\u770b\u51fa\u4ec0\u4e48\u662f\u5bf9\u76ee\u524d\u5b66\u4e60\u6700\u6709\u6548\u7684\u5185\u5bb9\uff1b
    4. \u6700\u540e\u662f\u4e00\u4e9b\u53ef\u4ee5\u62d4\u9ad8\u7684\u63a8\u8350\uff0c......\u3002
  3. \u7ebf\u6027\u4ee3\u6570\uff1a
    1. \u7ebf\u6027\u4ee3\u6570\u7684\u95ee\u9898\u5728\u4e8e\u5e02\u9762\u4e0a\u53c2\u8003\u8d44\u6599\u592a\u5c11\uff0c\u8fd9\u4e5f\u662f\u7f16\u5199 LALU \u7684\u4e00\u5927\u521d\u8877\uff1b
    2. \u4e00\u4e2a\u6709\u8da3\u7684\u4e8b\u5b9e\u662f\u5f88\u591a\u540c\u5b66\u53ef\u80fd\u5e76\u4e0d\u4f1a\u771f\u7684\u53bb\u770b LALU\uff0c\u6700\u591a\u5f53\u5de5\u5177\u4e66\u505a\u4f5c\u4e1a\u7684\u65f6\u5019\u67e5\u9605\u6216\u8003\u524d\u590d\u4e60\u770b\u4e00\u770b\uff1b
    3. \u56e0\u6b64\u8f85\u5b66\u7684\u76ee\u6807\u57fa\u672c\u4e0a\u662f\u53c2\u7167 LALU \u7684\u6846\u67b6\uff0c\u505a\u4e00\u4e2a\u91cd\u70b9\u7684\u7b5b\u9009\u5728\u4e0a\u8bfe\u7684\u65f6\u5019\u7ed9\u540c\u5b66\u4eec\u8bb2\uff0c\u8ba9\u4ed6\u4eec\u77e5\u9053\u770b\u54ea\u4e9b\u90e8\u5206\uff0c\u505a\u54ea\u4e9b\u9898\u5b66\u4e60\u6548\u7387\u6bd4\u8f83\u9ad8\uff1b
    4. \u9700\u8981\u6ce8\u610f\u7684\u662f\u7ebf\u6027\u4ee3\u6570\u8f85\u5b66\u5e94\u5f53\u6ce8\u91cd\u6982\u5ff5\u7406\u89e3\u548c\u4e60\u9898\u7684\u7ed3\u5408\uff0c\u4e24\u4e2a\u65b9\u9762\u90fd\u4e0d\u53ef\u6216\u7f3a\u3002\u6982\u5ff5\u4e00\u65b9\u9762\uff0c\u53e6\u4e00\u65b9\u9762\u7684\u53ef\u4ee5\u4ece\u66f4\u9ad8\u7684\u89d2\u5ea6\u51fa\u53d1\u7406\u89e3\uff0c\u4e60\u9898\u6ce8\u91cd\u603b\u7ed3\u57fa\u672c\u5957\u8def\uff0c\u7ed3\u5408\u8003\u8bd5\u91cd\u70b9\uff0c\u56e0\u4e3a\u8363\u8a89\u8bfe\u8001\u5e08\u6388\u8bfe\u4e0d\u91cd\u89c6\u8fd9\u4e9b\u3002
  4. \u7a0b\u5e8f\u8bbe\u8ba1\uff1a
    1. \u57fa\u7840\u548c\u63d0\u9ad8\u7684\u6743\u8861\uff08\uff1f\uff09
  5. \u6211\u4eec\u5fc5\u987b\u5f3a\u8c03\u7684\u4e00\u70b9\u662f\uff0c\u5c3d\u7ba1\u4ee5\u4e0a\u6d41\u7a0b\u770b\u8d77\u6765\u6bd4\u8f83\u523b\u677f\uff0c\u4f46\u89c4\u8303\u5316\u5e76\u4e0d\u662f\u8bf4\uff0c\u6211\u4eec\u9650\u5236\u8f85\u5b66\u6388\u8bfe\u53ea\u80fd\u8bb2\u4ec0\u4e48\u5185\u5bb9\u3002\u4e8b\u5b9e\u4e0a\u8fd9\u53ea\u662f\u4e00\u4e2a\u6d41\u7a0b\u4e0a\u7684\u89c4\u8303\uff0c\u6709\u52a9\u4e8e\u63d0\u5347\u8f85\u5b66\u5de5\u4f5c\u6548\u7387\uff0c\u63d0\u5347\u5907\u8bfe\u6388\u8bfe\u8d28\u91cf\u3001\u540c\u5b66\u7684\u542c\u8bfe\u4f53\u9a8c\uff0c\u4ee5\u53ca\u6709\u52a9\u4e8e\u4e0d\u65ad\u8fed\u4ee3\u66f4\u65b0\u8d44\u6599\u7684\u610f\u89c1\u3002\u6211\u4eec\u975e\u5e38\u9f13\u52b1\u6bcf\u4e00\u4f4d\u6388\u8bfe\u5b66\u957f\u878d\u5165\u81ea\u5df1\u7684\u98ce\u683c\uff0c\u63d0\u51fa\u81ea\u5df1\u7684\u770b\u6cd5\uff0c\u65e0\u8bba\u662f\u5bf9\u8bfe\u7a0b\u91cd\u70b9\u3001\u6388\u8bfe\u5185\u5bb9\u8fd8\u662f\u6574\u4f53\u6d41\u7a0b\u7b49\uff0c\u5e76\u5c06\u81ea\u5df1\u7684\u60f3\u6cd5\u878d\u5165\u5230\u6388\u8bfe\u5b9e\u8df5\u3002
"},{"location":"senior/#_6","title":"\u56db\u3001\u8f85\u5b66\u6388\u8bfe\u5927\u7eb2\uff08\u4ee5\u7ebf\u6027\u4ee3\u6570\u4e3a\u4f8b\uff09","text":"

\u6574\u4f53\u4fe1\u606f

\u6388\u8bfe\u6210\u5458\u540d\u5355\uff1a

\u6388\u8bfe\u5f62\u5f0f\uff1a\u7ebf\u4e0a\u7ebf\u4e0b\u7ed3\u5408\uff0c\u7ebf\u4e0a \u8bfe\u65f6\uff0c\u7ebf\u4e0b \u8bfe\u65f6\uff1b

\u53c2\u8003\u8d44\u6599\uff1a

\u6559\u6750\uff1a

  1. \u300a\u5927\u5b66\u6570\u5b66\uff1a\u4ee3\u6570\u4e0e\u51e0\u4f55\u300b\uff08\u7b2c\u4e8c\u7248\uff09\u8427\u6811\u94c1\uff0c\u6e05\u534e\u5927\u5b66\u51fa\u7248\u793e
  2. \u300a\u7ebf\u6027\u4ee3\u6570\u5e94\u8be5\u8fd9\u6837\u5b66\u300b\uff08\u7b2c\u56db\u7248\uff09[\u7f8e] Sheldon Axler\uff0c\u4eba\u6c11\u90ae\u7535\u51fa\u7248\u793e

\u91cd\u70b9\u53c2\u8003\u8d44\u6599\uff1a

  1. \u300a\u7ebf\u6027\u4ee3\u6570\uff1a\u672a\u7adf\u4e4b\u7f8e\u300b\u7afa\u53ef\u6862\u5b66\u9662\u8f85\u5b66\u8bb2\u4e49
  2. \u300a\u9ad8\u7b49\u4ee3\u6570\u5b66\u300b\uff08\u7b2c\u56db\u7248\uff09\u8c22\u542f\u9e3f\uff0c\u59da\u6155\u751f\uff0c\u5434\u6cc9\u6c34\uff0c\u590d\u65e6\u5927\u5b66\u51fa\u7248\u793e
  3. \u300a\u9ad8\u7b49\u4ee3\u6570\u5b66\uff08\u7b2c\u56db\u7248\uff09\u914d\u5957\u5b66\u4e60\u7528\u4e66\u300b\u8c22\u542f\u9e3f\uff0c\u59da\u6155\u751f\uff0c\u590d\u65e6\u5927\u5b66\u51fa\u7248\u793e

\u5176\u5b83\u53c2\u8003\u8d44\u6599\uff1a

  1. \u300a\u8003\u7814\u6570\u5b66\u7ebf\u6027\u4ee3\u6570\u8f85\u5bfc\u8bb2\u4e49\u300b\u6c64\u5bb6\u51e4\uff0c\u4e2d\u56fd\u77f3\u5316\u51fa\u7248\u793e
  2. \u300a\u9ad8\u7b49\u4ee3\u6570\u5f3a\u5316\u8bb2\u4e49\u300b\uff082023 \u8003\u7814\u7248\uff09\u674e\u626c

\u7b2c\u4e00\u6b21\u6388\u8bfe

\u4e3b\u9898\uff1a\u7ebf\u6027\u7a7a\u95f4

\u5f62\u5f0f\uff1a\u7ebf\u4e0b\uff0c\u7ea6 120 \u5206\u949f\uff08\u7ebf\u4e0a / \u7ebf\u4e0b + \u65f6\u957f\uff09

\u6388\u8bfe\u4eba\uff1a\u5434\u4e00\u822a

\u6388\u8bfe\u65f6\u95f4\uff1a2024 \u5e74 10 \u6708 20 \u65e5

\u6388\u8bfe\u5730\u70b9\uff1a\u7d2b\u91d1\u6e2f......\uff08\u7ebf\u4e0a\u65e0\uff09

\u6388\u8bfe\u5185\u5bb9\uff1a

  1. \u8bfe\u7a0b\u7eb5\u89c8\uff0c\u7ebf\u6027\u4ee3\u6570\u7684\u91cd\u8981\u6027\uff08\u8bfe\u524d\u95f2\u8c08\uff09
  2. n\u5143\u5411\u91cf\u4e0e\u77e9\u9635\u7684\u5b9a\u4e49
  3. \u9ad8\u65af\u6d88\u5143\u6cd5\uff1a\u603b\u7ed3\u4e00\u822c\u65b9\u6cd5\uff0c\u7ed9\u542b\u53c2\u6570\u7ebf\u6027\u65b9\u7a0b\u7ec4\u95ee\u9898\u7684\u4f8b\u5b50
  4. \u7ebf\u6027\u7a7a\u95f4\u7684\u5b9a\u4e49\u3001\u6ce8\u610f\u4e8b\u9879\u4e0e\u5178\u578b\u4f8b\u9898\uff0c\u7ebf\u6027\u5b50\u7a7a\u95f4\u7684\u5b9a\u4e49\u4e0e\u5178\u578b\u4f8b\u9898
  5. \u7ebf\u6027\u8868\u793a\u3001\u7ebf\u6027\u6269\u5f20\u3001\u7ebf\u6027\u76f8\u5173\u6027\u3001\u57fa\u4e0e\u7ef4\u6570\u7684\u57fa\u672c\u5b9a\u4e49\u4e0e\u6027\u8d28
  6. \u7ebf\u6027\u76f8\u5173\u6027\u7ecf\u5178\u4f8b\u9898\uff0c\u6781\u5927\u7ebf\u6027\u65e0\u5173\u7ec4\u7684\u6c42\u89e3\uff0c\u57fa\u4e0e\u7ef4\u6570\u5178\u578b\u4f8b\u9898
  7. \u7ebf\u6027\u7a7a\u95f4\u7684\u4ea4\u4e0e\u548c\u7684\u5b9a\u4e49\u4e0e\u6027\u8d28\uff0c\u7ebf\u6027\u7a7a\u95f4\u7ef4\u6570\u516c\u5f0f\u53ca\u5176\u8bc1\u660e\uff0c\u76f4\u548c\u7684\u5b9a\u4e49\u4e0e\u6027\u8d28
  8. \u6c42\u89e3\u7ebf\u6027\u7a7a\u95f4\u4ea4\u4e0e\u548c\u7684\u4f8b\u9898\uff0c\u8986\u76d6\u5b9a\u7406\uff0c\u76f4\u548c\u5224\u5b9a\u7684\u4e24\u79cd\u65b9\u6cd5

\u53c2\u8003\u8d44\u6599\uff1a

  1. \u300a\u7ebf\u6027\u4ee3\u6570\uff1a\u672a\u7adf\u4e4b\u7f8e\u300b\u7afa\u53ef\u6862\u5b66\u9662\u8f85\u5b66\u8bb2\u4e49
  2. \u300a\u9ad8\u7b49\u4ee3\u6570\u5b66\u300b\uff08\u7b2c\u56db\u7248\uff09\u8c22\u542f\u9e3f\uff0c\u59da\u6155\u751f\uff0c\u5434\u6cc9\u6c34\uff0c\u590d\u65e6\u5927\u5b66\u51fa\u7248\u793e
  3. \u300a\u9ad8\u7b49\u4ee3\u6570\u5b66\uff08\u7b2c\u56db\u7248\uff09\u914d\u5957\u5b66\u4e60\u7528\u4e66\u300b\u8c22\u542f\u9e3f\uff0c\u59da\u6155\u751f\uff0c\u590d\u65e6\u5927\u5b66\u51fa\u7248\u793e

\u6388\u8bfe\u53cd\u9988\uff1a

  1. \u8bfe\u524d\u53cd\u9988\uff1a
  2. \u8bfe\u540e\u53cd\u9988\uff1a
"},{"location":"test/","title":"\u6d4b\u8bd5","text":"

\u672c\u9875\u9762\u7528\u4e8e\u6d4b\u8bd5\u5404\u7c7b\u7ec4\u4ef6\u663e\u793a\u6d4b\u8bd5\u3002

"},{"location":"test/#bilibili-stats","title":"Bilibili Stats","text":"

\u8fd9\u91cc\u548c\u8fd9\u91cc\u7684\u4e24\u4e2a\u9879\u76ee\u529f\u80fd\u90fd\u6b8b\u7f3a\u4e86\uff0c\u8003\u8651\u540e\u7eed\u90e8\u7f72\u5230\u670d\u52a1\u5668\u4e0a\u3002

"},{"location":"test/#latex","title":"LaTeX","text":"

simple

\\[ x ={-b \\pm \\sqrt{b^2-4ac}\\over 2a} \\]

matrix

\\[ \\left\\{\\begin{matrix} x=a + r\\text{cos}\\theta \\\\ y=b + r\\text{sin}\\theta \\end{matrix}\\right. \\]

array

\\[ \\begin{array}{l} a\\mathop{{x}}\\nolimits^{{2}}+bx+c=0 \\\\ \\Delta =\\mathop{{b}}\\nolimits^{{2}}-4ac \\\\ \\mathop{{x}}\\nolimits_{{1,2}}=\\frac{{-b \\pm \\sqrt{{\\mathop{{b}}\\nolimits^{{2}}-4ac}}}}{{2a}} \\\\ \\mathop{{x}}\\nolimits_{{1}}+\\mathop{{x}}\\nolimits_{{2}}=-\\frac{{b}}{{a}} \\\\ \\mathop{{x}}\\nolimits_{{1}}\\mathop{{x}}\\nolimits_{{2}}=\\frac{{c}}{{a}} \\end{array} \\]

calculus

\\[ \\int \\frac{1}{\\sqrt{1-x^{2}}}\\mathrm{d}x= \\arcsin x +C \\]

algebra

\\[ \\begin{vmatrix} \\mathbf{i}& \\mathbf{j}& \\mathbf{k} \\\\ \\frac{\\partial X}{\\partial u}& \\frac{\\partial Y}{\\partial u}& 0 \\\\ \\frac{\\partial X}{\\partial v}& \\frac{\\partial Y}{\\partial v}& 0 \\\\ \\end{vmatrix} \\]

physics

\\[ \\mathop \\Phi \\nolimits_e = \\oint { \\mathord{ \\buildrel{ \\lower3pt \\hbox{$ \\scriptscriptstyle \\rightharpoonup$}} \\over E} \\cdot {d \\mathord{ \\buildrel{ \\lower3pt \\hbox{$ \\scriptscriptstyle \\rightharpoonup$}} \\over S}} = {1 \\over {{\\varepsilon _0}}}\\sum {q} } \\]

Unicode

\\[ %\u6b64\u516c\u5f0f\u9700\u8981\u5728\u8bbe\u7f6e\u4e2d\u5f00\u542f unicode \u6269\u5c55\u652f\u6301 \\begin{array}{l} {\\huge \\unicode{8751}}_\\mathbb{S} \\mathbf{E} \\cdot\\mathrm{d}s= \\cfrac{Q}{\\varepsilon_0} \\\\ {\\huge \\unicode{8751}}_\\mathbb{S} \\mathbf{B} \\cdot\\mathrm{d}s= 0 \\\\ {\\huge \\oint}_{\\mathbb{L}}^{} \\mathbf{E} \\cdot \\mathrm{d}l=-\\cfrac{\\mathrm{d}\\Phi _{\\mathbf{B}}}{\\mathrm{d}t } \\\\ {\\huge \\oint}_{\\mathbb{L}}^{} \\mathbf{B} \\cdot \\mathrm{d}l=\\mu_0I+ \\mu_0 \\varepsilon_0\\cfrac{\\mathrm{d}\\Phi _{\\mathbf{E}}}{\\mathrm{d}t } \\end{array} \\]

mhchem

\\[ %\u6b64\u516c\u5f0f\u9700\u8981\u5728\u3010\u8bbe\u7f6e\u3011\u4e2d\u5f00\u542f mhchem \u6269\u5c55\u652f\u6301 \u5177\u4f53\u7528\u6cd5\u8bf7\u53c2\u8003\u3010\u5e2e\u52a9\u30112.11.2 \\ce{SO4^2- + Ba^2+ -> BaSO4 v} \\]"},{"location":"algebra/","title":"\u7ebf\u6027\u4ee3\u6570\u8f85\u5b66","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u7ebf\u6027\u4ee3\u6570\u7248\u5757 \ud83e\udd17\u3002

"},{"location":"algebra/#_2","title":"\u5386\u5e74\u5377","text":""},{"location":"algebra/#ih","title":"\u7ebf\u6027\u4ee3\u6570 I\uff08H\uff09\u671f\u4e2d/\u5c0f\u6d4b\u5386\u5e74\u5377\u8bd5\u9898\u96c6","text":"\u8bd5\u5377 \u7b54\u6848 2022-2023 \u5b66\u5e74 \u5434\u5fd7\u7965 \u671f\u4e2d \u7b54\u6848 2022-2023 \u5b66\u5e74 \u8c08\u4e4b\u5955 \u671f\u4e2d \u6682\u65e0 2022-2023 \u5b66\u5e74 \u5218\u5eb7\u751f \u671f\u4e2d \u6682\u65e0 2021-2022 \u5b66\u5e74 \u5218\u5eb7\u751f \u5c0f\u6d4b \u6682\u65e0 2021-2022 \u5b66\u5e74 \u5434\u5fd7\u7965 \u671f\u4e2d \u7b54\u6848 2020-2021 \u5b66\u5e74 \u8c08\u4e4b\u5955 \u5c0f\u6d4b 1 \u6682\u65e0 2020-2021 \u5b66\u5e74 \u8c08\u4e4b\u5955 \u5c0f\u6d4b 2 \u6682\u65e0 2020-2021 \u5b66\u5e74 \u5434\u5fd7\u7965 \u671f\u4e2d \u6682\u65e0"},{"location":"algebra/#ih_1","title":"\u7ebf\u6027\u4ee3\u6570 I\uff08H\uff09\u671f\u672b\u5386\u5e74\u5377\u8bd5\u9898\u96c6","text":"\u8bd5\u5377 \u7b54\u6848 2009-2010 \u5b66\u5e74 \u6682\u65e0 2010-2011 \u5b66\u5e74 \u6682\u65e0 2011-2012 \u5b66\u5e74 \u6682\u65e0 2012-2013 \u5b66\u5e74 \u6682\u65e0 2013-2014 \u5b66\u5e74 \u6682\u65e0 2014-2015 \u5b66\u5e74 \u6682\u65e0 2018-2019 \u5b66\u5e74 \u6682\u65e0 2019-2020 \u5b66\u5e74 \u6682\u65e0 2021-2022 \u5b66\u5e74 \u6682\u65e0 2022-2023 \u5b66\u5e74 \u6682\u65e0 2023-2024 \u5b66\u5e74 \u6682\u65e0"},{"location":"algebra/#iih","title":"\u7ebf\u6027\u4ee3\u6570 II\uff08H\uff09\u671f\u4e2d/\u5c0f\u6d4b\u5386\u5e74\u5377\u8bd5\u9898\u96c6","text":"\u8bd5\u5377 \u7b54\u6848 2022-2023 \u5b66\u5e74 \u5434\u5fd7\u7965 \u671f\u4e2d \u6682\u65e0 2022-2023 \u5b66\u5e74 \u5218\u5eb7\u751f \u671f\u4e2d \u6682\u65e0 2020-2021 \u5b66\u5e74 \u8c08\u4e4b\u5955 \u671f\u4e2d \u6682\u65e0 2020-2021 \u5b66\u5e74 \u5218\u5eb7\u751f \u671f\u4e2d \u6682\u65e0"},{"location":"algebra/#iih_1","title":"\u7ebf\u6027\u4ee3\u6570 II\uff08H\uff09\u671f\u672b\u5386\u5e74\u5377\u8bd5\u9898\u96c6","text":"\u8bd5\u5377 \u7b54\u6848 2022-2023 \u5b66\u5e74 \u7b54\u6848 2022-2023 \u5b66\u5e74 \u5218\u5eb7\u751f \u8003\u524d\u7ec3\u4e60 \u6682\u65e0 2021-2022 \u5b66\u5e74 \u6682\u65e0"},{"location":"algebra/#_3","title":"\u5386\u5e74\u8d44\u6599\u5f52\u6863","text":""},{"location":"algebra/#2022-2023","title":"2022-2023 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":"\u4e3b\u8bb2\u4eba \u5185\u5bb9 \u8bb2\u4e49 \u56fe\u7075 2002 \u5468\u5065\u5747 \u7ebf\u4ee3 I \u671f\u4e2d\u590d\u4e60 \u8bb2\u4e49\u7b54\u6848 \u56fe\u7075 2001 \u5434\u4e00\u822a \u7ebf\u4ee3 I \u671f\u4e2d\u4e0e\u671f\u672b\u590d\u4e60 \u671f\u4e2d\u590d\u4e60\u671f\u672b\u590d\u4e60\u5df2\u7f16\u7e82\u6210 LALU \u6c42\u6570 2101 \u59dc\u61ff\u84c9 \u7ebf\u6027\u53d8\u6362 \u8bb2\u4e49\u7ffb\u8bd1\u7248 \u56fe\u7075 2101 \u9648\u5c0f\u5ddd \u884c\u5217\u5f0f \u8bb2\u4e49 \u5f3a\u6570 2101 \u51af\u7693\u3001\u5f6d\u6e43 \u7ebf\u6027\u56fe\u5f62\u4e0e\u5185\u79ef\u7a7a\u95f4 \u8bb2\u4e49\u7b54\u6848"},{"location":"algebra/2023/","title":"2023-2024 \u5b66\u5e74\u7ebf\u6027\u4ee3\u6570\u8f85\u5b66","text":""},{"location":"algebra/2023/#ih","title":"\u7ebf\u6027\u4ee3\u6570 I(H)","text":""},{"location":"algebra/2023/#_1","title":"\u8bfe\u9898\u7ec4\u6210\u5458","text":""},{"location":"algebra/2023/#_2","title":"\u8bfe\u7a0b\u5f55\u64ad","text":"

W \u4ee3\u8868\u9002\u914d\u5434\u5fd7\u7965\u73ed\uff0cT \u4ee3\u8868\u9002\u914d\u8c08\u4e4b\u5955\u73ed\uff0cH \u4ee3\u8868\u5408\u73ed\u4e0a\u8bfe\u3002

\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2\u4eba \u5f55\u64ad\u5730\u5740 \u8bb2\u4e49 W1 Oct.29 \u5f15\u5165\uff1a\u7ebf\u6027\u7a7a\u95f4 \u6885\u654f\u70ab Bilibili LALU T1 Oct.29 \u5f15\u5165\uff1a\u7ebf\u6027\u7a7a\u95f4 \u5434\u4e00\u822a Bilibili LALU H2 Nov.18 \u7ebf\u6027\u6620\u5c04\u53ca\u5176\u77e9\u9635\u8868\u793a \u5434\u4e00\u822a Bilibili LALU H3 Dec.3 \u77e9\u9635\u7684\u79e9\u4e0e\u5206\u5757\u77e9\u9635 \u6f58\u90b9\u7eac Bilibili \u8bb2\u4e49 H4 Dec.16 \u884c\u5217\u5f0f\u548c\u7ebf\u6027\u65b9\u7a0b\u7ec4 \u859b\u8fb0\u7acb Bilibili LALU H5 Dec.30 \u671f\u672b\u590d\u4e60 \u5434\u4e00\u822a Bilibili PPT"},{"location":"algebra/2023/#_3","title":"\u8bfe\u7a0b\u5b89\u6392","text":""},{"location":"algebra/2023/#iih","title":"\u7ebf\u6027\u4ee3\u6570 II(H)","text":""},{"location":"algebra/2023/#_4","title":"\u8bfe\u7a0b\u5f55\u64ad","text":"\u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2\u4eba \u5f55\u64ad\u5730\u5740 \u8bb2\u4e49 Jun.8 \u671f\u672b\u590d\u4e60 \u5434\u4e00\u822a Bilibili LALU

\u7b2c\u4e00\u8bb2\u7531\u4e8e\u5f55\u50cf\u7684\u5931\u8bef\u5bfc\u81f4\u6ca1\u6709\u58f0\u97f3\uff0c\u6240\u4ee5\u5e76\u672a\u4e0a\u4f20 B \u7ad9\u3002

"},{"location":"algebra/2023/#_5","title":"\u8bfe\u7a0b\u5b89\u6392","text":""},{"location":"algebra/2024/","title":"2024-2025 \u5b66\u5e74\u7ebf\u6027\u4ee3\u6570\u8f85\u5b66","text":""},{"location":"algebra/2024/#ih","title":"\u7ebf\u6027\u4ee3\u6570 I(H)","text":""},{"location":"algebra/2024/#_1","title":"\u8bfe\u9898\u7ec4\u6210\u5458","text":""},{"location":"algebra/2024/#_2","title":"\u8bfe\u7a0b\u5f55\u64ad","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2\u4eba \u5f55\u64ad\u5730\u5740 \u8bb2\u4e49 1 2024.10.27 \u9ad8\u65af\u6d88\u5143\u6cd5\uff0c\u7ebf\u6027\u7a7a\u95f4 \u6df7\u5408 2303 \u5f90\u827a\u7545 Bilibili \u8bb2\u4e49 2 2024.11.10 \u7ebf\u6027\u6620\u5c04\u53ca\u5176\u77e9\u9635\u8868\u793a \u56fe\u7075 2303 \u674e\u6587\u8000 Bilibili \u8bb2\u4e49 3 2024.11.24 \u77e9\u9635\u8ba1\u7b97 \u76f8\u62b5\u6807\u51c6\u5f62 \u56fe\u7075 2001 \u5434\u4e00\u822a Bilibili \u8bb2\u4e49"},{"location":"algebra/2024/#_3","title":"\u8bfe\u7a0b\u5b89\u6392","text":"

\u6388\u8bfe\u5f62\u5f0f\u4e3a\u7ebf\u4e0a\u7ebf\u4e0b\u7ed3\u5408\uff1a

"},{"location":"algebra/lalu/","title":"\u7ebf\u6027\u4ee3\u6570\uff1a\u672a\u7adf\u4e4b\u7f8e","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u7ebf\u6027\u4ee3\u6570\u8f85\u5b66\u7cbe\u54c1\u8bfe\u7a0b\u7248\u5757 \ud83e\udd17\u3002

"},{"location":"algebra/lalu/#_2","title":"\u8bfe\u7a0b\u7b80\u4ecb","text":"

\u7ebf\u6027\u4ee3\u6570\u4f5c\u4e3a\u5f88\u591a\u540c\u5b66\u5927\u5b66\u63a5\u89e6\u7684\u7b2c\u4e00\u95e8\u6570\u5b66\u8bfe\uff0c\u4e00\u65b9\u9762\u5176\u91cd\u8981\u6027\u4e0d\u8a00\u800c\u55bb\uff0c\u5728\u5f88\u591a\u4e13\u4e1a\u4e2d\u90fd\u662f\u5fc5\u8981\u7684\u9884\u4fee\u77e5\u8bc6\uff0c\u53e6\u4e00\u65b9\u9762\u5f88\u591a\u540c\u5b66\u4e5f\u662f\u7b2c\u4e00\u6b21\u63a5\u89e6\u5982\u6b64\u62bd\u8c61\u7684\u6570\u5b66\u5185\u5bb9\uff0c\u56e0\u6b64\u5728\u5b66\u4e60\u7ebf\u6027\u4ee3\u6570\u65f6\u4f1a\u9047\u5230\u5f88\u591a\u56f0\u96be\u3002\u7279\u522b\u662f\u6d59\u6c5f\u5927\u5b66\u56fe\u7075\u73ed\u540c\u5b66\u4e24\u5b66\u671f\u8981\u9762\u5bf9\u7684\u300a\u5927\u5b66\u6570\u5b66\uff1a\u4ee3\u6570\u4e0e\u51e0\u4f55\u300b\u548c\u300a\u7ebf\u6027\u4ee3\u6570\u5e94\u8be5\u8fd9\u6837\u5b66\u300b\u4e24\u672c\u6559\u6750\uff0c\u7b2c\u4e00\u672c\u76f4\u63a5\u4ece\u62bd\u8c61\u7684\u7ebf\u6027\u7a7a\u95f4\u548c\u7ebf\u6027\u6620\u5c04\u5f15\u5165\uff0c\u629b\u5f03\u4e86\u4f20\u7edf\u5de5\u79d1\u7ebf\u6027\u4ee3\u6570\u4ece\u884c\u5217\u5f0f\u8d77\u6b65\u7684\u6559\u6388\u65b9\u5f0f\uff0c\u66f4\u80fd\u8ba9\u540c\u5b66\u4e86\u89e3\u7ebf\u6027\u4ee3\u6570\u7684\u672c\u8d28\uff0c\u4f46\u5165\u95e8\u5b58\u5728\u4e00\u4e9b\u56f0\u96be\u3002\u800c\u7b2c\u4e8c\u672c\u6559\u6750\u98ce\u683c\u5219\u66f4\u504f\u5411\u4e8e\u6570\u5b66\u4e13\u4e1a\u8bfe\uff0c\u6574\u4f53\u6bd4\u8f83\u62bd\u8c61\uff0c\u4ee5\u201c\u7b97\u5b50\u201d\u4e3a\u6838\u5fc3\uff0c\u907f\u5f00\u884c\u5217\u5f0f\u53d9\u8ff0\u7ebf\u6027\u4ee3\u6570\u4e2d\u7684\u6838\u5fc3\u7406\u8bba\uff0c\u5176\u76ee\u7684\u53ea\u662f\u4e3a\u4e86\u8868\u660e\u4ed6\u6240\u8bb2\u7684\u5185\u5bb9\u548c\u4f20\u7edf\u7ebf\u6027\u4ee3\u6570\u662f\u7edf\u4e00\u7684\u3002

\u6211\u60f3\u5982\u679c\u80fd\u5c06\u8fd9\u4e24\u672c\u6559\u6750\u5b66\u597d\uff0c\u7ebf\u6027\u4ee3\u6570\u7684\u57fa\u7840\u5c06\u4f1a\u662f\u975e\u5e38\u624e\u5b9e\u7684\u3002\u4f46\u7406\u5ff5\u4e0e\u5b9e\u9645\u6267\u884c\u6709\u5f88\u5927\u7684\u504f\u5dee\uff0c\u5e76\u975e\u6240\u6709\u540c\u5b66\u90fd\u80fd\u5728\u521d\u5b66\u65f6\u5b8c\u5168\u63a5\u53d7\u62bd\u8c61\u7684\u6559\u5b66\u65b9\u5f0f\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u7ebf\u6027\u4ee3\u6570\uff08\u6216\u9ad8\u7b49\u4ee3\u6570\uff09\u8fd8\u6709\u5f88\u591a\u7684\u53c2\u8003\u8d44\u6599\uff08\u5982\u4e18\u7ef4\u58f0\u8001\u5e08\uff0c\u8c22\u542f\u9e3f\u8001\u5e08\u7684\u9ad8\u7b49\u4ee3\u6570\uff0c\u6216\u662f Strang \u8001\u5148\u751f\u7684\u7ebf\u6027\u4ee3\u6570\uff0c\u6216\u662f 3blue1brown \u7684\u7ebf\u6027\u4ee3\u6570\u7684\u672c\u8d28\uff09\uff0c\u4f46\u540c\u5b66\u4eec\u5982\u679c\u5b8c\u5168\u6295\u5165\u65f6\u95f4\u5230\u8fd9\u4e9b\u53c2\u8003\u4e66\uff0c\u5f88\u5bb9\u6613\u9677\u5165\u8ff7\u832b\uff0c\u5e76\u4e14\u4e0e\u6700\u7ec8\u7684\u8003\u8bd5\u98ce\u683c\u4e5f\u76f8\u8ddd\u8f83\u8fdc\u3002\u56e0\u6b64\u6211\u4eec\u5e0c\u671b\u6709\u4e00\u672c\u8bb2\u4e49\u80fd\u7efc\u5408\u8fd9\u4e9b\u8d44\u6599\u4e2d\u4e0e\u8fd9\u4e24\u95e8\u8bfe\u7684\u5b66\u4e60\u5173\u8054\u7684\u90e8\u5206\uff0c\u4f18\u5316\u5185\u5bb9\u5b89\u6392\uff0c\u5e76\u5b89\u6392\u8db3\u91cf\u7684\u4e60\u9898\u4f9b\u540c\u5b66\u7ec3\u4e60\uff0c\u4ee5\u4fbf\u540c\u5b66\u4eec\u80fd\u591f\u66f4\u597d\u5730\u5b66\u4e60\u7ebf\u6027\u4ee3\u6570\u3002

\u53e6\u4e00\u65b9\u9762\uff0c\u7ebf\u6027\u4ee3\u6570\u662f\u4e00\u4e2a\u53e4\u8001\u800c\u5e74\u8f7b\u7684\u5b66\u79d1\u3002\u5b83\u53d1\u8f6b\u4e8e\u65e9\u5148\u5bf9\u7ebf\u6027\u65b9\u7a0b\u7ec4\u7684\u7814\u7a76\uff0c\u7ecf\u5386\u4e86\u6f2b\u957f\u7684\u51e0\u4f55\u548c\u4ee3\u6570\u7684\u4ea4\u9519\u4f5c\u7528\uff0c\u6700\u540e\u53c8\u5728\u8fd1\u4e16\u4ee3\u6570\u7684\u53d1\u5c55\u8fc7\u7a0b\u4e2d\u88ab\u4e25\u683c\u5316\u3002\u76f4\u5230\u73b0\u5728\uff0c\u4e00\u4e9b\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u4f8b\u5982\u7ebf\u6027\u4ee3\u6570\u7fa4\u7684\u7814\u7a76\u5c1a\u4e14\u65b9\u5174\u672a\u827e\uff0c\u5728\u73b0\u4ee3\u6570\u5b66\u7684\u79cd\u79cd\u652f\u7ebf\u5f53\u4e2d\u4e5f\u6709\u7740\u91cd\u8981\u7684\u5e94\u7528\u3002\u53e6\u5916\uff0c\u5b83\u7684\u65b9\u6cd5\u8bba\uff0c\u5c24\u5176\u662f\u5176\u5bf9\u4ee3\u6570\u7ed3\u6784\u7684\u7814\u7a76\u5728\u73b0\u4ee3\u6570\u5b66\u4e2d\u4e5f\u5177\u5907\u7740\u4ee3\u8868\u6027\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u5e0c\u671b\u5448\u73b0\u4e00\u4e2a\u66f4\u5e7f\u9614\u7684\u7ebf\u6027\u4ee3\u6570\u89c2\uff0c\u4ece\u7ebf\u6027\u4ee3\u6570\u51fa\u53d1\uff0c\u5bf9\u5b83\u7684\u73b0\u4ee3\u53d1\u5c55\u548c\u5b83\u5728\u73b0\u4ee3\u6570\u5b66\u7684\u5404\u4e2a\u5206\u652f\u7684\u5e94\u7528\u8fdb\u884c\u4e00\u4e9b\u5bfc\u8bba\u6027\u7684\u4ecb\u7ecd\uff0c\u8fd9\u4e00\u65b9\u9762\u662f\u4e3a\u4e86\u4f7f\u5f97\u5e73\u6de1\u7684\u53d9\u8ff0\u66f4\u52a0\u6709\u8da3\uff0c\u53e6\u4e00\u65b9\u9762\u4e5f\u662f\u4e3a\u4e86\u56de\u7b54\u4e00\u4e2a\u7591\u95ee\uff1a\u7ebf\u6027\u4ee3\u6570\u5230\u5e95\u6709\u4ec0\u4e48\u7528\uff1f\u6211\u4eec\u76f8\u4fe1\uff0c\u8fd9\u662f\u8bb8\u591a\u521d\u5b66\u8005\u90fd\u6709\u7684\u4e00\u4e2a\u95ee\u9898\uff0c\u56de\u7b54\u8fd9\u4e2a\u95ee\u9898\u65e2\u9700\u8981\u5bf9\u7ebf\u6027\u4ee3\u6570\u7684\u6df1\u5165\u5b66\u4e60\uff0c\u4e5f\u9700\u8981\u6709\u4e00\u4e2a\u73b0\u4ee3\u6570\u5b66\u7684\u5168\u5c40\u89c2\uff0c\u8fd9\u4e5f\u5c31\u5e26\u6765\u4e86\u672c\u4e66\u7684\u53e6\u4e00\u4e2a\u90e8\u5206\uff0c\u672a\u7adf\u4e13\u9898\uff0c\u4e5f\u662f\u6211\u4eec\u8fd9\u672c\u4e66\u7684\u6807\u9898\u6765\u6e90\u3002

\u5177\u4f53\u800c\u8a00\uff0c\u6211\u4eec\u7684\u8bb2\u4e49\u76ee\u524d\u5206\u522b\u4e24\u4e2a\u90e8\u5206\uff1a

"},{"location":"algebra/lalu/#_3","title":"\u8bfe\u7a0b\u8bb2\u4e49","text":"\u8bb2\u4e49\uff08v0.6\uff09\u7b54\u6848\uff08v0.6\uff09

LALU \u8bfe\u7a0b\u7684\u8bb2\u4e49\u5b58\u653e\u5728\u4e0b\u9762\u7684\u4ed3\u5e93\u4e2d\uff0c\u4f60\u53ef\u4ee5\u70b9\u51fb\u56fe\u7247\u8df3\u8f6c\u5230\u4ed3\u5e93\u9875\u9762\u3002\u6b22\u8fce\u63d0\u51fa issue \u548c pull request\u3002

\u70b9\u51fb\u4e0b\u9762\u7684\u94fe\u63a5\u53ef\u4ee5\u4e0b\u8f7d\u8bb2\u4e49\u7684\u6700\u65b0 Release \u7248\u672c\uff1a

"},{"location":"analysis/","title":"\u6570\u5b66\u5206\u6790\u8f85\u5b66","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u6570\u5b66\u5206\u6790\u7248\u5757 \ud83e\udd17\u3002\u672c\u9875\u9762\u6c47\u603b\u4e86\u6570\u5b66\u5206\u6790\u7684\u8f85\u5b66\u8d44\u6599\uff0c\u5305\u62ec\u5386\u5e74\u8bd5\u5377\u3001\u8bb2\u4e49\u3001\u5f55\u64ad\u7b49\u3002

"},{"location":"analysis/#2024-2025","title":"2024-2025 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":""},{"location":"analysis/#ih","title":"\u79cb\u51ac\u5b66\u671f \u6570\u5b66\u5206\u6790 I\uff08H\uff09","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad\u5730\u5740 1 Oct.19 \u5b9e\u6570\u7cfb\u5b8c\u5907\u6027\u4e0e\u6570\u5217\u6781\u9650 \u5f3a\u7269 2201 \u6f58\u6210\u5586 \u8bb2\u4e49\u601d\u8003\u9898\u53cd\u9988 Bilibili 2 Oct.20 \u4e00\u5143\u51fd\u6570\u6781\u9650\u548c\u8fde\u7eed\u4e0e\u7b2c\u4e00\u6b21\u5c0f\u6d4b\u590d\u4e60 \u6df7\u5408 2206 \u8c22\u96c6 \u8bb2\u4e49\u7b54\u6848 Bilibili 3 Nov.10 \u5bfc\u6570\u3001\u5fae\u5206\u548c\u4e2d\u503c\u5b9a\u7406 \u56fe\u7075 2302 \u6768\u4e66\u534e \u8bb2\u4e49 Bilibili"},{"location":"analysis/#2023-2024","title":"2023-2024 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":""},{"location":"analysis/#ih_1","title":"\u79cb\u51ac\u5b66\u671f \u6570\u5b66\u5206\u6790 I\uff08H\uff09","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad\u5730\u5740 1 Oct.14 \u6570\u5217\u6781\u9650 \u6df7\u5408 2206 \u80e1\u80b2\u73ae \u8bb2\u4e49\u7b54\u6848 Bilibili 2 Oct.28 \u4e00\u5143\u51fd\u6570\u7684\u6781\u9650\u4e0e\u8fde\u7eed\u6027 \u56fe\u7075 2102 \u6f58\u6636\u7693 \u8bb2\u4e49 Bilibili 3 Nov.26 \u5fae\u5206\u4e2d\u503c\u5b9a\u7406\u548cTaylor\u516c\u5f0f\u62d3\u5c55\u5e94\u7528 \u6df7\u5408 2206 \u8c22\u96c6 \u8bb2\u4e49\u7b54\u6848 Bilibili 4 Dec.9/10 \u4e0d\u5b9a\u79ef\u5206 \u6df7\u5408 2203 \u4f55\u5146\u5e73"},{"location":"analysis/#iih","title":"\u6625\u590f\u5b66\u671f \u6570\u5b66\u5206\u6790 II\uff08H\uff09","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad\u5730\u5740 1 Mar.31 \u7ea7\u6570\u4e0e\u7b2c\u4e00\u6b21\u5c0f\u6d4b\u590d\u4e60 \u6df7\u5408 2206 \u8c22\u96c6 \u8bb2\u4e49\u7b54\u6848 Bilibili 2 May.12 \u591a\u5143\u51fd\u6570\u5fae\u5206\u5b66 \u56fe\u7075 2202 \u6885\u654f\u70ab \u8bb2\u4e49 Bilibili 3 Jun.2 \u591a\u5143\u51fd\u6570\u79ef\u5206\u5b66 \u6df7\u5408 2201 \u97e9\u8d8a \u8bb2\u4e49\u7b54\u6848 Bilibili 4 Jun.9 \u671f\u672b\u590d\u4e60 \u5f3a\u7269 2201 \u6f58\u6210\u5586 \u8bb2\u4e49\u8865\u5145 Bilibili 4 Jun.12 \u4e13\u9898\u8bfe \u5f3a\u7269 2201 \u6f58\u6210\u5586 Rn\u7684\u6570\u5b66\u7ed3\u6784\u91cd\u79ef\u5206 Bilibili"},{"location":"analysis/#_2","title":"\u5386\u5e74\u5377","text":""},{"location":"analysis/#ih_2","title":"\u6570\u5b66\u5206\u6790 I\uff08H\uff09","text":"\u5e74\u4efd \u8bd5\u5377 2023-2024 \u5c0f\u6d4b1 \u671f\u672b\u8bd5\u5377/\u7b54\u6848 2022-2023 \u5c0f\u6d4b1/\u7b54\u6848\u5c0f\u6d4b2/\u7b54\u6848\u671f\u672b\u8bd5\u5377/\u7b54\u6848\uff08zhw\uff09/\u7b54\u6848\uff08hz\uff09 2021-2022 \u5c0f\u6d4b/\u7b54\u6848\u671f\u672b\u8bd5\u5377/\u7b54\u6848\uff08lzw\uff09/\u7b54\u6848\uff08hz\uff09 2020-2021 \u671f\u672b\u8bd5\u5377\uff08\u90e8\u5206\uff09"},{"location":"analysis/#iih_1","title":"\u6570\u5b66\u5206\u6790 II\uff08H\uff09","text":"\u5e74\u4efd \u8bd5\u5377 2022-2023 \u5c0f\u6d4b1 2021-2022 \u671f\u672b\u8bd5\u5377 2020-2021 \u671f\u672b\u8bd5\u5377 \u672a\u77e5\u5e74\u4efd \u5c0f\u6d4b\u53ca\u7b54\u6848"},{"location":"analysis/#_3","title":"\u5386\u5e74\u8d44\u6599\u5f52\u6863","text":""},{"location":"analysis/#2022-2023","title":"2022-2023 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":"\u6388\u8bfe\u5185\u5bb9 \u4e3b\u8bb2\u4eba \u4e0d\u5b9a\u79ef\u5206 \u56fe\u7075 2101 \u9646\u6676\u5b87 \u6570\u5b66\u5206\u6790 I \u8003\u524d\u590d\u4e60 1 \u6df7\u5408 2003 \u90b1\u65e5\u5b8f \u6570\u5b66\u5206\u6790 I \u8003\u524d\u590d\u4e60 2 \u8bb2\u4e49\u7b54\u6848 \u56fe\u7075 2102 \u6f58\u6636\u7693 \u7ea7\u6570 \u8bb2\u4e49\u7b54\u6848 \u6df7\u5408 2102 \u5218\u5fd7\u709c \u66f2\u7ebf\u3001\u66f2\u9762\u3001\u542b\u53c2\u53d8\u91cf\u79ef\u5206 \u5f3a\u7269 2101 \u738b\u5bb8\u660a"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/","title":"\u7b2c\u4e00\u8bb2 \u6570\u5217\u6781\u9650","text":""},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_2","title":"\u5b9e\u6570\u5b8c\u5907\u6027\u5b9a\u7406","text":""},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_3","title":"\u8981\u6c42","text":"
  1. \u7ed9\u51fa\u6982\u5ff5\u3001\u5b9a\u7406\u7684\u540d\u5b57\u53ef\u4ee5\u4f7f\u7528\u6570\u5b66\u8bed\u8a00\u51c6\u786e\u53d9\u8ff0\u3002

  2. \u638c\u63e1\u57fa\u672c\u7684\u5b9a\u7406\u8bc1\u660e\u94fe\uff08\u8be6\u7ec6\u53c2\u80031.4.1 1.4.2\uff09\uff1a

    • \u786e\u754c\u539f\u7406\\(\\rightarrow\\)\u5355\u8c03\u6709\u754c\u5b9a\u7406\\(\\rightarrow\\)\u81f4\u5bc6\u6027\u5b9a\u7406\\(\\rightarrow\\)Cauchy\u51c6\u5219

    • \u5355\u8c03\u6709\u754c\u5b9a\u7406\\(\\rightarrow\\)\u95ed\u533a\u95f4\u5957\u5b9a\u7406\\(\\rightarrow\\)\u6709\u9650\u8986\u76d6\u5b9a\u7406\uff08\u805a\u70b9\u539f\u7406\u548cDedekind\u5206\u5272\u5b9a\u7406\u4e0d\u8981\u6c42\uff09

    • \u786e\u754c\u539f\u7406\\(\\rightarrow\\)\u5404\u4e2a\u5b9a\u7406

  3. \u671f\u672b\u8003\u8bd5\u4f1a\u5728\u8fd9\u51e0\u4e2a\u5b9a\u7406\u91cc\u51fa\u53d9\u8ff0\u9898\u548c\u8bc1\u660e\u9898\uff1b\u5c0f\u6d4b\u4f1a\u8003\u5404\u4e2a\u5b9a\u7406\u7684\u6570\u5b66\u53d9\u8ff0\u7ec6\u8282\u3002

"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_4","title":"\u6982\u5ff5\u53d9\u8ff0","text":"
  1. \u6709\u754c\uff0c\u65e0\u754c

    \\[ \\begin{align} \u6570\u5217\u6709\u754c: &\\quad\\forall n>0,\\exists M\\in \\text{R},\u4f7f|x_n|<M\u6052\u6210\u7acb\\\\ \u6570\u5217\u65e0\u754c: &\\quad\\forall M\\in \\text{R},\\exists n>0,\u4f7f|x_n|>M \\\\ \u9519\u8bef(?): &\\quad\\exists n>0,\\forall M\\in \\text{R},\u4f7fx_n>M \\end{align} \\]

    \u6570\u5b66\u8bed\u8a00\u7684\u5426\u5b9a\uff1a\u8f6c\u6362\u5168\u79f0\u91cf\u8bcd\u548c\u5b58\u5728\u91cf\u8bcd\uff0c\u6ce8\u610f\u91cf\u8bcd\u987a\u5e8f\uff0c\u6539\u53d8\u7b26\u53f7

  2. \u6700\u5927\u6570\uff0c\u6700\u5c0f\u6570

    \\[ \\begin{align} \\max\\{S\\}=a &\\iff a\\in S\u4e14\\forall x\\in S,a\\ge x\\\\ \\min\\{S\\}=b &\\iff b\\in S\u4e14\\forall x\\in S,b\\le x \\end{align} \\]
  3. \u4e0a\u786e\u754c\uff0c\u4e0b\u786e\u754c

    \\[ \\begin{align} M=\\sup\\{S\\}\\iff& \\forall x\\in S,x\\le M\u4e14\\forall\\epsilon>0,\\exists x'\\in S\u6709x'>M-\\epsilon\\\\ m=\\inf\\{S\\}\\iff& \\forall x\\in S,x\\ge m\u4e14\\forall\\epsilon>0,\\exists x'\\in S\u6709x'<M+\\epsilon \\end{align} \\]
"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_5","title":"\u5b9a\u7406\u53d9\u8ff0","text":"
  1. \u786e\u754c\u539f\u7406

    \u975e\u7a7a\u6709\u754c\u96c6\u5fc5\u6709\u4e0a\u4e0b\u786e\u754c

  2. \u5355\u8c03\u6709\u754c\u5b9a\u7406

    \u5355\u8c03\u6709\u754c\u6570\u5217\u5fc5\u6536\u655b

  3. \u81f4\u5bc6\u6027\u5b9a\u7406

    \u4efb\u4f55\u6709\u754c\u6570\u5217\u5fc5\u6709\u6536\u655b\u5b50\u5217

  4. Cauchy\u51c6\u5219

    \\[ a_n\u6536\u655b\\iff\\forall \\epsilon>0,\\exists N>0,\\forall m,n>N,\u5747\u6709|a_m-a_n|<\\epsilon \\\\ \\iff \\forall \\epsilon>0,\\exists N>0,\\forall n>N,p>0,\u5747\u6709|a_{n+p}-a_n|<\\epsilon \\]
  5. \u533a\u95f4\u5957\u5b9a\u7406

    \\[ \\begin{align} & \u8bbe\u95ed\u533a\u95f4\u5217\\{[a_n,b_n]\\}\u6ee1\u8db3:\\\\ & 1.[a_{n+1},b_{n+1}]\\subset[a_n,b_n],n=1,2,3..\\\\ & 2.\\lim_{n\\to\\infty}(b_n-a_n)=0 \\\\ & \u5219\u5b58\u5728\u552f\u4e00\u5b9e\u6570\\xi\uff0c\u6ee1\u8db3\\xi\\in[a_n,b_n],n=1,2.. \\end{align} \\]
  6. \u6709\u9650\u8986\u76d6\u5b9a\u7406

    \\[ \\begin{align} & \u8bbe[a,b]\u662f\u4e00\u4e2a\u95ed\u533a\u95f4\uff0c\\{E_\\lambda\\}_{\\lambda\\in\\Lambda}\u662f[a,b]\u7684\u4efb\u610f\u4e00\u4e2a\u5f00\u8986\u76d6\uff0c\\\\ & \u5219\u5fc5\u5b58\u5728\\{E_\\lambda\\}_{\\lambda\\in\\Lambda}\u7684\u4e00\u4e2a\u5b50\u96c6\u6784\u6210[a,b]\u7684\u4e00\u4e2a\u6709\u9650\u8986\u76d6\u3002 \\\\ \\iff & \u5728\\{E_\\lambda\\}_{\\lambda\\in\\Lambda}\u5fc5\u6709\u6709\u9650\u4e2a\u5f00\u533a\u95f4E_1,E_2..E_N\u4f7f[a,b]\\subset\\cup_{j=1}^NE_j \\end{align} \\]
"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_6","title":"\u5e38\u7528\u6280\u5de7","text":"
  1. \u8bc1\u660e\u96c6\u5408\u76f8\u7b49\u7684\u5e38\u7528\u65b9\u6cd5\uff1a\u76f8\u4e92\u5305\u542b

    \u4f8b\u9898\uff1a\u786e\u754c\u7684\u5173\u7cfb\u5f0f

    \u8bbe \\(A,B\\) \u662f\u4e24\u4e2a\u7531\u975e\u8d1f\u6570\u7ec4\u6210\u7684\u4efb\u610f\u6570\u96c6,\u8bd5\u8bc1\u660e \\(\\sup_{x\\in A}\\{x\\}\\cdot \\sup_{y\\in B}\\{y\\}=\\sup_{x\\in A,y\\in B}\\{xy\\}\\)

  2. \u5bf9\u4e8e\u5b9e\u6570\u5b8c\u5907\u6027\u5b9a\u7406\u7684\u8bc1\u660e\u9898\uff0c\u9996\u5148\u5c06\u7ed9\u7684\u6761\u4ef6\u548c\u8bc1\u660e\u5185\u5bb9\u5747\u7ffb\u8bd1\u6210\u6570\u5b66\u8bed\u8a00\uff08\u65b9\u4fbf\u9a97\u5206\uff09\uff0c\u518d\u89c2\u5bdf\u6761\u4ef6\u548c\u8bc1\u660e\u5185\u5bb9\u7684\u8054\u7cfb\u3002

"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_7","title":"\u4f8b\u9898&\u4e60\u9898","text":"
  1. \u7528\u786e\u754c\u539f\u7406\u8bc1\u660e\u5355\u8c03\u6709\u754c\u539f\u7406\u3001\u81f4\u5bc6\u6027\u5b9a\u7406\u3001Cauchy\u51c6\u5219\u3001\u95ed\u533a\u95f4\u5957\u5b9a\u7406\u3001\u6709\u9650\u8986\u76d6\u5b9a\u7406\u3002
  2. \u7528\u5355\u8c03\u6709\u754c\u5b9a\u7406\u8bc1\u660e\u95ed\u533a\u95f4\u5957\u5b9a\u7406\uff0c\u7528\u95ed\u533a\u95f4\u5957\u5b9a\u7406\u8bc1\u660e\u6709\u9650\u8986\u76d6\u5b9a\u7406\uff1b\u7528\u81f4\u5bc6\u6027\u5b9a\u7406\u8bc1\u660eCauchy\u6536\u655b\u51c6\u5219\u3002
  3. \\(f,g\u4e3aD\u4e0a\u6709\u754c\u51fd\u6570,\\text{pf:}\\inf\\{f(x)+g(x)\\}\\le\\inf{f(x)}+\\sup{g(x)}\\)
  4. \u8bbe\\(f(x)\u5728[0,1]\u4e0a\u9012\u589e,f(0)>0,f(1)<1,\u6c42\u8bc1:\\exists x_0\\in(0,1),\u4f7f\u5f97f(x_0)=x_0^2\\) (Hint:\u786e\u754c\u539f\u7406or\u533a\u95f4\u5957\u5b9a\u7406)
  5. \u8bbe\\(f(x)\\)\u5728\\([a,b]\\)\u4e0a\u6709\u5b9a\u4e49\u4e14\u5728\u6bcf\u4e00\u70b9\u5904\u51fd\u6570\u7684\u6781\u9650\u5b58\u5728\uff0c\u6c42\u8bc1\\(f(x)\\)\u5728\\([a,b]\\)\u4e0a\u6709\u754c (Hint:\u6709\u9650\u8986\u76d6)
  6. \\(\u8bbef(x)\u5728(a,b)\u5185\u6709\u5b9a\u4e49\uff0c\\forall\\xi\\in(a,b),\\exists\\delta>0,\u5f53x\\in(\\xi-\\delta,\\xi+\\delta)\\cap(a,b)\u65f6,\\)\u6709\u5f53\\(x<\\xi\\)\u65f6,\\(f(x)<f(\\xi), \u5f53x>\\xi\\)\u65f6,\\(f(x)>f(\\xi)\\).\u8bf7\u8bc1\u660e:\\(f(x)\u5728(a,b)\\)\u5185\u4e25\u683c\u9012\u589e (Hint:\u6709\u9650\u8986\u76d6)
"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_8","title":"\u6570\u5217\u6781\u9650","text":""},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_9","title":"\u8981\u6c42","text":"
  1. \u4ece\u5c0f\u6d4b\u7684\u89d2\u5ea6\u6765\u8bf4\uff0c\u6982\u5ff5\uff0c\u5b9a\u7406\u4ee5\u53ca\u5224\u65ad\u9898\u662f\u6bd4\u8f83\u91cd\u8981\uff08\u641e\u8111\u5b50\uff09\u7684\uff0c\u5f53\u7136\u4e5f\u4f1a\u6709\u8ba1\u7b97\u9898
  2. \u671f\u672b\u8003\u8bd5\u53ef\u80fd\u4f1a\u51fa1-2\u9053\u6c42\u6781\u9650\uff0c1\u9053\u975e\u5e38\u7b80\u5355\u7684\u6781\u9650\u8bc1\u660e\u9898\uff08\u9644\u5728\u5b9a\u7406\u53d9\u8ff0\u4e0a\uff09
  3. \u8ba1\u7b97\u4e5f\u9700\u8981\u638c\u63e1\uff0c\u4f46\u662f\u6280\u5de7\u6027\u5f3a\u7684\u53ef\u4ee5\u4e0d\u638c\u63e1
  4. \u5b66\u597d\u6570\u5217\u6781\u9650\u5bf9\u51fd\u6570\u6781\u9650\u548c\u7ea7\u6570\u90fd\u5f88\u6709\u5e2e\u52a9\uff0c\u800c\u5b66\u597d\u4e86\u51fd\u6570\u6781\u9650\u5c31\u53ef\u4ee5\u5b66\u597d\u5bfc\u6570\u548c\u79ef\u5206\uff0c\u7136\u540e\u4f60\u5c31\u5b66\u4f1a\u4e86\u6570\u52061
"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_10","title":"\u6982\u5ff5\u53d9\u8ff0","text":"
  1. \u6570\u5217\u6781\u9650\uff08\\(\\epsilon-N\\)\u8bed\u8a00\uff09
\\[ \\forall\\epsilon>0,\\exists N>0,\\forall n>N,|x_n-A|<\\epsilon\u79f0\\lim_{x\\rightarrow\\infty}x_n=A\\\\ *:|x_n-A|<f(\\epsilon),f(x)\u6ee1\u8db3\\lim _{x\\rightarrow0}f(x)=0\u5373\u53ef \\]
  1. \u6570\u5217\u53d1\u6563
\\[ \\forall A\\in R,\\exists\\epsilon_0>0,\\forall N>0,\\exists n_N>N,|x_n-A|\\ge\\epsilon_0 \\]
  1. \u5b50\u5217

    \\[ \\{a_n\\}\u6536\u655b\\iff \\{a_n\\}\u7684\u4efb\u610f\u5b50\u5217\u90fd\u6536\u655b\u4e8eA(\u8bf7\u6ce8\u610f\u51cf\u5f31\u547d\u9898) \\]
  2. \u65e0\u7a77\u5c0f\u91cf\u548c\u65e0\u7a77\u5927\u91cf

    \\[ \\begin{align} & \u65e0\u7a77\u5c0f\u91cf : \\lim_{x\\rightarrow\\infty}= 0 \\\\ & \u65e0\u7a77\u5927\u91cf : \\forall M>0,\\exists N,\\forall n>N,|x_n|>M \\end{align} \\]
"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_11","title":"\u5b9a\u7406\u53d9\u8ff0","text":"
  1. Stolz\u5b9a\u7406

    \u5e38\u7528\u4e8e\u8ba1\u7b97\u5f62\u5f0f\u9700\u8981\u6d1b\u5fc5\u8fbe\u7684\u6781\u9650

  2. Cauchy\u6536\u655b\u51c6\u5219\u3001\u7b49\u4ef7\u5f62\u5f0f\u53ca\u5426\u5b9a

\\[ \\begin{align} a_n\u6536\u655b& \\iff\\forall \\epsilon>0,\\exists N>0,\\forall m,n>N,\u5747\u6709|a_m-a_n|<\\epsilon \\\\ & \\iff \\forall \\epsilon>0,\\exists N>0,\\forall n>N,p>0,\u5747\u6709|a_{n+p}-a_n|<\\epsilon \\\\ \u5426\u5b9a\u5f62\u5f0f:a_n\u53d1\u6563& \\iff\\exists\\epsilon_0>0,\\forall N,\\exists n_0>N,p>0,|x_{n_0+p}-x_{n_0}|\\ge\\epsilon_0 \\end{align} \\]"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_12","title":"\u5e38\u7528\u6280\u5de7","text":"
  1. \u4e00\u4e9b\u5173\u7cfb\u94fe\uff1a

    1. \\(n\\rightarrow\\infty\u65f6\\)
    \\[ \\log\\log n\\ll \\log n \\ll n^a\\ll b^n\\ll n!\\ll n^n\\quad(a,b>0) \\]
    1. \\(x\\rightarrow0\u65f6\\)
    \\[ \\begin{align} x \\sim &\\sin x\\sim \\tan x \\sim \\arcsin x\\sim \\arctan x \\\\ \\sim &\\ln{(1+x)} \\sim \\text{e}^x-1 \\sim \\frac{a^x-1}{\\ln a}\\sim \\frac{(1+x)^b-1}b \\quad(a>0,b\\neq0)\\\\ & 1-\\cos x \\sim \\frac12 x^2 \\end{align} \\]
  2. \u8bc1\u660e\u6570\u5217\u6781\u9650\u5b58\u5728\uff1a

    1. \u5b9a\u4e49\uff08\\(\\epsilon-N\\)\u65b9\u6cd5\uff09

    \u6280\u5de7\uff1a\u653e\u5927\u6cd5(\u5e38\u7528)/\u5206\u6b65\u6cd5/\u6784\u9020\u5f62\u5f0f\u7c7b\u4f3c\u7684\u9879/\u62df\u5408\u6cd5(\u6280\u5de7\u6027\u8f83\u5f3a)

    1. Cauchy\u51c6\u5219\uff1a\u4e0d\u9700\u8981\u77e5\u9053\u6781\u9650\u503c

    2. Cauchy\u51c6\u5219\u7684\u63a8\u8bba\uff1a\u5e38\u7528\u4e8e\u5224\u65ad\u6570\u9879\u7ea7\u6570\u662f\u5426\u6536\u655b(\\(a_n=\\sum_{n=1}^{\\infty}f(n)\\))

    3. \u5355\u8c03\u6709\u754c\u539f\u7406\uff1a\u4e0d\u52a8\u70b9\uff0c\u9012\u63a8\u5f0f\u8003\u8651

    4. \u6781\u9650\u7684\u8fd0\u7b97\u6027\u8d28\uff1a\u672c\u8eab\u5b58\u5728\u6781\u9650 \u6709\u9650\u9879\u8fd0\u7b97

  3. \u8bc1\u660e\u6570\u5217\u6781\u9650\u4e0d\u5b58\u5728\uff1a

    1. Cauchy\u547d\u9898\u7684\u5426\u5b9a\u5f62\u5f0f
    2. \u5b50\u5217\u4e0d\u6536\u655b\u6216\u6536\u655b\u4e8e\u4e0d\u540c\u7684\u6570
  4. \u6c42\u6570\u5217(\u51fd\u6570)\u6781\u9650\uff1a

    1. \u6781\u9650\u7684\u8fd0\u7b97\u6027\u8d28

    \u4e00\u4e9b\u91cd\u8981\u6781\u9650\uff1a\\(\\lim\\limits_{n\\rightarrow\\infty}n^\\frac1n=1\\)\uff0c\\(\\lim\\limits_{n\\rightarrow\\infty}(1+\\frac1n)^n=e\\)

    1. Stolz\u5b9a\u7406

    2. \u5939\u903c\u5b9a\u7406

    3. \u7b49\u4ef7\u4ee3\u6362\u4e0e\u521d\u7b49\u53d8\u5f62

    4. \u9012\u63a8\u5f62\u5f0f\u7684\u6781\u9650\uff1a\u5355\u8c03\u6709\u754c\u539f\u7406+\u8bc1\u660e/\u538b\u7f29\u6620\u50cf(\u7565\u96be)/Stolz\u516c\u5f0f\u7684\u5e94\u7528

    5. Taylor/L'Hospital/\u79ef\u5206\u5b9a\u4e49/\u6570\u9879\u7ea7\u6570/\u7ea7\u6570\u7684\u8fde\u7eed\u6027...\uff1a \u5f88\u91cd\u8981\uff0c\u4f46\u8fd9\u662f\u540e\u4e8b\u4e86

"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_13","title":"\u4f8b\u9898&\u4e60\u9898","text":"
  1. \u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u5b50\u5217\u7684\u547d\u9898

    1. \u8bbe\\(\\{a_n\\}\\)\u662f\u4e00\u4e2a\u6570\u5217\uff0c\u82e5\u5728\u4efb\u4e00\u5b50\u5217\\(\\{a_{n_k}\\}\\)\u4e2d\u5747\u5b58\u5728\u6536\u655b\u5b50\u5217\\(\\(\\{a_{n_{k_r}}\\}\\)\\),\u5219\\(\\(\\{a_n\\}\\)\\)\u5fc5\u6536\u655b
    2. \\(\\{a_n\\}\u5355\u8c03\u9012\u589e\uff0c\\{a_{n_k}\\}\u4e3a\u5176\u4e2d\u4e00\u4e2a\u5b50\u5217\uff0c\\lim\\limits_{k\\rightarrow\\infty}a_{n_k}=a,\u5219\\lim\\limits_{n\\rightarrow\\infty}{a_n}=a\\)
    3. \\(\\{a_{2k}\\}\\{a_{2p+1}\\}\\{a_{2023t+2024}\\}\u5747\u6536\u655b\uff0c\u5219\\{a_n\\}\u6536\u655b\\)
    4. \\(\\{a_{2k}\\}\\{a_{2t+1}\\}\\{a_{6p+5}\\}\u5747\u6536\u655b\uff0c\u5219\\{a_n\\}\u6536\u655b\\)
  2. \u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u65e0\u7a77\u5c0f\u91cf\u7684\u547d\u9898

    1. \u65e0\u7a77\u591a\u4e2a\u65e0\u7a77\u5c0f\u91cf\u4e4b\u548c\u662f\u65e0\u7a77\u5c0f\u91cf
    2. \u65e0\u7a77\u591a\u4e2a\u65e0\u7a77\u5c0f\u91cf\u4e4b\u79ef\u662f\u65e0\u7a77\u5c0f\u91cf
    3. \u65e0\u7a77\u5c0f\u91cf\u4e0e\u6709\u754c\u91cf\u4e4b\u79ef\u4e3a\u65e0\u7a77\u5c0f\u91cf
  3. \u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u6570\u5217\u6781\u9650\u7684\u547d\u9898

    1. \u6570\u5217\\(a_n\\)\u6536\u655b\\(\\iff \\forall p\\in N,\\lim\\limits_{n\\rightarrow+\\infty}{|a_{n+p}-a_n|=0}\\)
    2. \\(\\lim\\limits_{n\\rightarrow\\infty}x_n=A\\iff\\forall k\\in \\text{N},\\exists N>0,\\forall n>N,|x_n-A|<\\frac1k\\)
    3. \\(a_n\u6536\u655b \\iff \\exists N>0,\\forall \\epsilon>0,\\forall m,n>N,\u5747\u6709|a_m-a_n|<\\epsilon\\)
  4. \u91cd\u8981\u7684\u4e8c\u7ea7\u7ed3\u8bba\uff1a

\\[ Cauchy\u5b9a\u7406:\\lim_{n\\rightarrow\\infty}x_n=A,\u5219\\lim_{n\\rightarrow\\infty}\\frac{x_1+x_2+...+x_n}{n}=A \\]
  1. \\(x_n=\\sum_{i=1}^n\\sin(\\frac{2i-1}{n^2}a),\\text{pf:}\\lim\\limits_{n\\rightarrow\\infty}x_n=a\\) (Hint:\u62df\u5408\u6cd5)

  2. \u6c42\u6781\u9650\\(\\lim\\limits_{n\\rightarrow\\infty}x_n\\)\uff1a

    1. \\(x_n=\\cos\\frac x2\\cos\\frac x{2^2}\\cdots\\cos\\frac x{2^n}\\)
    2. \\(x_n=(\\frac{\\sqrt[n]a+\\sqrt[n]b}{2})^n\\)
    3. \\(x_n=\\frac 1{\\sqrt[n]{n!}}\\)
    4. \\(x_n={(n!)}^{\\frac1{n^2}}\\)
    5. \\(x_n=\\sqrt[6]{x^6+x^5}-\\sqrt[6]{x^6-x^5}\\)
  3. (2019(?)\u5e74\u6570\u52061\u671f\u672b)

\\[ \\begin{align} & \u5bf9\u4e8e\u6570\u5217x_0=a,0<a<\\frac\\pi2,x_n=\\sin x_{n-1}(n=1,2,\\cdots). \\\\ &\\text{pf:}(1)\\lim\\limits_{n\\rightarrow\\infty}x_n=0;(2)\\lim\\limits_{n\\rightarrow\\infty}{\\sqrt\\frac n3}x_n=1 \\end{align} \\]"},{"location":"analysis/analysis1_paper/22test1_answer/","title":"22\u6570\u5206\u5c0f\u6d4b\u7b54\u6848","text":"

\u9898\u76ee\u3001\u9009\u9879\u987a\u5e8f\u53c2\u8003\u5c0f\u6d4b1

  1. D
  2. AC
  3. B
  4. A
  5. BCD
  6. ABD
  7. B
  8. B
  9. A (\u805a\u70b9\u5e94\u8be5\u4e0d\u8981\u6c42\uff0c\u53ef\u4ee5\u5ffd\u7565)
  10. C
"},{"location":"calculus/","title":"\u5fae\u79ef\u5206\u8f85\u5b66","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u5fae\u79ef\u5206\u7248\u5757 \ud83e\udd17\u3002

"},{"location":"calculus/#2023-2024","title":"2023-2024 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad 1 Oct.22 \u6781\u9650\u4e0e\u51fd\u6570\u7684\u8fde\u7eed\u6027 \u6df7\u5408 2106 \u5f20\u5fd7\u5fc3 \u8bb2\u4e49 \u7b54\u6848 Bilibili 2 Nov.5 \u671f\u4e2d\u590d\u4e60 \u6c42\u5316 2201 \u5218\u5b50\u6db5 \u8bb2\u4e49\u7b54\u6848 Bilibili 3 Dec.3 \u5fae\u5206\u4e2d\u503c\u5b9a\u7406\u548c\u4e0d\u5b9a\u79ef\u5206 \u5f3a\u533b 2101 \u5362\u601d\u7426 \u8bb2\u4e49 Bilibili"},{"location":"chemistry/","title":"\u666e\u901a\u5316\u5b66\u8f85\u5b66","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u666e\u901a\u5316\u5b66\u7248\u5757\ud83e\udd17\u3002

"},{"location":"chemistry/#_2","title":"\u8f85\u5b66\u8d44\u6599\u5f52\u6863","text":""},{"location":"chemistry/#2023-2024","title":"2023-2024 \u5b66\u5e74 \u79cb\u51ac\u5b66\u671f","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad 3 Dec.12 \u7535\u5316\u5b66\u4e0e\u7269\u8d28\u7ed3\u6784 \u6df7\u5408 2102 \u674e\u822a\u5947 \u8bb2\u4e49 Bilibili"},{"location":"other/","title":"\u5176\u4ed6\u8d44\u6e90","text":""},{"location":"other/#_2","title":"\u6982\u7387\u8bba\u4e0e\u6570\u7406\u7edf\u8ba1","text":""},{"location":"other/#_3","title":"\u5c0f\u6d4b\u9898\u5e93","text":"\u5b66\u671f \u8bd5\u5377 23\u79cb\u51ac \u5c0f\u6d4b\u4e00(1)\u5c0f\u6d4b\u4e8c(1)/\u5c0f\u6d4b\u4e8c(2)/\u5c0f\u6d4b\u4e8c(3)\u5c0f\u6d4b\u4e09(1)/\u5c0f\u6d4b\u4e09(2) 23\u6625\u590f \u5c0f\u6d4b\u4e00(1)"},{"location":"physics/","title":"\u666e\u7269\u8f85\u5b66","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u666e\u7269\u8f85\u5b66\u7248\u5757\ud83e\udd17\u3002\u4f60\u53ef\u4ee5\u5728\u5de6\u4fa7\u5bfc\u822a\u680f\u4e2d\u8be6\u7ec6\u6d4f\u89c8\u672c\u6a21\u5757\u7684\u5185\u5bb9\u3002

"},{"location":"physics/#2023-2024","title":"2023-2024 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":""},{"location":"physics/#ih","title":"\u6625\u590f\u5b66\u671f \u666e\u901a\u7269\u7406\u5b66 I\uff08H\uff09","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad\u5730\u5740 1 Mar.31 \u9884\u5907\u77e5\u8bc6\u3001\u52a8\u91cf\u3001\u8f6c\u52a8 \u6df7\u5408 2305 \u6768\u5f18\u6bc5 \u8bb2\u4e49\u7b54\u6848 Bilibili"},{"location":"programming/","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u7a0b\u8bbe\u7248\u5757\ud83e\udd17\u3002\u4f60\u53ef\u4ee5\u5728\u5de6\u4fa7\u5bfc\u822a\u680f\u4e2d\u6d4f\u89c8\u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66\u7684\u6240\u6709\u8d44\u6599\u3002

"},{"location":"programming/#_2","title":"\u5176\u4ed6\u8d44\u6e90","text":""},{"location":"programming/#_3","title":"\u5e38\u7528\u7f51\u7ad9","text":""},{"location":"programming/#_4","title":"\u5b66\u957f\u5b66\u59d0\u7684\u7b14\u8bb0\u672c","text":"

\u5f88\u591a\u5b66\u957f\u5b66\u59d0\u90fd\u5728\u81ea\u5df1\u7684\u535a\u5ba2/\u7b14\u8bb0\u672c\u4e2d\u5199\u4e86\u4e00\u4e9b\u5173\u4e8e\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u5185\u5bb9\uff0c\u8fd9\u91cc\u5217\u51fa\u4e00\u4e9b\u94fe\u63a5\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\u3002

"},{"location":"programming/24fall/","title":"24 \u79cb\u51ac \u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66","text":"

\u6b22\u8fce\u6765\u5230 24 \u79cb\u51ac\u7a0b\u8bbe\u8f85\u5b66\u8bfe\u7a0b\u9875\u9762\uff01\u672c\u5b66\u671f\u8ba1\u5212\u5f00\u8bfe 6 \u6b21\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a

\u8282\u6b21 \u65f6\u95f4 \u6388\u8bfe\u5b66\u957f \u8bfe\u7a0b\u6807\u9898 \u56de\u653e\u5730\u5740 \u4e00 \u79cb\u4e03\u5468 \u6df7\u5408 2301 \u502a\u665f\u7fd4 \u7f16\u7a0b\u5165\u95e8 Bilibili \u4e8c \u51ac\u4e8c\u5468 \u6df7\u5408 2205 \u6731\u5b9d\u6797 \u901a\u5f80 Pro \u7684\u7b2c\u4e00\u6b65\u547d\u4ee4\u884c\u4ea4\u4e92\u3001VSCode\u3001AI \u5de5\u5177 Bilibili \u4e09 \u51ac\u56db\u5468 \u56fe\u7075 2302 \u9ec4\u54f2 \u5f00\u6e90\u4e16\u754c\u751f\u5b58\u57fa\u7840SSH \u5bc6\u94a5\u3001ZJUGit\u3001Git\u3001\u8bb8\u53ef\u8bc1 Bilibili \u56db \u51ac\u4e94\u5468 \u56fe\u7075 2201 \u674e\u82f1\u7426 \u5982\u4f55\u5199\u51fa\u7b80\u6d01\u5de5\u6574\u7684\u62a5\u544aMarkdown\u3001LaTeX Bilibili \u4e94 \u51ac\u516d\u5468 \u56fe\u7075 2302 \u6768\u4e66\u534e \u671f\u672b\u590d\u4e60\uff08\u4e0a\uff09 \u516d \u51ac\u4e03\u5468 \u6df7\u5408 2301 \u53f8\u6d69\u8a00 \u671f\u672b\u590d\u4e60\uff08\u4e0b\uff09

\u5173\u4e8e\u8bfe\u7a0b\u96be\u5ea6\uff0c\u6211\u4eec\u4f1a\u4e25\u683c\u63a7\u5236\u5728\u5927\u4e00\u65b0\u751f\u521a\u63a5\u89e6\u8ba1\u7b97\u673a\u65f6\u7684\u6c34\u5e73\u3002\u53bb\u5e74\u6211\u4eec\u8bbe\u5b9a\u7684\u96be\u5ea6\u6709\u70b9\u9ad8\uff0c\u6548\u679c\u4e0d\u662f\u5f88\u597d\uff08\u6709\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u5728\u5de6\u4fa7\u5bfc\u822a\u680f\u6d4f\u89c8\u53bb\u5e74\u7684\u5185\u5bb9\uff09\u3002\u4eca\u5e74\u6211\u4eec\u7684\u76ee\u6807\u662f\u666e\u53ca\uff0c\u8ba9\u5c3d\u53ef\u80fd\u591a\u7684\u540c\u5b66\u53d7\u76ca\u3002

"},{"location":"programming/24fall/#_1","title":"\u8bfe\u7a0b\u52a8\u673a\u4e0e\u76ee\u6807","text":"

Hi\uff0cCSer\uff01\u6b22\u8fce\u4f60\u6765\u5230\u8ba1\u7b97\u673a\u4e13\u4e1a\u7684\u4e16\u754c\u3002\u4f46\u8fd9\u6761\u8def\u521a\u5f00\u59cb\u7684\u4e00\u6bb5\u53ef\u80fd\u5e76\u4e0d\u597d\u8d70\uff1a

\u5927\u4e00\u5165\u5b66\u65f6\u6211\u662f\u4e00\u4e2a\u5bf9\u8ba1\u7b97\u673a\u4e00\u65e0\u6240\u77e5\u7684\u5c0f\u767d\uff0c\u88c5\u4e86\u51e0\u5341\u4e2a G \u7684 Visual Studio \u5929\u5929\u548c OJ \u4f60\u6b7b\u6211\u6d3b\u3002\u51ed\u7740\u9ad8\u4e2d\u7684\u6570\u5b66\u5e95\u5b50\u6211\u6570\u5b66\u8bfe\u5b66\u5f97\u8fd8\u4e0d\u9519\uff0c\u4f46\u5728\u4e13\u4e1a\u8bfe\u4e0a\u5bf9\u7ade\u8d5b\u5927\u4f6c\u53ea\u6709\u4ef0\u671b\u3002\u63d0\u5230\u7f16\u7a0b\u6211\u53ea\u4f1a\u6253\u5f00\u90a3\u7b28\u91cd\u7684 IDE\uff0c\u65b0\u5efa\u4e00\u4e2a\u6211\u4e5f\u4e0d\u77e5\u9053\u5177\u4f53\u662f\u5e72\u5565\u7684\u547d\u4ee4\u884c\u9879\u76ee\uff0c\u7136\u540e\u5c31\u662f cin, cout, for \u5faa\u73af\uff0c\u7136\u540e CE, RE, WA \u5faa\u73af\u3002\u5f53\u65f6\u7684\u6211\u5c31\u5904\u5728\u4e00\u79cd\u62fc\u547d\u60f3\u5b66\u597d\u4f46\u4e0d\u77e5\u9053\u600e\u4e48\u5b66\uff0c\u8bfe\u4e0a\u8ba4\u771f\u542c\u8bb2\u4f46\u9898\u8fd8\u4e0d\u4f1a\u505a\uff0c\u8bfe\u540e\u505a\u4f5c\u4e1a\u5b8c\u5168\u662f\u7528\u65f6\u95f4\u548c\u5b83\u786c\u8017\u7684\u75db\u82e6\u72b6\u6001\u3002\u6211\u81f3\u4eca\u7535\u8111\u91cc\u8fd8\u5b58\u7740\u81ea\u5df1\u5927\u4e00\u4e0a\u5b66\u671f\u8ba1\u7b97\u6982\u8bba\u5927\u4f5c\u4e1a\u7684\u6e90\u4ee3\u7801 \u2014\u2014 \u4e00\u4e2a 1200 \u884c\u7684 C++ \u6587\u4ef6\uff0c\u6ca1\u6709\u5934\u6587\u4ef6\u3001\u6ca1\u6709\u7c7b\u3001\u6ca1\u6709\u5c01\u88c5\u3001\u6ca1\u6709 unit test\u3001\u6ca1\u6709 Makefile\u3001\u6ca1\u6709 Git\uff0c\u552f\u4e00\u7684\u4f18\u70b9\u662f\u5b83\u786e\u5b9e\u80fd\u8dd1\uff0c\u7f3a\u70b9\u662f\u201c\u80fd\u8dd1\u201d\u7684\u8865\u96c6\u3002\u6211\u4e00\u5ea6\u6000\u7591\u6211\u662f\u4e0d\u662f\u4e0d\u9002\u5408\u5b66\u8ba1\u7b97\u673a\uff0c\u56e0\u4e3a\u7ae5\u5e74\u5bf9\u4e8e\u6781\u5ba2\u7684\u6240\u6709\u60f3\u8c61\uff0c\u5df2\u7ecf\u88ab\u6211\u7b2c\u4e00\u4e2a\u5b66\u671f\u7684\u4f53\u9a8c\u5f7b\u5e95\u7c89\u788e\u4e86\u3002

\u4e0a\u9762\u8fd9\u6bb5\u8bdd\u6765\u81ea CS \u81ea\u5b66\u6307\u5357 \u7684\u4f5c\u8005\uff0c\u6211\u60f3\u4e5f\u662f\u5f88\u591a\u540c\u5b66\u7684\u771f\u5b9e\u5199\u7167\u3002\u8fd9\u6bb5\u8bdd\u771f\u5b9e\u5730\u63ed\u793a\u4e86\u56fd\u5185\u8ba1\u7b97\u673a\u672c\u79d1\u6559\u80b2\u7684\u4e00\u4e2a\u666e\u904d\u95ee\u9898\uff1a\u7f3a\u4e4f\u5de5\u5177\u548c\u6280\u80fd\u7684\u57f9\u517b\u3002\u8fd9\u4e00\u60c5\u51b5\u6b63\u5728\u597d\u8f6c\uff0c\u8d8a\u6765\u8d8a\u591a\u56fd\u5185\u5916\u5b66\u6821\u5f00\u59cb\u91cd\u89c6\u8fd9\u65b9\u9762\u7684\u6559\u80b2\uff0c\u5f00\u8bbe\u4e86\u76f8\u5173\u8bfe\u7a0b\uff1a

\u5b66\u6821 \u8bfe\u7a0b MIT\uff08\u9ebb\u7701\u7406\u5de5\u5b66\u9662\uff09 Missing Semester \u6e05\u534e\u5927\u5b66 \u5168\u90e8\u8bfe\u7a0b\u91c7\u7528\u6587\u6863 + \u5f00\u6e90\u4ee3\u7801\u6846\u67b6\u5de5\u5177\u548c\u6280\u80fd\u7684\u57f9\u517b\u5df2\u7ecf\u878d\u5165\u8bfe\u7a0b\u4f53\u7cfb \u4e2d\u56fd\u79d1\u5b66\u6280\u672f\u5927\u5b66 Linux 101 \u5357\u4eac\u5927\u5b66 ICS-PA2024

\u4f46\u5f88\u53ef\u60dc\uff0c\u6d59\u6c5f\u5927\u5b66\u8ba1\u7b97\u673a\u5b66\u9662\u7684\u8bfe\u6539\u8fd8\u6ca1\u6709\u8d70\u5230\u8fd9\u4e00\u6b65\uff0c\u4f60\u53ef\u4ee5\u770b\u5230\u90e8\u5206\u300a\u7a0b\u5e8f\u8bbe\u8ba1\u4e0e\u7b97\u6cd5\u57fa\u7840\u300b\u7684\u8001\u5e08\u8fd8\u5728\u4f7f\u7528 20 \u5e74\u524d\u7684 PPT\u3002\u6240\u4ee5\u6211\u4eec\u5e0c\u671d\u7740\u8fd9\u4e2a\u65b9\u5411\u52aa\u529b\uff0c\u5bf9\u9f50\u5176\u4ed6\u5b66\u6821\u7684\u8bfe\u7a0b\uff0c\u5e2e\u52a9\u540c\u5b66\u4eec\u5c3d\u65e9\u638c\u63e1\u8fd9\u4e9b\u6280\u80fd\uff0c\u8ba9\u4f60\u4eec\u5728\u4e13\u4e1a\u8bfe\u4e0a\u5c11\u8d70\u5f2f\u8def\u3002

\u53bb\u5e74\u6211\u4eec\u5f00\u8bbe\u4e86\u4e24\u5957\u8bfe\u7a0b\uff0c\u4f46\u663e\u7136\u5bf9\u5927\u4e00\u65b0\u751f\u6765\u8bf4\u5185\u5bb9\u8fc7\u591a\u4e14\u96be\u4e86\u3002\u672c\u5b66\u671f\u7684\u76ee\u6807\u662f\u666e\u53ca\uff0c\u8ba9\u5927\u4e00\u65b0\u751f\u6709\u4e00\u4e2a\u9002\u5e94\u7684\u8fc7\u7a0b\uff0c\u6240\u4ee5\u8bfe\u7a0b\u5185\u5bb9\u4f1a\u6781\u4e3a\u7b80\u5355\u3002\u6211\u4eec\u8ba1\u5212\u5728 25spring \u5f00\u8bbe\u6df1\u5165\u7684\u8bfe\u7a0b\uff0c\u5230\u65f6\u5019\u4f1a\u6709\u66f4\u591a\u6df1\u5165\u7684\u5185\u5bb9\u3002

\u611f\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u8fdb\u4e00\u6b65\u9605\u8bfb\uff1a\u8c08\u8c08\u5982\u4f55\u8ba9\u81ea\u5df1\u770b\u4e0a\u53bb\u3001\u95fb\u4e0a\u53bb\u90fd\u50cf\u4e00\u4e2a CS \u4eba - CC98\u3002

"},{"location":"programming/24fall/group-session/","title":"24fall \u7a0b\u8bbe\u8f85\u5b66\u6388\u8bfe\u7ec4\u6559\u7814\u4f1a","text":"

\u65e5\u671f\uff1a2024 \u5e74 10 \u6708 18 \u65e5 \u5730\u70b9\uff1a\u7389\u6e56 7 \u5e62 116 \u4eba\u5458\uff1a\u6731\u5b9d\u6797\u3001\u738b\u666e\u3001\u6768\u4e66\u534e\u3001\u502a\u665f\u7fd4\u3001\u674e\u82f1\u7426\u3001\u6885\u654f\u70ab\u3001\u82cf\u715c\u7a0b\u3001\u9ec4\u54f2\u3001\u53f8\u6d69\u8a00

"},{"location":"programming/24fall/lec1/","title":"\u7b2c\u4e00\u8bb2\uff1a\u7f16\u7a0b\u5165\u95e8","text":"

\u672c\u6b21\u8bfe\u7a0b\u5b9a\u4f4d\u4e3a\u7f16\u7a0b\u5165\u95e8\uff0c\u5e0c\u671b\u4e3b\u8981\u5411\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e9b\u57fa\u672c\u7684\u7f16\u7a0b\u601d\u60f3\uff0c\u5e76\u901a\u8fc7\u4f8b\u9898\u4e0e\u8bb2\u89e3\u7684\u5f62\u5f0f\u52a0\u4ee5\u6e17\u900f\u3002\u4f8b\u9898\u53c2\u8003\u81ea\u53bb\u5e74\u7684 PTA \u4e60\u9898\u3002

"},{"location":"programming/24fall/lec1/#_2","title":"\u8ba1\u7b97\u673a\u57fa\u7840\u77e5\u8bc6","text":"

\u51af\u8bfa\u4f9d\u66fc\u67b6\u6784\uff1a\u8f93\u5165\u3001\u50a8\u5b58\u3001\u8ba1\u7b97\u3001\u8f93\u51fa

\u8ba1\u7b97\u673a\u5982\u4f55\u50a8\u5b58\u6570\u636e\uff1f

\u8ba1\u7b97\u673a\u5982\u4f55\u8fd0\u7b97\u6570\u636e\uff1f

"},{"location":"programming/24fall/lec1/#_3","title":"\u7f16\u7a0b\u601d\u8def","text":"

\u7f16\u7a0b\u7684\u8fc7\u7a0b\u53ef\u4ee5\u662f\u4e00\u79cd\u76f4\u89c2\u601d\u8003\u7684\u62bd\u8c61\u5316\uff0c\u5bf9\u4e8e\u4e00\u822c\u7684\u7f16\u7a0b\u95ee\u9898\uff0c\u6211\u4e00\u822c\u628a\u5b83\u5206\u4e3a\u4e24\u7c7b\uff0c\u5373\uff1a

\u5bf9\u4e8e\u524d\u8005\uff0c\u6211\u4eec\u8fd8\u662f\u53ef\u4ee5\u6709\u4e00\u5b9a\u7684\u601d\u8def\u53bb\u89e3\u51b3\u7684\uff0c\u6bd4\u5982\u4e0b\u9762\u8fd9\u4e2a\u7ecf\u5178\u7684\u4f8b\u5b50\uff1a

\u4f8b\u5b50

\u516c\u9e21 5 \u5143\u4e00\u53ea\u3001\u6bcd\u9e21 3 \u5143\u4e00\u53ea\u3001\u5c0f\u9e21 1 \u5143 3 \u53ea\uff1b100 \u5143\u4e70\u4e86 100 \u53ea\u9e21\uff0c\u95ee\u5404\u591a\u5c11\u53ea\uff1f

\u5bf9\u4e8e\u540e\u8005\uff0c\u6bd4\u5982\uff1a

\u4f8b\u5b50

\u7ed9\u5b9a\u4e24\u4e2a\u5355\u8bcd word1 \u548c word2\uff0c\u8ba1\u7b97\u51fa\u5c06 word1 \u8f6c\u6362\u6210 word2 \u6240\u4f7f\u7528\u7684\u6700\u5c11\u64cd\u4f5c\u6570\u3002

\u7528\u6237\u53ef\u4ee5\u5bf9\u4e00\u4e2a\u5355\u8bcd\u8fdb\u884c\u5982\u4e0b\u4e09\u79cd\u64cd\u4f5c\uff1a\u63d2\u5165\u4e00\u4e2a\u5b57\u7b26\u3001\u5220\u9664\u4e00\u4e2a\u5b57\u7b26\u3001\u66ff\u6362\u4e00\u4e2a\u5b57\u7b26\u3002

\u8df3\u51fa\u505a\u9898\u7684\u6846\u67b6\uff0c\u6211\u4eec\u4e00\u822c\u628a\u7f16\u7a0b\u8303\u5f0f\u5206\u4e3a\u4ee5\u4e0b\u51e0\u79cd\uff1a

"},{"location":"programming/24fall/lec1/#_4","title":"\u57fa\u7840\u77e5\u8bc6\u590d\u4e60","text":""},{"location":"programming/24fall/lec1/#_5","title":"\u57fa\u672c\u8f93\u5165\u8f93\u51fa","text":"

\u53ef\u80fd\u8fd9\u4e00\u8282\u5185\u5bb9\u6709\u4e9b\u57fa\u7840\uff0c\u4f46\u4f5c\u4e3a\u6bcf\u9053\u7f16\u7a0b\u9898\u5fc5\u4e0d\u53ef\u5c11\u7684\u90e8\u5206\uff08\u6709\u65f6\u751a\u81f3\u662f\u901a\u8fc7\u7684\u5173\u952e\u6240\u5728\uff09\uff0c\u6211\u5e0c\u671b\u80fd\u4e3a\u5927\u5bb6\u7a0d\u5fae\u603b\u7ed3\u4e00\u4e0b\u600e\u6837\u8bfb\u6570\u636e\uff0c\u600e\u6837\u8f93\u51fa\u6570\u636e\u3002

\u76ee\u524d\uff0c\u6211\u4eec\u4e00\u822c\u4f7f\u7528 scanf() \u8bfb\u5165\u6570\u636e\uff0cprintf() \u8f93\u51fa\u6570\u636e\u3002\u5176\u4e2d\u7684 'f' \u610f\u4e3a \"format\"\uff0c\u5373\u683c\u5f0f\u5316\u8f93\u5165\u8f93\u51fa\u3002

scanf

scanf() \u7684\u5b9a\u4e49\u5982\u4e0b\uff1a

int scanf(const char *format, ...)\n

\u53c2\u6570\u7531\u4e24\u90e8\u5206\u7ec4\u6210\uff1a\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u3001\u8bfb\u5165\u53c2\u6570\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u524d\u9762\u4e00\u534a\u662f\u544a\u8bc9\u8ba1\u7b97\u673a\u600e\u4e48\u8bfb\uff0c\u540e\u9762\u4e00\u534a\u662f\u544a\u8bc9\u8ba1\u7b97\u673a\u8bfb\u5b8c\u4e86\u5b58\u5728\u54ea\u91cc\u3002

\u7c7b\u578b \u5408\u683c\u7684\u8f93\u5165 \u53c2\u6570\u7684\u7c7b\u578b \u5907\u6ce8 %c \u5355\u4e2a\u5b57\u7b26 char * \u53ef\u4ee5\u4f7f\u5176\u8bfb\u53d6\u591a\u4e2a\u5b57\u7b26 %d \u5341\u8fdb\u5236\u6574\u6570 int * 32 \u4f4d\u6574\u578b %l \u5341\u8fdb\u5236\u6574\u6570 long * 32 \u4f4d\u6574\u578b %ll \u5341\u8fdb\u5236\u6574\u6570 long long * 64 \u4f4d\u6574\u578b %e\u3001%E\u3001%f %F\u3001%g\u3001%G \u5355\u7cbe\u5ea6\u6d6e\u70b9\u6570 float * \u6ce8\u610f\u4e0d\u80fd\u7528\u6765\u8bfb double %lf \u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570 double * 64 \u4f4d\u6d6e\u70b9\u578b %i \u5341\u3001\u516b\u3001\u5341\u516d\u8fdb\u5236\u6574\u6570 int * \u6709\u7684\u65f6\u5019\u53ef\u4ee5\u7528\u6765\u5077\u61d2 %o \u516b\u8fdb\u5236\u6574\u6570 int * \u540c\u4e0a %x\u3001%X \u5341\u516d\u8fdb\u5236\u6574\u6570 int * \u540c\u4e0a\u4e0a %s \u5b57\u7b26\u4e32 char * \u8bfb\u53d6\u76f4\u5230\u9047\u5230\u7b2c\u4e00\u4e2a\u7a7a\u767d\u5b57\u7b26 %p \u6307\u9488 %% \u8bfb\u5165 % \u5b57\u7b26

\u4e00\u4e2a\u5f88\u5bb9\u6613\u72af\u7684\u9519\u8bef\uff1ascanf(%d, &var)\u5199\u6210scanf(%d, var)\u3002\u6b64\u5904\u4f7f\u7528&\u8fd0\u7b97\u7b26\u662f\u56e0\u4e3a\u6211\u4eec\u8981\u544a\u8bc9\u8ba1\u7b97\u673a\u50a8\u5b58\u6570\u636e\u7684\u4f4d\u7f6e &var \u800c\u4e0d\u662f var \u8fd9\u4e2a\u53d8\u91cf\u7684\u503c\u3002

\u800c\u65e5\u5e38\u88ab\u5ffd\u7565\u7684 scanf() \u8fd4\u56de\u503c\u4f1a\u544a\u8bc9\u6211\u4eec\u5b83\u6210\u529f\u8bfb\u5230\u4e86\u51e0\u4e2a\u53c2\u6570\uff08\u53ef\u7528\u4e8e\u5224\u5b9a\u6709\u6ca1\u6709\u8bfb\u5b8c\uff09\u3002

\u8bd5\u8bd5\u770b!\uff08\u53ea\u9700\u8981\u5199\u51fa\u8bfb\u53d6\u8f93\u5165\u7684\u8bed\u53e5\uff09

  1. \u8f93\u5165\u4ec5\u6709\u4e00\u884c\uff0c\u5171 7 \u4e2a\u7528\u7a7a\u683c\u9694\u5f00\u7684\u6574\u6570.
  2. \u7b2c\u4e00\u884c\u4e00\u4e2a\u6574\u6570 \\(N\\)\uff08\\(N\\) \u662f\u5076\u6570\u4e14 \\(1<N<100000\\)\uff09; \u7b2c\u4e8c\u884c \\(N-1\\) \u4e2a\u7528\u7a7a\u683c\u9694\u5f00\u7684\u6b63\u6574\u6570 \\(A_i (0<A_i<100000)\\).
  3. \u8f93\u5165\u7684\u7b2c\u4e00\u884c\u662f\u6574\u6570 \\(L\\)\uff08\\(1< L < 10000\\)\uff09\uff1b \u7b2c\u4e8c\u884c\u662f\u6574\u6570 \\(M\\)\uff08\\(0 < M < 100\\)\uff09\uff1b \u63a5\u4e0b\u6765\u7684 \\(M\\) \u884c\uff0c\u6bcf\u884c\u5305\u542b\u4e24\u4e2a\u4e0d\u540c\u7684\u6574\u6570\uff0c\u7528\u4e00\u4e2a\u7a7a\u683c\u9694\u5f00.
  4. \u8f93\u5165\u7531\u7a7a\u683c\u9694\u5f00\u7684\u6b63\u6570\uff08\u53ef\u4ee5\u662f\u5c0f\u6570\uff09\uff0c\u76f4\u5230\u8f93\u5165 -1.
  5. \u8f93\u5165\u662f 1~5 \u4e2a\u6b63\u6574\u6570.

printf

printf() \u7684\u5b9a\u4e49\u5982\u4e0b\uff1a

int printf(const char *format, ...)\n

\u76f8\u5bf9\u4e8e scanf() \u7684\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0cprintf() \u66f4\u52a0\u590d\u6742\uff1aprintf() \u7684\u683c\u5f0f\u5316\u53c2\u6570\u53ef\u4ee5\u8868\u8fbe\u4e3a\u4ee5\u4e0b\u5f62\u5f0f\uff1a

%[flags][width][.precision][length]specifier\n
\u5176\u4e2d\uff0cspecifier \u5373\u683c\u5f0f\u5b57\u7b26\uff0c\u4e0e scanf() \u4e00\u81f4\uff1b\u5176\u4ed6\u53c2\u6570\u5982\u4e0b\u6240\u793a\uff1a\uff08\u6765\u81ea \u83dc\u9e1f\u6559\u7a0b\uff09

flag \u63cf\u8ff0 - \u5728\u7ed9\u5b9a\u7684\u5b57\u6bb5\u5bbd\u5ea6\u5185\u5de6\u5bf9\u9f50\uff0c\u9ed8\u8ba4\u662f\u53f3\u5bf9\u9f50 + \u5f3a\u5236\u5728\u7ed3\u679c\u4e4b\u524d\u663e\u793a\u52a0\u53f7\u6216\u51cf\u53f7\uff08+ \u6216 -\uff09\uff0c\u5373\u6b63\u6570\u524d\u9762\u4f1a\u663e\u793a + \u53f7\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u53ea\u6709\u8d1f\u6570\u524d\u9762\u4f1a\u663e\u793a\u4e00\u4e2a - \u53f7 \u7a7a\u683c \u5982\u679c\u6ca1\u6709\u5199\u5165\u4efb\u4f55\u7b26\u53f7\uff0c\u5219\u5728\u8be5\u503c\u524d\u9762\u63d2\u5165\u4e00\u4e2a\u7a7a\u683c\u3002 # \u4e0e o\u3001x \u6216 X \u8bf4\u660e\u7b26\u4e00\u8d77\u4f7f\u7528\u65f6\uff0c\u975e\u96f6\u503c\u524d\u9762\u4f1a\u5206\u522b\u663e\u793a 0\u30010x \u6216 0X\u3002\u4e0e e\u3001E \u548c f \u4e00\u8d77\u4f7f\u7528\u65f6\uff0c\u4f1a\u5f3a\u5236\u8f93\u51fa\u5305\u542b\u4e00\u4e2a\u5c0f\u6570\u70b9\uff08\u5373\u4f7f\u540e\u8fb9\u6ca1\u6709\u6570\u5b57\u65f6\u4e5f\u4f1a\u663e\u793a\u5c0f\u6570\u70b9\uff09\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u540e\u8fb9\u6ca1\u6709\u6570\u5b57\u65f6\u5019\uff0c\u4e0d\u4f1a\u663e\u793a\u663e\u793a\u5c0f\u6570\u70b9\u3002\u4e0e g \u6216 G \u4e00\u8d77\u4f7f\u7528\u65f6\uff0c\u7ed3\u679c\u4e0e\u4f7f\u7528 e \u6216 E \u65f6\u76f8\u540c\uff0c\u4f46\u662f\u5c3e\u90e8\u7684\u96f6\u4e0d\u4f1a\u88ab\u79fb\u9664\u3002 0 \u5728\u6307\u5b9a\u586b\u5145 padding \u7684\u6570\u5b57\u5de6\u8fb9\u653e\u7f6e\u96f6\uff080\uff09\uff0c\u800c\u4e0d\u662f\u7a7a\u683c width \u63cf\u8ff0 (number) \u8981\u8f93\u51fa\u7684\u5b57\u7b26\u7684\u6700\u5c0f\u6570\u76ee\u3002\u5982\u679c\u8f93\u51fa\u7684\u503c\u77ed\u4e8e\u8be5\u6570\uff0c\u7ed3\u679c\u4f1a\u7528\u7a7a\u683c\u586b\u5145\u3002\u5982\u679c\u8f93\u51fa\u7684\u503c\u957f\u4e8e\u8be5\u6570\uff0c\u7ed3\u679c\u4e0d\u4f1a\u88ab\u622a\u65ad\u3002 * \u5bbd\u5ea6\u5728 format \u5b57\u7b26\u4e32\u4e2d\u672a\u6307\u5b9a\uff0c\u4f46\u662f\u4f1a\u4f5c\u4e3a\u9644\u52a0\u6574\u6570\u503c\u53c2\u6570\u653e\u7f6e\u4e8e\u8981\u88ab\u683c\u5f0f\u5316\u7684\u53c2\u6570\u4e4b\u524d\u3002 .precision \u63cf\u8ff0 .number \u5bf9\u4e8e\u6574\u6570\u8bf4\u660e\u7b26\uff08d\u3001i\u3001o\u3001u\u3001x\u3001X\uff09\uff1aprecision \u6307\u5b9a\u4e86\u8981\u5199\u5165\u7684\u6570\u5b57\u7684\u6700\u5c0f\u4f4d\u6570\u3002\u5982\u679c\u5199\u5165\u7684\u503c\u77ed\u4e8e\u8be5\u6570\uff0c\u7ed3\u679c\u4f1a\u7528\u524d\u5bfc\u96f6\u6765\u586b\u5145\u3002\u5982\u679c\u5199\u5165\u7684\u503c\u957f\u4e8e\u8be5\u6570\uff0c\u7ed3\u679c\u4e0d\u4f1a\u88ab\u622a\u65ad\u3002\u7cbe\u5ea6\u4e3a 0 \u610f\u5473\u7740\u4e0d\u5199\u5165\u4efb\u4f55\u5b57\u7b26\u3002\u5bf9\u4e8e e\u3001E \u548c f \u8bf4\u660e\u7b26\uff1a\u8981\u5728\u5c0f\u6570\u70b9\u540e\u8f93\u51fa\u7684\u5c0f\u6570\u4f4d\u6570\u3002\u5bf9\u4e8e g \u548c G \u8bf4\u660e\u7b26\uff1a\u8981\u8f93\u51fa\u7684\u6700\u5927\u6709\u6548\u4f4d\u6570\u3002\u5bf9\u4e8e s: \u8981\u8f93\u51fa\u7684\u6700\u5927\u5b57\u7b26\u6570\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u5b57\u7b26\u90fd\u4f1a\u88ab\u8f93\u51fa\uff0c\u76f4\u5230\u9047\u5230\u672b\u5c3e\u7684\u7a7a\u5b57\u7b26\u3002\u5bf9\u4e8e c \u7c7b\u578b\uff1a\u6ca1\u6709\u4efb\u4f55\u5f71\u54cd\u3002\u5f53\u672a\u6307\u5b9a\u4efb\u4f55\u7cbe\u5ea6\u65f6\uff0c\u9ed8\u8ba4\u4e3a 1\u3002\u5982\u679c\u6307\u5b9a\u65f6\u4e0d\u5e26\u6709\u4e00\u4e2a\u663e\u5f0f\u503c\uff0c\u5219\u5047\u5b9a\u4e3a 0\u3002

\u800c\u65e5\u5e38\u88ab\u5ffd\u7565\u7684 printf() \u8fd4\u56de\u503c\u4f1a\u544a\u8bc9\u6211\u4eec\u5199\u5165\u7684\u5b57\u7b26\u603b\u6570\uff08\u5982\u679c\u6709\u8f93\u51fa\uff09\uff0c\u5426\u5219\u4f1a\u662f\u4e00\u4e2a\u8d1f\u6570\uff08\u53ef\u7528\u4e8e\u5224\u5b9a\u6709\u6ca1\u6709\u8f93\u51fa\uff09\u3002

"},{"location":"programming/24fall/lec1/#_6","title":"\u4e00\u4e9b\u9898\u76ee","text":"

\u6c34\u4ed9\u82b1\u6570

\u627e\u51fa 0~999 \u95f4\u6240\u6709\u7684\u6c34\u4ed9\u82b1\u6570\u3002\u6c34\u4ed9\u82b1\u6570\u662f\u6307\u4e00\u4e2a\u4e09\u4f4d\u6570\uff0c\u5b83\u7684\u5404\u4f4d\u6570\u5b57\u7684\u4e09\u6b21\u5e42\u4e4b\u548c\u662f\u5176\u672c\u8eab\u3002

\u5b8c\u7f8e\u6570

\u5b9e\u73b0\u4e00\u4e2a\u8ba1\u7b97\u6574\u6570\u56e0\u5b50\u548c\u7684\u7b80\u5355\u51fd\u6570\uff0c\u5e76\u5229\u7528\u5176\u5b9e\u73b0\u53e6\u4e00\u4e2a\u51fd\u6570\uff0c\u8f93\u51fa\u4e24\u6b63\u6574\u6570 \\(m\\) \u548c \\(n\\)\uff08\\(0<m<n<10000\\)\uff09\u4e4b\u95f4\u7684\u6240\u6709\u5b8c\u6570\u3002\u6240\u8c13\u5b8c\u6570\u5c31\u662f\u8be5\u6570\u6070\u597d\u7b49\u4e8e\u9664\u81ea\u8eab\u5916\u7684\u56e0\u5b50\u4e4b\u548c\u3002\u4f8b\u5982\uff1a\\(6=1+2+3\\)\uff0c\u5176\u4e2d 1\u30012\u30013 \u4e3a 6 \u7684\u56e0\u5b50\u3002

Gram-Schmidt Algorithm

\uff08 \u9898\u76ee\u7701\u7565 \uff09

"},{"location":"programming/24fall/lec2/","title":"\u7b2c\u4e8c\u8bb2\uff1a\u901a\u5f80 Pro \u7684\u7b2c\u4e00\u6b65","text":"

Tip

\u672c\u8282\u8bfe\u5efa\u8bae\u540c\u5b66\u4eec\u643a\u5e26\u7b14\u8bb0\u672c\u7535\u8111\uff0c\u4ee5\u4fbf\u5b9e\u8df5\u3002

"},{"location":"programming/24fall/lec2/#_1","title":"\u4e3a\u4ec0\u4e48\u8981\u5b66\u4e60\u5b9e\u7528\u6280\u80fd\uff1f","text":"

\u4e3a\u4ec0\u4e48\u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66\u4e0d\u4e25\u683c\u6309\u7167\u8bfe\u5185\u5185\u5bb9\uff0c\u800c\u662f\u6269\u5c55\u5b66\u4e60\u8bfe\u5916\u7684\u547d\u4ee4\u884c\u548c AI \u5de5\u5177\uff1f\u4e3a\u4ec0\u4e48\u8981\u5b66\u4e60\u5404\u7c7b\u5b9e\u7528\u6280\u80fd\uff1f\u6211\u60f3\uff0c\u7528\u4e0b\u9762\u8fd9\u53e5\u8bdd\u6765\u56de\u7b54\u8fd9\u4e2a\u95ee\u9898\u6700\u4e3a\u5408\u9002\uff1a

\u5de5\u6b32\u5584\u5176\u4e8b\uff0c\u5fc5\u5148\u5229\u5176\u5668\u3002

\u5bf9\u4e8e\u6570\u5b66\u3001\u7269\u7406\u7b49\u5b66\u79d1\u6765\u8bf4\uff0c\u7eb8\u7b14\u5c31\u662f\u5de5\u5177\uff0c\u540c\u5b66\u4eec\u90fd\u80fd\u7528\u5f97\u5f88\u597d\u3002\u800c\u5bf9\u4e8e\u8ba1\u7b97\u673a\uff0c\u5982\u679c\u53ea\u4f7f\u7528\u7eb8\u7b14\uff0c\u90a3\u5c31\u53ea\u80fd\u505a\u8ba1\u7b97\u673a\u79d1\u5b66\uff0c\u505a\u4e0d\u4e86\u8ba1\u7b97\u673a\u6280\u672f\uff0c\u4f46\u8fd9\u4e24\u8005\u53c8\u7d27\u5bc6\u5173\u8054\u3002\u8ba1\u7b97\u673a\u8f6f\u786c\u4ef6\u5bf9\u5927\u90e8\u5206\u540c\u5b66\u6765\u8bf4\u76f8\u5bf9\u964c\u751f\uff0c\u800c\u4e14\u6ca1\u6709\u4e13\u95e8\u7684\u8bfe\u7a0b\u6765\u6559\u6388\u8fd9\u4e9b\u77e5\u8bc6\u3002\u7f3a\u4e4f\u5b9e\u7528\u6280\u80fd\u5df2\u7ecf\u6210\u4e3a\u592a\u591a\u8ba1\u7b97\u673a\u7cfb\u5b66\u751f\u5728\u5b66\u4e60\u3001\u5de5\u4f5c\u548c\u79d1\u7814\u8def\u4e0a\u7684\u7eca\u811a\u77f3\u3002\u6211\u4eec\u5e0c\u671b\u901a\u8fc7\u300a\u5b9e\u7528\u6280\u80fd\u62fe\u9057\u300b\u8f85\u5b66\u8bfe\u7a0b\uff0c\u8ba9\u66f4\u591a\u540c\u5b66\u5728\u521a\u5f00\u59cb\u63a5\u89e6\u8ba1\u7b97\u673a\u4e13\u4e1a\u65f6\u5c31\u638c\u63e1\u8fd9\u4e9b\u6280\u80fd\uff0c\u8fd9\u5c06\u4e3a\u4f60\u4eec\u4e4b\u540e\u7684\u5b66\u4e60\u548c\u79d1\u7814\u6253\u4e0b\u575a\u5b9e\u7684\u57fa\u7840\u3002

\u5b9e\u7528\u6280\u80fd\u62fe\u9057\u8bfe\u7a0b

\u6700\u65e9\u7531 21 \u7ea7\u56fe\u7075\u738b\u9e64\u7fd4\u5b66\u957f\u5f00\u8bbe\uff0c\u5148\u540e\u5728\u8ba1\u7b97\u673a\u5b66\u9662\u548c\u7afa\u53ef\u6862\u5b66\u9662\u4f5c\u4e3a\u8f85\u5b66\u8bfe\u7a0b\u3002\u8bfe\u7a0b\u5185\u5bb9\u975e\u5e38\u4f18\u8d28\uff0c\u4f60\u53ef\u4ee5\u5728 \u8fd9\u91cc \u627e\u5230\u5f80\u5e74\u7684\u8bfe\u7a0b\u8d44\u6599\u3002

\u4f46\u7531\u4e8e\u96be\u5ea6\u8f83\u9ad8\uff0c\u6211\u4eec\u8ba1\u5212\u5728\u4e0b\u5b66\u671f\u518d\u590d\u523b\u8fd9\u95e8\u8bfe\u7a0b\u3002\u5982\u679c\u4f60\u671f\u5f85\u6df1\u5165\u4e86\u89e3 Docker\u3001Shell\u3001Git \u7b49\u5185\u5bb9\uff0c\u6b22\u8fce\u5173\u6ce8\u540e\u7eed\u7684\u8f85\u5b66\u6d3b\u52a8\u3002

\u5728\u6b64\uff0c\u6211\u4eec\u8981\u5411\u738b\u9e64\u7fd4\u5b66\u957f\u8868\u793a\u6700\u8bda\u631a\u7684\u611f\u8c22\ud83d\ude4f\u3002

Example

\u8bf4\u4e86\u8fd9\u4e48\u591a\u53ef\u80fd\u6ca1\u6709\u4ec0\u4e48\u5b9e\u611f\uff0c\u8ba9\u6211\u4eec\u7b80\u5355\u4e3e\u51e0\u4e2a\u4f8b\u5b50\u3002

"},{"location":"programming/24fall/lec2/#_2","title":"\u521d\u8bc6\u547d\u4ee4\u884c\u754c\u9762","text":"

\u63a5\u4e0b\u6765\u8fdb\u5165\u672c\u8282\u8bfe\u7684\u524d\u534a\u90e8\u5206\uff0c\u521d\u8bc6\u547d\u4ee4\u884c\u754c\u9762\u3002\u6216\u8bb8\u540c\u5b66\u4eec\u73b0\u5728\u63a5\u89e6\u547d\u4ee4\u884c\u8fd8\u6bd4\u8f83\u5c11\uff0c\u4f46\u5982\u679c\u5b66\u4e60\u8ba1\u7b97\u673a\u79d1\u5b66\u4e13\u4e1a\uff0c\u4f60\u7684\u63a5\u4e0b\u6765\u7684\u4e00\u751f\u6216\u8bb8\u90fd\u79bb\u4e0d\u5f00\u547d\u4ee4\u884c\u754c\u9762\u3002

"},{"location":"programming/24fall/lec2/#_3","title":"\u6253\u5f00\u7ec8\u7aef","text":"

\u5f53\u6211\u4eec\u4f7f\u7528\u6587\u672c\u547d\u4ee4\u4e0e\u8ba1\u7b97\u673a\u4ea4\u4e92\u65f6\uff0c\u5c31\u662f\u5728\u4f7f\u7528\u547d\u4ee4\u884c\u4ea4\u4e92\u754c\u9762\uff08Command Line Interface\uff0cCLI\uff09\u3002\u8fd9\u4e0e\u6211\u4eec\u65e5\u5e38\u751f\u6d3b\u4e2d\u4f7f\u7528\u7684\u56fe\u5f62\u4ea4\u4e92\u754c\u9762\uff08Graphical User Interface\uff0cGUI\uff09\u4e0d\u540c\u3002

\u52a8\u624b\u505a\uff1a\u5728\u672c\u5730\u6253\u5f00\u7ec8\u7aef

WindowsmacOSLinux

\u6309\u4e0b Win \u952e\uff0c\u8f93\u5165 cmd \u6216 powershell\uff0c\u56de\u8f66\u3002

\u6309\u4e0b Cmd+Space\uff0c\u8f93\u5165 Terminal\uff0c\u56de\u8f66\u3002

\u4f60\u5e94\u8be5\u77e5\u9053\u600e\u4e48\u505a\ud83d\ude09\u3002

CLI \u7684\u51e0\u4e2a\u7ec4\u6210\u90e8\u5206\u4e4b\u95f4\u7684\u5173\u7cfb\u5982\u4e0b\u56fe\u6240\u793a\uff1a

"},{"location":"programming/24fall/lec2/#_4","title":"\u8fde\u63a5\u5230\u8fdc\u7a0b\u670d\u52a1\u5668","text":"

\u64cd\u4f5c\u7cfb\u7edf\u4e4b\u95f4\u6709\u663e\u8457\u7684\u5dee\u522b\uff0c\u4e0d\u540c Shell \u7684\u547d\u4ee4\u8bed\u6cd5\u4e5f\u4e0d\u540c\u3002\u5927\u5bb6\u4eca\u540e\u63a5\u89e6\u6700\u591a\u7684\u5e94\u8be5\u662f Linux \u7cfb\u7edf\u7684 Bash \u547d\u4ee4\u89e3\u91ca\u5668\uff0c\u6240\u4ee5\u6211\u4eec\u4e3a\u5927\u5bb6\u51c6\u5907\u4e86\u4e00\u4e2a\u8fdc\u7a0b\u670d\u52a1\u5668\uff0c\u63d0\u4f9b\u4e00\u4e2a\u7edf\u4e00\u7684\u73af\u5883\u6765\u5b66\u4e60\u547d\u4ee4\u884c\u3002

\u52a8\u624b\u505a\uff1a\u8fde\u63a5\u5230\u8fdc\u7a0b\u670d\u52a1\u5668

\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5e76\u6309\u63d0\u793a\u8f93\u5165\u5bc6\u7801\uff0c\u8fde\u63a5\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\uff1a

ssh \u4f60\u7684\u5b66\u53f7@clusters.zju.edu.cn -p 16145\n

\u521d\u6b21\u8fde\u63a5\u65f6\u4e00\u822c\u4f1a\u51fa\u73b0

\u7684\u63d0\u793a\uff0c\u8bf7\u8f93\u5165 yes \u5e76\u56de\u8f66\u3002

"},{"location":"programming/24fall/lec2/#bash","title":"Bash \u547d\u4ee4\u8bed\u6cd5","text":"
command [OPTIONS] arguments\n

\u4eca\u540e\u5f53\u4f60\u9605\u8bfb\u5404\u7c7b\u8d44\u6599\u65f6\uff0c\u7ecf\u5e38\u4f1a\u9047\u89c1\u4e0a\u9762\u8fd9\u79cd\u683c\u5f0f\u7684\u8bed\u6cd5\u3002\u5176\u4e2d\u51e0\u79cd\u62ec\u53f7\u7684\u542b\u4e49\u5982\u4e0b\uff1a

\u8ba9\u6211\u4eec\u6765\u770b\u4e00\u770b ls \u548c cat \u547d\u4ee4\ud83d\udc31\u3002

touch [OPTION]... FILE...\n

touch \u547d\u4ee4\u7528\u4e8e\u521b\u5efa\u7a7a\u6587\u4ef6\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e\u89e6\u6478\uff08touch\uff09\u6587\u4ef6\u7684\u65f6\u95f4\u6233\u3002

\u52a8\u624b\u505a 2.3.1

\u5728\u5f53\u524d\u76ee\u5f55 ~/ \u4e0b\u521b\u5efa\u4e00\u4e2a\u7a7a\u6587\u4ef6 2.3.1\u3002

\u63a5\u4e0b\u6765\u7684\u6bcf\u4e2a\u52a8\u624b\u505a\uff0c\u8bf7\u540c\u5b66\u4eec\u5b8c\u6210\u540e touch \u5bf9\u5e94\u7684\u6587\u4ef6\uff0c\u4ee5\u4fbf\u6211\u4eec\u540c\u6b65\u8fdb\u5ea6\ud83d\ude09\u3002

ls [OPTION]... [FILE]...\n

ls \u547d\u4ee4\u7528\u4e8e\u5217\u51fa\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u548c\u5b50\u76ee\u5f55\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e list\uff08\u5217\u51fa\uff09\u3002

\u52a8\u624b\u505a 2.3.2

\u4f7f\u7528 ls \u547d\u4ee4\u770b\u4e00\u770b\u5f53\u524d\u76ee\u5f55\u4e0b\u6709\u54ea\u4e9b\u6587\u4ef6\u548c\u76ee\u5f55\u5427\u3002

cat [OPTION]... [FILE]...\n

cat \u547d\u4ee4\u7528\u4e8e\u67e5\u770b\u6587\u4ef6\u5185\u5bb9\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e concatenate\uff08\u8fde\u63a5\uff09\u3002

\u52a8\u624b\u505a 2.3.3\uff1a\u5c1d\u8bd5 cat \u7684\u51e0\u79cd\u7528\u6cd5

"},{"location":"programming/24fall/lec2/#linux","title":"Linux \u6587\u4ef6\u8def\u5f84","text":"

\u4e0e\u5927\u5bb6\u719f\u6089\u7684 Windows \u4e0d\u540c\uff0cLinux \u6587\u4ef6\u7cfb\u7edf\u6ca1\u6709\u76d8\u7b26\u7684\u6982\u5ff5\u3002\u4f60\u53ef\u4ee5\u60f3\u8c61 Windows \u7684\u6587\u4ef6\u7cfb\u7edf\u662f\u4e00\u7247\u68ee\u6797\uff0c\u800c Linux \u7684\u6587\u4ef6\u7cfb\u7edf\u662f\u4e00\u68f5\u6811\u3002

Windows \u4e0e Linux \u6587\u4ef6\u8def\u5f84\u7684\u5bf9\u6bd4 \u56fe\u7247\u6765\u6e90\uff1aAutomate the Boring Stuff with Python

\u5728 Linux \u7cfb\u7edf\u4e2d\u8def\u5f84\u6709\u4e24\u79cd\u8868\u793a\u65b9\u6cd5\uff1a

\u7edd\u5bf9\u8def\u5f84\u4e0e\u76f8\u5bf9\u8def\u5f84 \u56fe\u7247\u6765\u6e90\uff1aAn Overview of Absolute Path in Linux - The Complete Guide

Question

\u4e0a\u56fe\u4e2d\uff0c\u4f60\u5728 Current \u76ee\u5f55\u3002\u5199\u51fa Dest \u76ee\u5f55\u7684\u76f8\u5bf9\u8def\u5f84\u548c\u7edd\u5bf9\u8def\u5f84\u3002

\u8ba9\u6211\u4eec\u719f\u6089\u51e0\u4e2a\u5728 Linux \u6587\u4ef6\u7cfb\u7edf\u4e2d\u5e38\u7528\u7684\u547d\u4ee4\uff1a

pwd\n

pwd \u547d\u4ee4\u7528\u4e8e\u663e\u793a\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u7684\u8def\u5f84\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e print working directory\uff08\u6253\u5370\u5de5\u4f5c\u76ee\u5f55\uff09\u3002

\u52a8\u624b\u505a 2.4.1

\u770b\u4e00\u770b\u4f60\u73b0\u5728\u5728\u54ea\u4e2a\u76ee\u5f55\u3002

cd [DIRECTORY]\n

cd \u547d\u4ee4\u7528\u4e8e\u5207\u6362\u5de5\u4f5c\u76ee\u5f55\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e change directory\uff08\u6539\u53d8\u76ee\u5f55\uff09\u3002

\u52a8\u624b\u505a 2.4.2

\u5c1d\u8bd5 cd \u7684\u51e0\u79cd\u7528\u6cd5

mkdir [OPTION]... DIRECTORY...\n

mkdir \u547d\u4ee4\u7528\u4e8e\u521b\u5efa\u76ee\u5f55\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e make directory\uff08\u521b\u5efa\u76ee\u5f55\uff09\u3002

\u52a8\u624b\u505a 2.4.3

\u5c1d\u8bd5\u521b\u5efa\u4e00\u4e2a\u76ee\u5f55 hello\u3002

touch [OPTION]... FILE...\n

touch \u547d\u4ee4\u7528\u4e8e\u521b\u5efa\u7a7a\u6587\u4ef6\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e\u89e6\u6478\uff08touch\uff09\u6587\u4ef6\u7684\u65f6\u95f4\u6233\u3002

\u52a8\u624b\u505a 2.4.4

\u5c1d\u8bd5\u5728 hello \u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u7a7a\u6587\u4ef6 world\u3002

rm [OPTION]... FILE...\n

rm \u547d\u4ee4\u7528\u4e8e\u5220\u9664\u6587\u4ef6\u6216\u76ee\u5f55\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e remove\uff08\u5220\u9664\uff09\u3002

\u52a8\u624b\u505a 2.4.5

\u5c1d\u8bd5\u5220\u9664 world \u6587\u4ef6\u3002

rmdir [OPTION]... DIRECTORY...\n

rmdir \u547d\u4ee4\u7528\u4e8e\u5220\u9664\u7a7a\u76ee\u5f55\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e remove directory\uff08\u5220\u9664\u76ee\u5f55\uff09\u3002

\u52a8\u624b\u505a 2.4.6

\u5c1d\u8bd5\u5220\u9664 hello \u76ee\u5f55\u3002

cp [OPTION]... SOURCE DEST\n

cp \u547d\u4ee4\u7528\u4e8e\u590d\u5236\u6587\u4ef6\u6216\u76ee\u5f55\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e copy\uff08\u590d\u5236\uff09\u3002

\u52a8\u624b\u505a 2.4.7

\u5c1d\u8bd5\u590d\u5236 /share/hello.c \u6587\u4ef6\u5230\u5bb6\u76ee\u5f55\u3002

"},{"location":"programming/24fall/lec2/#_5","title":"\u73af\u5883\u53d8\u91cf","text":"

\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u547d\u4ee4\u65f6\uff0cShell \u662f\u5982\u4f55\u627e\u5230\u8fd9\u4e2a\u547d\u4ee4\u7684\u5462\uff1f

  1. \u5185\u5efa\u547d\u4ee4\uff08Built-in Command\uff09\uff1aShell \u5185\u7f6e\u4e86\u4e00\u4e9b\u547d\u4ee4\uff0c\u5982 cd\u3001pwd \u7b49\u3002
  2. \u522b\u540d\uff08Alias\uff09\uff1a\u7528\u6237\u53ef\u4ee5\u4e3a\u547d\u4ee4\u8bbe\u7f6e\u522b\u540d\uff0c\u5982 alias ll='ls -l'\u3002
  3. \u73af\u5883\u53d8\u91cf\uff08Environment Variable\uff09\uff1aShell \u4f1a\u5728\u73af\u5883\u53d8\u91cf PATH \u4e2d\u5217\u51fa\u7684\u76ee\u5f55\u4e2d\u67e5\u627e\u547d\u4ee4\u3002PATH \u662f\u4e00\u4e2a\u5305\u542b\u76ee\u5f55\u8def\u5f84\u7684\u5b57\u7b26\u4e32\uff0c\u7528\u5192\u53f7 : \u5206\u9694\u3002

\u73af\u5883\u53d8\u91cf

\u6211\u4eec\u5df2\u7ecf\u5728 C \u8bed\u8a00\u8bfe\u4e0a\u5b66\u4e60\u8fc7\u53d8\u91cf\u7684\u6982\u5ff5\u3002\u800c\u73af\u5883\u53d8\u91cf\u7531\u64cd\u4f5c\u7cfb\u7edf\u7ef4\u62a4\uff0c\u7528\u4e8e\u5b58\u50a8\u8fdb\u7a0b\u8fd0\u884c\u65f6\u6240\u9700\u7684\u4e00\u4e9b\u4fe1\u606f\u3002\u7a0b\u5e8f\u53ef\u4ee5\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u51fd\u6570\u6765\u8bbf\u95ee\u73af\u5883\u53d8\u91cf\u3002\u6bd4\u5982\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 getenv \u51fd\u6570\u83b7\u53d6\u73af\u5883\u53d8\u91cf\u7684\u503c\u3002

#include <stdlib.h>\n\nchar *getenv(const char *name);\n

\u5728 Bash \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 env \u6216 printenv \u547d\u4ee4\u67e5\u770b\u5f53\u524d\u73af\u5883\u53d8\u91cf\u3002

\u547d\u4ee4\u89e3\u91ca\u5668\u901a\u5e38\u652f\u6301\u73af\u5883\u53d8\u91cf\u7684\u66ff\u6362\u3002\u5728 Bash \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 $ \u7b26\u53f7\u5f15\u7528\u73af\u5883\u53d8\u91cf\u7684\u503c\u3002\u6bd4\u5982 $HOME \u5c06\u88ab\u66ff\u6362\u4e3a\u5bb6\u76ee\u5f55\uff0c$PATH \u5c06\u88ab\u66ff\u6362\u4e3a\u547d\u4ee4\u641c\u7d22\u8def\u5f84\u3002\u8fd9\u4e00\u66ff\u6362\u53d1\u751f\u5728\u547d\u4ee4\u884c\u88ab\u89e3\u91ca\u4e4b\u524d\u3002

echo [OPTIONS] [STRING]\n

echo \u547d\u4ee4\u7528\u4e8e\u6253\u5370\u5b57\u7b26\u4e32\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e\u56de\u58f0\uff08echo\uff09\u3002

\u52a8\u624b\u505a 2.5.1

type [COMMAND]\n

type \u547d\u4ee4\u7528\u4e8e\u663e\u793a\u547d\u4ee4\u7684\u7c7b\u578b\u3002\u5b83\u4f1a\u544a\u8bc9\u4f60\u547d\u4ee4\u662f\u5185\u5efa\u547d\u4ee4\u3001\u522b\u540d\u3001\u8fd8\u662f\u5916\u90e8\u547d\u4ee4\u3002

\u52a8\u624b\u505a 2.5.2

\u5c1d\u8bd5\u67e5\u770b ls \u548c echo \u547d\u4ee4\u7684\u7c7b\u578b\u3002

"},{"location":"programming/24fall/lec2/#_6","title":"\u83b7\u53d6\u5e2e\u52a9","text":"

\u5728\u547d\u4ee4\u884c\u4e2d\u53ef\u4ee5\u65b9\u4fbf\u5730\u83b7\u53d6\u5e2e\u52a9\uff0c\u4e0d\u8981\u518d\u53bb\u7f51\u4e0a\u67e5 CSDN \u7b49\u52a3\u8d28\u8d44\u6599\u4e86\u3002\u6216\u8bb8\u5e2e\u52a9\u4e3b\u8981\u6709 3 \u4e2d\u65b9\u5f0f\uff1a

"},{"location":"programming/24fall/lec2/#gcc-c","title":"\u4f7f\u7528 gcc \u7f16\u8bd1 C \u7a0b\u5e8f","text":"

\u63a5\u4e0b\u6765\u7ec8\u4e8e\u5230\u4e86\u548c\u8bfe\u5185\u77e5\u8bc6\u6709\u4e00\u70b9\u5173\u8054\u7684\u90e8\u5206\u4e86\uff0c\u8ba9\u6211\u4eec\u5b66\u4e60\u5982\u4f55\u4f7f\u7528 gcc \u7f16\u8bd1 C \u7a0b\u5e8f\u3002

gcc [-c|-S|-E] [-std=standard]\n    [-g] [-pg] [-Olevel]\n    [-Wwarn...] [-Wpedantic]\n    [-Idir...] [-Ldir...]\n    [-Dmacro[=defn]...] [-Umacro]\n    [-foption...] [-mmachine-option...]\n    [-o outfile] [@file] infile...\n

gcc \u547d\u4ee4\u7528\u4e8e\u7f16\u8bd1 C \u7a0b\u5e8f\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e GNU Compiler Collection\uff08GNU \u7f16\u8bd1\u5668\u5957\u4ef6\uff09\u3002

\u52a8\u624b\u505a 2.7.1

-o outfile \u9009\u9879\u7528\u4e8e\u6307\u5b9a\u8f93\u51fa\u6587\u4ef6\u540d\u3002

\u521a\u624d\u6211\u4eec\u5df2\u7ecf\u628a hello.c \u6587\u4ef6\u590d\u5236\u5230\u5bb6\u76ee\u5f55\u4e86\uff0c\u5c1d\u8bd5\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u7f16\u8bd1 ~/hello.c \u7a0b\u5e8f\uff1a

gcc -o hello ~/hello.c\n

\u63a5\u4e0b\u6765\u518d\u590d\u5236 /share/error.c \u6587\u4ef6\u5230\u5bb6\u76ee\u5f55\uff0c\u5c1d\u8bd5\u7f16\u8bd1 ~/error.c \u7a0b\u5e8f\u3002

\u5982\u679c\u6ca1\u51fa\u610f\u5916\uff0cerror.c \u7a0b\u5e8f\u7206\u4e86\u3002\u4f60\u9700\u8981\u9010\u6e10\u5b66\u4f1a\u4ece\u9519\u8bef\u4fe1\u606f\u4e2d\u627e\u5230\u95ee\u9898\u6240\u5728\u3002\u4ee5\u540e\u9047\u5230\u7684\u9519\u8bef\u4fe1\u606f\u53ea\u4f1a\u8d8a\u6765\u8d8a\u590d\u6742\uff0c\u4f46\u4e5f\u4f1a\u4e3a\u4f60\u63d0\u4f9b\u66f4\u591a\u7684\u4fe1\u606f\u3002

\u4e0d\u8981\u61d2\u5f97\u8bfb\u9519\u8bef\u4fe1\u606f\uff01

\u5f88\u591a\u4eba\u559c\u6b22\u4e00\u9047\u5230\u9519\u8bef\u5c31\u628a\u9519\u8bef\u4fe1\u606f\u4e22\u5230\u4e2d\u6587\u641c\u7d22\u5f15\u64ce\u7136\u540e\u5bf9\u7740\u5404\u79cd\u7f51\u4e0a\u7684\u529e\u6cd5\u4e00\u901a\u4e71\u8c03\u3002\u5728\u8fd9\u4e4b\u524d\uff0c\u81f3\u5c11\u5e94\u5f53\u8ba4\u771f\u8bfb\u4e00\u8bfb\u9519\u8bef\u4fe1\u606f\uff0c\u5c1d\u8bd5\u7406\u89e3\u53d1\u751f\u4e86\u4ec0\u4e48\uff0c\u800c\u4e0d\u662f\u76f2\u4ece\u3002\u5e38\u5e38\u9519\u8bef\u4fe1\u606f\u672c\u8eab\u7ed9\u51fa\u7684\u7684\u4fe1\u606f\u5c31\u8db3\u4ee5\u89e3\u51b3\u95ee\u9898\u3002

\u6211\u4eec\u6765\u770b\u770b\u9519\u8bef\u4fe1\u606f\uff1a

error.c: In function \u2018main\u2019:\nerror.c:6:18: error: subscripted value is neither array nor pointer nor vector\n    6 |     printf(num[2][1]);\n      |\n

\u8bfe\u540e\uff1aVim

\u672c\u8282\u8bfe\u6211\u4eec\u4e0d\u6559\u5927\u5bb6\u4f7f\u7528\u547d\u4ee4\u884c\u6587\u672c\u7f16\u8f91\u5668\u3002\u6709\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u5b66\u4e60 Vim\uff0c\u5b83\u7684\u952e\u4f4d\u8bbe\u8ba1\u6210\u4e3a\u5404\u7c7b\u7f16\u8f91\u5668\u7684\u9ec4\u91d1\u51c6\u5219\uff0c\u80fd\u5927\u5e45\u63d0\u9ad8\u4f60\u5728\u5404\u79cd\u5730\u65b9\u7684\u7f16\u8f91\u6548\u7387\u3002

\u4e3e\u4f8b\uff1aVSCode\u3001\u547d\u4ee4\u884c\u3001Overleaf \u7b49\u90fd\u652f\u6301 Vim \u6a21\u5f0f\u3002

"},{"location":"programming/24fall/lec2/#vscode-ai","title":"\u4f7f\u7528 VSCode \u548c AI \u5de5\u5177","text":"

\u6211\u4eec\u7684\u547d\u4ee4\u884c\u4e4b\u65c5\u5230\u6b64\u544a\u4e00\u6bb5\u843d\u3002\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u56de\u5230\u719f\u6089\u7684\u56fe\u5f62\u754c\u9762\uff0c\u5b66\u4e60\u5982\u4f55\u4f7f\u7528 VSCode \u548c AI \u5de5\u5177\u3002

"},{"location":"programming/24fall/lec2/#dev-c-vscode","title":"\u5c3d\u5feb\u653e\u5f03 Dev-C++\uff0c\u62e5\u62b1 VSCode","text":"

2010 \u5e74\u7684\u6587\u7ae0\uff1a\u8acb\u4e0d\u8981\u7528 Dev-C++ | Smaller Things\u3002

\u5982\u679c\u9019\u6a23\u9084\u4e0d\u80fd\u8aaa\u670d\u4f60\uff0c\u55ef\uff0c\u4e8b\u5be6\u4e0a\u9019\u56db\u9ede\u5df2\u7d93\u5b8c\u5168\u5145\u5206\u69cb\u6210\u7406\u7531\uff0c\u5982\u679c\u4f60\u5b8c\u5168\u4e0d\u95dc\u5fc3\uff0c\u90a3\u9ebc\u4f60\u7684\u7a0b\u5f0f\u8a2d\u8a08\u5b78\u7fd2\u5927\u6982\u4e5f\u4e0d\u662f\u5f88\u8a8d\u771f\uff0c\u6240\u4ee5\u6216\u8a31\u7e7c\u7e8c\u7528 Dev-C++ \u4e5f\u6c92\u5dee\u5427\u3002

"},{"location":"programming/24fall/lec2/#vscode","title":"\u4f7f\u7528 VSCode \u8fde\u63a5\u5230\u8fdc\u7a0b\u670d\u52a1\u5668","text":"

\u52a8\u624b\u505a 3.2.1

"},{"location":"programming/24fall/lec2/#_7","title":"\u81ea\u52a8\u8865\u5168\u3001\u4ee3\u7801\u683c\u5f0f\u5316","text":"

VSCode \u672c\u8eab\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u6587\u672c\u7f16\u8f91\u5668\uff0c\u4f46\u662f\u901a\u8fc7\u63d2\u4ef6\u53ef\u4ee5\u5b9e\u73b0\u5f3a\u5927\u7684\u529f\u80fd\uff1a

"},{"location":"programming/24fall/lec2/#ai","title":"\u4f7f\u7528 AI \u5de5\u5177","text":"

\u6b63\u786e\u4f7f\u7528 AI \u5de5\u5177\u7684\u6001\u5ea6

"},{"location":"programming/24fall/lec2/#vscode_1","title":"VSCode \u63d2\u4ef6","text":"

\u5bf9\u4e8e\u5199\u4ee3\u7801\uff0c\u6700\u597d\u7684 AI \u5de5\u5177\u5e94\u8be5\u662f GitHub Copilot\uff0c\u4f46\u662f\u83b7\u53d6\u6761\u4ef6\u5bf9\u4e8e\u65b0\u624b\u53ef\u80fd\u6709\u4e9b\u56f0\u96be\uff1a

\u7136\u540e\u5c31\u53ef\u4ee5\u4f7f\u7528 Copilot \u4e86\u3002

\u8bfe\u540e\uff1a\u5c1d\u8bd5\u83b7\u53d6 Copilot\u3002\u53ef\u4ee5\u8ba9\u8eab\u8fb9\u6ce8\u518c\u6210\u529f\u7684\u540c\u5b66\u5e2e\u5fd9\u3002

\u56fd\u5185\u6709\u5f88\u591a\u7c7b\u4f3c\u7684\u5de5\u5177\uff0c\u6548\u679c\u4e0d\u6bd4 Copilot \u5dee\uff0c\u6bd4\u5982\uff1a

\u8bfe\u540e\uff1a\u81ea\u5df1\u9009\u62e9\u4e00\u4e2a AI \u63d2\u4ef6\u5c1d\u8bd5\u4e00\u4e0b

"},{"location":"programming/24fall/lec2/#_8","title":"\u5176\u4ed6","text":" \u4e00\u4e9b\u53c2\u8003

\u5c31\u5728\u5f00\u8bfe\u7684\u524d\u4e00\u5929\uff0c\u5357\u5927 C \u7a0b\u8bfe\u52a9\u6559\u6070\u597d\u4e5f\u53d1\u51fa\u4e86\u5173\u4e8e AI \u5de5\u5177\u7684\u89c6\u9891\uff1a \u3010\u540c\u5b66\uff0c\u4f60\u7684\u4ee3\u7801\u53c8\u53c8\u53c8\u2026\u2026\u54e6\uff0c\u4f60\u5931\u4e1a\u4e86\u301120241114-Part 3-\u718a\u4e18\u6853-LLM\u548c\u7b97\u6cd5\u7ade\u8d5b\uff0c\u6216\u8bb8\u8bb2\u7684\u66f4\u8be6\u7ec6\u4e00\u4e9b\u3002

"},{"location":"programming/24fall/lec2/#makefile","title":"\u7b80\u5355 Makefile","text":"

make \u662f\u4e00\u4e2a\u7ba1\u7406\u7a0b\u5e8f\u6784\u5efa\u7684\u5de5\u5177\uff0c\u5b83\u901a\u8fc7\u8bfb\u53d6\u4e00\u4e2a\u53eb\u505a Makefile \u7684\u6587\u4ef6\u6765\u6267\u884c\u6784\u5efa\u4efb\u52a1\u3002Makefile \u6587\u4ef6\u4e2d\u5305\u542b\u4e86\u4e00\u7cfb\u5217\u89c4\u5219\uff0c\u6bcf\u4e2a\u89c4\u5219\u63cf\u8ff0\u4e86\u4e00\u4e2a\u6784\u5efa\u4efb\u52a1\u7684\u4f9d\u8d56\u5173\u7cfb\u548c\u6784\u5efa\u6b65\u9aa4\u3002

target: dependencies\n    command\n

\u5bf9\u4e8e\u4e0a\u9762\u7684 hello.c\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 Makefile\uff1a

\u52a8\u624b\u505a 3.5.1

\u521b\u5efa\u4e00\u4e2a Makefile \u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a

hello: hello.c\n    gcc -o hello hello.c\n

\u7136\u540e\u5728\u7ec8\u7aef\u4e2d\u6267\u884c make \u547d\u4ee4\uff1a

make\n

\u4f7f\u7528 Makefile \u7684\u597d\u5904\uff1a

"},{"location":"programming/24fall/lec2/#vscode-gdb","title":"\u4f7f\u7528 VSCode \u53ef\u89c6\u5316 GDB \u8c03\u8bd5","text":"

\u8981\u4f7f\u7528 VSCode \u7ba1\u7406\u7a0b\u5e8f\u6784\u5efa\u548c\u8c03\u8bd5\uff0c\u9700\u8981\u914d\u7f6e\u4efb\u52a1\uff08task\uff09\u548c\u8c03\u8bd5\u4efb\u52a1\uff08launch\uff09\u3002\u6211\u4eec\u8ba9 VSCode \u81ea\u52a8\u4e3a\u6211\u4eec\u751f\u6210\u6a21\u677f\u3002

\u914d\u7f6e Task\uff1a

\u7136\u540e\u5c31\u53ef\u4ee5\u7528 VSCode \u4e00\u952e\u8fd0\u884c\u7a0b\u5e8f\u4e86\u3002\u7b80\u5355\u89e3\u91ca\u4e00\u4e0b\u751f\u6210\u7684 .vscode/tasks.json\uff1a

{\n \"version\": \"2.0.0\",\n \"tasks\": [\n  {\n   \"type\": \"cppbuild\",\n   \"label\": \"C/C++: gcc build active file\",\n   \"command\": \"/usr/bin/gcc\",\n   \"args\": [\n    \"-fdiagnostics-color=always\",\n    \"-g\",\n    \"${file}\",\n    \"-o\",\n    \"${fileDirname}/${fileBasenameNoExtension}\"\n   ],\n   \"options\": {\n    \"cwd\": \"${fileDirname}\"\n   },\n   \"problemMatcher\": [\n    \"$gcc\"\n   ],\n   \"group\": {\n    \"kind\": \"build\",\n    \"isDefault\": true\n   },\n   \"detail\": \"compiler: /usr/bin/gcc\"\n  }\n ]\n}\n

\u914d\u7f6e Launch\uff1a

\u7136\u540e\u5c31\u53ef\u4ee5\u7528 VSCode \u8c03\u8bd5\u7a0b\u5e8f\u4e86\u3002\u7b80\u5355\u89e3\u91ca\u4e00\u4e0b\u751f\u6210\u7684 .vscode/launch.json\uff1a

{\n// Use IntelliSense to learn about possible attributes.\n// Hover to view descriptions of existing attributes.\n// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\n\"version\": \"0.2.0\",\n\"configurations\": [\n    {\n        \"name\": \"(gdb) Launch\",\n        \"type\": \"cppdbg\",\n        \"request\": \"launch\",\n        \"program\": \"${fileDirname}/${fileBasenameNoExtension}\",\n        \"args\": [],\n        \"stopAtEntry\": false,\n        \"cwd\": \"${fileDirname}\",\n        \"environment\": [],\n        \"externalConsole\": false,\n        \"MIMode\": \"gdb\",\n        \"setupCommands\": [\n            {\n                \"description\": \"Enable pretty-printing for gdb\",\n                \"text\": \"-enable-pretty-printing\",\n                \"ignoreFailures\": true\n            },\n            {\n                \"description\": \"Set Disassembly Flavor to Intel\",\n                \"text\": \"-gdb-set disassembly-flavor intel\",\n                \"ignoreFailures\": true\n            }\n        ]\n    }\n]\n}\n

\u8ba9\u6211\u4eec\u5c1d\u8bd5\u8c03\u8bd5\u4e00\u4e0b\u4e0b\u9762\u7684\u547d\u4ee4\uff1a

Note

/dev/zero \u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u6587\u4ef6\uff0c\u5b83\u4f1a\u8fd4\u56de\u65e0\u9650\u591a\u4e2a 0 \u5b57\u8282\u3002

./gets < /dev/zero\n

\u52a8\u624b\u505a 3.6.1

\u5c1d\u8bd5\u8c03\u8bd5 gets \u7a0b\u5e8f\u3002

"},{"location":"programming/24fall/lec2/#_9","title":"\u7ed3\u8bed","text":"

\u901a\u8fc7\u4eca\u5929\u7684\u8bfe\u7a0b\uff0c\u4f60\u5e94\u8be5\u5177\u5907\u4e86\u4e0d\u8f93\u4e8e\u5927\u4f6c\u4eec\u7684\u81ea\u5b66\u8d44\u6e90\uff1a

\u5982\u679c\u672c\u8bfe\u7684\u5185\u5bb9\u4e0d\u80fd\u6ee1\u8db3\u4f60\uff0c\u63a8\u8350\u6d4f\u89c8\u53bb\u5e74\u7684\u8bfe\u7a0b\u3002

\u4e0b\u4e00\u8282\u8bfe\uff0c\u9ec4\u54f2\u5b66\u957f\u5c06\u5411\u5927\u5bb6\u4ecb\u7ecd\u66f4\u591a\u5b9e\u7528\u6280\u80fd\uff0c\u656c\u8bf7\u671f\u5f85\uff01

"},{"location":"programming/24fall/lec3/","title":"\u7b2c\u4e09\u8bb2\uff1a\u5f00\u6e90\u4e16\u754c\u751f\u5b58\u57fa\u7840","text":"

Tip

\u5efa\u8bae\u540c\u5b66\u4eec\u643a\u5e26\u7b14\u8bb0\u672c\u7535\u8111\uff0c\u5e76\u5728\u8bfe\u524d\u6309\u7167\u7b2c 2.2 \u8282\u5728\u81ea\u5df1\u7684\u7535\u8111\u4e0a\u5b89\u88c5\u597d Git\uff0c\u4ee5\u4fbf\u8bfe\u4e0a\u5b9e\u8df5\u3002

"},{"location":"programming/24fall/lec3/#what-why","title":"What & Why","text":"

\u5f00\u6e90\uff08Open Source\uff09\u662f\u6307\u5c06\u6e90\u4ee3\u7801\u516c\u5f00\u5230\u4e92\u8054\u7f51\u4e0a\uff0c\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u5728\u5f00\u6e90\u8bb8\u53ef\u8bc1\uff08License\uff09\u7684\u7ea6\u675f\u4e0b\u67e5\u770b\u3001\u4fee\u6539\u751a\u81f3\u91cd\u65b0\u53d1\u5e03\u4ee3\u7801\u3002

\u4e3a\u4e86\u4fbf\u4e8e\u7ba1\u7406\u548c\u534f\u4f5c\uff0c\u901a\u5e38\u4f1a\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff08Version Control Systems\uff0cVCS\uff09\u6765\u7ba1\u7406\u4ee3\u7801\uff0c\u5176\u4e2d\u6700\u6d41\u884c\u7684\u5de5\u5177\u662f Git\u3002\u4e0e\u6b64\u540c\u65f6\uff0c\u65e2\u7136\u4ee3\u7801\u662f\u516c\u5f00\u7684\uff0c\u5c31\u9700\u8981\u4e00\u4e2a\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\u6765\u5b58\u50a8\u548c\u7ba1\u7406\u4ee3\u7801\uff0c\u6700\u4e3a\u77e5\u540d\u7684\u5e73\u53f0\u662f GitHub\u3002\u8003\u8651\u5230\u56fd\u5185\u7684\u7f51\u7edc\u73af\u5883\uff0c\u672c\u8282\u8bfe\u5c06\u4ee5\u6d59\u6c5f\u5927\u5b66\u8d85\u7b97\u961f\u63d0\u4f9b\u7684 ZJU Git \u4e3a\u793a\u8303\u5e73\u53f0\u3002

Example

\u5f88\u597d\uff0c\u5f00\u6e90\u770b\u4e0a\u53bb\u5f88\u9177\uff0c\u4f46\u6211\u4e3a\u4ec0\u4e48\u8981\u5b66\u5b83\u5462\uff1f

\u5f88\u68d2\uff01\u90a3\u6211\u4eec\u5f00\u59cb\u5427\uff01

"},{"location":"programming/24fall/lec3/#git","title":"Git\uff1a\u6700\u4f18\u79c0\u7684\u7248\u672c\u63a7\u5236\u5de5\u5177","text":"

\u4f60\u662f\u5426\u9047\u5230\u8fc7\u8fd9\u6837\u7684\u60c5\u666f\uff1f

\u66f4\u8fdb\u4e00\u6b65\uff0c\u5f53\u4f60\u9ad8\u9ad8\u5174\u5174\u5730\u5199\u5b8c\u4e86\u62a5\u544a\uff0c\u521a\u628a\u5404\u79cd\u5907\u4efd\u6587\u4ef6\u5220\u9664\uff0c\u56de\u6536\u7ad9\u6e05\u7a7a\uff0c\u7136\u540e\u5bfc\u5e08\u7a81\u53d1\u5947\u60f3\uff0c\u544a\u8bc9\u4f60\u4ed6\u89c9\u5f97\u4ee5\u524d\u7684\u7248\u672c\u66f4\u597d\uff0c\u53eb\u4f60\u56de\u9000\u4ee5\u524d\u7684\u7248\u672c\uff0c\u8fd9\u65f6\u4f60\u7684\u5fc3\u60c5\u662f\u4ec0\u4e48\u6837\u7684\uff1f

Git \u5c31\u662f\u4e3a\u4e86\u89e3\u51b3\u8fd9\u79cd\u95ee\u9898\u800c\u751f\u7684\u3002\u901a\u8fc7\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u53ef\u4ee5\u5e2e\u4f60\u8bb0\u5f55\u6587\u4ef6\u7684\u81ea\u521b\u5efa\u4ee5\u6765\u7684\u6bcf\u4e00\u4e2a\u7248\u672c\uff0c\u751a\u81f3\u5141\u8bb8\u4f60\u5728\u4e0d\u540c\u7248\u672c\u4e4b\u95f4\u81ea\u7531\u5207\u6362\u3002

\u8fdc\u53e4\u65f6\u671f\u7684 Linux \u4ee3\u7801

\u4f60\u751a\u81f3\u53ef\u4ee5\u627e\u5230 Linux \u5185\u6838\u5728 GitHub \u4e0a\u7684\u7b2c\u4e00\u6b21\u63d0\u4ea4\uff01\uff08\u5b9e\u9645\u4e0a\uff0c\u56e0\u4e3a\u5e74\u4ee3\u8fc7\u4e8e\u4e45\u8fdc\uff0c\u8fd9\u4e2a\u63d0\u4ea4\u5728 GitHub \u63d0\u4ea4\u5217\u8868\u4e0a\u662f\u9690\u85cf\u7684\uff0c\u611f\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u81ea\u5df1\u8bd5\u8bd5\u770b\u770b\u80fd\u4e0d\u80fd\u628a\u5b83\u627e\u51fa\u6765\ud83d\ude09\uff09

\u68a6\u5f00\u59cb\u7684\u5730\u65b9

"},{"location":"programming/24fall/lec3/#_2","title":"\u5386\u53f2","text":"

Linus Torvalds \u5728\u5f00\u53d1 Linux \u5185\u6838\u65f6\uff0c\u539f\u672c\u4f7f\u7528\u7684\u7248\u672c\u7ba1\u7406\u7cfb\u7edf\u53eb BitKeeper\u3002\u4f46\u662f\u7531\u4e8e\u5f53\u65f6 BitKeeper \u7684\u514d\u8d39\u7248\u672c\u52a0\u5165\u4e86\u9650\u5236\uff0c\u4ed6\u51b3\u5b9a\u5f00\u53d1\u4e00\u6b3e\u81ea\u7531\u3001\u514d\u8d39\u7684\u7248\u672c\u7ba1\u7406\u7cfb\u7edf\uff0c\u987a\u5e26\u89e3\u51b3\u4e00\u4e0b\u5386\u4ee3 VCS \u7684\u7f3a\u9677\uff0c\u4e8e\u662f Git \u8bde\u751f\u4e86\u3002

"},{"location":"programming/24fall/lec3/#git_1","title":"Git \u5b89\u88c5\u53ca\u914d\u7f6e","text":"

\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165 git --version\uff0c\u5982\u679c\u6b63\u5e38\u8f93\u51fa\u7248\u672c\u53f7\uff0c\u5219\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u914d\u7f6e Git \u7684\u4e00\u4e9b\u57fa\u672c\u4fe1\u606f\uff0c\u4f8b\u5982\u7528\u6237\u540d\u548c\u90ae\u7bb1\u3002

git config --global user.name \"<\u4f60\u7684\u7528\u6237\u540d>\"\ngit config --global user.email \"<\u4f60\u7684\u90ae\u7bb1>\"\n
"},{"location":"programming/24fall/lec3/#git_2","title":"Git \u7684\u6570\u636e\u6a21\u578b","text":"

\u4ece Git \u7684\u4ea4\u4e92\u6307\u4ee4\u51fa\u53d1\u5f88\u5bb9\u6613\u8ba9\u4eba\u542c\u5f97\u4e00\u5934\u96fe\u6c34\uff0c\u6240\u4ee5\u6211\u4eec\u4ece\u5e95\u5c42\u51fa\u53d1\uff0c\u81ea\u4e0b\u800c\u4e0a\u5730\u5b66\u4e60 Git\u3002

\u56fe\u7247\u6765\u6e90\uff1aTonyCrane \u7684\u8bb2\u4e49

Git \u542f\u52a8\u65f6\uff0c\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a .git \u7684\u9690\u85cf\u6587\u4ef6\u5939\uff0c\u8fd9\u4e2a\u6587\u4ef6\u5939\u5c31\u662f Git \u7684\u7248\u672c\u5e93\uff08Repository\uff09\u3002

\u7248\u672c\u5e93\u4e2d\uff0c\u4fdd\u5b58\u7740\u6240\u6709\u6587\u4ef6\u7684\u5386\u53f2\uff08History\uff09\uff0c\u4ee5\u53ca\u4e00\u4e2a\u53eb\u6682\u5b58\u533a\uff08Stage\uff09\u7684\u4e1c\u897f\u3002

"},{"location":"programming/24fall/lec3/#_3","title":"\u5feb\u7167","text":"

\u4e3a\u4e86\u8bb0\u5f55\u6587\u4ef6\u7684\u5386\u53f2\uff0cGit \u4f1a\u7ed9\u6bcf\u4e00\u4e2a\u7248\u672c\u521b\u5efa\u4e00\u4e2a\u5feb\u7167\uff08Snapshot\uff0c\u53c8\u79f0 Commit\u3001\u63d0\u4ea4\uff09\uff0c\u4e0d\u540c\u7684\u5feb\u7167\u4e4b\u95f4\u901a\u8fc7\u4e00\u79cd\u53eb\u505a\u6709\u5411\u65e0\u73af\u56fe\uff08Directed Acyclic Graph\uff0cDAG\uff09\u7684\u6570\u636e\u7ed3\u6784\uff08\u5927\u5bb6\u4f1a\u5728\u5927\u4e00\u4e0b\u300a\u6570\u636e\u7ed3\u6784\u57fa\u7840\u300b\u7684\u8bfe\u7a0b\u4e2d\u5b66\u5230\uff09\u8054\u7cfb\u8d77\u6765\u3002

\u4e00\u79cd\u53ef\u80fd\u7684\u5386\u53f2 \u82e5\u672a\u7279\u6b8a\u8bf4\u660e\uff0c\u672c\u8bb2\u4e49\u4e2d\u624b\u7ed8\u98ce\u683c\u793a\u610f\u56fe\u5747\u4e3a\u539f\u521b\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904

\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u5386\u53f2\u5728 C \u5feb\u7167\u5904\u4ea7\u751f\u4e86\u4e24\u4e2a\u5206\u652f\uff08Branch\uff09\uff0c\u5e76\u5728 I \u5feb\u7167\u5904\u5408\u5e76\uff08Merge\uff09\u3002\u8fd9\u79cd\u5206\u652f\u548c\u5408\u5e76\u7684\u64cd\u4f5c\u662f Git \u7684\u5f3a\u5927\u4e4b\u5904\uff0c\u6211\u4eec\u4f1a\u5728\u540e\u9762\u8be6\u7ec6\u8bb2\u89e3\u3002

\u5728 Git \u4e2d\uff0c\u6bcf\u4e00\u4e2a\u5feb\u7167\u90fd\u7531\u4e00\u4e2a\u5341\u516d\u8fdb\u5236\u6570\u552f\u4e00\u6807\u8bc6\uff0c\u5b83\u76f8\u5f53\u4e8e\u5feb\u7167\u7684 ID\u3002\u901a\u5e38\u53ea\u9700\u8981\u524d\u51e0\u4f4d\u5c31\u53ef\u4ee5\u552f\u4e00\u786e\u5b9a\u4e00\u4e2a\u5feb\u7167\uff0c\u4f8b\u5982\u4e4b\u524d\u56fe\u7247\u4e2d\u7684 1da177e\u3002\u4f46\u5f88\u663e\u7136\uff0c\u8fd9\u79cd\u5341\u516d\u8fdb\u5236\u6570\u4e0d\u9002\u5408\u4eba\u7c7b\u8bb0\u5fc6\u3002\u56e0\u6b64 Git \u5141\u8bb8\u7ed9\u5feb\u7167\u521b\u5efa\u5f15\u7528\uff08Reference\uff09\uff0c\u5b83\u662f\u4e00\u4e2a\u6307\u5411\u5feb\u7167\u7684\u6307\u9488\uff0c\u4f8b\u5982\u4eba\u4eec\u901a\u5e38\u4f7f\u7528 master\u3001main \u7b49\u540d\u5b57\u6765\u8868\u793a\u6700\u65b0\u7684\u5feb\u7167\u3002

Git \u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u6307\u9488\u53eb\u505a HEAD\uff0c\u5b83\u6307\u5411\u5f53\u524d\u6240\u5728\u7684\u5206\u652f\u6216\u8005\u5feb\u7167\uff0c\u4e5f\u5c31\u662f\u5f53\u524d\u6b63\u5728\u5de5\u4f5c\u7684\u7248\u672c\u3002

\u6307\u5411\u5206\u652f\u7684\u6307\u9488

\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u5728\u4e0d\u540c\u5feb\u7167\u4e4b\u95f4\u5207\u6362\u3002

"},{"location":"programming/24fall/lec3/#_4","title":"\u6682\u5b58\u533a","text":"

\u4f60\u53ef\u80fd\u4f1a\u60f3\u8c61\uff0c\u6bcf\u6b21\u63d0\u4ea4\u90fd\u4f1a\u5bf9\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\uff08Working Directory\uff09\u6253\u4e00\u4e2a\u5feb\u7167\uff0c\u7136\u540e\u4fdd\u5b58\u5230\u7248\u672c\u5e93\u4e2d\uff0c\u4f46\u5b9e\u9645\u4e0a\u5e76\u975e\u5982\u6b64\u3002

\u8bbe\u60f3\u8fd9\u6837\u4e00\u4e2a\u573a\u666f\uff1a\u4f60\u540c\u65f6\u4fee\u6539\u4e86\u4e24\u4e2a\u6587\u4ef6\uff0c\u4f46\u53ea\u60f3\u63d0\u4ea4\u5176\u4e2d\u4e00\u4e2a\uff0c\u8fd9\u65f6\u5019\u5c31\u9700\u8981\u4e00\u4e2a\u4e2d\u95f4\u72b6\u6001\u6765\u4fdd\u5b58\u4f60\u7684\u4fee\u6539\u3002\u8fd9\u4e2a\u4e2d\u95f4\u72b6\u6001\u5c31\u662f\u6240\u8c13\u7684\u6682\u5b58\u533a\u3002

\u56fe\u7247\u6765\u6e90\uff1aTonyCrane \u7684\u8bb2\u4e49"},{"location":"programming/24fall/lec3/#_5","title":"\u57fa\u7840\u7528\u6cd5","text":"

Let's get our hands dirty!

\u56fe\u7247\u6765\u6e90\uff1aXKCD GIT"},{"location":"programming/24fall/lec3/#_6","title":"\u521d\u59cb\u5316\u7248\u672c\u5e93","text":"

\u5feb\u901f\u56de\u987e

\u5728 Linux / macOS \u7cfb\u7edf\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 ls \u547d\u4ee4\u67e5\u770b\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u548c\u6587\u4ef6\u5939\uff0c\u4f7f\u7528 cd \u547d\u4ee4\u5207\u6362\u76ee\u5f55\u3002

\u5bf9\u4e8e Windows \u7cfb\u7edf\uff0c\u8fd9\u91cc\u63a8\u8350\u5927\u5bb6\u4f7f\u7528\u7cfb\u7edf\u81ea\u5e26\u7684 Windows Terminal \u8fdb\u884c\u5b9e\u9a8c\uff0c\u5176\u8fd0\u884c\u7684\u9ed8\u8ba4\u7ec8\u7aef\u662f Powershell\uff0c\u4f7f\u7528\u4e60\u60ef\u66f4\u63a5\u8fd1 Linux\uff08\u76f8\u8f83\u4e8e cmd \u800c\u8a00\uff09\u3002

\u8981\u4f7f\u7528 Git\uff0c\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2a Git \u7248\u672c\u5e93\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u662f\u901a\u8fc7 git init \u547d\u4ee4\u5b8c\u6210\u7684\u3002

\u52a8\u624b\u505a\uff1a\u521d\u59cb\u5316\u7248\u672c\u5e93

\u5728\u81ea\u5df1\u7684\u7535\u8111\u4e0a\u6253\u5f00\u7ec8\u7aef\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5939\uff08mkdir \u547d\u4ee4\uff09\uff0c\u7136\u540e\u8fdb\u5165\u8fd9\u4e2a\u6587\u4ef6\u5939\uff08cd \u547d\u4ee4\uff09\uff0c\u5e76\u4f7f\u7528 git init \u521d\u59cb\u5316\u4e00\u4e2a Git \u7248\u672c\u5e93\u3002

mkdir my-repo\ncd my-repo\ngit init\n

\u5c1d\u8bd5\u4f7f\u7528 ls \u547d\u4ee4\u67e5\u770b\u5f53\u524d\u76ee\u5f55\u7684\u5185\u5bb9\uff0c\u80fd\u627e\u5230 .git \u6587\u4ef6\u5939\u5417\uff1f\u4e3a\u4ec0\u4e48\uff1f

"},{"location":"programming/24fall/lec3/#commit","title":"\u5e74\u8f7b\u4eba\u7684\u7b2c\u4e00\u4e2a Commit\uff01","text":"

\u73b0\u5728\u6211\u4eec\u5df2\u7ecf\u6709\u4e86\u4e00\u4e2a\u7a7a\u7684 Git \u7248\u672c\u5e93\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u5c1d\u8bd5\u5f80\u91cc\u9762\u6dfb\u52a0\u4e00\u4e9b\u6587\u4ef6\u3002

\u52a8\u624b\u505a\uff1a\u4e00\u4e9b\u51c6\u5907\u5de5\u4f5c

\u7528 VSCode \u6253\u5f00\u8fd9\u4e2a\u6587\u4ef6\u5939\uff0c\u521b\u5efa\u4e00\u4e2a hello.c \u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a

#include <stdio.h>\n\nint main() {\n    printf(\"Hello World\");\n    return 0;\n}\n

\u8fd9\u662f\u4e00\u4e2a\u7b80\u5355\u7684 Hello World \u7a0b\u5e8f\uff0c\u5b9e\u9645\u4f7f\u7528\u4e2d\u7684\u573a\u666f\u53ef\u80fd\u662f\u4f60\u7684\u5b9e\u9a8c\u62a5\u544a\u3001\u9879\u76ee\u4ee3\u7801\u7b49\uff0c\u8fd9\u91cc\u53ea\u662f\u4e3a\u4e86\u6f14\u793a\u3002

\u73b0\u5728\u7684\u5de5\u4f5c\u76ee\u5f55\u4e2d\u6709\u4e86\u4e00\u4e2a hello.c \u6587\u4ef6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 git status \u547d\u4ee4\u67e5\u770b\u5f53\u524d\u7248\u672c\u5e93\u7684\u72b6\u6001\u3002

git status\n

\u67e5\u770b\u5f53\u524d\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u5e93\u7684\u72b6\u6001\u3002

\u6587\u4ef6\u6709\u4e09\u4e2a\u7c7b\u522b\uff1a\u672a\u8ddf\u8e2a\uff08Untracked\uff09\u3001\u5df2\u8ffd\u8e2a\uff08Tracked\uff09\u3001\u88ab\u5ffd\u7565\uff08Ignored\uff09\u3002

\u52a8\u624b\u505a 2.4.1

\u8fd0\u884c git status \u547d\u4ee4\uff0c\u4f60\u770b\u5230\u4e86\u4ec0\u4e48\uff1f\u4f60\u80fd\u591f\u89e3\u91ca\u8fd9\u4e9b\u4fe1\u606f\u5417\uff1f

git add <FILE>\n

\u5c06\u6240\u9009\u7684\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u6dfb\u52a0\u5230\u6682\u5b58\u533a\u3002

\u52a8\u624b\u505a 2.4.2

\u628a hello.c \u6dfb\u52a0\u5230\u6682\u5b58\u533a\u3002\u8fd9\u4e2a\u65f6\u5019\u518d\u6b21\u8fd0\u884c git status\uff0c\u770b\u770b\u6709\u4ec0\u4e48\u53d8\u5316\u3002

\u601d\u8003\uff1a\u5982\u679c\u6211\u60f3\u4e00\u6b21\u6027\u6dfb\u52a0\u591a\u4e2a\u6587\u4ef6\uff0c\u6216\u8005\u8bf4\u6dfb\u52a0\u6240\u6709\u6587\u4ef6\uff0c\u5e94\u8be5\u600e\u4e48\u505a\u5462\uff1f

git commit -m \"<MESSAGE>\"\n

\u5c06\u6682\u5b58\u533a\u7684\u6587\u4ef6\u63d0\u4ea4\u5230\u7248\u672c\u5e93\uff0c-m \u53c2\u6570\u540e\u9762\u662f\u63d0\u4ea4\u7684\u4fe1\u606f\uff0c\u7528\u4e8e\u63cf\u8ff0\u8fd9\u6b21\u63d0\u4ea4\u7684\u5185\u5bb9\u3002

git log\n

\u67e5\u770b\u7248\u672c\u5e93\u7684\u5386\u53f2\u3002

\u52a8\u624b\u505a 2.4.3

\u63d0\u4ea4 hello.c \u6587\u4ef6\u5230\u7248\u672c\u5e93\uff0c\u63d0\u4ea4\u4fe1\u606f\u53ef\u4ee5\u662f\u4efb\u610f\u7684\uff0c\u4f8b\u5982 Add hello.c\u3002

git commit -m \"Add hello.c\"\n

\u8bd5\u4e00\u8bd5 git log \u547d\u4ee4\uff0c\u4f60\u80fd\u89e3\u91ca\u8fd9\u4e9b\u4fe1\u606f\u5417\uff1f

\ud83c\udf89 \u606d\u559c\u4f60\u5b8c\u6210\u4e86\u81ea\u5df1\u7684\u7b2c\u4e00\u4e2a Commit\uff01\u4e0b\u9762\u8ba9\u6211\u4eec\u591a\u6dfb\u52a0\u4e00\u4e9b\u6587\u4ef6\u3002

\u52a8\u624b\u505a\uff1a\u5e74\u8f7b\u4eba\u7684\u7b2c i \u4e2a Commit\uff08i = 2, 3, ...\uff09

\u4e00\u4e2a\u4f18\u79c0\u7684\u9879\u76ee\u53ea\u6709\u4ee3\u7801\u600e\u4e48\u884c\uff1f\u8ba9\u6211\u4eec\u6dfb\u52a0\u4e00\u4e2a\u4ecb\u7ecd\u6587\u6863\u5427\uff01\u521b\u5efa README.txt\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a

hello.c\uff1a\u4e00\u4e2a\u7b80\u5355\u7684 Hello World \u7a0b\u5e8f\uff08\u771f\u7684\u5f88\u7b80\u5355\uff01\uff09\u3002\n

\u7136\u540e\u63d0\u4ea4\u8fd9\u4e2a\u6587\u4ef6\u3002\u518d\u6b21\u8fd0\u884c git log\uff0c\u4f60\u770b\u5230\u4e86\u4ec0\u4e48\uff1f

\u8bd5\u7740\u4fee\u6539\u3001\u521b\u5efa\u3001\u5220\u9664\uff0c\u770b\u770b git status\uff0c\u7528 git diff \u67e5\u770b\u5f53\u524d\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u533a\u7684\u5dee\u5f02\uff0c\u7136\u540e\u63d0\u4ea4\u8fd9\u4e9b\u4fee\u6539\u3002

\u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u5e38\u7528\u7684\u547d\u4ee4\uff1a

\u52a8\u624b\u505a\uff1a\u73a9\u4e00\u73a9

\u8bd5\u7740\u4f7f\u7528\u4e0a\u9762\u63d0\u5230\u7684\u547d\u4ee4\uff0c\u73a9\u4e00\u73a9 Git \u5427\uff01\u5982\u679c\u6709\u4ec0\u4e48\u95ee\u9898\uff0c\u6b22\u8fce\u968f\u65f6\u63d0\u95ee\u3002

"},{"location":"programming/24fall/lec3/#_7","title":"\u5206\u652f","text":"

\u5206\u652f\uff08Branch\uff09\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u6982\u5ff5\u3002\u5b83\u5141\u8bb8\u4f60\u5728\u4e0d\u5f71\u54cd\u4e3b\u7ebf\u7684\u60c5\u51b5\u4e0b\u8fdb\u884c\u5f00\u53d1\uff0c\u7136\u540e\u518d\u5c06\u4f60\u7684\u5de5\u4f5c\u5408\u5e76\u5230\u4e3b\u7ebf\u4e0a\u3002

\u52a8\u624b\u505a\uff1a\u5206\u652f

\u5047\u5982\u8bf4\u6211\u60f3\u7ed9\u6211\u4eec\u7684 hello.c \u6dfb\u52a0\u4e00\u4e2a\u51fd\u6570\uff0c\u4f46\u662f\u7531\u4e8e\u8fd9\u4e2a\u51fd\u6570\u5f88\u590d\u6742\uff0c\u53ef\u80fd\u4f1a\u65ad\u65ad\u7eed\u7eed\u4fee\u6539\u5f88\u957f\u65f6\u95f4\uff0c\u6240\u4ee5\u6211\u4e0d\u60f3\u5f71\u54cd\u5230\u4e3b\u7ebf\u7684\u5f00\u53d1\u3002\u8fd9\u65f6\u5019\u5c31\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5206\u652f\uff0c\u7136\u540e\u5728\u8fd9\u4e2a\u5206\u652f\u4e0a\u4e0e\u4e3b\u7ebf\u5e73\u884c\u5f00\u53d1\u3002

\u8bd5\u7740\u521b\u5efa\u4e00\u4e2a dev \u5206\u652f\uff0c\u5207\u6362\u8fdb\u53bb\uff0c\u7136\u540e\u5728 hello.c \u4e2d\u6dfb\u52a0\u4e00\u4e2a print_hello() \u51fd\u6570\uff1a

void print_hello() {\n    printf(\"Hello from dev branch!\");\n}\n

\u7136\u540e\u63d0\u4ea4\u8fd9\u4e2a\u4fee\u6539\u3002\u518d\u8fd0\u884c git log\uff08\u4f60\u53ef\u4ee5\u540c\u65f6\u8bd5\u4e00\u8bd5\u5b83\u7684\u5404\u79cd\u53c2\u6570\uff09\uff0c\u4f60\u770b\u5230\u4e86\u4ec0\u4e48\uff1f\u5728\u8111\u6d77\u91cc\u60f3\u4e00\u60f3\u5f53\u524d\u7684\u5206\u652f\u7ed3\u6784\u3002

\u5207\u6362\u56de\u4e3b\u5206\u652f\uff08master \u6216\u8005 main\uff09\uff0chello.c \u91cc\u9762\u6709\u8fd9\u4e2a\u51fd\u6570\u5417\uff1f\u4e3a\u4ec0\u4e48\uff1f

Answer

"},{"location":"programming/24fall/lec3/#detached-head","title":"Detached HEAD \u95ee\u9898","text":"

\u6240\u8c13 Detached HEAD\uff0c\u6307\u7684\u662f HEAD \u6307\u5411\u7684\u4e0d\u662f\u4e00\u4e2a\u5206\u652f\uff0c\u800c\u662f\u4e00\u4e2a\u5177\u4f53\u7684\u5feb\u7167\u3002

\u5982\u679c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u8fdb\u884c\u4fee\u6539\u5e76\u63d0\u4ea4\uff0c\u65b0\u7684\u63d0\u4ea4\u4e0d\u5c5e\u4e8e\u4efb\u4f55\u5206\u652f\uff0c\u5b83\u53ea\u80fd\u901a\u8fc7 Commit ID \u6765\u8bbf\u95ee\uff0c\u76f8\u5f53\u4e8e\u4e22\u5931\u4e86\u3002

\u56fe\u7247\u6765\u6e90\uff1aTonyCrane \u7684\u8bb2\u4e49

\u6f14\u793a\uff1aDetached HEAD

\u4f7f\u7528 git log \u67e5\u770b\u5386\u53f2\uff0c\u627e\u5230\u4e00\u4e2a Commit ID\uff0c\u7136\u540e\u4f7f\u7528 git checkout <ID> \u5207\u6362\u5230\u8fd9\u4e2a\u5feb\u7167\uff0c\u4f60\u770b\u5230\u4e86\u4ec0\u4e48\uff1f

\u8bd5\u7740\u4fee\u6539\u8fd9\u4e2a\u5feb\u7167\uff0c\u63d0\u4ea4\uff0c\u7136\u540e\u4f7f\u7528 checkout \u56de\u5230\u4e3b\u5206\u652f\uff0c\u4f60\u8fd8\u80fd\u627e\u5230\u8fd9\u4e2a\u4fee\u6539\u5417\uff1f

\u5982\u679c\u6211\u60f3\u4fdd\u7559\u8fd9\u4e2a\u4fee\u6539\uff0c\u5e94\u8be5\u600e\u4e48\u505a\uff1f

"},{"location":"programming/24fall/lec3/#_8","title":"\u5408\u5e76","text":"
git merge <BRANCH1> [<BRANCH2> ...] -m \"<MESSAGE>\"\n

\u5c06\u4e00\u4e2a\u6216\u591a\u4e2a\u5206\u652f\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f\u3002\u5408\u5e76\u672c\u8eab\u4e5f\u662f\u4e00\u6b21\u63d0\u4ea4\uff0c-m \u53c2\u6570\u540e\u9762\u662f\u63d0\u4ea4\u4fe1\u606f\u3002

\u56fe\u7247\u6765\u6e90\uff1aTonyCrane \u7684\u8bb2\u4e49

\u52a8\u624b\u505a\uff1a\u5408\u5e76\u51b2\u7a81

\u5728\u4e3b\u5206\u652f\u7684 hello.c \u4e2d\u4e5f\u6dfb\u52a0\u4e00\u4e2a print_hello() \u51fd\u6570\uff08\u771f\u5b9e\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u662f\u4f60\u5728 dev \u548c main \u4e2d\u540c\u65f6\u4fee\u6539\u4e86\u67d0\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u6216\u8005\u4e24\u4e2a\u4eba\u4e0d\u7ecf\u610f\u95f4\u540c\u65f6\u4fee\u6539\u4e86\u540c\u4e00\u4e2a\u6587\u4ef6\uff09\uff1a

void print_hello() {\n    printf(\"Hello from main branch!\");\n}\n

\u63d0\u4ea4\u8fd9\u4e2a\u4fee\u6539\uff0c\u7136\u540e\u5c1d\u8bd5\u5408\u5e76 dev \u5206\u652f\u3002\u4f60\u6210\u529f\u4e86\u5417\uff1f\u5982\u679c\u6ca1\u6709\uff0c\u4f60\u5e94\u8be5\u600e\u4e48\u505a\uff1f

\u8bd5\u7740\u89e3\u51b3\u8fd9\u4e2a\u51b2\u7a81\uff0c\u7136\u540e\u63d0\u4ea4 merge\u3002

\u5b9e\u9645\u4e0a\uff0cMerge \u8fd8\u6709\u5f88\u591a\u5176\u4ed6\u7684\u7b56\u7565\u3002

\u56fe\u7247\u6765\u6e90\uff1aTonyCrane \u7684\u8bb2\u4e49"},{"location":"programming/24fall/lec3/#_9","title":"\u7be1\u6539\u5386\u53f2","text":"

\u6210\u4e3a\u5386\u53f2\u7684\u7f6a\u4eba

Git \u7684\u5386\u53f2\u4e00\u822c\u60c5\u51b5\u4e0b\u662f\u4e0d\u53ef\u7be1\u6539\u7684\uff0c\u4f46\u5b9e\u9645\u4e0a\u8fd8\u662f\u6709\u4e00\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5bf9\u5386\u53f2\u8fdb\u884c\u4fee\u6539\uff1a

"},{"location":"programming/24fall/lec3/#vscode-git","title":"\u5728 VSCode \u4e2d\u4f7f\u7528 Git","text":"

Visual Studio Code \u9ed8\u8ba4\u96c6\u6210\u4e86 Git\uff0c\u70b9\u51fb\u5de6\u4fa7\u6e90\u4ee3\u7801\u7ba1\u7406\uff08Source Control\uff09\u6309\u94ae\u5373\u53ef\u6253\u5f00\u56fe\u5f62\u5316\u7684 Git \u754c\u9762\u3002

\u52a8\u624b\u505a\uff1a\u73a9\u4e00\u73a9

\u7528 VSCode \u6253\u5f00\u770b\u770b\u4f60\u521a\u521a\u521b\u5efa\u7684 Git \u9879\u76ee\u5427\uff5e

"},{"location":"programming/24fall/lec3/#gitignore","title":".gitignore \u6587\u4ef6","text":"

\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u6709\u4e00\u4e9b\u6587\u4ef6\u662f\u4e0d\u9700\u8981\u7eb3\u5165\u7248\u672c\u5e93\u7684\uff0c\u4f8b\u5982\u7f16\u8bd1\u751f\u6210\u7684\u6587\u4ef6\u3001\u65e5\u5fd7\u6587\u4ef6\u3001\u7f13\u5b58\u6587\u4ef6\u7b49\u3002\u8fd9\u65f6\u5019\u5c31\u9700\u8981\u5728\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a .gitignore \u6587\u4ef6\u3002

.gitignore \u6587\u4ef6\u662f\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u6bcf\u4e00\u884c\u662f\u4e00\u4e2a\u5339\u914d\u89c4\u5219\uff0c\u4f8b\u5982\uff1a

# Logs\nlogs\n*.log\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\npnpm-debug.log*\nlerna-debug.log*\n\nnode_modules\n.DS_Store\ndist\ndist-ssr\ncoverage\n*.local\ncache\n\n/cypress/videos/\n/cypress/screenshots/\n\n# Editor directories and files\n.vscode/*\n!.vscode/extensions.json\n.idea\n*.suo\n*.ntvs*\n*.njsproj\n*.sln\n*.sw?\n\n*.tsbuildinfo\n.vercel\n

\u8bed\u6cd5\uff1a

\u5b98\u65b9\u6587\u6863\uff1agit-scm.com/docs/gitignore\uff0cGitHub \u4e5f\u63d0\u4f9b\u4e86\u4e00\u4e2a\u6a21\u677f\u3002

"},{"location":"programming/24fall/lec3/#github-zju-git","title":"GitHub / ZJU Git \u57fa\u7840","text":"

\u8bbe\u60f3\u591a\u4eba\u534f\u4f5c\u7684\u573a\u666f\uff0c\u6bcf\u4e2a\u4eba\u90fd\u5728\u672c\u5730\u6709\u81ea\u5df1\u7684\u7248\u672c\u5e93\uff0c\u90a3\u5982\u4f55\u5b9e\u73b0\u540c\u6b65\u5462\uff1f

\u7b54\u6848\u662f\u6bcf\u4e2a\u4eba\u90fd\u4f7f\u7528\u4e00\u4e2a\u201c\u6743\u5a01\u201d\u7684\u8fdc\u7a0b\u7248\u672c\u5e93\uff08Remote Repository\uff09\u3002

"},{"location":"programming/24fall/lec3/#_10","title":"\u8fdc\u7a0b\u7248\u672c\u5e93","text":"\u56fe\u7247\u6765\u6e90\uff1aTonyCrane \u7684\u8bb2\u4e49

\u8fdc\u7a0b\u7248\u672c\u5e93\u4e5f\u662f\u4e00\u4e2a\u666e\u901a\u7684 Git \u7248\u672c\u5e93\uff0c\u53ea\u4e0d\u8fc7\u7531\u4e8e\u4e0d\u9700\u8981\u5de5\u4f5c\u76ee\u5f55\u548c\u6682\u5b58\u533a\uff0c\u6240\u4ee5\u4e00\u822c\u4f7f\u7528\u88f8\u7248\u672c\u5e93\u3002

\u8fdc\u7a0b\u7248\u672c\u5e93\u53ef\u4ee5\u7b80\u5355\u5730\u7406\u89e3\u6210\u662f\u672c\u5730\u7684\u4e00\u4e2a origin/main \u5206\u652f\u3002

"},{"location":"programming/24fall/lec3/#zju-git","title":"ZJU Git","text":"

\u4f5c\u4e3a\u4e00\u4e2a\u5168\u7403\u9876\u5c16\u7684\u4e09\u672c\uff0c\u600e\u4e48\u80fd\u6ca1\u6709\u4e00\u4e2a\u81ea\u5df1\u7684 Git \u670d\u52a1\u5668\u5462\uff1f

\u7f51\u5740\uff1agit.zju.edu.cn\uff0c\u53ea\u80fd\u901a\u8fc7\u6821\u7f51\u6216 WebVPN \u8bbf\u95ee\u3002

\u6ce8\u610f\u533a\u5206

ZJU Git \u548c GitHub \u662f\u5e73\u884c\u7684\u5173\u7cfb\uff0c\u5b83\u4eec\u63d0\u4f9b\u7c7b\u4f3c\u7684\u529f\u80fd\uff08\u975e\u5e38\u7c7b\u4f3c\uff09\uff0c\u90fd\u53ef\u4ee5\u4f5c\u4e3a Git \u7684\u8fdc\u7a0b\u7248\u672c\u5e93\u3002

\u4e0d\u8981\u628a ZJU Git / GitHub \u548c Git \u6df7\u6dc6\uff01

"},{"location":"programming/24fall/lec3/#_11","title":"\u6ce8\u518c\u8d26\u53f7","text":"

\u4f7f\u7528\u7edf\u4e00\u8eab\u4efd\u8ba4\u8bc1\u767b\u5f55\u3002

\u8bbe\u60f3\u4e00\u4e0b\uff0cZJU Git \u5982\u4f55\u786e\u5b9a\u4f60\u7684\u8eab\u4efd\u5462\uff1f

SSH \u5bc6\u94a5

SSH \u5bc6\u94a5\u91c7\u7528\u975e\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5\uff0c\u5b83\u5305\u62ec\u516c\u94a5\u548c\u79c1\u94a5\u4e24\u90e8\u5206\u3002

\u901a\u8fc7 SSH \u5bc6\u94a5\uff0c\u53ef\u4ee5\u4e0e\u8fdc\u7a0b\u670d\u52a1\u5668\u5efa\u7acb\u5b89\u5168\u7684\u8fde\u63a5\u3002

\u52a8\u624b\u505a\uff1a\u8bbe\u7f6e SSH \u5bc6\u94a5

\u6253\u5f00 Git Bash\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a

ssh-keygen -t ed25519 -C \"<\u4f60\u7684\u90ae\u7bb1>\"\n

\u5b83\u4f1a\u5411\u4f60\u8be2\u95ee\u5bc6\u94a5\u7684\u4fdd\u5b58\u4f4d\u7f6e\u548c\u5bc6\u7801\uff0c\u76f4\u63a5\u56de\u8f66\u4f7f\u7528\u9ed8\u8ba4\u503c\u5373\u53ef\u3002

\u8fd9\u6761\u6307\u4ee4\u4f1a\u5728 ~/.ssh \u76ee\u5f55\uff08\u5bf9\u4e8e Windows\uff0c\u662f C:/Users/<\u7528\u6237\u540d>/.ssh\uff09\u4e0b\u751f\u6210\u4e24\u4e2a\u6587\u4ef6\uff1aid_ed25519 \u548c id_ed25519.pub\uff0c\u524d\u8005\u662f\u79c1\u94a5\uff0c\u540e\u8005\u662f\u516c\u94a5\u3002

\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00 id_ed25519.pub\uff0c\u590d\u5236\u91cc\u9762\u7684\u5185\u5bb9\uff0c\u7136\u540e\u5728 ZJU Git \u7684\u8bbe\u7f6e\u4e2d\u6dfb\u52a0 SSH \u5bc6\u94a5\u5373\u53ef\u3002

"},{"location":"programming/24fall/lec3/#_12","title":"\u521b\u5efa\u4ed3\u5e93","text":"

\u52a8\u624b\u505a\uff1a\u521b\u5efa\u4ed3\u5e93

\u5728 ZJU Git \u4e0a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u4ed3\u5e93\uff0c\u7136\u540e\u5c06\u672c\u5730\u7684 Git \u9879\u76ee\u63a8\u9001\u5230\u8fd9\u4e2a\u4ed3\u5e93\u3002

git remote add origin <\u4f60\u7684\u4ed3\u5e93\u5730\u5740>\ngit branch -M main\ngit push -uf origin main\n

\u56de\u5230 ZJU Git \u7f51\u7ad9\uff0c\u770b\u770b\u4f60\u7684\u4ed3\u5e93\u5427\uff01

\u52a8\u624b\u505a\uff1a\u63d0\u4ea4\u66f4\u65b0

\u5728\u672c\u5730\u4fee\u6539 hello.c\uff0c\u7136\u540e\u628a\u5b83\u63d0\u4ea4\u5230 ZJU Git \u4e0a\u3002

\u8fd8\u8bb0\u5f97\u8981\u7528\u54ea\u4e9b\u6307\u4ee4\u5417\uff1f\uff08add\u3001commit\u3001push\uff09

"},{"location":"programming/24fall/lec3/#_13","title":"\u591a\u4eba\u534f\u4f5c","text":"

\u52a8\u624b\u505a\uff1a\u5e74\u8f7b\u4eba\u7684\u7b2c\u4e00\u4e2a PR\uff01

Fork \u8fd9\u4e2a\u4ed3\u5e93\uff1alec3-git\u3002

\u7136\u540e cd \u5230\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5939\uff0c\u4f7f\u7528 git clone \u514b\u9686\u4f60 Fork \u7684\u4ed3\u5e93\u3002

\u968f\u4fbf\u6539\u4e00\u4e9b\u4e1c\u897f\u5427\uff5e\u7136\u540e\u628a\u8fd9\u4e9b\u4fee\u6539\u63d0\u4ea4\u5230\u4f60 Fork \u7684\u4ed3\u5e93\u3002

\u6700\u540e\uff0c\u5411\u539f\u4ed3\u5e93\u63d0\u4ea4\u4e00\u4e2a PR\uff0c\u8bf7\u6c42\u5408\u5e76\u4f60\u7684\u4fee\u6539\u3002

"},{"location":"programming/24fall/lec3/#github","title":"GitHub \u7b80\u4ecb","text":"

\u6240\u8c13 GitHub\uff0c\u5c31\u662f Git \u7684 Hub\uff08\u6211\u5728\u8bf4\u4ec0\u4e48\uff09\u3002

GitHub \u662f\u5168\u7403\u6700\u5927\u7684\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\uff0c\u62e5\u6709\u6570\u4ebf\u7684\u5f00\u53d1\u8005\uff08\u622a\u81f3 2023 \u5e74 1 \u6708\uff09\u548c\u6570\u4ee5\u4ebf\u8ba1\u7684\u4ee3\u7801\u4ed3\u5e93\u3002

\u8bfe\u540e\uff1a\u6ce8\u518c\u4e00\u4e2a GitHub \u8d26\u53f7

\u6ce8\u518c\u4e00\u4e2a\u81ea\u5df1\u7684 GitHub \u8d26\u53f7\u5427\uff5e\uff08\u4f60\u53ef\u80fd\u9700\u8981\u9b54\u6cd5\uff09

\u6253\u5f00\u6211\u4eec\u73b0\u5728\u8fd9\u4e2a\u7f51\u7ad9\u7684 GitHub \u4ed3\u5e93\uff0c\u770b\u4e00\u770b Commit \u8bb0\u5f55\uff0c\u4f53\u4f1a\u4e00\u4e0b\u771f\u5b9e\u9879\u76ee\u4e2d\u7684\u56e2\u961f\u534f\u4f5c\u5427\uff01\u5982\u679c\u4f60\u89c9\u5f97\u4e0d\u9519\uff0c\u4e0d\u59a8\u7ed9\u6211\u4eec\u4e00\u4e2a Star \u2b50\u3002

\u540c\u65f6\u63a8\u8350 TonyCrane \u5b66\u957f\u7684 Slides\uff0c\u6709\u66f4\u591a\u5173\u4e8e GitHub \u7684\u8be6\u7ec6\u7684\u4ecb\u7ecd\u3002

"},{"location":"programming/24fall/lec3/#_14","title":"\u5f00\u6e90\u9879\u76ee\u57fa\u7840","text":""},{"location":"programming/24fall/lec3/#_15","title":"\u8bb8\u53ef\u8bc1","text":"

\u516c\u5f00\u6e90\u4ee3\u7801\u4e0d\u4ee3\u8868\u4f60\u53ef\u4ee5\u62ff\u5b83\u505a\u4efb\u4f55\u60f3\u505a\u7684\u4e8b\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u9700\u8981\u8bb8\u53ef\u8bc1\uff08License\uff09\u3002

\u5e38\u7528\u8f6f\u4ef6\u5f00\u6e90\u8bb8\u53ef\u8bc1\uff1a

\u53c2\u8003 choosealicense.com\u3002

\u56fe\u7247\u6765\u6e90\uff1a\u962e\u4e00\u5cf0\u300a\u5982\u4f55\u9009\u62e9\u5f00\u6e90\u8bb8\u53ef\u8bc1\uff1f\u300b

\u5982\u679c\u6ca1\u6709\u8bb8\u53ef\u8bc1\u5462\uff1f

\u539f\u4f5c\u8005\u4fdd\u7559\u6240\u6709\u6743\u5229\uff0c\u4e0d\u5141\u8bb8\u590d\u5236\u3001\u5206\u53d1\u3001\u4fee\u6539\uff0c\u4f7f\u7528\u7684\u8bdd\u9700\u8981\u8054\u7cfb\u539f\u4f5c\u8005\uff01\uff08\u6ce8\u610f\u548c Unlicense \u533a\u5206\uff09

\u4fb5\u6743\u662f\u975e\u5e38\u4e25\u8083\u7684\u4e8b\u60c5\uff01

\u539f\u4f5c\u8005\u6709\u6743\u5bf9\u4f60\u7684\u9879\u76ee\u8fdb\u884c DMCA Takedown\uff08DMCA\uff1a\u300a\u5343\u79a7\u5e74\u6570\u5b57\u8457\u4f5c\u6743\u6cd5\u6848\u300b\uff09\uff0c\u751a\u81f3\u901a\u8fc7\u6cd5\u5f8b\u9014\u5f84\u8ffd\u7a76\u8d23\u4efb\uff01

\u6848\u4f8b\uff1a

\u5728\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u540d\u4e3a LICENSE \u7684\u6587\u4ef6\uff0c\u7136\u540e\u5728\u5176\u4e2d\u9644\u4e0a\u8bb8\u53ef\u8bc1\u7684\u5185\u5bb9\u3002\u5982\u679c\u4e0d\u540c\u90e8\u5206\u91c7\u7528\u4e86\u4e0d\u540c\u7684\u8bb8\u53ef\u8bc1\uff0c\u90a3\u4e48\u9700\u8981\u5728\u6bcf\u4e2a\u6587\u4ef6\u7684\u5f00\u5934\u6ce8\u660e\u3002

GitHub \u80fd\u591f\u81ea\u52a8\u8bc6\u522b\u5e38\u89c1\u7684\u8bb8\u53ef\u8bc1\u7c7b\u578b\uff0c\u5e76\u5728\u4ed3\u5e93\u7684\u4e3b\u9875\u4e0a\u663e\u793a\u3002

\u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u6709\u975e\u8f6f\u4ef6\u7c7b\u8bb8\u53ef\u8bc1\uff0c\u6700\u5e38\u4f7f\u7528\u7684\u662f CC\uff08Creative Commons\uff0c\u77e5\u8bc6\u5171\u4eab\uff09\u7cfb\u5217\u8bb8\u53ef\u8bc1\uff0c\u76ee\u524d\u6700\u5e7f\u6cdb\u4f7f\u7528\u7684\u7248\u672c\u662f 4.0\uff0c\u5b83\u5305\u542b\u5982\u4e0b\u51e0\u79cd\uff1a

\u5f80\u5f80\u901a\u8fc7\u4e00\u6bb5\u6587\u5b57\u5373\u53ef\u8868\u793a\u8bb8\u53ef\uff1a

\u672c\u4f5c\u54c1\u91c7\u7528\u77e5\u8bc6\u5171\u4eab\u7f72\u540d-\u975e\u5546\u4e1a\u6027\u4f7f\u7528-\u7981\u6b62\u6f14\u7ece 4.0 \u56fd\u9645\u8bb8\u53ef\u534f\u8bae\u8fdb\u884c\u8bb8\u53ef\u3002\n

\u601d\u8003

\u8fd9\u7bc7\u6587\u7ae0\u4e5f\u662f\u901a\u8fc7 CC \u8bb8\u53ef\u8bc1\u53d1\u5e03\u7684\uff0c\u4f60\u80fd\u627e\u5230\u5b83\u7684\u8bb8\u53ef\u8bc1\u5417\uff1f

"},{"location":"programming/24fall/lec3/#_16","title":"\u7ed3\u8bed","text":"

\u901a\u8fc7\u4eca\u5929\u7684\u5b66\u4e60\uff0c\u60f3\u5fc5\u4f60\u5df2\u7ecf\u5bf9\u5f00\u6e90\u6709\u4e86\u66f4\u6df1\u7684\u4e86\u89e3\uff0c\u6b22\u8fce\u4f60\u52a0\u5165\u5f00\u6e90\u7684\u5927\u5bb6\u5ead\uff01

\u4e00\u4e9b\u5b66\u4e60\u8d44\u6e90\uff1a

\u4e0b\u4e00\u6b21\u8bfe\uff0c\u674e\u82f1\u7426\u5b66\u957f\u5c06\u4e3a\u5927\u5bb6\u5e26\u6765 Markdown \u548c LaTeX \u7b49\u6392\u7248\u76f8\u5173\u7684\u5185\u5bb9\uff08\u5b9e\u9645\u4e0a\u8fd9\u4e2a\u8bb2\u4e49\u5c31\u662f\u7528 Markdown \u5199\u7684\uff09\uff0c\u656c\u8bf7\u671f\u5f85\uff5e

"},{"location":"programming/24fall/lec4/","title":"\u7b2c\u56db\u8bb2\uff1a\u5982\u4f55\u5199\u51fa\u7b80\u6d01\u5de5\u6574\u7684\u62a5\u544a","text":"

Danger

\u672c\u6587\u6863\u5c1a\u672a\u5b8c\u6210\u3002

"},{"location":"programming/24fall/lec5/","title":"\u7b2c\u4e94\u8bb2\uff1a\u671f\u672b\u590d\u4e60\uff08\u4e0a\uff09","text":""},{"location":"programming/24fall/lec5/#_2","title":"\u53d8\u91cf\u4e0e\u8ba1\u7b97","text":""},{"location":"programming/24fall/lec5/#_3","title":"\u53d8\u91cf","text":"
\u7c7b\u578b\u540d \u53d8\u91cf\u540d;\nint x;\n

\u5173\u952e\u5b57\u5982\u4e0b\uff1a

\u4f8b1.1-1

Which one below is NOT a valid identifier in the C programming language?

A. printf B. _m$ C. 114514 D. define

\u672a\u521d\u59cb\u5316\u7684\u53d8\u91cf\u7684\u503c\u662f\u4e0d\u786e\u5b9a\u7684

"},{"location":"programming/24fall/lec5/#_4","title":"\u6570\u636e\u7c7b\u578b\u548c\u5b57\u9762\u91cf","text":""},{"location":"programming/24fall/lec5/#_5","title":"\u6570\u636e\u7c7b\u578b","text":"

\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u5360\u636e\u4e0d\u540c\u7684\u5927\u5c0f\uff0c\u6709\u4e0d\u540c\u7684\u53d6\u503c\u8303\u56f4

unsigned short sht = 0;\nsht--;\n

\u4f8b1.2-1

0.1 + 0.2 == 0.3 ?

int n=1;\nchar ch='\\012'; \nprintf(\"%d\", ch*n++);\n// printf(\"%d\", ch*++n);\n

sizeof \u53ef\u4ee5\u83b7\u5f97\u67d0\u4e2a\u7c7b\u578b\u6216\u53d8\u91cf\u5728\u5185\u5b58\u4e2d\u6240\u5360\u636e\u7684\u5b57\u8282\u6570\uff0c\u5b83\u7684\u7ed3\u679c\u5728\u7f16\u8bd1\u65f6\u523b\u5c31\u51b3\u5b9a\u4e86\uff0c\u662f\u4e00\u4e2a\u8fd0\u7b97\u7b26\u800c\u4e0d\u662f\u51fd\u6570

int a = 1;\nprintf(\"%d\\n\", sizeof(a++));\nprintf(\"%d\\n\", a);\n
"},{"location":"programming/24fall/lec5/#_6","title":"\u5b57\u9762\u91cf","text":"

\u5b57\u9762\u91cf\u5373\u4e00\u4e2a\u503c\u7684\u8868\u793a\u65b9\u6cd5\uff0c\u540c\u4e00\u4e2a\u503c\u53ef\u80fd\u6709\u5f88\u591a\u79cd\u8868\u793a\u65b9\u6cd5

char a = 65;            // \u5341\u8fdb\u5236\nchar b = 0101;          // 0\u5f00\u5934\u8868\u793a\u516b\u8fdb\u5236\nchar c = 0x41;          // 0x\u5f00\u5934\u8868\u793a\u5341\u516d\u8fdb\u5236\n\nchar d = 'A';           // \u5355\u5f15\u53f7\uff0c\u5b57\u7b26\u5e38\u91cf\n\nchar e = '\\101';        // \u5355\u5f15\u53f7\u91cc\u9762\u53cd\u659c\u6760\u8f6c\u4e49\u6700\u591a\u4e09\u4e2a\u6570\u5b57\uff0c\u8868\u793a\u516b\u8fdb\u5236\uff0c\u9047\u52300-7\u4e4b\u5916\u7684\u5c31\u4f1a\u7ed3\u675f\nchar e0 = '\\08';        // \u9519\u8bef\uff0c\u8fd9\u662f\u4e24\u4e2a\u5b57\u7b26\u653e\u5230\u4e86\u4e00\u4e2a\u5355\u5f15\u53f7\u91cc\n\nchar f = '\\x41';        // \u5341\u516d\u8fdb\u5236\uff0c\u6ca1\u6709\u957f\u5ea6\u9650\u5236\uff0c\u9047\u5230\u975e\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u5c31\u4f1a\u7ed3\u675f\nchar f0 = '\\x00041';    // \u548c\u4e0a\u9762\u7684\u662f\u4e00\u6837\u7684\n
"},{"location":"programming/24fall/lec5/#_7","title":"\u8ba1\u7b97","text":"

\u5e26\u8fd0\u7b97\u7b26\u7684\u5f0f\u5b50\u662f\u8868\u8fbe\u5f0f\uff0c\u8868\u8fbe\u5f0f\u6709\u503c\u548c\u526f\u4f5c\u7528

"},{"location":"programming/24fall/lec5/#_8","title":"\u8fd0\u7b97\u7b26","text":"

% & << \u8fd0\u7b97\u7b26\u4e0d\u80fd\u7528\u5728 double \u4e0a

\u8fd0\u7b97\u987a\u5e8f\u95ee\u9898\uff0c\u7b80\u5355\u6765\u8bf4\uff1a\u8d4b\u503c\u8fd0\u7b97\u7b26\u548c\u4f4d\u8fd0\u7b97\u7b26\u8f83\u4f4e\uff0c\u7565\u9ad8\u7684\u662f\u7b97\u672f\u8fd0\u7b97\uff0c\u518d\u9ad8\u7684\u662f\u81ea\u589e/\u51cf

\u4f8b1.3-1

\u82e5\u5b9a\u4e49 int a=1,b=2,c=3,d=4 \u90a3\u4e48\u8868\u8fbe\u5f0f (a>b?c>a?c-3:c-1:b==c?d-a:d-c) \u7684\u503c\u4e3a

"},{"location":"programming/24fall/lec5/#_9","title":"\u8868\u8fbe\u5f0f\u7684\u7ed3\u679c","text":"

\u4f8b1.3-2

"},{"location":"programming/24fall/lec5/#_10","title":"\u5206\u652f\u548c\u5faa\u73af","text":""},{"location":"programming/24fall/lec5/#_11","title":"\u5206\u652f","text":"

else \u603b\u662f\u4e0e\u6700\u8fd1\u7684\u4e00\u4e2a\u6ca1\u6709\u88ab\u5339\u914d\u7684 if \u914d\u5bf9

if (x > -2){\n    if (x > 0) {\n        // do something\n        if (x > 2){\n            // do something\n        }\n    } else{\n        // do something\n        else {\n            // do something\n        }\n    }\n}\n

\u5206\u652f\u8bed\u53e5\u5982\u5305\u62ec\u6709\u4e00\u4e2a\u4ee5\u4e0a\u7684\u8bed\u53e5\uff0c\u5219\u5fc5\u987b\u7528\u4e00\u5bf9\u5927\u62ec\u53f7 {} \u62ec\u8d77\u6765\uff0c\u7ec4\u6210\u590d\u5408\u8bed\u53e5\uff0c\u590d\u5408\u8bed\u53e5\u5728\u8bed\u6cd5\u4e0a\u88ab\u8ba4\u4e3a\u662f\u4e00\u6761\u8bed\u53e5

if \u8bed\u53e5\u6267\u884c\u7684\u65f6\u5019\u4f1a\u5148\u6267\u884c () \u91cc\u7684\u8868\u8fbe\u5f0f\uff0c\u5982\u679c\u8be5\u8868\u8fbe\u5f0f\u7684\u503c\u975e\u96f6\uff0c\u5219\u6267\u884c {} \u91cc\u7684\u8bed\u53e5

int x = 10;\nif (x--) {\n    printf(\"x is %d\\n\", x);\n}\n

\u8bbe\u8ba1\u6d4b\u8bd5\u7528\u4f8b\u6765\u9a8c\u8bc1\u5206\u652f\u8bed\u53e5\u7684\u6b63\u786e\u6027

if (x < 0) {\n    y = 0;\n} else if (x <= 15) {\n    y = 4 * x / 3;\n} else { \n    y = 2.5 * x - 10.5;\n}   \n

\u5bf9\u4e8e switch \u8bed\u53e5\uff0ccase \u53ea\u89c4\u5b9a\u4e86\u8d77\u70b9\uff0c\u800c\u4f55\u65f6\u9000\u51fa switch \u5757\u5219\u7531 break \u51b3\u5b9a\uff0c\u53ea\u8981\u6ca1\u6709\u9047\u5230 break\uff0c\u5219\u4e00\u76f4\u5411\u4e0b\u6267\u884c\uff08\u5373\u4f7f\u78b0\u5230\u4e86\u4e0b\u4e00\u4e2a case \u4e14\u4e0d\u6ee1\u8db3\uff09

int i, b; i = b = 1;\nswitch (i) {\n    case 0: b += 1;\n    case 1: b += 2;\n    case '1': b += 3;\n    case 2 : switch (b) {\n        case 1: b += 4;\n        case 3: i++;\n        default: break;\n    }\n    i += 1;\n}\nprintf(\"%d#%d#\", i, b);\n
"},{"location":"programming/24fall/lec5/#_12","title":"\u5faa\u73af","text":"

\u5faa\u73af\u4f53\u5982\u5305\u62ec\u6709\u4e00\u4e2a\u4ee5\u4e0a\u7684\u8bed\u53e5\uff0c\u5219\u5fc5\u987b\u7528\u4e00\u5bf9\u5927\u62ec\u53f7 {} \u62ec\u8d77\u6765\uff0c\u7ec4\u6210\u590d\u5408\u8bed\u53e5\uff0c\u590d\u5408\u8bed\u53e5\u5728\u8bed\u6cd5\u4e0a\u88ab\u8ba4\u4e3a\u662f\u4e00\u6761\u8bed\u53e5\u3002

int a, i;\nfor (a=1, i=-1; -1 <= i < 1; i++) {\n    a++;\n    printf(\"%2d\", a);\n}\nprintf(\"%2d\", i);\n
"},{"location":"programming/24fall/lec5/#_13","title":"\u6570\u7ec4","text":"

\u6570\u7ec4\u7684\u5b9a\u4e49

\u7c7b\u578b\u540d \u6570\u7ec4\u540d[\u6570\u7ec4\u957f\u5ea6];\nint a[10];\n

\u6570\u7ec4\u7684\u521d\u59cb\u5316

\u7c7b\u578b\u540d \u6570\u7ec4\u540d[\u6570\u7ec4\u957f\u5ea6(\u53ef\u7701\u7565)] = {\u5143\u7d201, \u5143\u7d202, ...};\nint a[5] = {1, 2, 3, 4, 5};\nint b[ ] = {1, 2, 3, 4, 5};\nint c[5] = {1, 2, 3};        // \u5176\u4f59\u5143\u7d20\u4e3a0\n

\u5143\u7d20\u7c7b\u578b\u4e3a\u6570\u7ec4\u7684\u6570\u7ec4\u88ab\u79f0\u4e3a\u9ad8\u7ef4\u6570\u7ec4

int a[][];\n\nint b[3][];\n\nint c[][4];\n\nint d[3][4];\n\nint e[][] = {\n    {1, 2, 3, 4},\n    {5, 6, 7, 8},\n    {9, 10, 11, 12}\n};\n\nint f[][4] = {\n    {1, 2, 3, 4},\n    {5, 6, 7, 8},\n    {9, 10, 11, 12}\n};\n
"},{"location":"programming/24fall/lec5/#_14","title":"\u51fd\u6570","text":"

\u4f8b4-1

C\u8bed\u8a00\u4e2d\uff0c\u901a\u8fc7\u51fd\u6570\u8c03\u7528\u53ea\u80fd\u83b7\u5f97\u4e00\u4e2a\u8fd4\u56de\u503c\uff1f

\u4f8b4-2

\u51fd\u6570\u53ef\u4ee5\u5d4c\u5957\u8c03\u7528\u4f46\u4e0d\u80fd\u5d4c\u5957\u5b9a\u4e49\uff1f

\u4f8b4-3

\u82e5\u51fd\u6570\u8c03\u7528\u65f6\u7684\u5b9e\u53c2\u4e3a\u53d8\u91cf\uff0c\u4e0b\u5217\u5173\u4e8e\u51fd\u6570\u5f62\u53c2\u548c\u5b9e\u53c2\u7684\u53d9\u8ff0\u4e2d\u6b63\u786e\u7684\u662f( )\u3002

A. \u51fd\u6570\u7684\u5b9e\u53c2\u548c\u5176\u5bf9\u5e94\u7684\u5f62\u53c2\u5171\u5360\u540c\u4e00\u5b58\u50a8\u5355\u5143 B. \u5f62\u53c2\u53ea\u662f\u5f62\u5f0f\u4e0a\u7684\u5b58\u5728, \u4e0d\u5360\u7528\u5177\u4f53\u5b58\u50a8\u5355\u5143 C. \u540c\u540d\u7684\u5b9e\u53c2\u548c\u5f62\u53c2\u5360\u540c\u4e00\u5b58\u50a8\u5355\u5143 D. \u51fd\u6570\u7684\u5f62\u53c2\u548c\u5b9e\u53c2\u5206\u522b\u5360\u7528\u4e0d\u540c\u7684\u5b58\u50a8\u5355\u5143

#include <stdio.h>\n\nint x = 5, y = 7;\nvoid swap(int,int); // \u51fd\u6570\u58f0\u660e\nint main() {\n    int x = 3, y = 8;\n    swap(x,y);\n    printf(\"%d,%d\\n\", x, y);\n\n    return 0 ;\n}\n\nvoid swap(int x,int y) { // \u51fd\u6570\u5b9a\u4e49\n    int temp = x;\n    x = y;\n    y = temp;\n}\n

\u4f8b4-4

\u51fd\u6570\u8c03\u7528\u8bed\u53e5 function((a,b),c) \u4e2d\u542b\u6709\u7684\u5b9e\u53c2\u4e2a\u6570\u4e3a\uff1f

"},{"location":"programming/24fall/lec5/#_15","title":"\u6392\u5e8f","text":"\u7b97\u6cd5 \u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6 \u6700\u597d\u60c5\u51b5 \u6700\u574f\u60c5\u51b5 \u7a33\u5b9a\u6027 \u5192\u6ce1\u6392\u5e8f \\(O(n^2)\\) \\(O(n)\\) \\(O(n^2)\\) \u7a33\u5b9a \u9009\u62e9\u6392\u5e8f \\(O(n^2)\\) \\(O(n^2)\\) \\(O(n^2)\\) \u4e0d\u7a33\u5b9a \u63d2\u5165\u6392\u5e8f \\(O(n^2)\\) \\(O(n)\\) \\(O(n^2)\\) \u7a33\u5b9a"},{"location":"programming/24fall/lec5/#_16","title":"\u6307\u9488","text":""},{"location":"programming/24fall/lec5/#_17","title":"\u5b9a\u4e49","text":"

\u6307\u9488\u53d8\u91cf\u7684\u503c\u662f\u53d8\u91cf\u7684\u5730\u5740\uff0c\u6307\u9488\u53d8\u91cf\u672c\u8eab\u4e5f\u6709\u81ea\u5df1\u7684\u5185\u5b58\u5730\u5740

int a = 1;\nint *p = &a; // &\u662f\u53d6\u5730\u5740\u8fd0\u7b97\u7b26\n

\u6307\u9488\u53d8\u91cf p \u7684\u503c\u662f a \u7684\u5730\u5740\uff0c*p \u8868\u793a p \u6307\u5411\u7684\u53d8\u91cf\uff0c\u5373 a\uff0c*p \u7684\u503c\u662f a \u7684\u503c\uff0c\u5373 1

\u58f0\u660e\u4e2d * \u53ea\u5bf9\u76f4\u63a5\u7ed3\u5408\u7684\u6807\u8bc6\u7b26\u751f\u6548

\u4f8b6.1-1

\u53d8\u91cf\u5b9a\u4e49\uff1aint *p, q; \u4e2d\uff0cp \u548c q \u90fd\u662f\u6307\u9488\uff1f

\u6307\u9488\u5141\u8bb8\u6307\u5411\u4e00\u4e2a\u4e0d\u5b8c\u6574\u7c7b\u578b:

int *a[3];   // a\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u5143\u7d20\u662f\u6307\u9488\nint (*b)[3]; // b\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u5143\u7d20\u662fint,\u6570\u7ec4\u957f\u5ea6\u4e3a3\nint *c[];    // ?\nint (*d)[];  // d\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411\u4e00\u4e2a\u957f\u5ea6\u672a\u77e5\u7684\u6570\u7ec4\uff0c\u6570\u7ec4\u5143\u7d20\u662fint\n

\u4f8b6.1-2

Among the following statements, __ is equivalent to the declaration: int *p[4];

A.int p[4]; B.int **p; C.int *(p[4]); D.int (*p)[4];

void * \u662f\u5408\u6cd5\u7684\u6307\u9488\u7c7b\u578b\uff0c\u6307\u5411\u4e00\u4e2a\u7c7b\u578b\u672a\u77e5\u7684\u5bf9\u8c61\uff0c\u53ef\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u4efb\u610f\u5176\u4ed6\u7c7b\u578b\u7684\u6307\u9488

"},{"location":"programming/24fall/lec5/#_18","title":"\u7528\u6cd5","text":""},{"location":"programming/24fall/lec5/#_19","title":"\u6307\u9488\u7684\u8fd0\u7b97","text":""},{"location":"programming/24fall/lec5/#_20","title":"\u6307\u9488\u4e0e\u6570\u7ec4","text":"

\u6307\u9488\u548c\u6570\u7ec4\u5173\u7cfb\u7d27\u5bc6\uff1a

\u4f8b6.2-1

Given the declaration: int a[3][3]={1,2,3,4,5,6,7,8,9};, the value of a[-1][5] is ?

\u4f8b6.2-2

Given the declaration: int a[3][2]={1,2,3,4,5,6}; what is the value of expression (a[1]+1)[0]?

\u9690\u5f0f\u8f6c\u6362\uff1aC \u8bed\u8a00\u89c4\u5b9a\u4efb\u4f55\u6570\u7ec4\u7c7b\u578b\u7684\u5de6\u503c\u8868\u8fbe\u5f0f\uff0c\u5f53\u7528\u4e8e\u5f02\u4e8e

\u7684\u8bed\u5883\u65f6\uff0c\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\uff0c\u5178\u578b\u573a\u666f\uff1a

  1. \u4f5c\u4e3a\u51fd\u6570\u7684\u53c2\u6570\u65f6\uff0c\u6570\u7ec4\u540d\u88ab\u8f6c\u6362\u6210\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u6307\u9488
  2. \u66f4\u6539\u6570\u7ec4\u5143\u7d20\u65f6

\u4f8b6.2-3

According to the declaration: int p[5], *a[5]; the expression ______ is correct.

A. p=a B. p[0]=a C. *(a+1)=p D. a[0]=2

\u4e8c\u7ef4\u6570\u7ec4\u4e0d\u80fd\u9690\u5f0f\u8f6c\u6362\u4e3a\u4e8c\u7ea7\u6307\u9488

\u4f8b6.2-4

For the function declaration void f(char** p),the definition __ of var makes the function call f(var) incorrect.

A. char var[10][10]; B. char *var[10]; C. void *var = NULL; D. char *v=NULL, **var=&v; E. char var[10][10], **p=var;

"},{"location":"programming/24fall/lec5/#_21","title":"\u6307\u9488\u4e0e\u5b57\u7b26\u4e32","text":"

\u5b57\u7b26\u4e32\u5e38\u91cf\u5728\u5185\u5b58\u4e2d\u662f\u8fde\u7eed\u5b58\u50a8\u7684\uff0c\u5b57\u7b26\u4e32\u5e38\u91cf\u5728\u5185\u5b58\u4e2d\u7684\u5b58\u50a8\u5f62\u5f0f\u662f\u5b57\u7b26\u6570\u7ec4\u7684\u5f62\u5f0f\uff0c\u5b57\u7b26\u4e32\u5e38\u91cf\u5728\u5185\u5b58\u4e2d\u662f\u8fde\u7eed\u5b58\u50a8\u7684\uff0c\u5b57\u7b26\u4e32\u5e38\u91cf\u5728\u5185\u5b58\u4e2d\u7684\u5b58\u50a8\u5f62\u5f0f\u662f\u5b57\u7b26\u6570\u7ec4\u7684\u5f62\u5f0f

char *p = \"hello\";\nchar a[] = \"hello\";\nchar b[] = {'h', 'e', 'l', 'l', 'o', '\\0'};\n
"},{"location":"programming/24fall/lec6/","title":"\u7b2c\u516d\u8bb2\uff1a\u671f\u672b\u590d\u4e60\uff08\u4e0b\uff09","text":""},{"location":"programming/24fall/lec6/#_2","title":"\u6307\u9488","text":""},{"location":"programming/24fall/lec6/#_3","title":"\u5f62\u8c61\u7406\u89e3","text":""},{"location":"programming/24fall/lec6/#_4","title":"\u6307\u9488\u7684\u58f0\u660e","text":"
int *p, q;\n

\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c \u7528\u4e8e\u4fee\u9970 p \u53d8\u91cf\uff0c\u4f7f\u5176\u6210\u4e3a int \u6307\u9488\u7c7b\u578b \u7684\u53d8\u91cf\uff1b\u4f46\u662f\u53d8\u91cf q \u5e76\u6ca1\u6709\u88ab * \u4fee\u9970\uff0c\u6240\u4ee5\u5176\u8fd8\u662f int \u7c7b\u578b* \u7684\u53d8\u91cf\u3002

"},{"location":"programming/24fall/lec6/#_5","title":"\u6307\u9488\u7684\u8d4b\u503c","text":"
int a = 10;\nint *p, *q = &a;\np = &a;\n*p = 20;\n
"},{"location":"programming/24fall/lec6/#_6","title":"\u6307\u9488\u7684\u8fd0\u7b97","text":"

\u6307\u9488\u53ef\u4ee5\u8fdb\u884c\u52a0\u51cf\u8fd0\u7b97\uff0c\u5f97\u5230\u7684\u7ed3\u679c\u53ef\u4ee5\u8868\u793a\u5730\u5740\u7684\u5dee\u3002 \u4f46\u6ce8\u610f \uff0c\u6307\u9488\u51cf\u6cd5\u4e2d\u6d89\u53ca\u5230\u7684\u5e38\u6570\u4e0d\u662f\u771f\u6b63\u7684\u5730\u5740\u4e4b\u5dee\uff0c\u800c\u662f \u5730\u5740\u5dee/\u8be5\u7c7b\u578b\u5b57\u8282\u6570 \uff0c\u5982\uff1a

Example1

int a[10];\nint *p = a, *q = &a[1];\nprintf(\"%d\", q - p);\n
\u6700\u540e\u7684\u7ed3\u679c\u4e3a 1\u3002\u867d\u7136 a[1] \u548c a[0] \u4e4b\u95f4\u5730\u5740\u76f8\u5dee\u56db\u4e2a\u5b57\u8282\uff0c\u4f46\u662f\u7a0b\u5e8f\u6700\u540e\u4ecd\u4f1a\u8fd4\u56de 1\u3002

Example2

int a[10] = {1, 2, 3, 4};\nint *p = a;\nprintf(\"%d %d\", *p, *(p + 1));\n
\u6700\u540e\u7684\u8f93\u51fa\u7ed3\u679c\u4e3a 1 2\uff0c\u6240\u4ee5\u53ef\u89c1\uff0cp + 1 \u6307\u5411\u7684\u662f a \u6570\u7ec4\u4e2d\u7684 a[1] \u4f4d\u7f6e\uff0c\u800c\u4e0d\u662f a[0] \u7684\u4e0b\u4e00\u4e2a\u5b57\u8282\u5904\u3002

\u4f8b1.4.1

int a[] = {1, 2, 3, 4, 5};\nint *p = a, *q = &a[2];\nprintf(\"%lu\\n\", q - p);\n
\u4e0a\u8ff0\u4ee3\u7801\u7684\u8fd0\u7b97\u7ed3\u679c\u4e3a\uff1a

Answer: 2

"},{"location":"programming/24fall/lec6/#_7","title":"\u591a\u7ea7\u6307\u9488","text":"

int a = 10;\nint *p = &a;\nint **var = &p;\nprintf(\"%d = %d = %d\", a, *p, **var);\n
\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a \u4e8c\u7ea7\u6307\u9488 var\u3002\u4e8c\u7ea7\u6307\u9488\u53ef\u4ee5\u7406\u89e3\u4e3a \u201c\u6307\u9488\u7684\u6307\u9488\u201c\u3002\u4e00\u7ea7\u6307\u9488\u53ef\u4ee5\u7528\u6765\u5b58\u50a8\u4e00\u822c\u53d8\u91cf\u6216\u5176\u4ed6\u5e38\u91cf\u7684\u5730\u5740\uff0c\u800c\u4e00\u7ea7\u6307\u9488\u540c\u6837\u662f\u53d8\u91cf\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e8c\u7ea7\u6307\u9488\u6765\u5b58\u50a8\u4e00\u7ea7\u6307\u9488\u7684\u5730\u5740\u3002

[!warning] \u6ce8\u610f \u5728\u7a0b\u5e8f\u4e2d\uff0c\u6700\u597d\u4e0d\u8981\u6df7\u7528\u4e0d\u540c\u7ea7\u7684\u6307\u9488\u3002

"},{"location":"programming/24fall/lec6/#_8","title":"\u6570\u7ec4\u548c\u6307\u9488","text":"

\u6570\u7ec4\u540d\u5b9e\u9645\u4e0a\u5c31\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6570\u7ec4\u8868\u793a a[1] \u548c\u6307\u9488\u8868\u793a &(a + 1) \u5b9e\u9645\u4e0a\u6307\u7684\u662f\u540c\u4e00\u4e2a\u4e1c\u897f\uff0c\u4e24\u8005\u4e5f\u53ef\u4ee5\u76f8\u4e92\u8f6c\u5316\u3002 \u6b64\u5916\uff0c\u4e8c\u7ef4\u6570\u7ec4\u7684\u5730\u5740\u5206\u5e03\u548c\u6211\u4eec\u7684\u76f4\u89c2\u611f\u53d7\u5e76\u4e0d\u76f8\u540c\uff0c\u5176\u6709\u4e0b\u9762\u7684\u89c4\u5f8b\uff1a

\u4e8c\u7ef4\u6570\u7ec4

int a[3][2]; 1. \u9996\u5148\u9700\u8981\u77e5\u9053\uff0c\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u7684\u5730\u5740\u662f\u7ebf\u6027\u5206\u5e03\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\uff0ca[0][1] \u7684\u4e0b\u4e00\u4e2a\u5c31\u662f a[1][0] 2. \u5176\u6b21\uff0c\u4e8c\u7ef4\u6570\u7ec4\u662f\u5982\u4f55\u5b9e\u73b0\u4e8c\u7ef4\u5b58\u50a8\u6570\u636e\u7684\u5462\uff1f\u539f\u56e0\u5728\u4e8e\uff1aa \u662f\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\u7684\u6307\u9488\u3002\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0ca \u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a 2 \u7684 int \u6570\u7ec4\u7684\u6307\u9488\uff0c\u6240\u4ee5 a[0] \u6307\u5411\u7b2c\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\uff0ca[1] \u6307\u5411\u7b2c\u4e8c\u4e2a\u4e00\u7ef4\u6570\u7ec4\u3002 3. \u5b9e\u9645\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 *(*(a + i) + j) \u6765\u8868\u793a a[i][j]\u3002\u56e0\u4e3a *(a + i) \u6307\u5411\u7b2c i \u4e2a\u6570\u7ec4\uff08\u5047\u8bbe\u53eb b\uff09\uff0c\u800c\u6211\u4eec\u53ef\u4ee5\u7528 *(b + j) \u6765\u8868\u793a b[j]\u3002 4. \u53e6\u5916\uff0c\u4e8c\u7ef4\u6570\u7ec4\u4e0d\u80fd\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u4e8c\u7ea7\u6307\u9488 \u3002\u6211\u4eec\u4e0d\u80fd\u80a4\u6d45\u7684\u5c06\u4e8c\u7ef4\u6570\u7ec4\u7406\u89e3\u4e3a\u4e8c\u7ea7\u6307\u9488\u3002\u5b9e\u9645\u4e0a\uff0c\u65e0\u8bba\u6211\u4eec\u5b9a\u4e49\u591a\u5c11\u7ef4\u6570\u7ec4\uff0c\u5176\u90fd\u662f\u4e00\u7ea7\u6307\u9488\uff0c\u53ea\u662f\u6307\u5411\u7684\u5143\u7d20\u4e0d\u540c\u800c\u5df2\u3002

\u53e6\u5916\u6ce8\u610f\uff0cint *p[3] \u76f8\u5f53\u4e8e\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6307\u9488\u6570\u7ec4\uff0c\u5176\u5b58\u50a8\u7684\u6570\u636e\u90fd\u662f int \u7c7b\u578b\u6307\u9488\u3002 \u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0c\u5b57\u7b26\u4e32\u76f8\u5f53\u4e8e\u4e00\u4e2a\u4ee5 '\\0' \u7ed3\u5c3e\u7684 char \u7c7b\u578b\u6570\u7ec4\u3002

\u5b57\u7b26\u4e32\u76f8\u5173\u51fd\u6570

\u5934\u6587\u4ef6\uff1a<string.h> strlen: \u8fd4\u56de\u5b57\u7b26\u4e32\u957f\u5ea6\uff08\u4e0d\u5305\u62ec\u672b\u5c3e\u7684 '\\0'\uff09 strcpy: \u5c06 str2 \u76f4\u63a5\u62f7\u8d1d\u5230 str1 \u4e2d\uff08\u62f7\u8d1d\u5185\u5bb9\u4f1a\u5305\u62ec str2 \u672b\u5c3e\u7684 '\\0'\uff09 strcat: \u5c06 str2 \u8ffd\u52a0\u5230 str1 \u7684\u672b\u5c3e\uff08\u4ece str1 \u7684 '\\0' \u5904\u5f00\u59cb\u8ffd\u52a0\uff09 strcmp: \u5bf9\u4e24\u4e2a\u5b57\u7b26\u4e32\u505a\u5dee\uff0c\u8fd4\u56de\u5dee\u503c\uff08\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\uff09 strncpy strncat strncmp

\u4f8b1.6.1

Answer: A

\u4f8b1.6.2

char str1[20] = \"1234567890123\";\nchar str2[20] = \"hello\";\nstrcpy(str1, str2);\nint l = strlen(str1);\nprintf(\"%d %s\\n\", l, str1);\nfor(int i = 0; i < 10; ++ i)\n{\n    printf(\"%c\", str1[i]);\n}\n
\u6700\u540e\u7684\u8f93\u51fa\u7ed3\u679c\u4e3a\u4ec0\u4e48\uff1f

Answer: 5 hello hello7890

\u4f8b1.6.3

int a[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9);\nprintf(\"%d\\n\", a[-1][5]);\n
\u8fd0\u884c\u7ed3\u679c\u4e3a\uff1f

Answer: 3

\u4f8b1.6.4

\u7ed9\u51fa\uff1a char s[2][3] = {\"ab\", \"cd\"}, *p = (char *)s; \u4e0b\u9762\u54ea\u4e00\u9879\u662f\u6b63\u786e\u4e14\u548c s[1][1] \u7684\u503c\u76f8\u7b49\uff1f A. *(s + 3) B. *s + 2 C. p[1][1] D. *++p + 2

Answer: D

\u4f8b1.6.5

char *week[]={\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"}, **pw=week;\nchar c1, c2;\nc1 = (*++pw)[1];\nc2 = *++pw[1];\nprintf(\"%c %c\\n\", c1, c2);\n
\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a

Answer: u e

"},{"location":"programming/24fall/lec6/#_9","title":"\u7a7a\u6307\u9488\u548c\u91ce\u6307\u9488","text":"

\u5728\u7a0b\u5e8f\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 0 \u6216 NULL \u6765\u8868\u793a\u4e00\u4e2a\u7a7a\u6307\u9488\uff0c\u5f53\u4e00\u4e2a\u6307\u9488\u662f\u7a7a\u6307\u9488\u65f6\uff0c\u6211\u4eec\u65e0\u6cd5\u4f7f\u7528 * \u6765\u5bf9\u8be5\u6307\u9488\u8fdb\u884c\u8bfb\u53d6\uff0c\u4f1a\u51fa\u73b0\u6bb5\u9519\u8bef\u3002 \u56e0\u6b64\uff0c\u7a7a\u6307\u9488\u5728\u521d\u59cb\u5316\u548c\u5f02\u5e38\u60c5\u51b5\u5904\u7406\u65f6\u975e\u5e38\u91cd\u8981\u3002 \u7528\u6765\u5904\u7406\u4ec0\u4e48\u5f02\u5e38\u60c5\u51b5\u5462\uff1f

\u91ce\u6307\u9488

\u5f53\u6211\u4eec\u5199

int *p\n*p = 10;\n
\u7f16\u8bd1\u5668\u5c31\u4f1a\u62a5\u9519\u3002\u8fd9\u662f\u56e0\u4e3a\u6211\u4eec\u8fd9\u91cc\u7684 p \u662f\u4e00\u4e2a \u91ce\u6307\u9488\u3002

\u7c7b\u4f3c\u4e0a\u9762\u7684\u4f8b\u5b50\uff0c\u5f53\u6211\u4eec\u5199 int *p \u65f6\uff0c\u6211\u4eec\u5e76\u6ca1\u6709\u7ed9\u8fd9\u4e2a\u6307\u9488 p \u8fdb\u884c\u5730\u5740\u7684\u8d4b\u503c\u3002\u8fd9\u4e5f\u5c31\u8bf4\u660e\uff0c\u6211\u4eec\u5e76\u6ca1\u6709\u7ed9 p \u4e00\u4e2a\u771f\u6b63\u7684\u7a7a\u95f4\uff0c\u800c\u662f\u8ba9\u8fd9\u4e2a\u6307\u9488\u4e71\u6307\uff08\u663e\u7136\uff0c\u8fd9\u662f 100% \u4e0d\u5b89\u5168\u7684\uff09\uff0c\u8fd9\u5c31\u662f\u91ce\u6307\u9488\u3002\u6b64\u65f6\u82e5\u6211\u4eec\u5bf9 p \u8fdb\u884c\u53d6\u6570\u636e\u64cd\u4f5c\uff0c\u81ea\u7136\u4f1a\u5f97\u5230\u7f16\u8bd1\u5668\u7684\u62a5\u9519\u3002 \u91ce\u6307\u9488\u4e5f\u662f\u521d\u5b66\u8005\u5199\u76f8\u5173\u7a0b\u5e8f\u6700\u5bb9\u6613\u72af\u7684\u9519\u8bef\uff08\u5305\u62ec\u6211\uff09\u3002\u56e0\u6b64\uff0c\u5bf9\u6307\u9488\u8fdb\u884c\u521d\u59cb\u5316\uff0c\u9632\u6b62\u6307\u9488\u4e71\u6307\u5c31\u53d8\u5f97\u975e\u5e38\u6709\u5fc5\u8981\u4e86\u3002

\u4f8b1.7.1

\u7ed9\u51fa char *s, str[10]\uff0c\u4e0b\u5217\u9009\u9879\u4e2d\u8868\u8fbe\u5b8c\u5168\u6b63\u786e\u7684\u662f\uff1a A. strcpy(s, \"hello\"); B. str = \"hello\" + 1; C. s = *&(str + 1); D. s = str + 1

Answer: D

"},{"location":"programming/24fall/lec6/#_10","title":"\u51fd\u6570\u6307\u9488*","text":"

\u5f88\u5c11\u6d89\u53ca\uff0c\u5177\u4f53\u5185\u5bb9\u53ef\u4ee5\u67e5\u770b\u8f85\u5b66\u7f51\u7ad9\u3002

"},{"location":"programming/24fall/lec6/#_11","title":"\u5f62\u53c2\u548c\u5b9e\u53c2","text":"

\u5b9e\u53c2

\u5b9e\u9645\u53c2\u6570\u3002\u5176\u53ef\u4ee5\u662f\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u8868\u8fbe\u5f0f\u7b49\u7b49\uff0c\u5728\u51fd\u6570\u8c03\u7528\u65f6\uff0c\u5b9e\u53c2\u5c06\u5177\u4f53\u7684\u503c\u4f20\u9012\u7ed9\u51fd\u6570\u3002

int a = 10;//\u8fd9\u662f\u5b9e\u53c2\nint b = 20;//\u8fd9\u4e5f\u662f\u5b9e\u53c2\n

\u5f62\u53c2

\u5f62\u5f0f\u53c2\u6570\u3002\u5176\u4e0d\u662f\u771f\u5b9e\u5b58\u5728\u7684\u53d8\u91cf\uff0c\u800c\u662f\u7528\u6765\u63a5\u6536\u8c03\u7528\u51fd\u6570\u65f6\u4f20\u5165\u7684\u53c2\u6570\u800c\u8bbe\u7f6e\u7684\u53d8\u91cf\u3002 ``` int max(int a, int b)//\u8fd9\u91cc\u7684 a, b \u90fd\u662f\u5f62\u53c2 { return (a > b ? a : b); }

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5f53\u6211\u4eec\u4f7f\u7528\u5b9e\u53c2\u5c06\u6570\u636e\u4f20\u5230\u51fd\u6570\u5185\u90e8\u4e4b\u540e\uff0c\u6211\u4eec\u5728\u51fd\u6570\u5185\u4f7f\u7528\u7684\u53d8\u91cf\u5c31\u4e0d\u662f\u539f\u6765\u7684\u53d8\u91cf\u4e86\uff0c\u800c\u662f\u4e3a\u4e86\u5728\u51fd\u6570\u5185\u4fdd\u5b58\u8fd9\u4e9b\u6570\u636e\u800c\u81ea\u52a8\u8bbe\u7f6e\u7684\u5f62\u53c2\u3002\u6240\u4ee5\uff0c\u5f53\u6211\u4eec\u5728\u51fd\u6570\u5185\u5bf9\u5f62\u53c2\u8fdb\u884c\u8fd0\u7b97\u65f6\uff0c\u5e76\u4e0d\u4f1a\u5bf9\u539f\u6765\u7684\u5b9e\u53c2\u4ea7\u751f\u4efb\u4f55\u5f71\u54cd \u3002 \u8ba9\u6211\u4eec\u6765\u770b\u4e0b\u9762\u7684\u4f8b\u5b50\uff1a

void swap(int a, int b)\n{\n    int t = a;\n    a = b;\n    b = t;\n    return ;\n}\nint main()\n{\n    int a = 10, b = 20;\n    printf(\"%d %d\\n\", a, b);\n    swap(a, b);\n    printf(\"%d %d\", a, b);\n}\n

\u5f53\u6211\u4eec\u8fd0\u884c\u4e4b\u540e\uff0c\u4f1a\u53d1\u73b0\uff1a\u4e0a\u4e0b\u4e24\u884c\u7684\u8f93\u51fa\u7ed3\u679c\u6ca1\u6709\u4efb\u4f55\u6539\u53d8\u3002\u800c\u539f\u56e0\u5c31\u662f\u4e0a\u9762\u63d0\u5230\u7684\u5f62\u53c2\u548c\u5b9e\u53c2\u3002 \u90a3\u4e48\u6211\u4eec\u5e94\u8be5\u5982\u4f55\u81ea\u5df1\u5b9e\u73b0 swap \u529f\u80fd\u5462\uff1f\u53ef\u4ee5\u4f7f\u7528\u6307\u9488\u6765\u89e3\u51b3\u3002

Solution

void swap(int *a, int *b)\n{\n    int t = *a;\n    *a = *b;\n    *b = t;\n    return ;\n}\nint main()\n{\n    int a = 10, b = 20;\n    printf(\"%d %d\\n\", a, b);\n    swap(&a, &b);\n    printf(\"%d %d\", a, b);\n}\n

\u5982\u4e0a\uff0c\u6211\u4eec\u5728 swap \u51fd\u6570\u4e2d\u4f7f\u7528\u6307\u9488\u6765\u8fdb\u884c\u4ea4\u6362\u3002\u6b64\u65f6\uff0c\u7531\u4e8e\u6211\u4eec\u4ea4\u6362\u65f6\u4f7f\u7528\u7684\u662f\u6307\u9488\u5b58\u50a8\u5730\u5740\u6240\u4ee3\u8868\u7684\u6570\u636e\uff0c\u800c\u51fd\u6570\u4f20\u9012\u6307\u9488\u53c2\u6570\u65f6\uff0c\u8fd9\u4e2a\u5730\u5740\u4f5c\u4e3a\u88ab\u4f20\u9012\u7684\u6570\u636e\u662f\u4e0d\u4f1a\u6539\u53d8\u7684\uff08\u8fd9\u91cc\u7684\u5f62\u53c2\u662f swap \u5185\u7684\u6307\u9488\u53d8\u91cf a\u3001b\uff09\u6240\u4ee5\u6211\u4eec\u5728\u4ea4\u6362\u65f6\u53ef\u4ee5\u76f4\u63a5\u5f71\u54cd\u5230\u4e3b\u51fd\u6570\u4e2d\u7684\u53d8\u91cf a\u3001b\uff0c\u4ece\u800c\u5b9e\u73b0\u6211\u4eec\u7684\u76ee\u7684\u3002 \u6240\u4ee5\uff0c\u5f53\u6211\u4eec\u9700\u8981\u5728\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u5f71\u54cd\u5230\u539f\u51fd\u6570\u7684\u53d8\u91cf\u65f6\uff0c\u53ef\u4ee5\u5c06\u4f20\u9012\u7684\u53c2\u6570\u6539\u4e3a\u53d8\u91cf\u7684\u6307\u9488\u800c\u4e0d\u662f\u539f\u6765\u7684\u53d8\u91cf \u3002

"},{"location":"programming/24fall/lec6/#linked-list","title":"\u94fe\u8868 Linked-List","text":""},{"location":"programming/24fall/lec6/#_12","title":"\u7ed3\u6784","text":"

\u5927\u6982\u7684\u7ed3\u6784\u5982\u4e0b\uff1a

\u5176\u4e2d\uff0c\u5176\u4e2d\u6bcf\u4e00\u4e2a\u70b9\u90fd\u662f\u4e00\u4e2a\u7ed3\u6784\u4f53\uff0c\u524d\u540e\u4e24\u4e2a\u8282\u70b9\u4f7f\u7528\u6307\u9488\u76f8\u8fde\u63a5\u3002 \u6700\u57fa\u672c\u7684\u94fe\u8868\u5927\u6982\u662f\u4e0b\u9762\u8fd9\u4e2a\u6837\u5b50\uff1a

typedef struct List_Node* Node\nstruct List_Node{\n    Element_type data;\n    Node next;\n};\n

"},{"location":"programming/24fall/lec6/#_13","title":"\u8bb2\u70b9\u57fa\u7840\u77e5\u8bc6","text":""},{"location":"programming/24fall/lec6/#_14","title":"\u7ed3\u6784\u4f53\u6307\u9488","text":"

\u6bd4\u5982\u6211\u4eec\u73b0\u5728\u5b9a\u4e49\u4e86\u4ee5\u4e0b\u7ed3\u6784\u4f53\u548c\u5176\u6307\u9488\uff1a

struct course{\n    char name[100];\n    float credit;\n    int score;\n    float point;\n}A;\nint main()\n{\n    struct course* p = &A;\n    return 0;\n}\n
\u90a3\u4e48\u5f53\u6211\u4eec\u9700\u8981\u5bf9 A \u8fdb\u884c\u8d4b\u503c\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a
A.name = \"FDS\";\nA.credit = 2.5;\n
\u800c\u82e5\u89c4\u5b9a\u6211\u4eec\u4e0d\u4f7f\u7528 A \u8fdb\u884c\u8d4b\u503c\uff0c\u4f7f\u7528\u6307\u9488 p \u4ee3\u66ff A \u8fdb\u884c\u8d4b\u503c\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u9700\u8981\u8fd9\u6837\u5199\uff1a
p -> name = \"FDS\";//\u5f53\u7136\uff0c\u4e5f\u53ef\u4ee5\u5199 (*p).name = \"FDS\"\np -> credit = 2.5;\n

Tip

\u5f53\u6211\u4eec\u4f7f\u7528\u6307\u9488\u6765\u63cf\u8ff0\u7ed3\u6784\u4f53\u65f6\uff0c\u9700\u8981\u4f7f\u7528 '->' \u7b26\u53f7\u800c\u4e0d\u662f '.' \u7b26\u53f7\u3002

"},{"location":"programming/24fall/lec6/#_15","title":"\u5185\u5b58\u5206\u914d\u4e0e\u91ca\u653e","text":"

\u5728\u5b9e\u9645\u4f7f\u7528\u65f6\uff0c\u6211\u4eec\u901a\u5e38\u90fd\u9700\u8981\u8ba9\u4e00\u4e2a\u7ed3\u6784\u4f53\u6307\u9488\u6307\u5411\u4e00\u4e2a\u5b9e\u9645\u6709\u5185\u5b58\u7684\u7ed3\u6784\u4f53\uff08\u4e5f\u5c31\u662f\u8ba9 p \u6307\u5411 A\uff09\u3002\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u662f\u5148\u5b9a\u4e49\u4e86\u7ed3\u6784\u4f53 A\uff0c\u7136\u540e\u518d\u8bbe\u4e86\u4e00\u4e2a\u7ed3\u6784\u4f53\u6307\u9488\u6307\u5411 A\u3002\u90a3\u4e48\u80fd\u5426\u6709\u4e00\u4e2a\u66f4\u7b80\u4fbf\u7684\u505a\u6cd5\u5462\uff1f\\

\u5c0f\u5fc3\u91ce\u6307\u9488

\u6ce8\u610f\uff0c\u5343\u4e07\u4e0d\u8981\u5b9a\u4e49\u4e00\u4e2a\u7ed3\u6784\u4f53\u6307\u9488 p \u540e\u5c31\u76f4\u63a5\u8fdb\u884c\u76f8\u5173\u8d4b\u503c\u3002\u56e0\u4e3a\u6b64\u65f6\u6211\u4eec\u8fd8\u6ca1\u6709\u7ed9\u6307\u9488 p \u5206\u914d\u4e00\u4e2a\u786e\u5b9a\u7684\u7a7a\u95f4\uff0c\u53ef\u4ee5\u7406\u89e3\u6210 p \u6307\u5411\u4e86\u4e00\u4e2a\u865a\u65e0\u7f25\u7f08\u7684\u5730\u65b9\uff0c\u662f\u4e00\u4e2a \u91ce\u6307\u9488 \u3002

\u6b64\u65f6\uff0c\u5c31\u9700\u8981 malloc \u51fd\u6570 \u4e86\u3002\u5176\u7528\u6cd5\u5982\u4e0b\uff1a

malloc

#include <stdlib.h>\nvoid* malloc (size_t size);\n

malloc \u51fd\u6570\u7684\u53c2\u6570\u4e3a size\uff0c\u5176\u662f\u4e00\u4e2a\u65e0\u7b26\u53f7\u6574\u578b\uff0c\u8868\u793a\u9700\u8981\u7533\u8bf7\u7684\u7a7a\u95f4\u5927\u5c0f\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u501f\u52a9 sizeof \u6765\u7b80\u5355\u6613\u61c2\u7684\u8868\u793a\u8fd9\u4e2a\u53c2\u6570\u3002 malloc \u51fd\u6570\u7684\u8fd4\u56de\u503c\u662f void \u4e5f\u5c31\u662f\u65e0\u7c7b\u578b\u6307\u9488\uff0c\u5f53\u6211\u4eec\u7ed9\u4e00\u4e2a\u6307\u9488\u7528 malloc \u7533\u8bf7\u7a7a\u95f4\u65f6\uff0c\u9700\u8981\u5728 malloc \u524d\u9762\u4f7f\u7528\u5176\u4ed6\u6307\u9488\u7c7b\u578b\u5f3a\u5236\u8f6c\u6362\u3002\u82e5 malloc \u51fd\u6570\u7533\u8bf7\u7a7a\u95f4\u5931\u8d25\uff0c\u5176\u4f1a\u8fd4\u56de NULL \u7a7a\u6307\u9488\uff0c\u6b64\u65f6\u4e00\u5b9a\u8981\u6ce8\u610f\u68c0\u67e5\u3002 \u6ce8\u610f\uff1a* \u4f7f\u7528 malloc \u51fd\u6570\u7533\u8bf7\u7a7a\u95f4\u4e4b\u540e\uff0c\u8fd9\u5757\u7a7a\u95f4\u91cc\u9762\u6709\u4ec0\u4e48\u5185\u5bb9\u662f\u4e0d\u786e\u5b9a\u7684\uff0c\u6240\u4ee5\u5728\u4f7f\u7528\u4e4b\u524d\u4e00\u5b9a\u8981\u5bf9\u8fd9\u4e9b\u5185\u5b58\u8fdb\u884c\u521d\u59cb\u5316\u3002 \u4e3e\u4e2a\u6817\u5b50\uff1a

Example

\u5bf9\u4e0a\u9762\u7684\u4f8b\u5b50\u6765\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u5199\u4ee5\u4e0b\u4ee3\u7801\uff1a

struct course{\n    char name[100];\n    float credit;\n    int score;\n    float point;\n};\nint main()\n{\n    struct course* p = (struct course*)malloc(sizeof(struct course));\n    memset(p -> name, 0, sizeof(p -> name));\n    p -> credit = 0;\n    p -> score = 0;\n    p -> point = 0;\n    return 0;\n}\n

\u6b64\u5916\uff0c\u7531\u4e8e\u6307\u9488 p \u6307\u5411\u7684\u7a7a\u95f4\u662f\u6211\u4eec\u4f7f\u7528 malloc \u51fd\u6570\u5411\u7535\u8111\u7533\u8bf7\u7684\uff0c\u5f53\u6211\u4eec\u4e0d\u518d\u9700\u8981\u4f7f\u7528\u8fd9\u5757\u5185\u5b58\u540e\uff0c\u9700\u8981\u5c06\u8fd9\u5757\u5185\u5b58 \u201c\u8fd8\u7ed9\u201d \u7535\u8111\uff0c\u6b64\u65f6\u9700\u8981\u4f7f\u7528 free \u51fd\u6570 \u3002

free

\u4f7f\u7528 free(\u6307\u9488) \u5373\u53ef\u3002

"},{"location":"programming/24fall/lec6/#_16","title":"\u521d\u59cb\u5316","text":"

\u5f53\u6211\u4eec\u9700\u8981\u65b0\u5efa\u4e00\u4e2a\u94fe\u8868\u65f6\uff0c\u4e00\u822c\u90fd\u662f\u5148\u5b9a\u4e49\u4e00\u4e2a\u5934\u8282\u70b9\uff0c\u5c06\u5176\u521d\u59cb\u5316\u4e3a\u7a7a\u6307\u9488 NULL\u3002\u53ea\u6709\u5f53\u6211\u4eec\u9700\u8981\u5f80\u91cc\u9762\u585e\u5185\u5bb9\u65f6\uff0c\u6211\u4eec\u624d\u5411\u7535\u8111\u7533\u8bf7\u7a7a\u95f4\u5e76\u521d\u59cb\u5316\u3001\u8d4b\u503c\u7b49\u3002

"},{"location":"programming/24fall/lec6/#_17","title":"\u94fe\u8868\u7684\u904d\u5386","text":"

\u5bf9\u4e8e\u4e00\u4e2a\u6570\u7ec4\u800c\u8a00\uff0c\u6211\u4eec\u60f3\u8bbf\u95ee\u8fd9\u4e2a\u6570\u7ec4\u4ec0\u4e48\u5730\u65b9\u5c31\u53ef\u4ee5\u8bbf\u95ee\u4ec0\u4e48\u5730\u65b9\uff0c\u53ea\u9700\u8981\u9009\u5bf9\u4e0b\u6807\u5c31\u53ef\u4ee5\u3002\u6bd4\u5982\u8bbf\u95ee\u6570\u7ec4\u7684\u5f00\u5934\uff1aa[0]\uff1b\u8bbf\u95ee\u6570\u7ec4\u7684\u7b2c\u4e94\u4e2a\u4f4d\u7f6e\uff1aa[4]\uff1b\u8bbf\u95ee\u6570\u7ec4\u672b\u5c3e\uff08\u5047\u8bbe\u6570\u7ec4\u6709 10 \u4e2a\u4f4d\u7f6e\uff09\uff1aa[9]\u3002 \u4f46\u662f\u5bf9\u94fe\u8868\u800c\u8a00\uff0c\u8fd9\u6837\u7684\u64cd\u4f5c\u662f\u65e0\u6cd5\u5b9e\u73b0\u7684\u3002\u5f53\u6211\u4eec\u9700\u8981\u8bbf\u95ee\u94fe\u8868\u672b\u5c3e\u7684\u6570\u636e\u65f6\uff0c\u53ea\u80fd\u4ece\u94fe\u8868\u7684\u5934\u8282\u70b9\u5f00\u59cb\uff0c\u4e00\u76f4\u6cbf\u7740\u6307\u9488\u5f80\u4e0b\u627e\uff0c\u76f4\u5230\u627e\u5230\u6700\u540e\u7684\u4f4d\u7f6e\u4e3a\u6b62\u3002\u56e0\u6b64\uff0c\u5728\u94fe\u8868\u4e2d\u8bbf\u95ee\u6570\u636e\u975e\u5e38\u6d88\u8017\u65f6\u95f4\u3002

"},{"location":"programming/24fall/lec6/#_18","title":"\u54e8\u5175\u8282\u70b9","text":"

\u6216\u8005\u53ef\u4ee5\u53eb\u505a \u201d\u50f5\u5c38\u8282\u70b9\u201c\u3002 \u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u4e00\u4e2a\u94fe\u8868\u4e0d\u4f1a\u4ece\u5934\u8282\u70b9\u5f00\u59cb\u5c31\u5b58\u50a8\u6570\u636e\uff0c\u800c\u662f\u4f7f\u7528\u4e00\u4e2a\u4e0d\u5b58\u50a8\u6570\u636e\u7684\u7a7a\u767d\u8282\u70b9\u5f53\u4f5c\u5934\u8282\u70b9\uff0c\u5176\u540e\u9762\u4f7f\u7528\u6307\u9488\u8fde\u63a5\u5176\u4ed6\u5b58\u6709\u6570\u636e\u7684\u8282\u70b9\u3002\u8fd9\u6837\u7684\u7a7a\u767d\u8282\u70b9\u53eb \u54e8\u5175\u8282\u70b9 \u3002

"},{"location":"programming/24fall/lec6/#_19","title":"\u94fe\u8868\u7684\u5176\u4ed6\u5f62\u5f0f","text":"

\u9664\u4e86\u6211\u4eec\u4e00\u5f00\u59cb\u63d0\u5230\u7684 \u201c\u5355\u5411\u94fe\u8868\u201d\uff0c\u94fe\u8868\u8fd8\u6709\u5176\u4ed6\u51e0\u79cd\u5f62\u5f0f\uff0c\u5982 \u201d\u53cc\u5411\u94fe\u8868\u201c\u3001\u201d\u5faa\u73af\u5355\u5411\u94fe\u8868\u201c\u3001\u201d\u5faa\u73af\u53cc\u5411\u94fe\u8868\u201c \u7b49\u3002

\u4f8b2.3.1

\u4f7f\u7528\u73af\u5f62\u94fe\u8868\u6a21\u4eff\u7ea6\u745f\u592b\u95ee\u9898\u3002

"},{"location":"programming/24fall/lec6/#_20","title":"\u94fe\u8868\u7684\u57fa\u672c\u64cd\u4f5c","text":"

\u4ee5\u4e0b\u90fd\u662f\u4ee5\u5355\u5411\u94fe\u8868\u4e3a\u4f8b\u3002

"},{"location":"programming/24fall/lec6/#_21","title":"\u589e","text":"

\u5f53\u6211\u4eec\u9700\u8981\u5f80\u91cc\u9762\u589e\u52a0\u4e00\u4e2a\u8282\u70b9\u65f6\uff0c\u9996\u5148\u6211\u4eec\u9700\u8981\u60f3\u529e\u6cd5\u76f4\u5230\u63d2\u5165\u8282\u70b9\u7684\u4f4d\u7f6e\uff0c\u4e5f\u5c31\u662f\u9700\u8981\u76f4\u5230\u5f85\u63d2\u5165\u8282\u70b9\u7684\u524d\u9a71\u8282\u70b9\u662f\u4ec0\u4e48\u3002 \u5f53\u6211\u4eec\u5f97\u5230\u524d\u9a71\u8282\u70b9\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u8fdb\u884c\u63d2\u5165\u4e86\u3002\u6bd4\u5982\u6211\u4eec\u7684\u524d\u9a71\u8282\u70b9\u4e3a front\uff0c\u5f85\u63d2\u5165\u8282\u70b9\u4e3a p\uff0cf \u539f\u6765\u7684\u540e\u9a71\u8282\u70b9\u4e3a back\uff1a

\u8282\u70b9 p \u8d4b\u503c\nNode back = front -> next;//\u5c06 front \u7684\u540e\u9a71\u8282\u70b9 back \u8bb0\u5f55\u4e0b\u6765\uff0c\u65b9\u4fbf\u540e\u7eed\u64cd\u4f5c\nfront -> next = p;//\u5c06 front \u7684\u540e\u9a71\u8282\u70b9\u6539\u4e3a p\np -> next = back;//\u5c06 p \u7684\u540e\u9a71\u8282\u70b9\u8d4b\u503c\u4e3a back\n

"},{"location":"programming/24fall/lec6/#_22","title":"\u5220","text":"

\u5f53\u6211\u4eec\u9700\u8981\u5220\u9664\u4e00\u4e2a\u8282\u70b9\u65f6\uff0c\u9996\u5148\u4e5f\u662f\u9700\u8981\u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\u7684\u4f4d\u7f6e\u3002\u5728\u627e\u7684\u540c\u65f6\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u4e00\u8d77\u8bb0\u5f55\u5f53\u524d\u70b9\u7684\u524d\u9a71\u8282\u70b9\u662f\u4ec0\u4e48\u3002 \u5f53\u5f85\u5220\u9664\u70b9\u627e\u5230\u4e4b\u540e\uff0c\u5047\u8bbe\u4e3a p\uff0c\u5176\u524d\u9a71\u8282\u70b9\u4e3a front\uff0cp \u7684\u540e\u9a71\u8282\u70b9\u4e3a back\uff1a

front -> next = p -> next;//\u5c06 front \u7684\u540e\u9a71\u8282\u70b9\u6539\u4e3a back\uff0c\u8fd9\u91cc\u7701\u7565\u4e86\u8bb0\u5f55 back \u7684\u8fc7\u7a0b\nfree(p);//\u8bb0\u5f97\u5c06 p \u7684\u7a7a\u95f4\u91ca\u653e\u6389\n

"},{"location":"programming/24fall/lec6/#_23","title":"\u6539","text":"

\u5f53\u6211\u4eec\u9700\u8981\u6539\u53d8\u4e00\u4e2a\u8282\u70b9\u4e2d\u7684\u6570\u636e\u65f6\uff0c\u53ea\u9700\u8981\u5148\u627e\u5230\u8fd9\u4e2a\u8282\u70b9\u7684\u4f4d\u7f6e\uff0c\u7136\u540e\u5bf9\u5176\u6570\u636e\u8fdb\u884c\u4fee\u6539\u5373\u53ef\u3002

"},{"location":"programming/24fall/lec6/#_24","title":"\u67e5","text":"

\u524d\u9762\u4e09\u4e2a\u64cd\u4f5c\u90fd\u662f\u5efa\u7acb\u5728\u67e5\u7684\u57fa\u7840\u4e0a\u3002\u5f53\u6211\u4eec\u9700\u8981\u5728\u94fe\u8868\u4e2d\u67e5\u4e00\u4e2a\u70b9\u65f6\uff0c\u6211\u4eec\u9700\u8981\u4ece\u5934\u8282\u70b9\u5f00\u59cb\u4e00\u76f4\u5f80\u4e0b\u627e\uff0c\u76f4\u5230\u627e\u5230\u7b26\u5408\u8981\u6c42\u7684\u70b9\u4e3a\u6b62\u3002 \u5047\u8bbe\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u51fd\u6570 int check(Node p) \u7528\u6765\u68c0\u9a8c\u8be5\u8282\u70b9\u662f\u5426\u662f\u6211\u4eec\u9700\u8981\u627e\u7684\u8282\u70b9\uff08\u7b26\u5408\u8981\u6c42\u5219\u8fd4\u56de 1\uff09\uff0c\u5e76\u5047\u8bbe\u5934\u8282\u70b9\u4e3a\u54e8\u5175\u8282\u70b9\uff1a

Node find(Node head)\n{\n    int p = head -> next;//\u4ece\u7b2c\u4e00\u4e2a\u5b58\u6709\u6570\u636e\u7684\u8282\u70b9\u5f00\u59cb\u627e\n    while(p != NULL)//\u4e00\u76f4\u627e\u5230\u6574\u4e2a\u94fe\u8868\u5168\u90e8\u904d\u5386\u5b8c\u4e3a\u6b62\n    {\n        if(check(p))\n        {\n            return p;//\u82e5\u627e\u5230\u7b26\u5408\u8981\u6c42\u7684\u8282\u70b9\uff0c\u5c31\u8fd4\u56de\u8fd9\u4e2a\u70b9\uff0c\u540c\u65f6\u7ed3\u675f\u7a0b\u5e8f\n        }\n        p = p -> next;//\u5982\u679c\u7a0b\u5e8f\u6267\u884c\u5230\u8fd9\u91cc\uff0c\u8bf4\u660e\u524d\u9762\u6ca1\u627e\u5230\u3002\u6b64\u65f6\u66f4\u65b0 p\uff0c\u8ba9\u5176\u53d8\u6210\u4e0b\u4e00\u4e2a\u70b9\uff0c\u7ee7\u7eed\u5bfb\u627e\n    }\n    return NULL;//\u82e5\u6267\u884c\u5230\u8fd9\u91cc\uff0c\u8bf4\u660e\u904d\u5386\u6574\u4e2a\u94fe\u8868\u90fd\u6ca1\u627e\u5230\u5bf9\u5e94\u7684\u8282\u70b9\u3002\u6b64\u65f6\u76f4\u63a5\u8fd4\u56de NULL\n}\n

"},{"location":"programming/24fall/lec6/#_25","title":"\u8f93\u51fa\u94fe\u8868","text":"

\u82e5\u6211\u4eec\u9700\u8981\u5c06\u6574\u4e2a\u94fe\u8868\u8f93\u51fa\uff0c\u53ea\u9700\u8981\u904d\u5386\u6574\u4e2a\u94fe\u8868\uff0c\u8fb9\u904d\u5386\u8fb9\u6253\u5370\u5373\u53ef\u3002 \u5047\u8bbe\u8be5\u94fe\u8868\u6709\u54e8\u5175\u8282\u70b9\uff0c\u540c\u65f6\u6211\u4eec\u5b9a\u4e49 void print(Node p) \u7528\u6765\u8f93\u51fa\u76f8\u5173\u6570\u636e\u3002

int p = head -> next;//\u4ece\u7b2c\u4e00\u4e2a\u5b58\u6709\u6570\u636e\u7684\u8282\u70b9\u5f00\u59cb\u6253\u5370\nwhile(p != NULL)//\u4e00\u76f4\u6253\u5370\u76f4\u5230\u904d\u5386\u5b8c\u6574\u4e2a\u94fe\u8868\u4e3a\u6b62\n{\n    print(p);//\u6253\u5370\u76f8\u5173\u5185\u5bb9\n    p = p -> next;//\u66f4\u65b0 p\uff0c\u8ba9 p \u53d8\u4e3a\u4e0b\u4e00\u4e2a\u8282\u70b9\u7ee7\u7eed\u6253\u5370\n}\nreturn ;\n

"},{"location":"programming/24fall/lec6/#_26","title":"\u5220\u9664\u94fe\u8868","text":"

\u5f53\u6211\u4eec\u9700\u8981\u5220\u9664\u4e00\u4e2a\u94fe\u8868\u65f6\uff0c\u6211\u4eec\u540c\u6837\u4e5f\u9700\u8981\u904d\u5386\u6574\u4e2a\u94fe\u8868\uff0c\u4e00\u8fb9\u904d\u5386\u4e00\u8fb9\u91ca\u653e\u7a7a\u95f4\u3002 \u5047\u8bbe\u8be5\u94fe\u8868\u6709\u54e8\u5175\u8282\u70b9\uff1a

int p = head;//\u54e8\u5175\u8282\u70b9\u540c\u6837\u9700\u8981\u5220\u9664\nwhile(p != NULL)//\u76f4\u5230\u904d\u5386\u5b8c\u6574\u4e2a\u94fe\u8868\u4e3a\u6b62\n{\n    free(p);//\u91ca\u653e\u7a7a\u95f4\n    p = p -> next;//\u66f4\u65b0 p\n}\nreturn ;\n

"},{"location":"programming/24fall/lec6/#_27","title":"\u7b80\u5355\u4ecb\u7ecd\u4e24\u79cd\u6570\u636e\u7ed3\u6784","text":""},{"location":"programming/24fall/lec6/#stack","title":"\u6808 stack","text":"

\u6808\u6bd4\u8f83\u7c7b\u4f3c\u4e00\u645e\u7897\uff0c\u5f53\u6211\u4eec\u9700\u8981\u62ff\u7897\u6216\u8005\u653e\u7897\u7684\u65f6\u5019\uff0c\u53ea\u80fd\u4ece\u6700\u9876\u4e0a\u5f00\u59cb\u62ff\u6216\u8005\u653e\u3002

\u4f7f\u7528\u6570\u7ec4\u6216\u8005\u94fe\u8868\u90fd\u53ef\u4ee5\u5b9e\u73b0\u6808\u3002

"},{"location":"programming/24fall/lec6/#queue","title":"\u961f\u5217 queue","text":"

\u60f3\u8c61\u8bb8\u591a\u4eba\u6392\u961f\u7ad9\u5728\u72ed\u7a84\u901a\u9053\u5185\u90e8\uff0c\u6b64\u65f6\u4eba\u9700\u8981\u51fa\u53bb\u5c31\u53ea\u80fd\u4ece\u6700\u524d\u9762\u8d70\uff0c\u4eba\u9700\u8981\u8fdb\u6765\u5c31\u53ea\u80fd\u4ece\u6700\u540e\u9762\u8fdb\u3002

\u540c\u6837\u7684\uff0c\u4f7f\u7528\u6570\u7ec4\u6216\u8005\u94fe\u8868\u90fd\u53ef\u4ee5\u5b9e\u73b0\u961f\u5217\u3002

\u4f8b2.5.2.1

Answer: A

"},{"location":"programming/24fall/lec6/#_28","title":"\u591a\u6587\u4ef6\u7f16\u7a0b","text":""},{"location":"programming/24fall/lec6/#_29","title":"\u5b8f","text":"

\u4e0b\u9762\uff0c\u6211\u4eec\u6765\u56de\u987e\u4e00\u4e0b\u5b8f\u5b9a\u4e49\u76f8\u5173\u7684\u77e5\u8bc6\u3002

"},{"location":"programming/24fall/lec6/#_30","title":"\u6700\u57fa\u672c\u7684\u7528\u6cd5\uff1a\u5b9a\u4e49\u4e00\u4e2a\u5e38\u6570","text":"

#define \u7684\u7528\u6cd5\u4e3a\uff1adefine <\u540d\u5b57> <\u503c> \uff0c\u5176\u6700\u540e\u4e0d\u4f7f\u7528\u5206\u53f7\uff0c \u5728\u7a0b\u5e8f\u5f00\u59cb\u7f16\u8bd1\u4e4b\u524d\uff0c\u7f16\u8bd1\u5668\u4f1a\u5c06\u7a0b\u5e8f\u4e2d\u6240\u6709\u8bbe\u8ba1\u5b8f\u5b9a\u4e49\u7684\u91cf\u8fdb\u884c\u66ff\u6362\u3002

"},{"location":"programming/24fall/lec6/#_31","title":"\u4f7f\u7528\u5b8f\u5b9a\u4e49\u7b80\u5355\u51fd\u6570","text":"

\u5b8f\u5b9a\u4e49\u53ef\u4ee5\u4f7f\u7528\u53c2\u6570\uff0c\u5982\uff1a

#define cube(x) ((x) * (x) * (x))\n
\u6b64\u65f6\uff0c\u5c31\u76f8\u5f53\u4e8e\u6211\u4eec\u4f7f\u7528\u5b8f\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u7b97\u7acb\u65b9\u7684\u51fd\u6570\u3002 \u5728\u7f16\u8bd1\u65f6\uff0c\u7f16\u8bd1\u5668\u4f1a\u5c06\u6240\u6709 cube(x) \u66ff\u6362\u4e3a ((x) * (x) * (x)) \uff08\u5176\u4e2d x \u4e3a\u4e00\u4e2a\u53c2\u6570\uff0c\u53ef\u4ee5\u662f 2\u30013.5\u3001a \u7b49\u6570\u5b57\u6216\u53d8\u91cf\uff09\uff0c\u7136\u540e\u8ba1\u7b97\u5f97\u5230\u7ed3\u679c\u3002

\u5f53\u4f7f\u7528\u5b8f\u5b9a\u4e49\u4e00\u4e2a\u6709\u53c2\u6570\u7684\u5f0f\u5b50\u65f6\uff0c\u4e00\u5b9a\u8981\u6ce8\u610f\u52a0\u4e0a\u62ec\u53f7\u3002\u4e0d\u4ec5\u662f\u7ed9\u53c2\u6570\u52a0\u4e0a\u62ec\u53f7\uff0c\u8fd8\u8981\u7ed9\u6574\u4f53\u52a0\u4e0a\u62ec\u53f7\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u9519\u8bef\u3002

#define RADTODEG(x) (x * 57.29) \u5f53\u6211\u4eec\u5199 RADTODEG(4 - 3) \u65f6\uff0c\u7f16\u8bd1\u5668\u4f1a\u66ff\u6362\u4e3a\uff1a4 - 3 * 57.29 \uff0c\u548c\u6211\u4eec\u7684\u76ee\u7684\u76f8\u6096\u3002 #define RADTODEG(x) (x) * 57.29 \u5f53\u6211\u4eec\u5199 4 / RADTODEG(3) \u65f6\uff0c\u7f16\u8bd1\u5668\u4f1a\u66ff\u6362\u4e3a\uff1a4 / 3 * 57.29 \uff0c\u548c\u6211\u4eec\u7684\u76ee\u7684\u4e5f\u76f8\u6096\u3002

\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u53c2\u6570\uff0c\u6784\u9020\u66f4\u591a\u7684\u51fd\u6570\uff1a

#define MAX(a,b) ((a) > (b) ? (a) : (b))\n

"},{"location":"programming/24fall/lec6/#define","title":"\u65e0\u5b9a\u4e49\u503c\u7684 define","text":"

\u6211\u4eec\u53ef\u4ee5\u5728\u6587\u4ef6\u5f00\u59cb\u5199 #define SEARCH \u7c7b\u4f3c\u7684\u5b8f\u5b9a\u4e49\u3002\u8fd9\u7c7b\u5b8f\u5b9a\u4e49\u7684\u4e3b\u8981\u662f\u8d77\u6807\u8bc6\u4f5c\u7528\uff0c\u4e00\u822c\u9700\u8981\u548c #ifdef\u3001#else\u3001#endif \u7b49\u914d\u5408\u4f7f\u7528\u3002 \u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6587\u4ef6\u4e00\u5f00\u59cb\u4f7f\u7528 #define \u5b9a\u4e49\u6807\u8bc6\u7b26\uff0c\u7136\u540e\u4f7f\u7528 #ifdef \u6807\u8bc6\u7b26 \u68c0\u67e5\u524d\u9762\u662f\u5426\u6709\u5b9a\u4e49\u8be5\u6807\u8bc6\u7b26\uff0c\u82e5\u6709\uff0c\u5219\u6267\u884c #ifdef \u540e\u9762\u7684\u7a0b\u5e8f\uff1b\u82e5\u6ca1\u6709\uff0c\u5219\u6267\u884c #else \u540e\u9762\u7684\u7a0b\u5e8f\u3002\u6700\u540e\uff0c\u8bb0\u5f97\u4f7f\u7528 #endif \u505a\u7ed3\u5c3e\u3002

"},{"location":"programming/24fall/lec6/#_32","title":"\u591a\u6587\u4ef6\u7f16\u7a0b","text":"

\u5f53\u6211\u4eec\u6709\u5f88\u591a\u5f88\u591a\u4ee3\u7801\u53ca\u5f88\u591a\u5f88\u591a\u51fd\u6570\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u51fd\u6570\u653e\u5230\u4e0d\u540c\u7684\u6587\u4ef6\u4e2d\u5206\u522b\u7f16\u8bd1\uff0c\u6700\u540e\u518d\u8fde\u63a5\u5230\u4e00\u8d77\u6784\u6210\u4e00\u4e2a\u5927\u7a0b\u5e8f\u3002 \u800c\u8fde\u63a5\u5c31\u9700\u8981\u901a\u8fc7 #include \u5b9a\u4e49\u3002

"},{"location":"programming/24fall/lec6/#_33","title":"\u5feb\u901f\u4e0a\u624b","text":"
  1. \u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5e93\u51fd\u6570\u6587\u4ef6\uff0c\u540e\u7f00\u662f '.h'\u3002
  2. \u5728\u8be5\u6587\u4ef6\u4e2d\uff08\u6211\u4eec\u5047\u8bbe\u53eb 'a.h'\uff09\uff0c\u6211\u4eec\u9700\u8981\u5199\uff1a
    #ifndef \u67d0\u6807\u8bc6\u7b26\n#define \u67d0\u6807\u8bc6\u7b26//\u8fd9\u91cc\u662f\u4e3a\u4e86\u9632\u6b62\u4e4b\u524d\u5df2\u7ecf\u5b9a\u4e49\u8fc7\u8be5\u6807\u8bc6\u7b26\uff0c\u4ece\u800c\u51fa\u73b0\u91cd\u590d\u58f0\u660e\u7684\u9519\u8bef\n\u4f60\u7684\u51fd\u6570\u58f0\u660e\n#endif\n
  3. \u7136\u540e\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a '.c' \u6587\u4ef6\uff0c\u5e76\u5728\u6587\u4ef6\u5f00\u5934\u5199\u4e0a\uff1a
    #include \"a.h\"//\u5f53\u5f15\u5165\u540c\u4e00\u76ee\u5f55\u4e0b\u7684\u5e93\u65f6\uff0c\u6211\u4eec\u4f7f\u7528\u53cc\u5f15\u53f7\uff1b\u82e5\u6211\u4eec\u4f7f\u7528 '<>'\uff0c\u5219\u7f16\u8bd1\u5668\u4f1a\u76f4\u63a5\u53bb\u6307\u5b9a\u76ee\u5f55\u4e0b\u9762\u5bfb\u627e\u5bf9\u5e94\u7684\u5e93\n
  4. \u5e76\u4e14\uff0c\u6211\u4eec\u9700\u8981\u5728\u8be5 'a.c' \u6587\u4ef6\u5185\u5199\u4e0a 'a.h' \u4e2d\u5df2\u58f0\u660e\u51fd\u6570\u7684\u8be6\u7ec6\u4ee3\u7801\u3002
  5. \u6700\u540e\u7684\u6700\u540e\uff0c\u6211\u4eec\u9700\u8981\u5728\u5305\u542b\u4e3b\u51fd\u6570\u7684 '.c' \u6587\u4ef6\u4e2d\u4e5f\u5199\u4e0a #include \"a.h\" \u3002\u8fd9\u6837\uff0c\u5c31\u7b97\u5927\u529f\u544a\u6210\u4e86\u3002
  6. \u6700\u540e\uff0c\u6211\u4eec\u53ea\u9700\u8981\u4f9d\u9760\u4e00\u70b9\u624b\u6bb5\u5c06\u6240\u6709\u6587\u4ef6\u90fd\u7f16\u8bd1\u8fde\u63a5\u5373\u53ef\u3002
"},{"location":"programming/24fall/lec6/#_34","title":"\u539f\u7406\uff1f","text":"

\u6211\u4eec\u53ef\u4ee5\u5c06 #include \u7406\u89e3\u4e3a\u4e00\u4e2a\u63a5\u53e3\uff0c\u5f53\u6211\u4eec\u5728\u4ee3\u7801\u6700\u5f00\u59cb\u5199 #include \u5e76\u7f16\u8bd1\u3001\u8fde\u63a5\u7a0b\u5e8f\u65f6\uff0c\u4f1a\u6839\u636e #include \u540e\u7684\u6587\u4ef6\u5c06\u5bf9\u5e94\u7684\u51fd\u6570\u548c\u6211\u4eec\u81ea\u5df1\u5199\u7684\u51fd\u6570\u653e\u5230\u4e00\u8d77\u3002\u6240\u4ee5\u6211\u4eec\u624d\u53ef\u4ee5\u4f7f\u7528\u672c\u6587\u4ef6\u5b9a\u4e49\u51fd\u6570\u4e4b\u5916\u7684\u5176\u4ed6\u51fd\u6570\u3002 \u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5199\u4e86 #include \"a.h\" \uff0c\u5728\u7f16\u8bd1\u8fde\u63a5\u65f6\uff0c\u7535\u8111\u4f1a\u5c06\u540c\u6837\u63a5\u4e86 #include \"a.h\" \u63a5\u53e3\u7684 'a.c' \u6587\u4ef6\u4e00\u8d77\u653e\u8fdb\u6765\uff0c\u6240\u4ee5\u6211\u4eec\u624d\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u6587\u4ef6\u5b9a\u4e49\u7684\u51fd\u6570\u3002

"},{"location":"programming/24fall/lec6/#static","title":"static \u53d8\u91cf","text":"

\u89c2\u5bdf\u4e0b\u9762\u7684\u4ee3\u7801\uff1a

void function();\nint main()\n{\n    for(int i = 0; i < 5; ++ i)\n    {\n        function();\n    }\n    return 0;\n}\nvoid function()\n{\n    int j = 1;\n    j ++;\n    printf(\"j = %d\\n\", j);\n    return ;\n}\n
\u7a0b\u5e8f\u6267\u884c\u4e4b\u540e\uff0c\u4e0d\u96be\u770b\u51fa\uff0c\u6700\u540e\u7684\u7ed3\u679c\u5c06\u4f1a\u662f 5 \u884c \"j = 2\"\u3002 \u4f46\u662f\u82e5\u6211\u4eec\u5c06 function \u4e2d\u7684 int j = 1 \u6539\u4e3a static int j = 1 \uff0c\u90a3\u4e48\u7ed3\u679c\u5c31\u4f1a\u5927\u5927\u4e0d\u540c\uff1a
void function();\nint main()\n{\n    for(int i = 0; i < 5; ++ i)\n    {\n        function();\n    }\n    return 0;\n}\nvoid function()\n{\n    static int j = 1;\n    j ++;\n    printf(\"j = %d\\n\", j);\n    return ;\n}\n
\u5f97\u5230\u7684\u7ed3\u679c\u5c06\u662f 2\u30013\u30014\u30015\u30016\u3002 \u8fd9\u662f\u56e0\u4e3a\uff0cstatic \u4fee\u9970\u7684 j \u53d8\u91cf\u6539\u53d8\u4e86\u751f\u547d\u5468\u671f\u3002\u539f\u672c j \u5728 function \u51fd\u6570\u7ed3\u675f\u4e4b\u540e\u5c31\u4f1a\u88ab\u6e05\u9664\uff0c\u4e0b\u4e00\u6b21\u6267\u884c function \u65f6\uff0cj \u53d8\u91cf\u4f1a\u88ab\u91cd\u65b0\u5b9a\u4e49\u3002\u4f46\u662f\u82e5\u4f7f\u7528 static \u4fee\u9970 j \u53d8\u91cf\uff0c\u90a3\u4e48\u5728 function \u51fd\u6570\u7ed3\u675f\u4e4b\u540e\uff0cj \u4e0d\u4f1a\u88ab\u6e05\u9664\uff0c\u5176\u503c\u4e5f\u4e0d\u4f1a\u88ab\u6e05\u9664\u3002\u867d\u7136\u5728\u5176\u4ed6\u51fd\u6570\u4e2d\u65e0\u6cd5\u4f7f\u7528\u8fd9\u4e2a j \u53d8\u91cf\uff0c\u4f46\u662f\u5f53\u56de\u5230 function \u51fd\u6570\u4e2d\uff0cj \u4f1a\u5e26\u7740\u4e0a\u4e00\u6b21\u8fd0\u884c\u51fd\u6570\u7559\u4e0b\u7684\u7ed3\u679c\u91cd\u65b0\u53c2\u4e0e\u8fd0\u7b97\u3002

"},{"location":"programming/24fall/lec5.assets/","title":"Index","text":"

lec5 images

"},{"location":"programming/archive/23fall/","title":"\uff0823fall\uff09\u7a0b\u8bbe\u8f85\u5b66\u8bfe\u7a0b \u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u7a0b\u8bbe\u8f85\u5b66\u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057\u7248\u5757 \ud83e\udd17\u3002\u4f60\u53ef\u4ee5\u5728\u5de6\u4fa7\u5bfc\u822a\u680f\u4e2d\u8be6\u7ec6\u6d4f\u89c8\u672c\u6a21\u5757\u7684\u5185\u5bb9\u3002

"},{"location":"programming/archive/23fall/#_1","title":"\u8bfe\u7a0b\u7b80\u4ecb","text":"

\u7a0b\u5e8f\u8bbe\u8ba1\u4e0e\u7b97\u6cd5\u57fa\u7840\u8bfe\u7a0b\u8bb2\u8ff0\u7684\u5185\u5bb9\u5c40\u9650\u4e8e\u8bed\u8a00\u672c\u8eab\uff0c\u8f83\u4e3a\u8868\u8c61\u3002\u7136\u800c\uff0cC \u8bed\u8a00\u5b9e\u8d28\u4e0a\u662f\u4e00\u95e8\u5f88\u96be\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u4e0d\u61c2\u7f16\u8bd1\u539f\u7406\u3001\u64cd\u4f5c\u7cfb\u7edf\u548c\u8ba1\u7b97\u673a\u4f53\u7cfb\u7ed3\u6784\u65e0\u6cd5\u83b7\u5f97\u6df1\u5165\u7684\u7406\u89e3\uff0c\u800c\u8fd9\u4e9b\u4e5f\u662f\u5b66\u4e60\u8ba1\u7b97\u673a\u4e13\u4e1a\u7684\u540c\u5b66\u5e94\u5f53\u5c3d\u65e9\u4e86\u89e3\u7684\u77e5\u8bc6\u3002

\u672c\u8f85\u5b66\u8bfe\u7a0b\u5c06\u7ed3\u5408\u8ba1\u7b97\u673a\u7cfb\u7edf\u65b9\u9762\u7684\u77e5\u8bc6\uff0c\u4e3a\u540c\u5b66\u4eec\u63d0\u4f9b\u6df1\u5165\u7406\u89e3 C \u8bed\u8a00\u7684\u89c6\u89d2\u3002\u6211\u4eec\u7684\u76ee\u7684\u662f\u89e3\u7b54\u7a0b\u5e8f\u8bbe\u8ba1\u4e2d\u8f83\u4e3a\u5e95\u5c42\u7684\u95ee\u9898\uff1a

\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u80fd\u591f\u4e3a\u4f60\u5f00\u542f\u4ece C \u8bed\u8a00\u5230\u8ba1\u7b97\u673a\u79d1\u5b66\u4e0e\u6280\u672f\u7684\u771f\u6b63\u7684\u5927\u95e8\u3002\u5982\u679c\u5bf9\u8bfe\u7a0b\u5185\u5bb9\u6709\u4efb\u4f55\u7591\u95ee\u548c\u5efa\u8bae\uff0c\u6b22\u8fce\u4f60\u8054\u7cfb\u6211\u4eec\u3002\u4f60\u53ef\u4ee5\u5728\u4ed3\u5e93\u4e2d\u53d1\u8d77 issue \u6216\u53d1\u9001\u90ae\u4ef6\u5230 zhubaolin228@gmail.com\u3002

"},{"location":"programming/archive/23fall/#_2","title":"\u8bfe\u7a0b\u5b89\u6392","text":"

2023-2024 \u5b66\u5e74\uff0c\u7a0b\u8bbe\u8f85\u5b66\u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057\u8bfe\u9898\u7ec4\u540c\u5b66\u6709\uff1a

\u8bfe\u7a0b\u5b89\u6392\u5982\u4e0b\uff1a

\u8282\u6b21 \u5185\u5bb9 \u4e3b\u8bb2 \u65f6\u95f4 \u5730\u70b9 PPT \u4e0e\u8bb2\u4e49 \u76f4\u64ad\u56de\u653e 1 \u7a0b\u5e8f\u7f16\u8bd1\u8fc7\u7a0b\u4e0e\u8c03\u8bd5\u6280\u672f \u6731\u5b9d\u6797 10.14 \u4e0b\u5348 2:30-4:30 \u4e1c 1A-132 \u8bfe\u524d\u51c6\u5907\u8bb2\u4e49 Bilibili 2 \u7c7b\u578b\u7cfb\u7edf\u4e0e\u5185\u5b58\u6a21\u578b \u674e\u82f1\u7426 10.29 \u65e9 9:30-11:30 \u5317 1-311 \u8bfe\u524d\u51c6\u5907\u8bb2\u4e49 Bilibili 3 I/O \u4e0e\u6587\u4ef6 \u80e1\u80b2\u73ae 11.18 \u4e0b\u5348 14:30-16:30 \u5317 1-312 \u8bfe\u524d\u51c6\u5907\u8bb2\u4e49 Bilibili 4 C \u6807\u51c6\u5e93 \u6731\u5b9d\u6797 12.2 \u65e9 9:00-11:00 \u5317 2-225 \u8bb2\u4e49\u8bfe\u540e\u6269\u5c55 Bilibili 5 \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5 \u8c22\u96c6\u82cf\u715c\u7a0b \u3010\u6682\u5b9a\u301112.15"},{"location":"programming/archive/23fall/lec1/lec1/","title":"\u8bb2\u4e49\uff1a\u7a0b\u5e8f\u7f16\u8bd1\u8fc7\u7a0b\u4e0e\u8c03\u8bd5\u6280\u672f","text":"\u76f4\u64ad\u56de\u653e

Bilibili

\u5185\u5bb9\u63d0\u8981 \u5982\u4f55\u98df\u7528\u672c\u8bb2\u4e49

\u4f5c\u4e3a\u5728\u7ebf\u8bb2\u4e49\uff0c\u6211\u4f1a\u5c3d\u91cf\u5199\u5f97\u8be6\u7ec6\u4e00\u4e9b\uff0c\u4e3a\u540c\u5b66\u4eec\u63d0\u4f9b\u590d\u4e60\u548c\u8fdb\u4e00\u6b65\u6269\u5c55\u7684\u6307\u5f15\u3002\u56e0\u4e3a\u65f6\u95f4\u6709\u9650\uff0c\u5728\u8bfe\u4e0a\u6211\u65e0\u6cd5\u8986\u76d6\u8bb2\u4e49\u4e2d\u6240\u6709\u7684\u5185\u5bb9\u3002\u540c\u5b66\u4eec\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u4e60\u60ef\u9009\u62e9\u5728\u8bfe\u524d\u8bfe\u540e\u6d4f\u89c8\u672c\u8bb2\u4e49\uff5e

\u672c\u6b21\u8bfe\u7684\u6838\u5fc3\u5185\u5bb9\u4ece\u300c\u7a0b\u5e8f\u7684\u7f16\u8bd1\u8fc7\u7a0b\u300d\u5f00\u59cb\u3002\u524d\u9762\u7684\u5185\u5bb9\u4f5c\u4e3a\u9884\u5907\u77e5\u8bc6\uff0c\u5728\u8bfe\u4e0a\u5c06\u4f1a\u5feb\u901f\u5e26\u8fc7\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_2","title":"\u8bfe\u7a0b\u5bfc\u8a00","text":"

Hi\uff0c\u6b22\u8fce\u5404\u4f4d\u540c\u5b66\u6765\u5230\u7afa\u9662\u7a0b\u8bbe\u8f85\u5b66\u300c\u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057\u300d\u7684\u7b2c\u4e00\u8282\u8bfe\u3002

\u5728\u524d\u51e0\u5468\u7684\u7a0b\u5e8f\u8bbe\u8ba1\u8bfe\u7a0b\u4e2d\uff0c\u8001\u5e08\u4eec\u5e94\u8be5\u5df2\u7ecf\u4e3a\u540c\u5b66\u4eec\u8bb2\u89e3\u4e86 C \u8bed\u8a00\u7684\u57fa\u7840\u8bed\u6cd5\u7b49\u77e5\u8bc6\u3002\u4f46\u662f\u540c\u5b66\u4eec\u6216\u8bb8\u4f1a\u6709\u4e0b\u9762\u8fd9\u4e9b\u7591\u95ee\uff1a

\u8f85\u5b66\u8bfe\u7a0b\u7684\u76ee\u7684\u5c31\u662f\u5e2e\u52a9\u540c\u5b66\u4eec\u89e3\u51b3\u8fd9\u4e9b\u8fdb\u4e00\u6b65\u7684\u95ee\u9898\u3002\u5b9e\u8d28\u4e0a C \u8bed\u8a00\u662f\u4e00\u95e8\u5f88\u96be\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u4e0d\u61c2\u7f16\u8bd1\u539f\u7406\u3001\u64cd\u4f5c\u7cfb\u7edf\u548c\u8ba1\u7b97\u673a\u4f53\u7cfb\u7ed3\u6784\u65e0\u6cd5\u83b7\u5f97\u6df1\u5165\u7684\u7406\u89e3\u3002\u6211\u4eec\u5e0c\u671b\u901a\u8fc7\u7ebf\u4e0b\u6388\u8bfe\uff0c\u4e3a\u540c\u5b66\u4eec\u63d0\u4f9b\u8bed\u8a00\u4e4b\u5916\u7684\u8fdb\u4e00\u6b65\u7684\u77e5\u8bc6\u6269\u5c55\u548c\u6280\u80fd\u8bad\u7ec3\u3002\u8ba9\u540c\u5b66\u4eec\u5728\u8ba1\u7b97\u673a\uff08\u800c\u975e\u7b97\u6cd5\u9898\uff09\u7684\u8bed\u5883\u4e0b\u7406\u89e3 C \u8bed\u8a00\uff0c\u7406\u89e3\u7a0b\u5e8f\u8bbe\u8ba1\u3002

\u90a3\u4e48\u5728\u672c\u8282\u8bfe\uff0c\u6211\u4eec\u5c06\u4e3a\u5927\u5bb6\u7cfb\u7edf\u8bb2\u89e3\u7a0b\u5e8f\u7f16\u8bd1\u8fc7\u7a0b\u4e0e\u8c03\u8bd5\u6280\u672f\uff0c\u4e3a\u540e\u7eed\u7684\u8bfe\u7a0b\u505a\u94fa\u57ab\u3002\u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec\u4e00\u8d77\u8fdb\u5165\u8ba1\u7b97\u673a\u7684\u4e16\u754c\u5427\uff01

"},{"location":"programming/archive/23fall/lec1/lec1/#_3","title":"\u57fa\u7840\u77e5\u8bc6","text":"

\u9996\u5148\uff0c\u6211\u4eec\u6765\u4e86\u89e3\u4e00\u4e0b\u6211\u4eec\u5b66\u4e60\u7684\u5bf9\u8c61\u2014\u2014\u8ba1\u7b97\u673a\u7684\u57fa\u672c\u77e5\u8bc6\u3002\u5b83\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff1f\u6211\u4eec\u5982\u4f55\u4e0e\u5b83\u4ea4\u6d41\uff1f

"},{"location":"programming/archive/23fall/lec1/lec1/#_4","title":"\u8ba1\u7b97\u673a\u80fd\u505a\u4ec0\u4e48\uff1f","text":"

\u73b0\u4ee3\u8ba1\u7b97\u673a\u7531\u591a\u79cd\u90e8\u4ef6\u6784\u6210\uff0c\u6bd4\u5982\u4e2d\u592e\u5904\u7406\u5355\u5143\uff08Central Processing Unit\uff0cCPU\uff09\u3001\u968f\u673a\u5b58\u53d6\u5185\u5b58\uff08Random Access Memory\uff0cRAM\uff09\u3001\u786c\u76d8\uff08Hard Disk\uff09\u7b49\u3002\u5176\u4e2d CPU \u8d1f\u8d23\u5904\u7406\u7a0b\u5e8f\u3002

RISC CPU

\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684 CPU \u7684\u7535\u8def\uff0c\u5b83\u80fd\u591f\u6267\u884c\u4f60\u7528 0 \u548c 1 \u7f16\u5199\u7684\u673a\u5668\u6307\u4ee4\u3002

CPU \u57fa\u672c\u7ed3\u6784

CPU \u4e3b\u8981\u7531\u63a7\u5236\u5355\u5143\u3001\u7b97\u672f\u903b\u8f91\u5355\u5143\u548c\u5bc4\u5b58\u5668\u7ec4\u6210\u3002\u63a7\u5236\u5355\u5143\u4e2d\u6709\u7a0b\u5e8f\u8ba1\u6570\u5668\u548c\u6307\u4ee4\u5bc4\u5b58\u5668\u3002

CPU \u65e0\u6cd5\u76f4\u63a5\u8bfb\u61c2\u4f60\u5199\u7684 C \u8bed\u8a00\u4ee3\u7801\uff0c\u5b83\u662f\u7531\u6570\u5b57\u7535\u8def\u6784\u6210\u7684\u3002\u6570\u5b57\u7535\u8def\u53ea\u80fd\u5904\u7406 0 \u548c 1\uff0c\u56e0\u6b64\u8ba1\u7b97\u673a\u4e2d\u7684\u4efb\u4f55\u6570\u636e\u90fd\u5fc5\u987b\u4f7f\u7528\u4e8c\u8fdb\u5236\u8868\u793a\uff0c\u7a0b\u5e8f\u4e5f\u662f\u5982\u6b64\u3002

\u5728\u8ba1\u7b97\u673a\u521a\u521a\u8bde\u751f\u7684\u9636\u6bb5\uff0c\u5de5\u7a0b\u5e08\u4eec\u4e0d\u5f97\u4e0d\u4f7f\u7528 0 \u548c 1 \u6784\u6210\u7684\u6307\u4ee4\u5e8f\u5217\u548c\u8ba1\u7b97\u673a\u6253\u4ea4\u9053\uff0c\u8fd9\u5c31\u662f\u673a\u5668\u8bed\u8a00\u3002\u56e0\u4e3a\u5177\u4f53\u7535\u8def\u8bbe\u8ba1\u4e0d\u540c\uff0c\u6bcf\u79cd CPU \u6240\u80fd\u7406\u89e3\u7684\u6307\u4ee4\u6709\u9650\uff0c\u8fd9\u4e9b\u6307\u4ee4\u7684\u96c6\u5408\u53eb\u505a\u6307\u4ee4\u96c6\u3002

CPU \u7684\u5de5\u4f5c\u975e\u5e38\u7b80\u5355\uff1a\u4ece\u5185\u5b58\u4e2d\u8bfb\u53d6\u5e76\u6267\u884c\u4e00\u6761\u6307\u4ee4\uff0c\u518d\u4ece\u5185\u5b58\u4e2d\u8bfb\u53d6\u5e76\u6267\u884c\u4e0b\u4e00\u6761\u6307\u4ee4\u2026\u20261 GHz \u7684 CPU \u6bcf\u79d2\u80fd\u91cd\u590d\u8fd9\u4e00\u64cd\u4f5c\u7ea6\u5341\u4ebf\u6b21\u3002

\u8fd9\u4e9b\u6307\u4ee4\u90fd\u76f8\u5f53\u5177\u4f53\uff0c\u6bd4\u5982\u628a\u4e00\u4e2a\u6570\u5b57\u4ece\u4e00\u4e2a\u4f4d\u7f6e\u79fb\u52a8\u5230\u53e6\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u628a\u4e24\u4e2a\u6570\u5b57\u76f8\u52a0\u5e76\u628a\u7ed3\u679c\u5b58\u50a8\u518d\u67d0\u4e2a\u5730\u65b9\u3002\u662f\u7684\uff0c\u4f60\u7684 CPU \u4e5f\u5728\u75af\u72c2\u505a\u7740\u8fd9\u4e9b\u4e8b\u60c5\u3002\u4f46\u662f\u901a\u8fc7\u7cbe\u5de7\u7684\u8bbe\u8ba1\uff0c\u8fd9\u4e9b\u7b80\u5355\u7684\u6307\u4ee4\u5c31\u80fd\u6784\u5efa\u8d77\u7a0b\u5e8f\u7684\u63a7\u5236\u903b\u8f91\uff0c\u5b9e\u73b0\u590d\u6742\u7684\u529f\u80fd\u3002

CPU \u8fd8\u6709\u81ea\u5df1\u7684\u5c0f\u5de5\u4f5c\u533a\u2014\u2014\u7531\u82e5\u5e72\u5bc4\u5b58\u5668\uff08Register\uff09\u7ec4\u6210\u7684\u5bc4\u5b58\u5668\u7ec4\u3002\u6bcf\u4e2a\u5bc4\u5b58\u5668\u80fd\u5b58\u50a8\u4e00\u4e2a\u6570\u5b57\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_5","title":"\u4ece\u673a\u5668\u8bed\u8a00\u3001\u6c47\u7f16\u8bed\u8a00\u5230\u9ad8\u7ea7\u8bed\u8a00","text":"

\u73b0\u4ee3\u8ba1\u7b97\u673a\u7684\u7ed3\u6784\u4e0e 70 \u5e74\u524d\u5e76\u6ca1\u6709\u672c\u8d28\u4e0a\u7684\u4e0d\u540c\uff0c\u4f46\u662f\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u53d6\u5f97\u4e86\u5f88\u5927\u7684\u53d1\u5c55\uff0c\u4ea7\u751f\u4e86\u6c47\u7f16\u8bed\u8a00\u548c\u9ad8\u7ea7\u8bed\u8a00\u3002\u6211\u4eec\u4ecd\u7136\u4e0d\u80fd\u76f4\u63a5\u5bf9 CPU \u8bf4\uff1a\u4e3a\u6211\u8ba1\u7b97 \\(1 + 1\\)\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u7528\u9ad8\u7ea7\u8bed\u8a00\u7b80\u6d01\u7684\u8868\u8fbe\u5b83\uff0c\u8ba9\u7f16\u8bd1\u5668\uff08compiler\uff09\u548c\u6c47\u7f16\u5668\uff08assembler\uff09\u5c06\u5176\u7ffb\u8bd1\u6210 0101 \u7684\u673a\u5668\u8bed\u8a00\u3002\u4e0b\u56fe\u5c55\u793a\u4e86\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u7684\u53d1\u5c55\u5386\u53f2\uff0c\u7f16\u8bd1\u8fc7\u7a0b\u5176\u5b9e\u5c31\u662f\u8fd9\u4e00\u5386\u53f2\u7684\u53cd\u5411\u3002

\u673a\u5668\u8bed\u8a00 Machine Code

\u8fd9\u662f\u7b2c\u4e00\u4ee3\u7f16\u7a0b\u8bed\u8a00\uff0c\u4e5f\u662f\u8ba1\u7b97\u673a\u552f\u4e00\u80fd\u8bc6\u522b\u7684\u8bed\u8a00\u3002\u4e0a\u56fe\u5c55\u793a\u4e86\u4e16\u754c\u4e0a\u7b2c\u4e00\u4e2a\u8ba1\u7b97\u673a\u7a0b\u5e8f\uff0c\u5b83\u7528\u6765\u627e\u51fa\u4e00\u4e2a\u6570\u6700\u5927\u7684\u56e0\u6570\u3002

\u6c47\u7f16\u8bed\u8a00 Assembly Language

\u8fd9\u662f\u7b2c\u4e8c\u4ee3\u7f16\u7a0b\u8bed\u8a00\uff0c\u5176\u5b9e\u5c31\u662f\u673a\u5668\u8bed\u8a00\u7684\u52a9\u8bb0\u7b26\u3002\u5b83\u4f7f\u5f97\u7a0b\u5e8f\u5458\u4e0d\u7528\u518d\u76f4\u63a5\u4e0e 0 \u548c 1 \u6253\u4ea4\u9053\uff0c\u7a0b\u5e8f\u7684\u53ef\u8bfb\u6027\u4e5f\u66f4\u5f3a\u4e86\u3002\u4e0a\u56fe\u663e\u793a\u4e86\u5c06\u4e24\u4e2a\u6574\u6570\u76f8\u52a0\u7684\u6c47\u7f16\u4ee3\u7801\u3002

\u9ad8\u7ea7\u8bed\u8a00 High-level Language

\u8fd9\u662f\u7b2c\u4e09\u4ee3\u7f16\u7a0b\u8bed\u8a00\uff0c\u5b83\u8ba9\u7a0b\u5e8f\u5458\u4eec\u4e0d\u7528\u518d\u5173\u6ce8\u8ba1\u7b97\u673a\u7ed3\u6784\u4e0a\u7684\u7ec6\u8282\uff0c\u800c\u662f\u5c06\u6ce8\u610f\u529b\u8f6c\u79fb\u5230\u8981\u89e3\u51b3\u7684\u95ee\u9898\u4e0a\u6765\u3002

\u4e0b\u9762\u4e09\u884c\u4ee3\u7801\u5206\u522b\u662f\u7528 C \u8bed\u8a00\u3001\u6c47\u7f16\u8bed\u8a00\u548c\u673a\u5668\u8bed\u8a00\uff08\u5341\u516d\u8fdb\u5236\uff09\u63cf\u8ff0\u7684\u540c\u4e00\u4ef6\u4e8b\uff1a

\u7b80\u5355\u7684\u4f8b\u5b50\u590d\u6742\u7684\u4f8b\u5b50
c = a + b;\n
add $t0, $t1, $t2\n
01 2a 40 20\n
void multstore(long x, long y, long *dest) {\n    long t = mult2(x, y);\n    *dest = t;\n}\n
multstore:\n    pushq   %rbx\n    movq    %rdx, %rbx\n    call    mult2\n    movq    %rax, (%rbx)\n    popq    %rbx\n    ret\n
53 48 89 d3 48 83 ec 08 e8 00 00 00 00 48 89 03 5b c3\n
\u4e3a\u4ec0\u4e48\u9700\u8981\u9ad8\u7ea7\u8bed\u8a00\uff1f
  1. \u673a\u5668\u8bed\u8a00\u548c\u6c47\u7f16\u8bed\u8a00\u90fd\u662f\u975e\u5e38\u5e95\u5c42\u7684\u8bed\u8a00\uff0c\u7a0b\u5e8f\u5458\u9700\u8981\u5173\u6ce8\u8ba1\u7b97\u673a\u7684\u7ec6\u8282\uff0c\u8fd9\u4f7f\u5f97\u7a0b\u5e8f\u7684\u53ef\u8bfb\u6027\u5f88\u5dee\u3002\u4f7f\u7528\u9ad8\u7ea7\u8bed\u8a00\uff0c\u7a0b\u5e8f\u5458\u80fd\u5c06\u6ce8\u610f\u529b\u8f6c\u79fb\u5230\u8981\u89e3\u51b3\u7684\u95ee\u9898\u4e0a\u6765\u3002
  2. \u673a\u5668\u8bed\u8a00\u548c\u6c47\u7f16\u8bed\u8a00\u90fd\u662f\u4e0e\u5177\u4f53 CPU \u76f8\u5173\u7684\uff0c\u7a0b\u5e8f\u5458\u9700\u8981\u4e3a\u4e0d\u540c\u7684 CPU \u7f16\u5199\u4e0d\u540c\u7684\u7a0b\u5e8f\uff0c\u53ef\u79fb\u690d\u6027\u5dee\u3002\u4f7f\u7528\u9ad8\u7ea7\u8bed\u8a00\uff0c\u7a0b\u5e8f\u5458\u53ea\u9700\u8981\u5199\u4e00\u6b21\u7a0b\u5e8f\uff0c\u518d\u4f7f\u7528\u7f16\u8bd1\u5668\u5c31\u80fd\u5c06\u5176\u7ffb\u8bd1\u6210\u80fd\u5728\u7279\u5b9a CPU \u7684\u673a\u5668\u8bed\u8a00\u3002
\u524d\u77bb\uff1a\u7b2c\u56db\u4ee3\u548c\u7b2c\u4e94\u4ee3\u7f16\u7a0b\u8bed\u8a00

\u7f16\u7a0b\u8bed\u8a00\u4ecd\u5728\u53d1\u5c55\u6f14\u5316\u3002\u76ee\u524d\u5df2\u7ecf\u6709\u4e86\u7b2c\u56db\u4ee3\u548c\u7b2c\u4e94\u4ee3\u7f16\u7a0b\u8bed\u8a00\u7684\u6982\u5ff5\u3002\u7b2c\u4e09\u4ee3\u7684\u7f16\u7a0b\u8bed\u8a00\u867d\u7136\u662f\u7528\u8bed\u53e5\u7f16\u7a0b\u800c\u4e0d\u76f4\u63a5\u7528\u6307\u4ee4\u7f16\u7a0b\uff0c\u4f46\u8bed\u53e5\u4e5f\u5206\u4e3a\u8f93\u5165\u3001\u8f93\u51fa\u3001\u57fa\u672c\u8fd0\u7b97\u3001\u6d4b\u8bd5\u5206\u652f\u548c\u5faa\u73af\u7b49\u51e0\u79cd\uff0c\u548c\u6307\u4ee4\u6709\u76f4\u63a5\u7684\u5bf9\u5e94\u5173\u7cfb\u3002\u800c\u7b2c\u56db\u4ee3\u4ee5\u540e\u7684\u7f16\u7a0b\u8bed\u8a00\u66f4\u591a\u662f\u63cf\u8ff0\u8981\u505a\u4ec0\u4e48\uff08Declarative\uff09\u800c\u4e0d\u63cf\u8ff0\u5177\u4f53\u4e00\u6b65\u4e00\u6b65\u600e\u4e48\u505a\uff08Imperative\uff09\uff0c\u5177\u4f53\u4e00\u6b65\u4e00\u6b65\u600e\u4e48\u505a\u5b8c\u5168\u7531\u7f16\u8bd1\u5668\u6216\u89e3\u91ca\u5668\u51b3\u5b9a\uff0c\u4f8b\u5982SQL\u8bed\u8a00\uff08SQL\uff0cStructured Query Language\uff0c\u7ed3\u6784\u5316\u67e5\u8be2\u8bed\u8a00\uff09\u5c31\u662f\u8fd9\u6837\u7684\u4f8b\u5b50\u3002

\u5bf9\u673a\u5668\u8bed\u8a00\u6709\u5174\u8da3\uff1f

\u8fd9\u91cc\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5c06\u6c47\u7f16\u8bed\u8a00\u8f6c\u6362\u4e3a MIPS \u6307\u4ee4\u96c6\u673a\u5668\u8bed\u8a00\u7684\u57fa\u7840\u4f8b\u5b50\uff0c\u6709\u5174\u8da3\u53ef\u4ee5\u4e86\u89e3\u4e00\u4e0b\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_6","title":"\u7a0b\u5e8f\u7684\u57fa\u672c\u8bed\u6cd5\u7ed3\u6784","text":"

\u7ecf\u8fc7\u4e86 2-3 \u5468\u8bfe\u7a0b\u7684\u5b66\u4e60\uff0c\u76f8\u4fe1\u540c\u5b66\u4eec\u591a\u5c11\u90fd\u5199\u8fc7\u4e86\u4e00\u4e9b\u4ee3\u7801\uff0c\u5bf9\u8bed\u8a00\u6709\u4e86\u4e00\u4e9b\u57fa\u672c\u8ba4\u8bc6\u3002\u672c\u8282\u5c06\u7cfb\u7edf\u5730\u68b3\u7406\u7a0b\u5e8f\u7684\u8bed\u6cd5\u548c\u7ed3\u6784\u77e5\u8bc6\uff0c\u5e2e\u52a9\u5927\u5bb6\u7406\u6e05\u601d\u8def\uff0c\u4e3a\u540e\u7eed\u7406\u89e3\u7a0b\u5e8f\u7f16\u8bd1\u8fc7\u7a0b\u548c\u8c03\u8bd5\u6280\u672f\u4f5c\u94fa\u57ab\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_7","title":"\u5199\u7a0b\u5e8f\u7684\u76ee\u6807\u662f\u4ec0\u4e48\uff1f","text":"

\u4ece\u6839\u672c\u4e0a\u8bf4\uff0c\u8ba1\u7b97\u673a\u662f\u7531\u6570\u5b57\u7535\u8def\u7ec4\u6210\u7684\u8fd0\u7b97\u673a\u5668\uff0c\u53ea\u80fd\u5bf9\u6570\u5b57\u505a\u8fd0\u7b97\uff0c\u7a0b\u5e8f\u4e4b\u6240\u4ee5\u80fd\u505a\u7b26\u53f7\u8fd0\u7b97\uff0c\u662f\u56e0\u4e3a\u7b26\u53f7\u5728\u8ba1\u7b97\u673a\u5185\u90e8\u4e5f\u662f\u7528\u6570\u5b57\u8868\u793a\u7684\u3002\u6b64\u5916\uff0c\u7a0b\u5e8f\u8fd8\u53ef\u4ee5\u5904\u7406\u58f0\u97f3\u548c\u56fe\u50cf\uff0c\u58f0\u97f3\u548c\u56fe\u50cf\u5728\u8ba1\u7b97\u673a\u5185\u90e8\u5fc5\u7136\u4e5f\u662f\u7528\u6570\u5b57\u8868\u793a\u7684\uff0c\u8fd9\u4e9b\u6570\u5b57\u7ecf\u8fc7\u4e13\u95e8\u7684\u786c\u4ef6\u8bbe\u5907\u8f6c\u6362\u6210\u4eba\u53ef\u4ee5\u542c\u5230\u3001\u770b\u5230\u7684\u58f0\u97f3\u548c\u56fe\u50cf\u3002

\u7a0b\u5e8f\u7531\u4e00\u7cfb\u5217\u6307\u4ee4\uff08Instruction\uff09\u7ec4\u6210\uff0c\u6307\u4ee4\u662f\u6307\u793a\u8ba1\u7b97\u673a\u505a\u67d0\u79cd\u8fd0\u7b97\u7684\u547d\u4ee4\uff0c\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u51e0\u7c7b\uff1a

\u5bf9\u4e8e\u7a0b\u5e8f\u6765\u8bf4\uff0c\u6709\u4e0a\u9762\u8fd9\u51e0\u7c7b\u6307\u4ee4\u5c31\u8db3\u591f\u4e86\u3002\u4f60\u66fe\u7528\u8fc7\u7684\u4efb\u4f55\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u4e0d\u7ba1\u5b83\u6709\u591a\u4e48\u590d\u6742\uff0c\u90fd\u662f\u7531\u8fd9\u51e0\u7c7b\u6307\u4ee4\u7ec4\u6210\u7684\u3002\u7a0b\u5e8f\u662f\u90a3\u4e48\u7684\u590d\u6742\uff0c\u800c\u7f16\u5199\u7a0b\u5e8f\u53ef\u4ee5\u7528\u7684\u6307\u4ee4\u5374\u53ea\u6709\u8fd9\u4e48\u7b80\u5355\u7684\u51e0\u79cd\uff0c\u8fd9\u4e2d\u95f4\u5de8\u5927\u7684\u843d\u5dee\u5c31\u8981\u7531\u7a0b\u5e8f\u5458\u53bb\u586b\u4e86\uff0c\u6240\u4ee5\u7f16\u5199\u7a0b\u5e8f\u7406\u5e94\u662f\u4e00\u4ef6\u76f8\u5f53\u590d\u6742\u7684\u5de5\u4f5c\u3002\u7f16\u5199\u7a0b\u5e8f\u53ef\u4ee5\u8bf4\u5c31\u662f\u8fd9\u6837\u4e00\u4e2a\u8fc7\u7a0b\uff1a\u628a\u590d\u6742\u7684\u4efb\u52a1\u5206\u89e3\u6210\u5b50\u4efb\u52a1\uff0c\u628a\u5b50\u4efb\u52a1\u518d\u5206\u89e3\u6210\u66f4\u7b80\u5355\u7684\u4efb\u52a1\uff0c\u5c42\u5c42\u5206\u89e3\uff0c\u76f4\u5230\u6700\u540e\u7b80\u5355\u5f97\u53ef\u4ee5\u7528\u4ee5\u4e0a\u6307\u4ee4\u6765\u5b8c\u6210\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_8","title":"\u8bcd\u6cd5\u548c\u8bed\u6cd5\u89c4\u5219","text":"

\u8bcd\u6cd5\uff08Lexical\uff09\u548c\u8bed\u6cd5\uff08Syntax\uff09\u662f\u7f16\u7a0b\u8bed\u8a00\u7684\u4e24\u4e2a\u57fa\u672c\u6982\u5ff5\u3002\u8bcd\u6cd5\u89c4\u5219\u5b9a\u4e49\u4e86\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u57fa\u672c\u7b26\u53f7\uff0c\u8bed\u6cd5\u89c4\u5219\u5b9a\u4e49\u4e86\u8fd9\u4e9b\u7b26\u53f7\u5982\u4f55\u7ec4\u6210\u5408\u6cd5\u7684\u8868\u8fbe\u5f0f\u3001\u8bed\u53e5\u548c\u7a0b\u5e8f\u3002

C \u7684\u8bcd\u6cd5\u89c4\u5219\uff1a\u8d2a\u5fc3\u6cd5

\u672f\u8bed token \uff08\u7b26\u53f7\uff09\u662f\u8bed\u8a00\u7684\u57fa\u672c\u8868\u610f\u5355\u5143\u3002\u5b57\u7b26\u7ec4\u6210\u7b26\u53f7\u3002\u4f8b\u5b50: ->\u3001file \u90fd\u662f\u7b26\u53f7\u3002\u540c\u4e00\u7ec4\u5b57\u7b26\u5e8f\u5217\u5728\u4e0d\u540c\u4e0a\u4e0b\u6587\u4e2d\u53ef\u80fd\u5c5e\u4e8e\u4e0d\u540c\u7b26\u53f7\u3002

\u5982\u679c\u8be5\u5b57\u7b26\u53ef\u80fd\u7ec4\u6210\u7b26\u53f7\uff0c\u90a3\u4e48\u518d\u8bfb\u5165\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff0c\u76f4\u5230\u8bfb\u5165\u7684\u5b57\u7b26\u4e32\u5df2\u7ecf\u4e0d\u53ef\u80fd\u518d\u7ec4\u6210\u4e00\u4e2a\u6709\u610f\u4e49\u7684\u7b26\u53f7\u3002

\u8bcd\u6cd5\u7ec3\u4e60\uff1a\u8bf7\u601d\u8003\u4e0b\u9762\u8fd9\u4e9b\u8868\u8fbe\u5f0f\u7684\u884c\u4e3a

\u70b9\u51fb\u300c+\u300d\u53f7\u5c55\u5f00\u7b54\u6848\u3002

a---b /*(1)!*/\na -- - b /*(2)!*/\na - -- b /*(3)!*/\n\n//\u4e0b\u9762\u7684 p \u6307\u5411\u9664\u6570\u3002\ny = x/*p     \n/*(4)!*/\ny = x / *p /*(5)!*/\n\nn-->0 /*(6)!*/\nn-- >0 /*(7)!*/\nn- -> 0 /*(8)!*/\n\na+++++b /*(9)!*/\n
  1. \u7b49\u4ef7\u4e8e (a--) - b\u3002\u6309\u7167\u8d2a\u5fc3\u6cd5\uff0c\u7f16\u8bd1\u5668\u8bfb\u5165\u4e24\u4e2a\u8fde\u7eed\u7684 - \u53f7\u540e\uff0c\u5df2\u7ecf\u4e0d\u53ef\u80fd\u518d\u7ec4\u6210\u4e00\u4e2a\u6709\u610f\u4e49\u7684\u7b26\u53f7\uff0c\u56e0\u6b64\u8fd9\u4e2a\u7b26\u53f7\u88ab\u786e\u5b9a\u4e3a\u540e\u7f00\u9012\u51cf\u8fd0\u7b97\u7b26\u3002\u63a5\u7740\u8bfb\u53d6\u4e0b\u4e00\u4e2a\u7b26\u53f7\u3002
  2. \u7b49\u4ef7\u4e8e (a--) - b
  3. \u7b49\u4ef7\u4e8e a - (--b)
  4. \u7b49\u4ef7\u4e8e y = x\u3002/* \u88ab\u8d2a\u5fc3\u6cd5\u89e3\u91ca\u4e3a\u6ce8\u91ca\u7684\u5f00\u5934\u3002
  5. \u7b49\u4ef7\u4e8e y = x / (*p)
  6. \u7b49\u4ef7\u4e8e (n--) > 0
  7. \u7b49\u4ef7\u4e8e (n--) > 0
  8. \u7b49\u4ef7\u4e8e (n-) -> 0\u3002\u8fd9\u662f\u4e00\u4e2a\u65e0\u6548\u7684\u8bed\u53e5\uff0cn- \u672c\u8eab\u4e0d\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u8868\u8fbe\u5f0f\uff0c\u4e5f\u65e0\u6cd5\u7528\u4f5c -> \u7684\u64cd\u4f5c\u6570\u3002
  9. \u7b49\u4ef7\u4e8e ((a++)++) + b\u3002\u8bf7\u601d\u8003\u4e00\u4e0b\uff0c\u8fd9\u4e2a\u8bed\u53e5\u6709\u6548\u5417\uff1f
\u8bed\u6cd5\uff1a\u6807\u8bc6\u7b26\u3001\u8868\u8fbe\u5f0f\u548c\u8bed\u53e5

\u4e3a\u4e86\u4fbf\u4e8e\u521d\u5b66\u8005\u7406\u89e3\uff0c\u6211\u4eec\u91c7\u7528\u4e00\u5957\u7b80\u5316\u7684\u8bed\u6cd5\u89c4\u5219\uff1a

\u5bf9\u8c61\u7684\u4e0d\u540c\u542b\u4e49

\u5728\u8fd9\u91cc\uff0c\u5bf9\u8c61\uff08Object\uff09\u7684\u542b\u4e49\u4e0e C++ \u4e2d\u4e0d\u540c\u3002\u8fd9\u91cc\u7684\u5bf9\u8c61\u6307\u6570\u636e\u5b58\u50a8\u7684\u4e00\u4e2a\u533a\u57df\uff0c\u5176\u5185\u5bb9\u53ef\u4ee5\u8868\u793a\u503c\u3002\u6bd4\u5982\u4e0b\u9762\u7684\u8bed\u53e5\u521b\u5efa\u4e86\u4e00\u4e2a\u5bf9\u8c61\uff1a

int a;\n

\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u7684\u610f\u601d\u5c31\u662f\u5206\u914d\u4e86\u4e00\u5757\u5b58\u50a8\u7a7a\u95f4\u3002\u6807\u8bc6\u7b26 a \u7528\u4e8e\u6307\u4ee3\u8fd9\u4e2a\u5bf9\u8c61\u3002\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u6709\u5927\u5c0f\u3001\u751f\u5b58\u671f\u3001\u5b58\u50a8\u5668\u3001\u503c\u7b49\u5c5e\u6027\uff0c\u6211\u4eec\u5c06\u5728\u4e0b\u8282\u8bfe\u8be6\u7ec6\u5c55\u5f00\u3002

\u5b8c\u6574\u7684 C \u8bed\u6cd5\u89c4\u5219\u8bf7\u53c2\u8003\uff1a

\u8bed\u6cd5\u5c06\u5728\u540e\u7eed\u8bfe\u7a0b\u4e2d\u4f5c\u6df1\u5165\u8bb2\u89e3\uff08\u7b2c 2 \u8bb2\u6d89\u53ca\u7c7b\u578b\u76f8\u5173\u7684\u8bed\u6cd5\uff0c\u7b2c 4 \u8bb2\u6d89\u53ca\u51fd\u6570\u6307\u9488\uff09\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#c","title":"\u51fd\u6570\uff1aC \u7a0b\u5e8f\u7684\u57fa\u672c\u6a21\u5757","text":"

\u300c\u6307\u4ee4\u300d\u662f\u7b2c\u4e00\u3001\u4e8c\u4ee3\u7f16\u7a0b\u8bed\u8a00\u7684\u57fa\u672c\u7ed3\u6784\u3002C \u8bed\u8a00\u662f\u9762\u5411\u8fc7\u7a0b\u7684\u9ad8\u7ea7\u8bed\u8a00\uff0c\u5b83\u7684\u57fa\u672c\u6a21\u5757\u662f\u51fd\u6570\uff08Function\uff09\u3002

\u5173\u952e\u6982\u5ff5\uff1a\u51fd\u6570

\u4ece\u5916\u9762\u770b\uff0c\u51fd\u6570\u5c31\u50cf\u4e00\u4e2a\u9ed1\u76d2\u5b50\uff0c\u53ea\u80fd\u770b\u5230\u51fd\u6570\u7684\u4e09\u5927\u8981\u7d20\uff1a

\u4e0b\u9762\u8fd9\u884c\u8bed\u53e5\u88ab\u79f0\u4e3a\u51fd\u6570\u7b7e\u540d\uff08Function Signature\uff09\u6216\u51fd\u6570\u539f\u578b\uff08Function Prototype\uff09\u3002\u5b83\u7ed9\u51fa\u4e86\u51fd\u6570\u5bf9\u5916\u7684\u4e00\u5207\u4fe1\u606f\uff1a

int MyFunc(int a, int b);\n

\u4ece\u91cc\u9762\u770b\uff0c\u51fd\u6570\u662f\u4e00\u7ec4\u6307\u4ee4\u7684\u96c6\u5408\uff0c\u5b83\u4eec\u6309\u7167\u4e00\u5b9a\u7684\u987a\u5e8f\u6267\u884c\uff0c\u5b8c\u6210\u67d0\u4e2a\u7279\u5b9a\u7684\u529f\u80fd\u3002

\u5f53\u6211\u4eec\u8c03\u7528\u4e00\u4e2a\u51fd\u6570\u65f6\uff0c\u6211\u4eec\u5e94\u5f53\u6309\u7167\u51fd\u6570\u7b7e\u540d\u4e2d\u7684\u8981\u6c42\u4f20\u5165\u53c2\u6570\uff0c\u5e76\u53ef\u4ee5\u83b7\u5f97\u5b83\u7684\u8fd4\u56de\u503c\u3002\u5728\u51fd\u6570\u7b7e\u540d\u7684\u8bed\u5883\u4e0b\uff0cvoid \u8868\u793a\u7a7a\uff0c\u5373\u4e0d\u5b58\u5728\u3002\u4e0b\u9762\u7684\u8fd9\u4e2a\u51fd\u6570\u6ca1\u6709\u53c2\u6570\uff0c\u4e5f\u6ca1\u6709\u8fd4\u56de\u503c\u3002

void MyFunc(void);\n

\u56e0\u4e3a\u6211\u4eec\u6bd4\u8f83\u5173\u5fc3\u51fd\u6570\u8fd4\u56de\u503c\u7684\u7c7b\u578b\uff0c\u6709\u65f6\u4f1a\u628a\u51fd\u6570\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u79f0\u4e3a\u8fd9\u4e2a\u51fd\u6570\u7684\u201c\u7c7b\u578b\u201d\uff0c\u6bd4\u5982\u4f1a\u8bf4 MyFunc \u8fd9\u4e2a\u51fd\u6570\u662f\u4e00\u4e2a void \u51fd\u6570\u3002

\u5173\u4e8e void

Q\uff1avoid \u5230\u5e95\u6709\u54ea\u4e9b\u542b\u4e49\uff1f

A: \u4e0b\u9762\u662f void \u7684\u4e00\u822c\u7528\u6cd5

\u4ece\u8fd9\u4e9b\u7528\u6cd5\u6765\u770b\uff0c\u4f3c\u4e4e void \u662f\u4e00\u79cd\u7c7b\u578b\uff0c\u4f46\u8fd9\u4f1a\u5f15\u8d77\u4e0b\u9762\u95ee\u9898\u4e2d\u7684\u77db\u76fe\u3002\u53e6\u4e00\u79cd\u770b\u5f85\u65b9\u5f0f\u662f\uff1a\u4e0a\u9762\u7684\u7528\u6cd5\u90fd\u662f\u7279\u6b8a\u7684\u8bed\u6cd5\uff0c\u4e0d\u8fc7\u662f\u6070\u597d\u7528\u4e86\u540c\u4e00\u4e2a\u5173\u952e\u5b57 void \u7f62\u4e86\u3002

Q\uff1a\u6240\u4ee5 void \u662f\u4e00\u79cd\u7c7b\u578b\u5417\uff1f

A\uff1aC \u6807\u51c6\u4ece\u6982\u5ff5\u4e0a\u5c06 void \u4f5c\u4e3a\u4e00\u79cd\u7c7b\u578b\u3002\u4f46\u662f void \u7c7b\u578b\u7684\u53d8\u91cf\u662f\u4e0d\u5b58\u5728\u7684\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u5927\u5c0f\uff0c\u7f16\u8bd1\u5668\u4e5f\u4e0d\u5141\u8bb8\u4f60\u5199\u4e0b void a;\u3002\u8fd9\u4f1a\u5f15\u8d77\u4e00\u4e9b\u56f0\u60d1\u3002

\u51fd\u6570\u6709\u4e24\u4e2a\u529f\u80fd\uff1a

\u4e00\u4e9b\u4f8b\u5b50\uff1a

\u51fd\u6570\u7b7e\u540d \u8fd4\u56de\u503c\u7684\u542b\u4e49 \u526f\u4f5c\u7528 int printf(const char *format, ...); \u6253\u5370\u7684\u5b57\u7b26\u6570 \u6253\u5370\u5b57\u7b26\u4e32\u5230\u6807\u51c6\u8f93\u51fa int scanf(const char *format, ...); \u8bfb\u53d6\u7684\u5b57\u7b26\u6570 \u4ece\u6807\u51c6\u8f93\u5165\u8bfb\u53d6\u5b57\u7b26\u4e32 int rand(void); \u751f\u6210\u7684\u968f\u673a\u6570 \u65e0 void exit(int status); \u65e0 \u9000\u51fa\u7a0b\u5e8f

\u6bcf\u4e2a C \u8bed\u8a00\u7a0b\u5e8f\u90fd\u5fc5\u987b\u5305\u542b\u4e00\u4e2a main \u51fd\u6570\uff0c\u5b83\u662f\u7a0b\u5e8f\u7684\u5165\u53e3\u3002main \u7684\u51fd\u6570\u7b7e\u540d\u4e00\u822c\u662f\u8fd9\u6837\u7684\uff1a

int main(void);\nint main(int argc, char *argv[]); //\u4ee5\u540e\u5b66\u547d\u4ee4\u884c\u53c2\u6570\u5c31\u4f1a\u7528\u5230\u8fd9\u79cd\u5f62\u5f0f\n

main \u7684\u8c03\u7528\u8005\u662f\u64cd\u4f5c\u7cfb\u7edf\u3002\u64cd\u4f5c\u7cfb\u7edf\u770b\u5230 main \u7684\u7b7e\u540d\u4e2d\u8bf4\u8fd4\u56de\u503c\u4e3a int\uff0c\u56e0\u6b64\u7cfb\u7edf\u4f1a\u7b49\u5f85 main \u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u3002\u8fd9\u4e2a\u6574\u6570\u4e00\u822c\u88ab\u7528\u4e8e\u544a\u77e5\u64cd\u4f5c\u7cfb\u7edf\u7a0b\u5e8f\u7684\u6267\u884c\u72b6\u6001\uff0c0 \u8868\u793a\u6b63\u5e38\u7ed3\u675f\uff0c\u5176\u4ed6\u503c\u53ef\u4ee5\u4f20\u9012\u5176\u4ed6\u4fe1\u606f\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48 main \u7684\u672b\u5c3e\u5e94\u5f53\u5199 return 0\u3002\u5982\u679c main \u51fd\u6570\u4e2d\u6ca1\u6709 return \u8bed\u53e5\uff0c\u6709\u4e9b\u7f16\u8bd1\u5668\u4f1a\u4e3a\u4f60\u8865\u5168\uff08\u5176\u4ed6\u51fd\u6570\u4e0d\u4f1a\uff09\u3002\u4f46\u8bf7\u8bb0\u5f97\u5199\u4e0a\uff0c\u8fd9\u662f\u4f60\u7684\u8d23\u4efb\u3002

\u6ca1\u6709\u8fd4\u56de\u503c\u7684\u51fd\u6570\u4e5f\u53ef\u4ee5\u4f7f\u7528 return \u8bed\u53e5\uff0c\u6b64\u65f6\u5b83\u6ca1\u6709\u8fd4\u56de\u503c\u7684\u4f5c\u7528\uff0c\u800c\u662f\u7ed3\u675f\u5f53\u524d\u51fd\u6570\u7684\u6267\u884c\u5e76\u8fd4\u56de\u3002\u4f8b\u5b50\uff1a

void print_logarithm(double x)\n{\n if (x <= 0.0) {\n  printf(\"Positive numbers only, please.\\n\");\n  return;\n }\n printf(\"The log of x is %f\", log(x));\n}\n
\u5176\u4ed6\u5efa\u8bae

\u6bcf\u4e2a\u51fd\u6570\u90fd\u5e94\u8be5\u8bbe\u8ba1\u5f97\u5c3d\u53ef\u80fd\u7b80\u5355\uff0c\u7b80\u5355\u7684\u51fd\u6570\u624d\u5bb9\u6613\u7ef4\u62a4\u3002\u5e94\u9075\u5faa\u4ee5\u4e0b\u539f\u5219\uff1a

  1. \u5b9e\u73b0\u4e00\u4e2a\u51fd\u6570\u53ea\u662f\u4e3a\u4e86\u505a\u597d\u4e00\u4ef6\u4e8b\u60c5\uff0c\u4e0d\u8981\u628a\u51fd\u6570\u8bbe\u8ba1\u6210\u7528\u9014\u5e7f\u6cdb\u3001\u9762\u9762\u4ff1\u5230\u7684\uff0c\u8fd9\u6837\u7684\u51fd\u6570\u80af\u5b9a\u4f1a\u8d85\u957f\uff0c\u800c\u4e14\u5f80\u5f80\u4e0d\u53ef\u91cd\u7528\uff0c\u7ef4\u62a4\u56f0\u96be\u3002

  2. \u51fd\u6570\u5185\u90e8\u7684\u7f29\u8fdb\u5c42\u6b21\u4e0d\u5b9c\u8fc7\u591a\uff0c\u4e00\u822c\u4ee5\u5c11\u4e8e 4 \u5c42\u4e3a\u5b9c\u3002\u5982\u679c\u7f29\u8fdb\u5c42\u6b21\u592a\u591a\u5c31\u8bf4\u660e\u8bbe\u8ba1\u5f97\u592a\u590d\u6742\u4e86\uff0c\u5e94\u8003\u8651\u5206\u5272\u6210\u66f4\u5c0f\u7684\u51fd\u6570\uff08Helper Function\uff09\u6765\u8c03\u7528\u3002

  3. \u51fd\u6570\u4e0d\u8981\u5199\u5f97\u592a\u957f\uff0c\u5efa\u8bae\u5728 24 \u884c\u7684\u6807\u51c6\u7ec8\u7aef\u4e0a\u4e0d\u8d85\u8fc7\u4e24\u5c4f\uff0c\u592a\u957f\u4f1a\u9020\u6210\u9605\u8bfb\u56f0\u96be\uff0c\u5982\u679c\u4e00\u4e2a\u51fd\u6570\u8d85\u8fc7\u4e24\u5c4f\u5c31\u5e94\u8be5\u8003\u8651\u5206\u5272\u51fd\u6570\u4e86\u3002[CodingStyle]\u4e2d\u7279\u522b\u8bf4\u660e\uff0c\u5982\u679c\u4e00\u4e2a\u51fd\u6570\u5728\u6982\u5ff5\u4e0a\u662f\u7b80\u5355\u7684\uff0c\u53ea\u662f\u957f\u5ea6\u5f88\u957f\uff0c\u8fd9\u5012\u6ca1\u5173\u7cfb\u3002\u4f8b\u5982\u51fd\u6570\u7531\u4e00\u4e2a\u5927\u7684 switch \u7ec4\u6210\uff0c\u5176\u4e2d\u6709\u975e\u5e38\u591a\u7684 case\uff0c\u8fd9\u662f\u53ef\u4ee5\u7684\uff0c\u56e0\u4e3a\u5404 case \u5206\u652f\u4e92\u4e0d\u5f71\u54cd\uff0c\u6574\u4e2a\u51fd\u6570\u7684\u590d\u6742\u5ea6\u53ea\u7b49\u4e8e\u5176\u4e2d\u4e00\u4e2a case \u7684\u590d\u6742\u5ea6\uff0c\u8fd9\u79cd\u60c5\u51b5\u5f88\u5e38\u89c1\uff0c\u4f8b\u5982 TCP \u534f\u8bae\u7684\u72b6\u6001\u673a\u5b9e\u73b0\u3002

  4. \u6267\u884c\u51fd\u6570\u5c31\u662f\u6267\u884c\u4e00\u4e2a\u52a8\u4f5c\uff0c\u51fd\u6570\u540d\u901a\u5e38\u5e94\u5305\u542b\u52a8\u8bcd\uff0c\u4f8b\u5982 get_current\u3001radix_tree_insert\u3002

  5. \u6bd4\u8f83\u91cd\u8981\u7684\u51fd\u6570\u5b9a\u4e49\u4e0a\u4fa7\u5fc5\u987b\u52a0\u6ce8\u91ca\uff0c\u8bf4\u660e\u6b64\u51fd\u6570\u7684\u529f\u80fd\u3001\u53c2\u6570\u3001\u8fd4\u56de\u503c\u3001\u9519\u8bef\u7801\u7b49\u3002

  6. \u53e6\u4e00\u79cd\u5ea6\u91cf\u51fd\u6570\u590d\u6742\u5ea6\u7684\u529e\u6cd5\u662f\u770b\u6709\u591a\u5c11\u4e2a\u5c40\u90e8\u53d8\u91cf\uff0c5 \u5230 10 \u4e2a\u5c40\u90e8\u53d8\u91cf\u5df2\u7ecf\u5f88\u591a\u4e86\uff0c\u518d\u591a\u5c31\u5f88\u96be\u7ef4\u62a4\u4e86\uff0c\u5e94\u8be5\u8003\u8651\u5206\u5272\u6210\u591a\u4e2a\u51fd\u6570\u3002

\u6269\u5c55\uff1a\u7f16\u8bd1\u548c\u89e3\u91ca

\u7b80\u5355\u4e86\u89e3\u4e00\u4e0b\u5c31\u597d\u3002

\u5c06\u9ad8\u7ea7\u8bed\u8a00\u7f16\u5199\u7684\u6e90\u4ee3\u7801\u8f6c\u5316\u6210\u673a\u5668\u8bed\u8a00\u7684\u76ee\u6807\u7a0b\u5e8f\u7684\u8fc7\u7a0b\u7edf\u79f0\u4e3a\u7ffb\u8bd1\uff08Translation\uff09\u3002\u7ffb\u8bd1\u7684\u65b9\u5f0f\u6709\u4e24\u79cd\uff1a\u7f16\u8bd1\uff08Compile\uff09\u548c\u89e3\u91ca\uff08Interpret\uff09\u3002\u7f16\u8bd1\u5c06\u6574\u4e2a\u7a0b\u5e8f\u7ffb\u8bd1\u6210\u673a\u5668\u8bed\u8a00\uff0c\u89e3\u91ca\u5219\u662f\u8fb9\u7ffb\u8bd1\u8fb9\u6267\u884c\u3002

C \u8bed\u8a00\u662f\u5178\u578b\u7684\u7f16\u8bd1\u578b\u8bed\u8a00\uff0c\u6e90\u4ee3\u7801\u9700\u8981\u7ecf\u8fc7\u7f16\u8bd1\u540e\u624d\u80fd\u8fd0\u884c\uff0c\u800c\u7f16\u8bd1\u9636\u6bb5\u5e76\u4e0d\u4f1a\u6267\u884c\u7a0b\u5e8f\u3002Python \u5219\u662f\u5178\u578b\u7684\u89e3\u91ca\u578b\u8bed\u8a00\uff0c\u9010\u53e5\u6267\u884c\u6e90\u4ee3\u7801\uff0c\u4e0d\u9700\u8981\u4ea7\u751f\u53ef\u6267\u884c\u6587\u4ef6\u3002

\u8fd9\u4e9b\u63cf\u8ff0\u7684\u90fd\u662f\u4e00\u79cd\u8bed\u8a00\u7684\u5178\u578b\u7528\u6cd5\u3002\u4e8b\u5b9e\u4e0a C \u8bed\u8a00\u4e5f\u5f00\u53d1\u51fa\u4e86\u76f8\u5e94\u7684\u89e3\u91ca\u5668\uff0cPython \u4e5f\u5f00\u53d1\u51fa\u4e86\u76f8\u5e94\u7684\u7f16\u8bd1\u5668\u3002\u4e24\u79cd\u7ffb\u8bd1\u65b9\u5f0f\u5404\u6709\u4f18\u52a3\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_9","title":"\u73b0\u5728\u4f60\u662f\u7f16\u8bd1\u5668","text":"

\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u5316\u8eab C \u8bed\u8a00\u7f16\u8bd1\u5668\uff0c\u89e3\u8bfb\u4e00\u4e9b\u4ee3\u7801\u3002\u76f8\u4fe1\u7ecf\u8fc7\u4e0b\u9762\u7684\u8bad\u7ec3\uff0c\u4f60\u5bf9\u4ee3\u7801\u548c\u7a0b\u5e8f\u6267\u884c\u7684\u7406\u89e3\u4f1a\u66f4\u52a0\u6df1\u5165\u3002

\u4f8b\u5b50\uff1a\u8bed\u6cd5\u6811
printf(\"%d:%d is %d minutes after 00:00\\n\", hour, minute, hour * 60 + minute);\n

\u7f16\u8bd1\u5668\u5728\u7ffb\u8bd1\u8fd9\u6761\u8bed\u53e5\u65f6\uff0c\u9996\u5148\u6839\u636e\u4e0a\u8ff0\u8bed\u6cd5\u89c4\u5219\u628a\u8fd9\u4e2a\u8bed\u53e5\u89e3\u6790\u6210\u4e0b\u56fe\u6240\u793a\u7684\u8bed\u6cd5\u6811\uff0c\u7136\u540e\u518d\u6839\u636e\u8bed\u6cd5\u6811\u751f\u6210\u76f8\u5e94\u7684\u6307\u4ee4\u3002\u8bed\u6cd5\u6811\u7684\u672b\u7aef\u7684\u662f\u4e00\u4e2a\u4e2aToken\uff0c\u6bcf\u4e00\u6b65\u5c55\u5f00\u5229\u7528\u4e00\u6761\u8bed\u6cd5\u89c4\u5219\u3002

\u7406\u89e3\u7ec4\u5408\uff08Composition\uff09\u89c4\u5219\u662f\u7406\u89e3\u8bed\u6cd5\u89c4\u5219\u7684\u5173\u952e\u6240\u5728\uff0c\u6b63\u56e0\u4e3a\u53ef\u4ee5\u6839\u636e\u8bed\u6cd5\u89c4\u5219\u4efb\u610f\u7ec4\u5408\uff0c\u6211\u4eec\u624d\u53ef\u4ee5\u7528\u7b80\u5355\u7684\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u8868\u8fbe\u5f0f\u3001\u8bed\u53e5\u642d\u5efa\u51fa\u4efb\u610f\u590d\u6742\u7684\u7a0b\u5e8f\uff0c\u4ee5\u540e\u6211\u4eec\u5b66\u4e60\u65b0\u7684\u8bed\u6cd5\u89c4\u5219\u65f6\u4f1a\u8fdb\u4e00\u6b65\u4f53\u4f1a\u5230\u8fd9\u4e00\u70b9\u3002\u4ece\u4e0a\u9762\u7684\u4f8b\u5b50\u53ef\u4ee5\u770b\u51fa\uff0c\u8868\u8fbe\u5f0f\u4e0d\u5b9c\u8fc7\u5ea6\u7ec4\u5408\uff0c\u5426\u5219\u4f1a\u7ed9\u9605\u8bfb\u548c\u8c03\u8bd5\u5e26\u6765\u56f0\u96be\u3002

\u8868\u8fbe\u5f0f\u4e0d\u5b9c\u8fc7\u5ea6\u7ec4\u5408

\u8fd9\u6d89\u53ca\u4ee3\u7801\u53ef\u8bfb\u6027\u95ee\u9898\u3002\u770b\u770b\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\uff1a

double distance(double x1, double y1, double x2, double y2)\n{\n  return sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));\n}\n

\u8fd9\u6837\u5199\u5f88\u7b80\u6d01\uff0c\u4f46\u5982\u679c\u5199\u9519\u4e86\u5462\uff1f\u53ea\u77e5\u9053\u662f\u8fd9\u4e00\u957f\u4e32\u8868\u8fbe\u5f0f\u6709\u9519\uff0c\u6839\u672c\u4e0d\u77e5\u9053\u9519\u5728\u54ea\uff0c\u800c\u4e14\u6574\u4e2a\u51fd\u6570\u5c31\u4e00\u4e2a\u8bed\u53e5\uff0c\u63d2printf\u90fd\u6ca1\u5730\u65b9\u63d2\u3002\u6240\u4ee5\u7528\u4e34\u65f6\u53d8\u91cf\u6709\u5b83\u7684\u597d\u5904\uff0c\u4f7f\u7a0b\u5e8f\u66f4\u6e05\u6670\uff0c\u8c03\u8bd5\u66f4\u65b9\u4fbf\uff0c\u800c\u4e14\u6709\u65f6\u5019\u53ef\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\uff0c\u4f8b\u5982\u4e0a\u9762\u8fd9\u4e00\u884c\u8868\u8fbe\u5f0f\u8981\u628a(x2-x1)\u8ba1\u7b97\u4e24\u904d\uff0c\u5982\u679c\u7b97\u5b8c(x2-x1)\u628a\u7ed3\u679c\u5b58\u5728\u4e00\u4e2a\u4e34\u65f6\u53d8\u91cfdx\u91cc\uff0c\u5c31\u4e0d\u9700\u8981\u518d\u7b97\u7b2c\u4e8c\u904d\u4e86\uff08\u867d\u7136\u8fd9\u4e9b\u4f18\u5316\u73b0\u4ee3\u7f16\u8bd1\u5668\u90fd\u4f1a\u66ff\u4f60\u81ea\u52a8\u5b8c\u6210\uff09\u3002\u4e0b\u9762\u8fd9\u4e2a\u7248\u672c\u662f\u53ef\u8bfb\u6027\u9ad8\u7684\u4ee3\u7801\uff1a

double distance(double x1, double y1, double x2, double y2)\n{\n double dx = x2 - x1;\n double dy = y2 - y1;\n double dsquared = dx * dx + dy * dy;\n double result = sqrt(dsquared);\n\n return result;\n}\n

\u7801\u98ce\u4e0d\u662f\u6b7b\u7684\uff0c\u8bf7\u540c\u5b66\u4eec\u89c6\u60c5\u51b5\u5207\u6362\u7801\u98ce\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#lap","title":"Lap\uff1a\u5173\u4e8e\u505a\u9898\u76ee","text":"

\u5982\u679c\u60f3\u505a\u9898\u7684\u8bdd\uff0c\u6709\u57fa\u7840\u7684\u540c\u5b66\u53ef\u4ee5\u65e9\u70b9\u5f00\u59cb\u505a\u5386\u5e74\u5377\uff0c\u4e86\u89e3\u4e00\u4e0b\u7a0b\u8bbe\u8003\u8bd5\u90fd\u8003\u4e9b\u5565\u3002

\u7b80\u5355\u63d0\u4e00\u4e9b Tips\uff1a

\u5e72\u788e\u4e00\u7247\u4eba\u7684\u9009\u62e9\u9898

Suppose T is a type name and t is a variable of type T. Which of the following is NOT a valid expression?

A. sizeof(T) B. sizeof(t) C. sizeof T D. sizeof t

\u7b54\u6848

\u7b54\u6848\u662f C\uff0c\u4e0d\u77e5\u9053\u4f60\u731c\u5bf9\u4e86\u5417\uff1f

\u5927\u5bb6\u4e00\u822c\u5199\u4ee3\u7801 sizeof \u540e\u9762\u90fd\u4f1a\u52a0\u62ec\u53f7\u7684\u5bf9\u5427\uff0c\u4f46\u4f60\u77e5\u9053\u4e3a\u4ec0\u4e48\u5417\uff1f\u60f3\u8981\u77e5\u9053\u4e3a\u4ec0\u4e48\uff0c\u9700\u8981\u56de\u987e\u524d\u9762\u5b66\u4e60\u7684\u8bed\u6cd5\u77e5\u8bc6\u3002

sizeof \u662f\u4e00\u4e2a\u8fd0\u7b97\u7b26\uff0c\u5b83\u6709\u4e24\u79cd\u4f7f\u7528\u65b9\u5f0f\uff1a

sizeof(\u7c7b\u578b)\nsizeof \u8868\u8fbe\u5f0f\n

\u6211\u4eec\u77e5\u9053\uff0ct \u662f\u8868\u8fbe\u5f0f\uff0c(t) \u4e5f\u662f\u8868\u8fbe\u5f0f\u3002sizeof(T) \u7684\u4f7f\u7528\u7b26\u5408\u89c4\u8303\u3002\u56e0\u6b64 A\u3001B\u3001D \u90fd\u662f\u6b63\u786e\u7684\u3002\u4e3a\u4ec0\u4e48\u4e0d\u89c4\u5b9a sizeof \u7c7b\u578b \u7684\u7528\u6cd5\u5462\uff1f\u56e0\u4e3a\u8fd9\u53ef\u80fd\u5f15\u8d77\u6b67\u4e49\uff0c\u6709\u4e9b\u7c7b\u578b\u540d\u5c31\u643a\u5e26\u7a7a\u683c\uff0c\u6bd4\u5982\uff1ashort int\u3001struct node \u7b49\u7b49\u3002\u4e86\u89e3\u4e86\u8fd9\u4e9b\u77e5\u8bc6\uff0c\u4f60\u80fd\u8bf4\u8bf4\u4e0b\u9762\u7684\u8bed\u53e5\u662f\u5426\u5408\u6cd5\u5417\uff1f\u5982\u679c\u5408\u6cd5\uff0c\u4f60\u80fd\u89e3\u91ca\u5b83\u7684\u542b\u4e49\u5417\uff1f\u5982\u679c\u4e0d\u89c4\u5b9a\u7c7b\u578b\u5fc5\u987b\u5e26\u62ec\u53f7\uff0c\u53ef\u80fd\u4f1a\u4ea7\u751f\u54ea\u4e9b\u4e8c\u4e49\u6027\uff1f

sizeof int***p\nsizeof(int)*p\nsizeof int * + 1\n

\u5982\u679c\u4f60\u60f3\u7684\u8bdd\uff0c\u53ef\u4ee5\u518d\u6765\u4e24\u9053\uff1a

C \u5927 16 \u5e74\u9009\u62e9\u9898

In the following notations, _____ can express a character constant( \u5b57\u7b26\u5e38\u91cf ) correctly.

A. '\\x100' B. 125 C. '\\08' D. '\\'

\u7b54\u6848

B

"},{"location":"programming/archive/23fall/lec1/lec1/#_10","title":"\u7a0b\u5e8f\u7684\u7f16\u8bd1\u8fc7\u7a0b","text":"

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u4e86\u89e3\u7f16\u8bd1\u5668\u548c\u6c47\u7f16\u5668\u662f\u5982\u4f55\u4e00\u6b65\u6b65\u628a\u4f60\u7684\u7a0b\u5e8f\u7f16\u8bd1\u6210\u673a\u5668\u7801\u7684\u3002\u6211\u4eec\u4ee5\u6700\u7ecf\u5178\u7684 C \u8bed\u8a00\u7f16\u8bd1\u7cfb\u7edf GCC \u4e3a\u4f8b\u3002

\u4ec0\u4e48\u662f GCC\uff1f

\u7b80\u5355\u5730\u8bf4\uff0cGNU \u9879\u76ee\u65e8\u5728\u5f00\u53d1\u4e00\u4e2a\u5b8c\u5168\u81ea\u7531\u7684\u64cd\u4f5c\u7cfb\u7edf\u4ee5\u53ca\u914d\u5957\u7684\u8f6f\u4ef6\u3002GCC \u6700\u65e9\u662f GNU C Compiler \u7684\u7b80\u79f0\uff0c\u73b0\u5728\u4ee3\u8868 GNU Compiler Collection\u3002\u8fd9\u8868\u660e\u5b83\u4e0d\u662f\u5355\u4e2a\u7a0b\u5e8f\uff0c\u800c\u662f\u4e00\u7cfb\u5217\u7f16\u8bd1\u5de5\u5177\u7684\u96c6\u5408\uff0c\u5305\u62ec\u4e86 C\u3001C++\u3001Objective-C\u3001Fortran\u3001Ada\u3001Go\u3001D \u7b49\u8bed\u8a00\u7684\u524d\u7aef\uff0c\u4ee5\u53ca\u6c47\u7f16\u5668\u3001\u94fe\u63a5\u5668\u7b49\u540e\u7aef\uff0c\u548c\u8fd9\u4e9b\u8bed\u8a00\u7684\u5e93\u6587\u4ef6\u3002

\u5f53\u6211\u4eec\u4f7f\u7528\u547d\u4ee4 gcc -o test test.c \u7f16\u8bd1\u4e00\u4e2a C \u8bed\u8a00\u7a0b\u5e8f\u65f6\uff0cGCC \u4f1a\u8c03\u7528\u4e00\u7cfb\u5217\u7684\u7a0b\u5e8f\u5c06\u6e90\u4ee3\u7801\u7ffb\u8bd1\u6210\u6c47\u7f16\u8bed\u8a00\u3001\u518d\u7ffb\u8bd1\u6210\u673a\u5668\u8bed\u8a00\uff0c\u6700\u540e\u7ecf\u8fc7\u94fe\u63a5\u4ea7\u751f\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4e0b\u56fe\u5c55\u793a\u4e86\u8fd9\u4e2a\u8fc7\u7a0b\u3002

  1. \u9884\u5904\u7406\uff1a\u7531 C \u9884\u5904\u7406\u5668\uff08C Preprocessor\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u6e90\u4ee3\u7801\u4e2d\u7684\u5b8f\u5b9a\u4e49\u5c55\u5f00\uff0c\u5c06\u5934\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u63d2\u5165\u5230\u6e90\u4ee3\u7801\u4e2d\uff0c\u5220\u9664\u6ce8\u91ca\u7b49\u3002\u9884\u5904\u7406\u540e\u7684\u4ee3\u7801\u6587\u4ef6\u4ee5 .i \u4e3a\u540e\u7f00\u3002
  2. \u7f16\u8bd1\uff1a\u7531 C \u7f16\u8bd1\u5668\uff08C Compiler\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u9884\u5904\u7406\u540e\u7684\u6587\u4ef6\u7ffb\u8bd1\u6210\u6c47\u7f16\u8bed\u8a00\u3002\u7f16\u8bd1\u540e\u5f97\u5230\u7684\u6c47\u7f16\u4ee3\u7801\u6587\u4ef6\u4ee5 .s \u4e3a\u540e\u7f00\u3002
  3. \u6c47\u7f16\uff1a\u7531\u6c47\u7f16\u5668\uff08Assembler\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u6c47\u7f16\u4ee3\u7801\u7ffb\u8bd1\u6210\u673a\u5668\u8bed\u8a00\u3002\u6c47\u7f16\u540e\u5f97\u5230\u7684\u673a\u5668\u4ee3\u7801\u6587\u4ef6\u4ee5 .o \u4e3a\u540e\u7f00\u3002
  4. \u94fe\u63a5\uff1a\u7531\u94fe\u63a5\u5668\uff08Linker\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u591a\u4e2a\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u94fe\u63a5\u540e\u5f97\u5230\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4ee5 .exe \u4e3a\u540e\u7f00\u3002
"},{"location":"programming/archive/23fall/lec1/lec1/#gcc","title":"\u89e3\u8bfb gcc \u663e\u793a\u7684\u8be6\u7ec6\u4fe1\u606f","text":"

\u4e0b\u9762\u8fd9\u4e9b\u6587\u672c\u662f gcc -v -o prog main.c sum.c \u547d\u4ee4\u7684\u8f93\u51fa\u7ed3\u679c\u3002

gcc \u7684\u8f93\u51fa\u4fe1\u606f

\u70b9\u51fb\u6587\u672c\u4e2d\u5e26\u5706\u5708\u7684 + \u53f7\u53ef\u4ee5\u5c55\u5f00\u8be6\u7ec6\u4fe1\u606f\uff0c\u9ad8\u4eae\u7684\u884c\u662f\u8fd0\u884c\u67d0\u4e2a\u7f16\u8bd1\u5de5\u5177\u7684\u5177\u4f53\u547d\u4ee4\u3002

<!--(1)!-->Using built-in specs.\nCOLLECT_GCC=gcc\nCOLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper\nOFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa\nOFFLOAD_TARGET_DEFAULT=1\nTarget: x86_64-linux-gnu\nConfigured with: ../src/configure -v --with-pkgversion='Ubuntu 12.3.0-1ubuntu1~23.04' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-12-DAPbBt/gcc-12-12.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-DAPbBt/gcc-12-12.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu\nThread model: posix\nSupported LTO compression algorithms: zlib zstd\ngcc version 12.3.0 (Ubuntu 12.3.0-1ubuntu1~23.04) \nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n<!--(2)!--> /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -quiet -v -imultiarch x86_64-linux-gnu main.c -quiet -dumpdir prog- -dumpbase main.c -dumpbase-ext .c -mtune=generic -march=x86-64 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/ccClT5M4.s\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nignoring nonexistent directory \"/usr/local/include/x86_64-linux-gnu\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/include-fixed\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include\"\n<!--(3)!-->#include \"...\" search starts here:\n#include <...> search starts here:\n /usr/lib/gcc/x86_64-linux-gnu/12/include\n /usr/local/include\n /usr/include/x86_64-linux-gnu\n /usr/include\nEnd of search list.\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nCompiler executable checksum: d9353c3f0a32d3e91a16ba312e2a9024\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n<!--(4)!--> as -v --64 -o /tmp/ccEgqpgY.o /tmp/ccClT5M4.s\nGNU assembler version 2.40 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.40\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n<!--(5)!--> /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -quiet -v -imultiarch x86_64-linux-gnu sum.c -quiet -dumpdir prog- -dumpbase sum.c -dumpbase-ext .c -mtune=generic -march=x86-64 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/ccClT5M4.s\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nignoring nonexistent directory \"/usr/local/include/x86_64-linux-gnu\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/include-fixed\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include\"\n#include \"...\" search starts here:\n#include <...> search starts here:\n /usr/lib/gcc/x86_64-linux-gnu/12/include\n /usr/local/include\n /usr/include/x86_64-linux-gnu\n /usr/include\nEnd of search list.\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nCompiler executable checksum: d9353c3f0a32d3e91a16ba312e2a9024\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n as -v --64 -o /tmp/ccxMA26W.o /tmp/ccClT5M4.s\nGNU assembler version 2.40 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.40\nCOMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/\nLIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../:/lib/:/usr/lib/\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog.'\n<!--(6)!--> /usr/lib/gcc/x86_64-linux-gnu/12/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/12/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper -plugin-opt=-fresolution=/tmp/ccyzC2ZB.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o prog /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/12/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/12 -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/12/../../.. /tmp/ccEgqpgY.o /tmp/ccxMA26W.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/12/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crtn.o\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog.'\n
  1. \u6700\u5f00\u5934\u662f gcc \u7684\u76f8\u5173\u4fe1\u606f\uff0c\u5305\u62ec\u5b83\u8fd0\u884c\u7684\u5e73\u53f0\u3001\u914d\u7f6e\u7684\u9009\u9879\u7b49\u3002
  2. \u8fd9\u91cc\u8c03\u7528\u4e86 cc1 \u5b8c\u6210\u9884\u5904\u7406\u548c\u7f16\u8bd1\u9636\u6bb5\uff0c\u5c06\u6e90\u4ee3\u7801\u6587\u4ef6 main.c \u7f16\u8bd1\u6210\u4e86 ASCII \u7f16\u7801\u7684\u6c47\u7f16\u6587\u4ef6 /tmp/ccCWi0p2.s\u3002
  3. \u8fd9\u91cc\u663e\u793a\u4e86\u5934\u6587\u4ef6\u641c\u7d22\u8def\u5f84\uff0c\u5982\u679c\u4f60\u7f16\u8bd1\u65f6\u62a5\u9519\u7f3a\u5c11\u5934\u6587\u4ef6\uff0c\u53ef\u4ee5\u68c0\u67e5\u4e00\u4e0b\u8fd9\u91cc\u6709\u6ca1\u6709\u5305\u542b\u5bf9\u5e94\u7684\u8def\u5f84\u3002
  4. \u8fd9\u91cc\u8c03\u7528\u4e86 as \u5b8c\u6210\u6c47\u7f16\u9636\u6bb5\uff0c\u5c06\u6c47\u7f16\u6587\u4ef6 /tmp/ccCWi0p2.s \u7ffb\u8bd1\u6210\u4e86\u673a\u5668\u8bed\u8a00\u6587\u4ef6 /tmp/ccAnKDEo.o\u3002
  5. \u63a5\u4e0b\u6765\u53c8\u5bf9 sum.c \u91cd\u590d\u9884\u5904\u7406\u3001\u7f16\u8bd1\u548c\u6c47\u7f16\u7684\u8fc7\u7a0b\uff0c\u5f97\u5230\u4e86 /tmp/ccgMFTqK.o\u3002
  6. \u6700\u540e\u8c03\u7528 collect2 \uff08\u8fd9\u662f ld \u7684\u5305\u88c5\u7a0b\u5e8f\uff09\u5b8c\u6210\u94fe\u63a5\u9636\u6bb5\uff0c\u5c06\u4e24\u4e2a\u6e90\u4ee3\u7801\u751f\u6210\u7684\u76ee\u6807\u6587\u4ef6 /tmp/ccAnKDEo.o \u548c /tmp/ccgMFTqK.o \u4e0e\u5176\u4ed6\u5f88\u591a\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u6210\u4e86\u53ef\u6267\u884c\u6587\u4ef6 prog\u3002\u8fd9\u5c31\u662f\u4f60\u80fd\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u7684\u7a0b\u5e8f\u3002
\u4e3a\u4ec0\u4e48\u6ca1\u6709\u770b\u89c1\u9884\u5904\u7406\u5668 cpp \u7684\u6267\u884c\u5462\uff1f

\u67d0\u4e9b\u7248\u672c\u7684 gcc \u4f1a\u5c06\u9884\u5904\u7406\u5668 cpp \u548c\u7f16\u8bd1\u5668 gcc \u5408\u5e76\u6210\u4e00\u4e2a\u6307\u4ee4\uff0c\u6bd4\u5982\u4e0a\u9762\u7684 cc1\uff0c\u8fd9\u6837\u5c31\u4e0d\u7528\u5355\u72ec\u8c03\u7528 cpp \u4e86\u3002

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u8be6\u89e3\u5176\u4e2d\u7684\u6bcf\u4e00\u4e2a\u9636\u6bb5\u4ee5\u53ca\u53ef\u80fd\u4f1a\u53d1\u751f\u7684\u95ee\u9898\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_11","title":"\u9884\u5904\u7406","text":"

\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u67e5\u770b\u9884\u5904\u7406\u540e\u7684\u6587\u4ef6 hello.i\uff1a

cpp hello.c > hello.i\n

\u4f60\u4f1a\u53d1\u73b0\uff0c\u539f\u6765 hello.c \u4e2d #include \u9884\u5904\u7406\u6307\u4ee4\u7684\u5730\u65b9\u88ab\u66ff\u6362\u4e3a\u5b8c\u6574\u7684 stdio.h \u6587\u4ef6\u5185\u5bb9\uff0c\u8fd9\u4e9b\u5185\u5bb9\u5305\u62ec printf \u7b49\u51fd\u6570\u7684\u539f\u578b\u3002\u5176\u4ed6\u9884\u5904\u7406\u6307\u4ee4\uff08\u5728\u540e\u7eed\u8bfe\u7a0b\u4f1a\u5b66\u4e60\u5230\uff09\u6bd4\u5982 #define \u4e5f\u4f1a\u5728\u8fd9\u4e00\u9636\u6bb5\u751f\u6548\u3002\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u53ea\u63d2\u5165\u4e86\u51fd\u6570\u539f\u578b\u800c\u6ca1\u6709\u5b9a\u4e49\uff0c\u63a5\u4e0b\u6765\u7684\u94fe\u63a5\u9636\u6bb5\u4f1a\u89e3\u7b54\u3002

\u9884\u5904\u7406\u9636\u6bb5\u6700\u7ecf\u5e38\u4ea7\u751f\u7684\u95ee\u9898\u662f\u627e\u4e0d\u5230\u5934\u6587\u4ef6\u3002C \u8bed\u8a00\u5934\u6587\u4ef6\u641c\u7d22\u89c4\u5219\u5982\u4e0b\uff1a

\u5982\u679c\u4f60\u7684\u5934\u6587\u4ef6\u4e0d\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\uff0c\u90a3\u4e48\u4f60\u9700\u8981\u4f7f\u7528 -I \u9009\u9879\u544a\u8bc9\u7f16\u8bd1\u5668\u5934\u6587\u4ef6\u7684\u4f4d\u7f6e\u3002\u6bd4\u5982\u4f60\u7684\u5934\u6587\u4ef6\u5728 include \u76ee\u5f55\u4e0b\uff1a

.\n\u251c\u2500\u2500 hello.c\n\u2514\u2500\u2500 include\n \u00a0\u00a0 \u2514\u2500\u2500 header.h\n

\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8bd1\uff1a

gcc -Iinclude -o hello hello.c\n

\u8def\u5f84\u53ef\u4ee5\u662f\u76f8\u5bf9\u8def\u5f84\u6216\u7edd\u5bf9\u8def\u5f84\uff0c\u6bd4\u5982\uff1a

gcc -I../include -o hello hello.c\ngcc -I/home/user/include -o hello hello.c\n

\u53e6\u4e00\u79cd\u65b9\u5f0f\u662f\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf CPATH \u6307\u5b9a\u641c\u7d22\u8def\u5f84\u3002

export CPATH=\"$HOME/.local:$CPATH\"\n

\u8bbe\u7f6e\u540e\uff0c\u4f60\u5e94\u5f53\u80fd\u5728\u7f16\u8bd1\u5668\u7684\u8f93\u51fa\u4fe1\u606f\u4e2d\u770b\u5230\u65b0\u589e\u7684\u8def\u5f84\u3002

#include <...> search starts here:\n /home/bowling/.local\n
"},{"location":"programming/archive/23fall/lec1/lec1/#_12","title":"\u7f16\u8bd1","text":"

\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u67e5\u770b\u7f16\u8bd1\u540e\u7684\u6587\u4ef6 hello.s\uff1a

gcc -S hello.i\n

\u6240\u6709\u9ad8\u7ea7\u8bed\u8a00\u5c42\u9762\u7684\u7c7b\u578b\u3001\u63a7\u5236\u7ed3\u6784\u7b49\uff0c\u90fd\u88ab\u4e0e\u7279\u5b9a CPU \u6307\u4ee4\u96c6\u76f8\u5173\u7684\u6c47\u7f16\u6307\u4ee4\u4ee3\u66ff\u3002\u5728\u6c47\u7f16\u8bed\u8a00\u4e2d\uff0c\u6240\u6709\u6570\u636e\u90fd\u662f\u5b57\u8282\u5757\uff0c\u6ca1\u6709\u7c7b\u578b\u7684\u6982\u5ff5\u3002

\u5728\u8fd9\u4e2a\u9636\u6bb5\uff0c\u7f16\u8bd1\u5668\u4f1a\u68c0\u67e5\u4e00\u4e9b\u95ee\u9898\uff0c\u5e76\u629b\u51fa\u4e0d\u540c\u7b49\u7ea7\u7684\u4fe1\u606f\uff1a

error.c: In function \u2018main\u2019:\nerror.c:9:5: error: too many arguments to function \u2018my_print\u2019\n    9 |     my_print(1);\n      |     ^~~~~~~~\nerror.c:4:6: note: declared here\n    4 | void my_print(void)\n      |      ^~~~~~~~\n
warning.c: In function \u2018main\u2019:\nwarning.c:8:18: warning: format \u2018%d\u2019 expects argument of type \u2018int\u2019, but argument 2 has type \u2018double\u2019 [-Wformat=]\n    8 |     printf(\"a = %d\\n\", a);\n      |                 ~^     ~\n      |                  |     |\n      |                  int   double\n      |                 %f\n

\u5927\u90e8\u5206\u8b66\u544a\u4fe1\u606f\u9ed8\u8ba4\u4e0d\u4f1a\u8f93\u51fa\uff0c\u4f7f\u7528 -Wall \u548c -Wextra \u9009\u9879\u53ef\u4ee5\u6253\u5f00\u66f4\u591a\u7684\u8b66\u544a\u4fe1\u606f\u3002\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 -Werror \u9009\u9879\u5c06\u8b66\u544a\u4fe1\u606f\u89c6\u4e3a\u9519\u8bef\uff0c\u8fd9\u6837\u7f16\u8bd1\u5668\u5c31\u4f1a\u505c\u6b62\u7f16\u8bd1\u3002\u5728\u7f16\u8bd1\u65f6\u5e26\u4e0a\u8fd9\u4e9b\u53c2\u6570\u662f\u4e00\u4e2a\u597d\u4e60\u60ef\u3002

gcc -Wall -Wextra -Werror -o hello hello.c\n
"},{"location":"programming/archive/23fall/lec1/lec1/#_13","title":"\u6c47\u7f16","text":"

\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u6c47\u7f16\u5668\u5c06\u6c47\u7f16\u6307\u4ee4\u7ffb\u8bd1\u4e3a\u673a\u5668\u7801\uff0c\u4ea7\u751f\u53ef\u91cd\u5b9a\u4f4d\u76ee\u6807\u6587\u4ef6 hello.o\uff1a

as -o hello.o hello.s\n
\u76ee\u6807\u6587\u4ef6

\u76ee\u6807\u6587\u4ef6\u4e2d\u5305\u542b\u8ba1\u7b97\u673a\u80fd\u8bfb\u61c2\u7684\u673a\u5668\u4ee3\u7801\u548c\u6570\u636e\uff0c\u6709\u4e09\u79cd\u5f62\u5f0f\uff1a

\u5f62\u5f0f \u7531\u8c01\u4ea7\u751f \u6709\u4ec0\u4e48\u7528 \u53ef\u91cd\u5b9a\u4f4d\u76ee\u6807\u6587\u4ef6 \u7f16\u8bd1\u5668\u6216\u6c47\u7f16\u5668 \u53ea\u5305\u542b\u7f16\u8bd1\u5668\u4e3a\u4f60\u7f16\u5199\u7684\u4ee3\u7801\u7ffb\u8bd1\u7684\u673a\u5668\u8bed\u8a00\u4ee3\u7801\uff0c\u9700\u8981\u4e0e\u5176\u4ed6\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u5408\u5e76\u4e3a\u53ef\u6267\u884c\u76ee\u6807\u6587\u4ef6 \u53ef\u6267\u884c\u76ee\u6807\u6587\u4ef6 \u94fe\u63a5\u5668 \u5305\u542b\u4f60\u7f16\u5199\u7684\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u7684\u5e93\u51fd\u6570\u548c\u542f\u52a8\u4ee3\u7801\u7684\u673a\u5668\u4ee3\u7801\uff0c\u80fd\u591f\u88ab\u64cd\u4f5c\u7cfb\u7edf\u6b63\u786e\u8fd0\u884c \u5171\u4eab\u76ee\u6807\u6587\u4ef6 \u7f16\u8bd1\u5668\u6216\u6c47\u7f16\u5668 \u7ed9\u5176\u4ed6\u7a0b\u5e8f\u7528\u7684\u4ee3\u7801\uff0c\u53ef\u4ee5\u5728\u7a0b\u5e8f\u52a0\u8f7d\u6216\u8fd0\u884c\u65f6\u94fe\u63a5

hello.o \u4e2d\u5305\u542b\u4e86 hello.c \u4e2d\u7684 C \u8bed\u8a00\u4ee3\u7801\u7ffb\u8bd1\u6210\u7684\u4e8c\u8fdb\u5236\u4ee3\u7801\u4ee5\u53ca\u4e00\u4e9b\u6570\u636e\uff0c\u6bd4\u5982\u5b57\u7b26\u4e32 Hello, world.\\n\u3002\u5982\u679c\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00 hello.o\uff0c\u4f60\u4f1a\u770b\u89c1\u4e00\u5806\u4e71\u7801\uff0c\u5176\u4e2d\u5939\u6742\u7740\u4e00\u4e9b\u5b57\u7b26\u3002\u56e0\u4e3a\u5b57\u7b26\u5728\u6e90\u6587\u4ef6\u548c\u5185\u5b58\u4e2d\u90fd\u662f\u7528 ASCII \u7f16\u7801\u7684\uff0c\u6240\u4ee5 ASCII \u5b57\u7b26\u4ecd\u80fd\u88ab\u6587\u672c\u7f16\u8f91\u5668\u8bc6\u522b\uff0c\u4f46\u5176\u4ed6\u7684\u673a\u5668\u6307\u4ee4\u548c\u6570\u636e\u53ea\u4f1a\u88ab\u89e3\u8bfb\u4e3a\u4e71\u7801\u3002

\u5982\u679c\u8fd0\u884c ./hello.o\uff0c\u7ec8\u7aef\u4f1a\u544a\u8bc9\u4f60\u8fd9\u4e2a\u6587\u4ef6\u4e0d\u80fd\u88ab\u64cd\u4f5c\u7cfb\u7edf\u6267\u884c\u3002

exec: Failed to execute process: './hello.o' the file could not be run by the operating system.\n

\u5b83\u8fd8\u7f3a\u5c11\u4e00\u4e9b\u4e1c\u897f\uff0c\u5982\uff1a

\u4e00\u4e2a\u4e0d\u5e26\u542f\u52a8\u4ee3\u7801\u7684\u4f8b\u5b50

Linux \u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u4e00\u822c\u662f _start\uff0c\u5b83\u5b8c\u6210\u4e00\u4e9b\u5185\u5b58\u521d\u59cb\u5316\u7684\u5de5\u4f5c\uff0c\u7136\u540e\u8df3\u8f6c\u5230 main \u51fd\u6570\u3002\u6211\u4eec\u5728\u94fe\u63a5\u9636\u6bb5\u4e0d\u5e26\u4e0a\u542b\u6709\u542f\u52a8\u4ee3\u7801\u7684\u76ee\u6807\u6587\u4ef6\uff0c\u770b\u770b\u5728\u7f3a\u5c11 _start \u7684\u60c5\u51b5\u4e0b\u4f1a\u53d1\u751f\u4ec0\u4e48\u3002

$ ld hello.o -o hello -lc --dynamic-linker /lib64/ld-linux-x86-64.so.2\nld: warning: cannot find entry symbol _start; defaulting to 0000000000401030\n$ ./hello\nHello World.\nfish: Job 1, './hello' terminated by signal SIGSEGV (Address boundary error)\n

\u8fd9\u4e2a\u7a0b\u5e8f\u6e90\u4ee3\u7801\u6b63\u5e38\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u6bb5\u9519\u8bef\u5462\uff1f

\u5728\u94fe\u63a5\u9636\u6bb5\uff0cld \u7684\u8f93\u51fa\u8868\u660e\u627e\u4e0d\u5230\u5165\u53e3\u70b9 _start\uff0c\u56e0\u6b64\u628a\u5165\u53e3\u70b9\u9ed8\u8ba4\u653e\u5728\u4e86 0000000000401030 \u5904\u7684\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u662f main \u51fd\u6570\u3002\u56e0\u6b64\uff0c\u5f53\u7a0b\u5e8f\u6267\u884c\u5230 main \u51fd\u6570\u7684\u6700\u540e\u4e00\u6761\u6307\u4ee4\u65f6\uff0c\u4f1a\u7ee7\u7eed\u5f80\u4e0b\u6267\u884c\uff0c\u4f46\u6b64\u65f6\u6808\u5df2\u7ecf\u88ab\u6e05\u7a7a\uff0c\u56e0\u6b64\u4f1a\u53d1\u751f\u6bb5\u9519\u8bef\u3002

\u4f7f\u7528 gdb \u67e5\u770b\u9519\u8bef\u4f4d\u7f6e\uff1a

Program received signal SIGSEGV, Segmentation fault.\n0x0000000000000001 in ?? ()\n

\u8bc1\u5b9e\u4e86\u4e0a\u9762\u7684\u5206\u6790\u3002

crt \u662f C Runtime \u7684\u7f29\u5199\u3002C \u8bed\u8a00\u76f8\u5173\u542f\u52a8\u4ee3\u7801\u5728\u8fd9\u4e9b\u76ee\u6807\u6587\u4ef6\u4e2d\uff1a

Linux \u5e73\u53f0\u4e0b\uff0c\u5b83\u4eec\u7684\u94fe\u63a5\u987a\u5e8f\u4e3a\uff1a

ld crt1.o crti.o [user_objects] [system_libraries] crtn.o\n

\u5728\u63a5\u4e0b\u6765\u7684\u94fe\u63a5\u6b65\u9aa4\uff0c\u6211\u4eec\u5c06\u8fd9\u4e9b\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u5230\u6211\u4eec\u7684\u7a0b\u5e8f\u4e2d\uff0c\u751f\u6210\u53ef\u4ee5\u6267\u884c\u7684\u7a0b\u5e8f\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_14","title":"\u94fe\u63a5","text":"

\u94fe\u63a5\u6709\u4e24\u79cd\u7c7b\u578b\uff1a\u9759\u6001\u94fe\u63a5\u548c\u52a8\u6001\u94fe\u63a5\u3002

\u9759\u6001\u94fe\u63a5

\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u4e0e\u9759\u6001\u5e93\u94fe\u63a5\uff0c\u90a3\u4e48\u94fe\u63a5\u5668\u4f1a\u5c06\u9759\u6001\u5e93\u4e2d\u7684\u4ee3\u7801\u590d\u5236\u5230\u4f60\u7684\u7a0b\u5e8f\u4e2d\u3002\u8fd9\u6837\uff0c\u4f60\u7684\u7a0b\u5e8f\u5c31\u4e0d\u518d\u4f9d\u8d56\u9759\u6001\u5e93\u4e86\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u8fd0\u884c\u3002\u4f46\u662f\uff0c\u5982\u679c\u9759\u6001\u5e93\u4e2d\u7684\u4ee3\u7801\u53d1\u751f\u4e86\u53d8\u5316\uff0c\u4f60\u7684\u7a0b\u5e8f\u5e76\u4e0d\u4f1a\u81ea\u52a8\u66f4\u65b0\uff0c\u4f60\u9700\u8981\u91cd\u65b0\u7f16\u8bd1\u4f60\u7684\u7a0b\u5e8f\u3002

\u5728 Linux \u7cfb\u7edf\u4e0a\uff0c\u9759\u6001\u5e93\u7684\u6587\u4ef6\u540d\u4ee5 .a \u7ed3\u5c3e\uff0c\u6bd4\u5982 libm.a\u3002\u5728 Window \u4e0a\uff0c\u9759\u6001\u5e93\u7684\u6587\u4ef6\u540d\u4ee5 .lib \u7ed3\u5c3e\uff0c\u6bd4\u5982 libm.lib\u3002\u9759\u6001\u5e93\u53ef\u4ee5\u4f7f\u7528 ar \uff08archive program\uff09\u5de5\u5177\u521b\u5efa\u3002

\u52a8\u6001\u94fe\u63a5

\u5f53\u4f60\u7684\u7a0b\u5e8f\u4e0e\u52a8\u6001\u5e93\u94fe\u63a5\u65f6\uff0c\u7a0b\u5e8f\u4e2d\u521b\u5efa\u4e86\u4e00\u4e2a\u8868\u3002\u5728\u7a0b\u5e8f\u8fd0\u884c\u524d\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5c06\u9700\u8981\u7684\u5916\u90e8\u51fd\u6570\u7684\u673a\u5668\u7801\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u8fd9\u5c31\u662f\u52a8\u6001\u94fe\u63a5\u8fc7\u7a0b\u3002

\u4e0e\u9759\u6001\u94fe\u63a5\u76f8\u6bd4\uff0c\u52a8\u6001\u94fe\u63a5\u4f7f\u7a0b\u5e8f\u6587\u4ef6\u66f4\u5c0f\uff0c\u56e0\u4e3a\u4e00\u4e2a\u52a8\u6001\u5e93\u53ef\u4ee5\u88ab\u591a\u4e2a\u7a0b\u5e8f\u5171\u4eab\uff0c\u8282\u7701\u78c1\u76d8\u7a7a\u95f4\u3002\u90e8\u5206\u64cd\u4f5c\u7cfb\u7edf\u8fd8\u5141\u8bb8\u52a8\u6001\u5e93\u4ee3\u7801\u5728\u5185\u5b58\u4e2d\u7684\u5171\u4eab\uff0c\u8fd8\u80fd\u591f\u8282\u7701\u5185\u5b58\u3002\u52a8\u6001\u5e93\u5347\u7ea7\u65f6\uff0c\u4e5f\u4e0d\u9700\u8981\u91cd\u5199\u7f16\u8bd1\u4f60\u7684\u7a0b\u5e8f\u3002

\u5728 Linux \u7cfb\u7edf\u4e0a\uff0c\u52a8\u6001\u5e93\u7684\u6587\u4ef6\u540d\u4ee5 .so \u7ed3\u5c3e\uff0c\u6bd4\u5982 libm.so\u3002\u5728 Window \u4e0a\uff0c\u52a8\u6001\u5e93\u7684\u6587\u4ef6\u540d\u4ee5 .dll \u7ed3\u5c3e\uff0c\u6bd4\u5982 libm.dll\u3002

\u52a8\u6001\u94fe\u63a5\u5177\u6709\u4e0a\u9762\u63cf\u8ff0\u7684\u4f18\u70b9\uff0c\u56e0\u6b64 GCC \u5c3d\u53ef\u80fd\u5730\u6267\u884c\u52a8\u6001\u94fe\u63a5\u3002

\u94fe\u63a5\u76f8\u5173\u7684\u95ee\u9898\u53ef\u80fd\u51fa\u73b0\u5728\u94fe\u63a5\u65f6\uff08\u9759\u6001\u94fe\u63a5\uff09\u3001\u7a0b\u5e8f\u8fd0\u884c\u524d\u548c\u8fd0\u884c\u4e2d\uff08\u52a8\u6001\u94fe\u63a5\uff09\u3002\u4e0b\u9762\u65f6\u4e00\u4e9b\u5e38\u89c1\u7684\u95ee\u9898\u3002

\u672a\u5b9a\u4e49\u7684\u5f15\u7528

\u5f53\u540c\u5b66\u4eec\u5f00\u59cb\u4f7f\u7528\u5176\u4ed6\u5e93\u6784\u5efa\u5927\u578b\u9879\u76ee\u65f6\uff0c\u8fd9\u6216\u8bb8\u4f1a\u6210\u4e3a\u6700\u5934\u75bc\u7684\u95ee\u9898\u3002\u9996\u5148\u5e94\u5f53\u9605\u8bfb\u5e93\u7684\u4f7f\u7528\u8bf4\u660e\uff0c\u63a5\u4e0b\u6765\u641c\u7d22\u7f3a\u5931\u7684\u7b26\u53f7\u53ef\u80fd\u4f4d\u4e8e\u54ea\u4e9b\u5e93\u6587\u4ef6\u4e2d\u3002

\u7f3a\u5931 .dll

\u5e38\u7528 Windows \u7684\u540c\u5b66\u591a\u591a\u5c11\u5c11\u89c1\u8fc7\u8fd9\u4e2a\u62a5\u9519\uff0c\u53ef\u4ee5\u53bb\u7f51\u4e0a\u641c\u7d22\u76f8\u5e94 .dll \u6587\u4ef6\u653e\u7f6e\u5230\u6b63\u786e\u7684\u76ee\u5f55\u3002

\u7f3a\u5931 .so

Linux \u4e0a\u7684\u52a8\u6001\u5e93\u4e00\u822c\u901a\u8fc7 apt \u7ba1\u7406\uff0c\u641c\u7d22\u76f8\u5e94\u7684\u5305\u5e76\u5b89\u88c5\u5373\u53ef\u3002

\u4e0b\u9762\u8fd9\u884c\u547d\u4ee4\u5728\u6211\u7684\u7cfb\u7edf\u4e0a\u5b8c\u6210\u4e86 hello \u7a0b\u5e8f\u7684\u6b63\u786e\u94fe\u63a5\uff0c\u4e0d\u4e00\u5b9a\u80fd\u5728\u4f60\u7684\u7cfb\u7edf\u4e0a\u8fd0\u884c\u3002\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u67e5\u627e\u5e93\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u8ba9\u5b83\u6210\u529f\u8fd0\u884c\u3002

ld --output hello --dynamic-linker /lib64/ld-linux-x86-64.so.2  /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crti.o -lc hello.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crtn.o\n
"},{"location":"programming/archive/23fall/lec1/lec1/#_15","title":"\u52a8\u6001\u94fe\u63a5\u8fc7\u7a0b","text":"

\u5982\u679c\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u4f9d\u8d56\u4e8e\u52a8\u6001\u5e93\uff0c\u90a3\u4e48\u7a0b\u5e8f\u8fd0\u884c\u524d\uff0c\u52a8\u6001\u94fe\u63a5\u5668\uff08interpreter\uff09\u4f1a\u88ab\u5148\u52a0\u8f7d\u8fd0\u884c\u3002\u5b83\u5c06\u5bfb\u627e\u9700\u8981\u7684\u52a8\u6001\u5e93\uff0c\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u7136\u540e\u5c06\u63a7\u5236\u6743\u4ea4\u7ed9\u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u3002

ld \u7684\u9009\u9879 --dynamic-linker \u5c31\u6307\u5b9a\u4e86\u52a8\u6001\u94fe\u63a5\u5668\u7684\u8def\u5f84\u3002\u76ee\u524d Linux \u7cfb\u7edf\u4f7f\u7528\u7684\u52a8\u6001\u94fe\u63a5\u5668\u4e00\u822c\u662f /lib64/ld-linux-x86-64.so.2\u3002\u5b83\u4e5f\u662f\u4e00\u4e2a\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c\u7684\u7a0b\u5e8f\uff0c\u4f60\u53ef\u4ee5\u8bd5\u8bd5\u8fd0\u884c\u5b83\uff1a

$ /lib64/ld-linux-x86-64.so.2 --help\nYou have invoked 'ld.so', the program interpreter for dynamically-linked ELF programs.  Usually, the program interpreter is invoked automatically when a dynamically-linked executable is started.\n\nYou may invoke the program interpreter program directly from the command line to load and run an ELF executable file; this is like executing that file itself, but always uses the program interpreter you invoked, instead of the program interpreter specified in the executable file you run.  Invoking the program interpreter directly provides access to additional diagnostics, and changing the dynamic linker behavior without setting environment variables (which would be inherited by subprocesses).\n

\u8be5\u9009\u9879\u5c06\u4f1a\u5728\u53ef\u6267\u884c\u76ee\u6807\u6587\u4ef6\u524d\u9762\u52a0\u4e0a\u5bf9\u52a8\u6001\u94fe\u63a5\u5668\u7684\u8bf7\u6c42\u3002\u4f7f\u7528 readelf \u53ef\u4ee5\u67e5\u770b ELF \u683c\u5f0f\u53ef\u6267\u884c\u76ee\u6807\u6587\u4ef6\u7684\u5934\u90e8\u4fe1\u606f\u3002

$ readelf -l /usr/bin/ls | head -20\n\nElf file type is DYN (Shared object file)\nEntry point 0x6b10\nThere are 13 program headers, starting at offset 64\n\nProgram Headers:\n  Type           Offset             VirtAddr           PhysAddr\n                 FileSiz            MemSiz              Flags  Align\n  PHDR           0x0000000000000040 0x0000000000000040 0x0000000000000040\n                 0x00000000000002d8 0x00000000000002d8  R      0x8\n  INTERP         0x0000000000000318 0x0000000000000318 0x0000000000000318\n                 0x000000000000001c 0x000000000000001c  R      0x1\n      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]\n  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000\n                 0x0000000000003510 0x0000000000003510  R      0x1000\n  LOAD           0x0000000000004000 0x0000000000004000 0x0000000000004000\n                 0x0000000000013111 0x0000000000013111  R E    0x1000\n  LOAD           0x0000000000018000 0x0000000000018000 0x0000000000018000\n                 0x0000000000007530 0x0000000000007530  R      0x1000\n  LOAD           0x000000000001ff70 0x0000000000020f70 0x0000000000020f70\n
"},{"location":"programming/archive/23fall/lec1/lec1/#_16","title":"\u9759\u6001\u94fe\u63a5\u8fc7\u7a0b","text":"

\u8fdb\u884c\u9759\u6001\u94fe\u63a5\u65f6\u9700\u8981\u6ce8\u610f\u547d\u4ee4\u884c\u4e2d\u6587\u4ef6\u7684\u987a\u5e8f\u3002

\u770b\u770b\u4e0b\u9762\u7684\u547d\u4ee4\u884c\u53d1\u751f\u4e86\u4ec0\u4e48\uff1f

$ gcc -static ./libvector.a main2.c\n/tmp/cc9XH6Rp.o: In function `main':\nmain2.c:(.text+0x1a): undefined reference to `vector_add'\n

\u94fe\u63a5\u5668\u68c0\u67e5 libvector.a \u5e93\u6587\u4ef6\u65f6\uff0c\u8fd8\u6ca1\u6709\u8bb0\u5f55\u4efb\u4f55\u7b26\u53f7\u5b9a\u4e49\u548c\u5f15\u7528\uff0c\u56e0\u6b64\u5b83\u88ab\u6574\u4e2a\u4e22\u5f03\u4e86\u3002\u5f53\u94fe\u63a5\u5668\u5f00\u59cb\u68c0\u67e5 main2.c \u65f6\uff0c\u4e0d\u4f1a\u518d\u56de\u53bb\u627e libvector.a \u4e86\u3002

\u603b\u800c\u8a00\u4e4b\uff0c\u9759\u6001\u94fe\u63a5\u65f6\uff0c\u5e93\u6587\u4ef6\u4e00\u822c\u653e\u5728\u672b\u5c3e\u3002\u5982\u679c\u5e93\u6587\u4ef6\u4e4b\u95f4\u6709\u76f8\u4e92\u4f9d\u8d56\uff0c\u4e5f\u9700\u8981\u5bf9\u5b83\u4eec\u8fdb\u884c\u6392\u5e8f\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_17","title":"\u7a0b\u5e8f\u8c03\u8bd5\u6280\u672f","text":"\u6742\u8c08\uff1aBug \u7684\u5178\u6545

\u7f16\u7a0b\u662f\u4e00\u4ef6\u590d\u6742\u7684\u5de5\u4f5c\uff0c\u56e0\u4e3a\u662f\u4eba\u505a\u7684\u4e8b\u60c5\uff0c\u6240\u4ee5\u96be\u514d\u7ecf\u5e38\u51fa\u9519\u3002\u636e\u8bf4\u6709\u8fd9\u6837\u4e00\u4e2a\u5178\u6545\uff1a\u65e9\u671f\u7684\u8ba1\u7b97\u673a\u4f53\u79ef\u90fd\u5f88\u5927\uff0c\u6709\u4e00\u6b21\u4e00\u53f0\u8ba1\u7b97\u673a\u4e0d\u80fd\u6b63\u5e38\u5de5\u4f5c\uff0c\u5de5\u7a0b\u5e08\u4eec\u627e\u4e86\u534a\u5929\u539f\u56e0\u6700\u540e\u53d1\u73b0\u662f\u4e00\u53ea\u81ed\u866b\u94bb\u8fdb\u8ba1\u7b97\u673a\u4e2d\u9020\u6210\u7684\u3002\u4ece\u6b64\u4ee5\u540e\uff0c\u7a0b\u5e8f\u4e2d\u7684\u9519\u8bef\u88ab\u53eb\u505a\u81ed\u866b\uff08Bug\uff09\uff0c\u800c\u627e\u5230\u8fd9\u4e9bBug\u5e76\u52a0\u4ee5\u7ea0\u6b63\u7684\u8fc7\u7a0b\u5c31\u53eb\u505a\u8c03\u8bd5\uff08Debug\uff09\u3002\u6709\u65f6\u5019\u8c03\u8bd5\u662f\u4e00\u4ef6\u975e\u5e38\u590d\u6742\u7684\u5de5\u4f5c\uff0c\u8981\u6c42\u7a0b\u5e8f\u5458\u6982\u5ff5\u660e\u786e\u3001\u903b\u8f91\u6e05\u6670\u3001\u6027\u683c\u6c89\u7a33\uff0c\u8fd8\u9700\u8981\u4e00\u70b9\u8fd0\u6c14\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#bug","title":"Bug \u7684\u7c7b\u578b","text":"

\u8c03\u8bd5\u7684\u6280\u80fd\u6211\u4eec\u5728\u540e\u7eed\u7684\u5b66\u4e60\u4e2d\u6162\u6162\u57f9\u517b\uff0c\u4f46\u9996\u5148\u6211\u4eec\u8981\u533a\u5206\u6e05\u695a\u7a0b\u5e8f\u4e2d\u7684 Bug \u5206\u4e3a\u54ea\u51e0\u7c7b\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_18","title":"\u7f16\u8bd1\u65f6\u9519\u8bef","text":"

\u7f16\u8bd1\u5668\u53ea\u80fd\u7ffb\u8bd1\u8bed\u6cd5\u6b63\u786e\u7684\u7a0b\u5e8f\uff0c\u5426\u5219\u5c06\u5bfc\u81f4\u7f16\u8bd1\u5931\u8d25\uff0c\u65e0\u6cd5\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5bf9\u4e8e\u81ea\u7136\u8bed\u8a00\u6765\u8bf4\uff0c\u4e00\u70b9\u8bed\u6cd5\u9519\u8bef\u4e0d\u662f\u5f88\u4e25\u91cd\u7684\u95ee\u9898\uff0c\u56e0\u4e3a\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u8bfb\u61c2\u53e5\u5b50\u3002\u800c\u7f16\u8bd1\u5668\u5c31\u6ca1\u90a3\u4e48\u5bbd\u5bb9\u4e86\uff0c\u53ea\u8981\u6709\u54ea\u6015\u4e00\u4e2a\u5f88\u5c0f\u7684\u8bed\u6cd5\u9519\u8bef\uff0c\u7f16\u8bd1\u5668\u5c31\u4f1a\u8f93\u51fa\u4e00\u6761\u9519\u8bef\u63d0\u793a\u4fe1\u606f\u7136\u540e\u7f62\u5de5\uff0c\u4f60\u5c31\u5f97\u4e0d\u5230\u4f60\u60f3\u8981\u7684\u7ed3\u679c\u3002\u867d\u7136\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\u7f16\u8bd1\u5668\u7ed9\u51fa\u7684\u9519\u8bef\u63d0\u793a\u4fe1\u606f\u5c31\u662f\u4f60\u51fa\u9519\u7684\u4ee3\u7801\u884c\uff0c\u4f46\u4e5f\u6709\u4e2a\u522b\u65f6\u5019\u7f16\u8bd1\u5668\u7ed9\u51fa\u7684\u9519\u8bef\u63d0\u793a\u4fe1\u606f\u5e2e\u52a9\u4e0d\u5927\uff0c\u751a\u81f3\u4f1a\u8bef\u5bfc\u4f60\u3002\u5728\u5f00\u59cb\u5b66\u4e60\u7f16\u7a0b\u7684\u524d\u51e0\u4e2a\u661f\u671f\uff0c\u4f60\u53ef\u80fd\u4f1a\u82b1\u5927\u91cf\u7684\u65f6\u95f4\u6765\u7ea0\u6b63\u8bed\u6cd5\u9519\u8bef\u3002\u7b49\u5230\u6709\u4e86\u4e00\u4e9b\u7ecf\u9a8c\u4e4b\u540e\uff0c\u8fd8\u662f\u4f1a\u72af\u8fd9\u6837\u7684\u9519\u8bef\uff0c\u4e0d\u8fc7\u4f1a\u5c11\u5f97\u591a\uff0c\u800c\u4e14\u4f60\u80fd\u66f4\u5feb\u5730\u53d1\u73b0\u9519\u8bef\u539f\u56e0\u3002\u7b49\u5230\u7ecf\u9a8c\u66f4\u4e30\u5bcc\u4e4b\u540e\u4f60\u5c31\u4f1a\u89c9\u5f97\uff0c\u8bed\u6cd5\u9519\u8bef\u662f\u6700\u7b80\u5355\u6700\u4f4e\u7ea7\u7684\u9519\u8bef\uff0c\u7f16\u8bd1\u5668\u7684\u9519\u8bef\u63d0\u793a\u4e5f\u5c31\u90a3\u4e48\u51e0\u79cd\uff0c\u5373\u4f7f\u9519\u8bef\u63d0\u793a\u662f\u6709\u8bef\u5bfc\u7684\u4e5f\u80fd\u591f\u7acb\u523b\u627e\u51fa\u771f\u6b63\u7684\u9519\u8bef\u539f\u56e0\u662f\u4ec0\u4e48\u3002\u76f8\u6bd4\u4e0b\u9762\u4e24\u79cd\u9519\u8bef\uff0c\u8bed\u6cd5\u9519\u8bef\u89e3\u51b3\u8d77\u6765\u8981\u5bb9\u6613\u5f97\u591a\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_19","title":"\u8fd0\u884c\u65f6\u9519\u8bef","text":"

\u7f16\u8bd1\u5668\u68c0\u67e5\u4e0d\u51fa\u8fd9\u7c7b\u9519\u8bef\uff0c\u4ecd\u7136\u53ef\u4ee5\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4f46\u5728\u8fd0\u884c\u65f6\u4f1a\u51fa\u9519\u800c\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002\u5bf9\u4e8e\u6211\u4eec\u63a5\u4e0b\u6765\u7684\u51e0\u7ae0\u5c06\u7f16\u5199\u7684\u7b80\u5355\u7a0b\u5e8f\u6765\u8bf4\uff0c\u8fd0\u884c\u65f6\u9519\u8bef\u5f88\u5c11\u89c1\uff0c\u5230\u4e86\u540e\u9762\u7684\u7ae0\u8282\u4f60\u4f1a\u9047\u5230\u8d8a\u6765\u8d8a\u591a\u7684\u8fd0\u884c\u65f6\u9519\u8bef\u3002\u8bfb\u8005\u5728\u4ee5\u540e\u7684\u5b66\u4e60\u4e2d\u8981\u65f6\u523b\u6ce8\u610f\u533a\u5206\u7f16\u8bd1\u65f6\u548c\u8fd0\u884c\u65f6\uff08Run-time\uff09\u8fd9\u4e24\u4e2a\u6982\u5ff5\uff0c\u4e0d\u4ec5\u5728\u8c03\u8bd5\u65f6\u9700\u8981\u533a\u5206\u8fd9\u4e24\u4e2a\u6982\u5ff5\uff0c\u5728\u5b66\u4e60 C \u8bed\u8a00\u7684\u5f88\u591a\u8bed\u6cd5\u65f6\u90fd\u9700\u8981\u533a\u5206\u8fd9\u4e24\u4e2a\u6982\u5ff5\uff0c\u6709\u4e9b\u4e8b\u60c5\u5728\u7f16\u8bd1\u65f6\u505a\uff0c\u6709\u4e9b\u4e8b\u60c5\u5219\u5728\u8fd0\u884c\u65f6\u505a\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_20","title":"\u903b\u8f91\u9519\u8bef\u548c\u8bed\u4e49\u9519\u8bef","text":"

\u7b2c\u4e09\u7c7b\u9519\u8bef\u662f\u903b\u8f91\u9519\u8bef\u548c\u8bed\u4e49\u9519\u8bef\u3002\u5982\u679c\u7a0b\u5e8f\u91cc\u6709\u903b\u8f91\u9519\u8bef\uff0c\u7f16\u8bd1\u548c\u8fd0\u884c\u90fd\u4f1a\u5f88\u987a\u5229\uff0c\u770b\u4e0a\u53bb\u4e5f\u4e0d\u4ea7\u751f\u4efb\u4f55\u9519\u8bef\u4fe1\u606f\uff0c\u4f46\u662f\u7a0b\u5e8f\u6ca1\u6709\u5e72\u5b83\u8be5\u5e72\u7684\u4e8b\u60c5\uff0c\u800c\u662f\u5e72\u4e86\u522b\u7684\u4e8b\u60c5\u3002\u5f53\u7136\u4e0d\u7ba1\u600e\u4e48\u6837\uff0c\u8ba1\u7b97\u673a\u53ea\u4f1a\u6309\u4f60\u5199\u7684\u7a0b\u5e8f\u53bb\u505a\uff0c\u95ee\u9898\u5728\u4e8e\u4f60\u5199\u7684\u7a0b\u5e8f\u4e0d\u662f\u4f60\u771f\u6b63\u60f3\u8981\u7684\uff0c\u8fd9\u610f\u5473\u7740\u7a0b\u5e8f\u7684\u610f\u601d\uff08\u5373\u8bed\u4e49\uff09\u662f\u9519\u7684\u3002\u627e\u5230\u903b\u8f91\u9519\u8bef\u5728\u54ea\u9700\u8981\u5341\u5206\u6e05\u9192\u7684\u5934\u8111\uff0c\u8981\u901a\u8fc7\u89c2\u5bdf\u7a0b\u5e8f\u7684\u8f93\u51fa\u56de\u8fc7\u5934\u6765\u5224\u65ad\u5b83\u5230\u5e95\u5728\u505a\u4ec0\u4e48\u3002

\u901a\u8fc7\u672c\u8282\u4f60\u5c06\u638c\u63e1\u7684\u6700\u91cd\u8981\u7684\u6280\u5de7\u5c31\u662f\u8c03\u8bd5\u3002\u8c03\u8bd5\u7684\u8fc7\u7a0b\u53ef\u80fd\u4f1a\u8ba9\u4f60\u611f\u5230\u4e00\u4e9b\u6cae\u4e27\uff0c\u4f46\u8c03\u8bd5\u4e5f\u662f\u7f16\u7a0b\u4e2d\u6700\u9700\u8981\u52a8\u8111\u7684\u3001\u6700\u6709\u6311\u6218\u548c\u4e50\u8da3\u7684\u90e8\u5206\u3002\u4ece\u67d0\u79cd\u89d2\u5ea6\u770b\u8c03\u8bd5\u5c31\u50cf\u4fa6\u63a2\u5de5\u4f5c\uff0c\u6839\u636e\u638c\u63e1\u7684\u7ebf\u7d22\u6765\u63a8\u65ad\u662f\u4ec0\u4e48\u539f\u56e0\u548c\u8fc7\u7a0b\u5bfc\u81f4\u4e86\u4f60\u6240\u770b\u5230\u7684\u7ed3\u679c\u3002\u8c03\u8bd5\u4e5f\u50cf\u662f\u4e00\u95e8\u5b9e\u9a8c\u79d1\u5b66\uff0c\u6bcf\u6b21\u60f3\u5230\u54ea\u91cc\u53ef\u80fd\u6709\u9519\uff0c\u5c31\u4fee\u6539\u7a0b\u5e8f\u7136\u540e\u518d\u8bd5\u4e00\u6b21\u3002\u5982\u679c\u5047\u8bbe\u662f\u5bf9\u7684\uff0c\u5c31\u80fd\u5f97\u5230\u9884\u671f\u7684\u6b63\u786e\u7ed3\u679c\uff0c\u5c31\u53ef\u4ee5\u63a5\u7740\u8c03\u8bd5\u4e0b\u4e00\u4e2a Bug\uff0c\u4e00\u6b65\u4e00\u6b65\u903c\u8fd1\u6b63\u786e\u7684\u7a0b\u5e8f\uff1b\u5982\u679c\u5047\u8bbe\u9519\u8bef\uff0c\u53ea\u597d\u53e6\u5916\u518d\u627e\u601d\u8def\u518d\u505a\u5047\u8bbe\u3002\u201c\u5f53\u4f60\u628a\u4e0d\u53ef\u80fd\u7684\u5168\u90e8\u5254\u9664\uff0c\u5269\u4e0b\u7684\u2014\u2014\u5373\u4f7f\u770b\u8d77\u6765\u518d\u600e\u4e48\u4e0d\u53ef\u80fd\u2014\u2014\u5c31\u4e00\u5b9a\u662f\u4e8b\u5b9e\u3002\u201d\uff08\u5373\u4f7f\u4f60\u6ca1\u770b\u8fc7\u798f\u5c14\u6469\u65af\u4e5f\u8be5\u770b\u8fc7\u67ef\u5357\u5427\uff09\u3002

\u4e5f\u6709\u4e00\u79cd\u89c2\u70b9\u8ba4\u4e3a\uff0c\u7f16\u7a0b\u548c\u8c03\u8bd5\u662f\u4e00\u56de\u4e8b\uff0c\u7f16\u7a0b\u7684\u8fc7\u7a0b\u5c31\u662f\u9010\u6b65\u8c03\u8bd5\u76f4\u5230\u83b7\u5f97\u671f\u671b\u7684\u7ed3\u679c\u4e3a\u6b62\u3002\u4f60\u5e94\u8be5\u603b\u662f\u4ece\u4e00\u4e2a\u80fd\u6b63\u786e\u8fd0\u884c\u7684\u5c0f\u89c4\u6a21\u7a0b\u5e8f\u5f00\u59cb\uff0c\u6bcf\u505a\u4e00\u6b65\u5c0f\u7684\u6539\u52a8\u5c31\u7acb\u523b\u8fdb\u884c\u8c03\u8bd5\uff0c\u8fd9\u6837\u7684\u597d\u5904\u662f\u603b\u6709\u4e00\u4e2a\u6b63\u786e\u7684\u7a0b\u5e8f\u505a\u53c2\u8003\uff1a\u5982\u679c\u6b63\u786e\u5c31\u7ee7\u7eed\u7f16\u7a0b\uff0c\u5982\u679c\u4e0d\u6b63\u786e\uff0c\u90a3\u4e48\u4e00\u5b9a\u662f\u521a\u624d\u7684\u5c0f\u6539\u52a8\u51fa\u4e86\u95ee\u9898\u3002\u4f8b\u5982\uff0cLinux \u64cd\u4f5c\u7cfb\u7edf\u5305\u542b\u4e86\u6210\u5343\u4e0a\u4e07\u884c\u4ee3\u7801\uff0c\u4f46\u5b83\u4e5f\u4e0d\u662f\u4e00\u5f00\u59cb\u5c31\u89c4\u5212\u597d\u4e86\u5185\u5b58\u7ba1\u7406\u3001\u8bbe\u5907\u7ba1\u7406\u3001\u6587\u4ef6\u7cfb\u7edf\u3001\u7f51\u7edc\u7b49\u7b49\u5927\u7684\u6a21\u5757\uff0c\u4e00\u5f00\u59cb\u5b83\u4ec5\u4ec5\u662f Linus Torvalds \u7528\u6765\u7422\u78e8 Intel 80386 \u82af\u7247\u800c\u5199\u7684\u5c0f\u7a0b\u5e8f\u3002\u636e Larry Greenfield \u8bf4\uff0c\u201cLinus \u7684\u65e9\u671f\u5de5\u7a0b\u4e4b\u4e00\u662f\u7f16\u5199\u4e00\u4e2a\u4ea4\u66ff\u6253\u5370 AAAA \u548c BBBB \u7684\u7a0b\u5e8f\uff0c\u8fd9\u73a9\u610f\u513f\u540e\u6765\u8fdb\u5316\u6210\u4e86 Linux\u3002\u201d\uff08\u5f15\u81ea The Linux User's Guide Beta1 \u7248\uff09\u5728\u540e\u7eed\u7684\u8bfe\u7a0b\u4e2d\u4f1a\u7ed9\u51fa\u66f4\u591a\u5173\u4e8e\u8c03\u8bd5\u548c\u7f16\u7a0b\u5b9e\u8df5\u7684\u5efa\u8bae\u3002

\u6742\u8c08\uff1a\u4e3a\u4ec0\u4e48\u5f88\u591a\u540c\u5b66\u611f\u89c9\u8c03\u8bd5\u7684\u8fc7\u7a0b\u5341\u5206\u714e\u71ac\uff1f

\u6216\u8bb8\u4f60\u4e5f\u4f1a\u5728\u540e\u7eed\u7684\u5b66\u4e60\u4e2d\u4eb2\u8eab\u4f53\u4f1a\u6216\u770b\u5230\uff0c\u540c\u5b66\u4eec\u88ab\u7a0b\u5e8f\u7684 Bug\uff08\u6700\u5178\u578b\u7684\u662f\u6bb5\u9519\u8bef\uff09\u6298\u78e8\u5f97\u7126\u5934\u70c2\u989d\u3002\u8fd9\u53ef\u80fd\u6709\u4ee5\u4e0b\u539f\u56e0\uff1a

"},{"location":"programming/archive/23fall/lec1/lec1/#fprintfstderr","title":"fprintf(stderr) \u662f\u4f60\u6700\u597d\u7684\u670b\u53cb","text":"

\u867d\u7136\u63a5\u4e0b\u6765\u8981\u4ecb\u7ecd\u7684 gdb \u529f\u80fd\u5f3a\u5927\uff0c\u4f46\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u7b80\u5355\u5730\u6253\u5370\u53d8\u91cf\u5c31\u80fd\u5e2e\u4f60\u5b9a\u4f4d\u95ee\u9898\u6240\u5728\u3002

\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528 fprintf(stderr, ...) \u6253\u5370\u8c03\u8bd5\u4fe1\u606f\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5b9a\u4f4d\u5230\u7a0b\u5e8f\u4e2d\u7684\u9519\u8bef\u3002fprintf \u5411\u6307\u5b9a\u7684\u6d41\u8f93\u51fa\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0cstderr \u662f\u6807\u51c6\u9519\u8bef\u6d41\uff0c\u5b83\u4e0d\u4f1a\u88ab\u7f13\u51b2\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u5728\u7a0b\u5e8f\u5d29\u6e83\u65f6\u770b\u5230\u6700\u540e\u7684\u8c03\u8bd5\u4fe1\u606f\uff08\u8fd9\u4e9b\u8f93\u5165\u8f93\u51fa\u7684\u77e5\u8bc6\u4f1a\u5728\u540e\u9762\u7684\u8bfe\u7a0b\u4e2d\u5b66\u5230\uff09\u3002

\u4ee5\u4e00\u4e2a\u5f02\u5e38\u7ec8\u6b62\u7684\u7a0b\u5e8f\u4e3a\u4f8b\uff1a

#include <stdio.h>\n#include <stdlib.h>\n\nint main(void)\n{\n    printf(\"printf \");\n    fprintf(stderr, \"fprintf \");\n    abort();\n}\n

\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a

$ ./debug\nfprintf fish: Job 1, './debug' terminated by signal SIGABRT (Abort)\n

\u53ef\u4ee5\u770b\u5230\u53ea\u6709 fprintf \u51fd\u6570\u7684\u8f93\u51fa\u3002\u5982\u679c\u5728 printf \u8bed\u53e5\u540e\u9762\u52a0\u4e0a\u6362\u884c\u7b26\uff0c\u4f60\u4f1a\u53d1\u73b0 printf \u7684\u8f93\u51fa\u4e5f\u88ab\u6253\u5370\u51fa\u6765\u4e86\u3002\u56e0\u4e3a\u5f53\u8f93\u51fa\u7f13\u51b2\u533a\u9047\u5230 \\n \u65f6\u4e5f\u4f1a\u7acb\u5373\u8f93\u51fa\u3002

\u6b64\u5916\uff0c\u5c06\u9519\u8bef\u4fe1\u606f\u5bfc\u5411\u6807\u51c6\u9519\u8bef\u6d41\u8fd8\u6709\u53e6\u4e00\u4e2a\u597d\u5904\uff0c\u5c31\u662f\u4f60\u53ef\u4ee5\u5206\u522b\u6536\u96c6\u8c03\u8bd5\u4fe1\u606f\u548c\u6b63\u5e38\u8f93\u51fa\u3002\u6bd4\u5982\u4f60\u53ef\u4ee5\u5c06\u8c03\u8bd5\u4fe1\u606f\u91cd\u5b9a\u5411\u5230\u4e00\u4e2a\u6587\u4ef6\uff0c\u800c\u5c06\u6b63\u5e38\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u53e6\u4e00\u4e2a\u6587\u4ef6\u3002

./debug 2> debug.log 1> output.log\n
"},{"location":"programming/archive/23fall/lec1/lec1/#gdb","title":"\u4f7f\u7528 gdb \u8c03\u8bd5\u7a0b\u5e8f","text":"

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u4ee5\u88ab C \u6807\u51c6\u5f03\u7528\u7684\u5e93\u51fd\u6570 gets \u4e3a\u4f8b\uff0c\u7528 gdb \u5bf9\u5176\u8fdb\u884c\u8c03\u8bd5\uff1a

gets.c
char *gets(char *s)\n{\n    int c;\n    char *dest = s;\n    while((c = getchar()) != '\\n' && c != EOF)\n        *dest++ = c;\n    if(c == EOF && dest == s)\n        return NULL;\n    *dest++ = '\\0';\n    return s;\n}\n\nvoid echo()\n{\n    char buf[8];\n    gets(buf);\n    puts(buf);\n}\n
"},{"location":"programming/archive/23fall/lec1/lec1/#_21","title":"\u7f16\u8bd1\u65f6\u5f00\u542f\u8c03\u8bd5\u4fe1\u606f","text":"

\u5728\u7f16\u8bd1\u65f6\uff0c\u4f7f\u7528 -g \u9009\u9879\u5728\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u52a0\u5165\u6e90\u4ee3\u7801\u7684\u4fe1\u606f\uff0c\u6bd4\u5982\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u7b2c\u51e0\u6761\u673a\u5668\u6307\u4ee4\u5bf9\u5e94\u6e90\u4ee3\u7801\u7684\u7b2c\u51e0\u884c\uff0c\u4f46\u5e76\u4e0d\u662f\u628a\u6574\u4e2a\u6e90\u6587\u4ef6\u5d4c\u5165\u5230\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\uff0c\u6240\u4ee5\u5728\u8c03\u8bd5\u65f6\u5fc5\u987b\u4fdd\u8bc1 gdb \u80fd\u627e\u5230\u6e90\u6587\u4ef6\u3002\u8fd9\u4e9b\u4fe1\u606f\u53ef\u4ee5\u5e2e\u52a9\u8c03\u8bd5\u5668\u5b9a\u4f4d\u5230\u6e90\u4ee3\u7801\u7684\u4f4d\u7f6e\u3002

gcc -g -o gets gets.c\n

\u6709\u65f6\uff0c\u56e0\u4e3a GCC \u7684\u7279\u6027\uff0c\u53ef\u80fd\u5bfc\u81f4\u5141\u8bb8\u67d0\u4e9b\u4e0d\u7b26\u5408 C \u6807\u51c6\u7684\u4e8b\u60c5\u53d1\u751f\u3002\u8fd9\u65f6\u4f60\u53ef\u4ee5\u4f7f\u7528 -ansi -pedantic-errors \u6765\u5173\u95ed GCC \u7279\u6027\uff0c\u4e25\u683c\u9075\u5b88 ANSI C\u3002\u8fd9\u6784\u6210\u4e86\u5e38\u7528\u7684\u7f16\u8bd1\u9009\u9879\u3002

gcc -Wall -Werror -ansi -pedantic-errors -g prog1.c -o prog1\n
"},{"location":"programming/archive/23fall/lec1/lec1/#gdb_1","title":"gdb \u7684\u57fa\u672c\u4f7f\u7528","text":"

\u542f\u52a8 gdb \u7a0b\u5e8f\uff1a

GNU gdb (Ubuntu 10.2-6ubuntu1) 10.2\n...\nReading symbols from ./hello...\n(gdb)\n

\u547d\u4ee4\u884c\u7684\u63d0\u793a\u7b26\u4ece $ \u53d8\u6210\u4e86 (gdb)\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u5df2\u7ecf\u8fdb\u5165\u4e86 gdb \u7684\u4ea4\u4e92\u754c\u9762\u3002gdb \u4e2d\u5e38\u7528\u7684\u547d\u4ee4\u5982\u4e0b\uff1a

"},{"location":"programming/archive/23fall/lec1/lec1/#_22","title":"\u68c0\u67e5\u7a0b\u5e8f\u60c5\u51b5","text":"

Linux \u7cfb\u7edf\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u8bbe\u5907\u6587\u4ef6 /dev/zero\uff0c\u5b83\u80fd\u591f\u4f5c\u4e3a\u8f93\u5165\uff0c\u63d0\u4f9b\u65e0\u7a77\u65e0\u5c3d\u7684 0 \u5b57\u8282\u3002\u6211\u4eec\u5c06\u5b83\u4f5c\u4e3a\u8f93\u5165\uff0c\u770b\u770b\u7a0b\u5e8f\u4f1a\u53d1\u751f\u4ec0\u4e48\u3002

(gdb) file gets\nReading symbols from gets...\n(gdb) run < /dev/zero\nStarting program: /mnt/f/Code/_repo/study-assist/docs/programming_lecture/lecture1/code/gets < /dev/zero\n[Thread debugging using libthread_db enabled]\nUsing host libthread_db library \"/lib/x86_64-linux-gnu/libthread_db.so.1\".\n\nProgram received signal SIGSEGV, Segmentation fault.\n0x00005555555551b2 in gets (s=0x7fffffffd760 \"\") at gets.c:8\n8               *dest++ = c;\n

\u56e0\u4e3a\u7a0b\u5e8f\u8bbf\u95ee\u4e86\u975e\u6cd5\u7684\u5730\u5740\u7a7a\u95f4\uff0c\u7cfb\u7edf\u5411\u7a0b\u5e8f\u53d1\u9001\u4fe1\u53f7 SIGSEGV\uff0c\u7a0b\u5e8f\u7ec8\u6b62\u8fd0\u884c\u3002gdb \u4f1a\u81ea\u52a8\u505c\u5728\u53d1\u751f\u9519\u8bef\u7684\u4f4d\u7f6e\uff0c\u8fd9\u91cc\u662f gets.c \u7684\u7b2c 8 \u884c\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 backtrace \u547d\u4ee4\u67e5\u770b\u51fd\u6570\u8c03\u7528\u6808\u3002

(gdb) backtrace\n#0  0x00005555555551b2 in gets (s=0x7fffffffd760 \"\") at gets.c:8\n#1  0x000055555555521b in echo () at gets.c:18\n#2  0x0000000000000000 in ?? ()\n

\u4f7f\u7528 print \u547d\u4ee4\u67e5\u770b\u5404\u4e2a\u53d8\u91cf\u7684\u503c\u3002print/x \u80fd\u591f\u6307\u5b9a\u4ee5\u5341\u516d\u8fdb\u5236\u7684\u5f62\u5f0f\u6253\u5370\u53d8\u91cf\u7684\u503c\u3002

(gdb) print dest\n$1 = 0x7ffffffff001 <error: Cannot access memory at address 0x7ffffffff001>\n(gdb) print s\n$2 = 0x7fffffffd760 \"\"\n(gdb) print dest - s\n$3 = 6305\n(gdb) print c\n$4 = 0\n

gdb \u4e3a\u4f60\u505a\u4e86\u4e00\u4e9b\u63d0\u793a\uff0c\u6bd4\u5982 dest \u73b0\u5728\u6240\u6307\u5411\u7684\u5730\u5740 0x7ffffffff001 \u662f\u7a0b\u5e8f\u65e0\u6cd5\u8bbf\u95ee\u7684\u3002\u68c0\u67e5 dest - s \u7684\u503c\u6211\u4eec\u77e5\u9053\u6b64\u65f6 dest \u6307\u5411\u7684\u5730\u5740\u5df2\u7ecf\u662f s \u540e 6305 \u4e2a\u5b57\u8282\uff0c\u8fdc\u8fdc\u8d85\u51fa\u4e86\u6570\u7ec4 s \u7684\u7a7a\u95f4\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u68c0\u67e5\u5f53\u524d\u8f93\u5165\u7684\u5b57\u7b26 c\uff0c\u5b83\u663e\u7136\u662f 0\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_23","title":"\u65ad\u70b9\u8c03\u8bd5","text":"

\u4f7f\u7528 break <filename>:<line> \u53ef\u4ee5\u5728\u6307\u5b9a\u6587\u4ef6\u6307\u5b9a\u884c\u8bbe\u7f6e\u65ad\u70b9\u3002\u5bf9\u4e8e\u5355\u6587\u4ef6\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u7701\u7565\u6e90\u4ee3\u7801\u6587\u4ef6\u540d\u3002break \u8fd8\u53ef\u4ee5\u63a5\u6536\u51fd\u6570\u540d\u548c\u5730\u5740\u4f5c\u4e3a\u53c2\u6570\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u6761\u4ef6\u8868\u8fbe\u5f0f\uff0c\u8bf7\u4f7f\u7528 help break \u67e5\u770b\u8be6\u7ec6\u7528\u6cd5\u3002

\u6211\u4eec\u5728\u7a0b\u5e8f\u7b2c 8 \u884c *dest++=c \u5904\u8bbe\u7f6e\u4e00\u4e2a\u65ad\u70b9\uff0c\u7136\u540e\u8fd0\u884c\u7a0b\u5e8f\u3002

(gdb) b 8\nBreakpoint 1 at 0x11a3: file gets.c, line 8.\n(gdb) r < /dev/zero\nStarting program: /mnt/f/Code/_repo/study-assist/docs/programming_lecture/lecture1/code/gets < /dev/zero\n\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8               *dest++ = c;\n(gdb) print dest - s\n$1 = 0\n

next \u547d\u4ee4\u5c06\u4f1a\u5355\u884c\u6267\u884c\u7a0b\u5e8f\uff0c\u4e14\u4e0d\u4f1a\u8fdb\u5165\u51fd\u6570\u5185\u90e8\uff08\u5373\u628a\u6574\u4e2a\u51fd\u6570\u5f53\u4f5c\u4e00\u884c\uff09\u3002step \u4f1a\u8fdb\u5165\u51fd\u6570\u5185\u90e8\u4e00\u884c\u4e00\u884c\u6267\u884c\u3002continue \u547d\u4ee4\u5c06\u7ee7\u7eed\u6267\u884c\u7a0b\u5e8f\uff0c\u76f4\u5230\u4e0b\u4e00\u4e2a\u65ad\u70b9\u3002

(gdb) next\n7               while((c = getchar()) != '\\n' && c != EOF)\n(gdb) next\nBreakpoint 1,gets (s=0x7fffffffd760 \"\") at gets.c:8\n8               *dest++ = c;\n(gdb) print dest - s\n$2 =1\n(gdb) continue\nContinuing.\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8               *dest++ = c;\n(gdb) print dest - s\n$3 = 2\n

next \u548c step \u547d\u4ee4\u90fd\u53ef\u4ee5\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\uff0c\u8868\u793a\u6267\u884c\u591a\u5c11\u884c\uff0c\u4e14\u4f1a\u5728\u65ad\u70b9\u5904\u505c\u4e0b\u3002continue \u547d\u4ee4\u4e5f\u53ef\u4ee5\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\uff0c\u8868\u793a\u5ffd\u7565\u63a5\u4e0b\u6765\u5730\u591a\u5c11\u4e2a\u65ad\u70b9\u3002

(gdb) next 20\n\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8               *dest++ = c;\n(gdb) print dest - s\n$4 = 3\n(gdb) continue 20\nWill ignore next 19 crossings of breakpoint 1.  Continuing.\n\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8               *dest++ = c;\n(gdb) print dest - s\n$5 = 23\n
\u8c03\u8bd5\u6280\u5de7

\u76f4\u63a5\u6309 Enter \u952e\uff0cgdb \u4f1a\u91cd\u590d\u4e0a\u4e00\u6761\u547d\u4ee4\u3002\u8fd9\u6837\u5c31\u4e0d\u7528\u4e00\u76f4\u8f93\u5165 next \u6216 step \u4e86\u3002

\u5728\u4e00\u4e9b\u66f4\u4e3a\u590d\u6742\u7684\u7a0b\u5e8f\u4e2d\uff0c\u4f7f\u7528 gdb \u8c03\u8bd5\u7684\u4f18\u8d8a\u6027\u5c31\u9010\u6e10\u663e\u73b0\u51fa\u6765\u4e86\u3002\u4f60\u4e0d\u7528\u9891\u7e41\u66f4\u6539\u6e90\u4ee3\u7801\u63d2\u5165 printf \u8bed\u53e5\uff0c\u53ea\u9700\u8981\u5728 gdb \u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u7136\u540e\u9010\u6b65\u6267\u884c\u7a0b\u5e8f\uff0c\u67e5\u770b\u53d8\u91cf\u7684\u503c\uff0c\u5c31\u80fd\u627e\u5230\u9519\u8bef\u6240\u5728\u3002

\u8fdb\u4e00\u6b65\u5b66\u4e60

\u7531\u4e8e\u4e2a\u4eba\u6c34\u5e73\u4e0d\u8db3\u4ee5\u53ca\u65f6\u95f4\u6709\u9650\uff0c\u6ca1\u80fd\u5199\u51fa\u4e00\u4e2a\u4f53\u9a8c\u8f83\u597d\u7684 GDB \u8c03\u8bd5\u5b9e\u9a8c\u3002\u5341\u5206\u5e0c\u671b\u540c\u5b66\u4eec\u5728\u8bfe\u540e\u53bb\u770b\u770b\u8fd9\u7bc7\u6587\u7ae0Linux C \u4e00\u7ad9\u5f0f\u7f16\u7a0b\uff1a\u7b2c 10 \u7ae0 gdb\uff0c\u628a\u8fd9\u8fb9\u7684\u8c03\u8bd5\u5b9e\u4f8b\u90fd\u8fc7\u4e00\u904d\uff5e

"},{"location":"programming/archive/23fall/lec1/lec1/#_24","title":"\u53c2\u8003\u8d44\u6599","text":"\u53c2\u8003\u8d44\u6599 "},{"location":"programming/archive/23fall/lec1/pre/","title":"\u8bfe\u524d\uff1a\u51c6\u5907\u5f00\u53d1\u4e0e\u8c03\u8bd5\u73af\u5883","text":"

Info

\u672c\u6587\u6863\u66f4\u6539\u81ea\u5468\u5065\u5747\u5b66\u957f\u4e3a\u56fe\u7075\u7a0b\u7b97\u8bfe\u7a0b\u51c6\u5907\u7684\u8d44\u6599\uff0c\u611f\u8c22\u5468\u5065\u5747\u5b66\u957f\u7684\u4ed8\u51fa\u3002

\u5185\u5bb9\u63d0\u8981

\u5728\u53c2\u4e0e\u7ebf\u4e0b\u6388\u8bfe\u524d\uff0c\u540c\u5b66\u4eec\u6700\u597d\u80fd\u591f\u5b89\u88c5\u597d\u76f8\u5173\u7684\u5f00\u53d1\u73af\u5883\uff0c\u4ee5\u4fbf\u80fd\u591f\u66f4\u597d\u7684\u8ddf\u968f\u8001\u5e08\u7684\u8bb2\u89e3\u3002

\u540c\u5b66\u4eec\u53ef\u4ee5\u4ece\u53f3\u4fa7\uff08\u7535\u8111\u7aef\uff09\u6216\u5de6\u4fa7\uff08\u624b\u673a\u7aef\uff09\u76ee\u5f55\u8df3\u8f6c\u5230\u81ea\u5df1\u9700\u8981\u7684\u7ae0\u8282\u3002

\u975e\u8ba1\u7b97\u673a\u4e13\u4e1a\u540c\u5b66\uff0c\u4f7f\u7528 Dev-C++ \u7b49 IDE \u6216\u5728\u7ebf IDE \u5373\u53ef\u3002

\u672c\u7bc7\u6587\u7ae0\u63cf\u8ff0\u7684\u5185\u5bb9\u9002\u7528\u4e8e\u8ba1\u7b97\u673a\u4e13\u4e1a\u7684\u540c\u5b66\u3002\u975e\u8ba1\u7b97\u673a\u4e13\u4e1a\u7684\u540c\u5b66\uff0c\u4e0d\u9700\u8981\u638c\u63e1\u547d\u4ee4\u884c\u7684\u4f7f\u7528\uff0c\u4f7f\u7528 IDE \u5373\u53ef\u3002\u5e76\u4e14\u66f4\u52a0\u63a8\u8350\u5728\u7ebf IDE\uff0c\u56e0\u4e3a\u672c\u5730 IDE \u6709\u65f6\u4e5f\u4f1a\u51fa\u9519\u3002\u6700\u5e38\u89c1\u7684\u4e00\u4e2a\u4f8b\u5b50\u662f\uff1a\u8fd0\u884c\u4e86\u4e00\u6b21\u7a0b\u5e8f\uff0c\u6ca1\u6709\u4ee5\u6070\u5f53\u7684\u65b9\u5f0f\u7ed3\u675f\u8fdb\u7a0b\uff0c\u518d\u6b21\u70b9\u51fb\u7f16\u8bd1\u65f6\u7f16\u8bd1\u5668 ld \u5c31\u4f1a\u56e0\u4e3a .exe \u88ab\u5360\u7528\u65e0\u6cd5\u5199\u5165\u800c\u62a5\u9519\uff0c\u4f46\u62a5\u9519\u4fe1\u606f\u5e76\u4e0d\u4f1a\u8868\u660e\u662f\u4e0a\u4e00\u4e2a\u7a0b\u5e8f\u6ca1\u5173\uff0c\u641e\u4e0d\u61c2\u662f\u600e\u4e48\u56de\u4e8b\u3002\u6211\u8fd8\u89c1\u8fc7\u6709\u540c\u5b66\uff0c\u6bcf\u6b21\u7f16\u8bd1\u5b8c\u8fd0\u884c\u7a0b\u5e8f\uff0c\u90fd\u8981\u88ab 360 \u5148\u626b\u63cf\u4e00\u904d\uff0c\u7b49\u4e2a\u534a\u5206\u949f\u624d\u80fd\u663e\u793a\u7a97\u53e3\u3002\u5728\u7ebf IDE \u4e0d\u53d7\u4f60\u7535\u8111\u7684\u5f71\u54cd\uff0c\u4e0d\u4f1a\u4ea7\u751f\u8fd9\u4e9b\u95ee\u9898\u3002

\u4e0b\u9762\u7684\u5757\u4ee5 Online GDB \u4e3a\u4f8b\uff0c\u5c55\u793a\u5728\u7ebf IDE \u7684\u7528\u6cd5\u3002\u914d\u597d\u73af\u5883\u7684\u540c\u5b66\u4e5f\u53ef\u4ee5\u770b\u4e00\u770b\uff0c\u56e0\u4e3a\u4f60\u53ef\u80fd\u5076\u5c14\u4e34\u65f6\u7528\u5230\u4e00\u4e2a\u6ca1\u6709\u914d\u7f6e\u73af\u5883\u7684\u7535\u8111\uff0c\u8fd9\u65f6\u4f7f\u7528\u5728\u7ebf IDE \u6700\u4e3a\u4fbf\u6377\u3002

Online GDB \u7684\u4f7f\u7528

\u53ef\u4ee5\u8df3\u8fc7\u672c\u7bc7\u6587\u7ae0\u7684\u540c\u5b66

\u7b26\u5408\u4ee5\u4e0b\u63cf\u8ff0\u7684\u540c\u5b66\u53ef\u4ee5\u8df3\u8fc7\u672c\u7bc7\u6587\u7ae0\uff1a

\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\u7684\u540c\u5b66\uff0c\u4e5f\u8bf7\u770b\u4e00\u4e0b Shell \u90e8\u5206\u3002

\u6e29\u99a8\u63d0\u793a

"},{"location":"programming/archive/23fall/lec1/pre/#shell","title":"Shell \u4f7f\u7528\u62fe\u9057","text":"

\u672c\u8282\u6211\u4eec\u8981\u8ba4\u8bc6\u4e00\u4e2a\u5373\u5c06\u6210\u4e3a\u4f60\u7684\u8001\u670b\u53cb\u7684\u4e1c\u897f\u2014\u2014Shell\u3002\u4e0b\u9762\u662f\u540c\u5b66\u4eec\u63a5\u4e0b\u6765\u4f1a\u7ecf\u5e38\u89c1\u5230\u7684\u51e0\u4e2a\u540d\u8bcd\uff1a

\u771f\u6b63\u610f\u4e49\u4e0a\u7684 Terminal

\u5728\u8ba1\u7b97\u673a\u53d1\u5c55\u7684\u65e9\u671f\u9636\u6bb5\uff0c\u8fd8\u6ca1\u6709\u50cf\u73b0\u5728\u7684 Windows \u8fd9\u6837\u7684\u56fe\u5f62\u7528\u6237\u754c\u9762\u3002\u90a3\u65f6\u4eba\u4eec\u4f7f\u7528\u7ec8\u7aef\u4e0e\u8ba1\u7b97\u673a\u4ea4\u4e92\u3002

Terminal \u548c Shell \u7684\u4f8b\u5b50

\u8fd9\u5f20\u56fe\u5c55\u793a\u4e86 Windows Terminal \u548c Powershell\u3002

Terminal \u548c Shell \u7684\u5173\u7cfb

\u53ef\u4ee5\u5c06 Terminal \u7406\u89e3\u6210\u663e\u793a\u5668\uff0c\u5c06 Shell \u7406\u89e3\u6210\u7535\u8111\u4e3b\u673a\u3002

\u6742\u8c08\uff1a\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u547d\u4ee4\u884c\u4ea4\u4e92\u754c\u9762\u5462\uff1f

\u5f88\u7b80\u5355\uff0c\u56e0\u4e3a\u6211\u4eec\u4e0d\u4ec5\u662f\u5728\u4f7f\u7528\u8ba1\u7b97\u673a\uff0c\u800c\u4e14\u662f\u5728\u5b66\u4e60\u8ba1\u7b97\u673a\u3002GUI \u81ea\u7136\u662f\u6700\u9002\u5408\u4e0e\u4eba\u4ea4\u4e92\u7684\uff0c\u4f46\u5b83\u4e5f\u662f\u7531 CLI \u642d\u5efa\u8d77\u6765\u7684\u3002\u6bd4\u5982\uff0c\u4f60\u53ef\u80fd\u5728\u4f7f\u7528 Dev-C++ \u6216 Visual Studio \u7b49 IDE \u8fdb\u884c\u7f16\u7a0b\uff0c\u53ea\u9700\u8981\u70b9\u4e00\u4e0b\u6309\u94ae\u5c31\u80fd\u81ea\u52a8\u5b8c\u6210\u7a0b\u5e8f\u7f16\u8bd1\u6b65\u9aa4\u3002\u8fd9\u56fa\u7136\u65b9\u4fbf\uff0c\u4f46\u662f\u5b83\u672c\u8d28\u4e0a\u662f\u5e2e\u4f60\u5199\u597d\u5e76\u6267\u884c\u4e86\u4e00\u7cfb\u5217\u7f16\u8bd1\u547d\u4ee4\uff0c\u5e2e\u4f60\u5b8c\u6210\u4e86\u547d\u4ee4\u884c\u7684\u64cd\u4f5c\u3002\u5f53\u4f60\u5f00\u59cb\u6784\u5efa\u5927\u578b\u9879\u76ee\u65f6\uff0c\u8fd9\u5f53\u7136\u662f\u6700\u9002\u5408\u7684\u65b9\u6cd5\u3002\u4f46\u4f5c\u4e3a\u521d\u5b66\u8005\uff0c\u6211\u4eec\u5e94\u5f53\u8d81\u6b64\u673a\u4f1a\u4e86\u89e3\u5176\u80cc\u540e\u7684\u539f\u7406\u3002

\u603b\u4e4b\uff1a\u5982\u679c\u8981\u5b66\u4e60\u8ba1\u7b97\u673a\uff0c\u90a3\u4e48\u5c31\u9700\u8981\u5b66\u4e60\u4f7f\u7528\u547d\u4ee4\u4e0e\u8ba1\u7b97\u673a\u4ea4\u4e92\uff0c\u8fd9\u6837\u624d\u80fd\u66f4\u597d\u5730\u7406\u89e3\u8ba1\u7b97\u673a\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002\u6b64\u5916\uff0c\u547d\u4ee4\u884c\u4ea4\u4e92\u754c\u9762\u4e5f\u6709\u8bb8\u591a\u6709\u70b9\uff0c\u6bd4\u5982\uff1a

\u6700\u4e3b\u8981\u7684\u662f\uff0c\u4f60\u4eca\u540e\u4f1a\u7528\u5230\u7684\u5f88\u591a\u5de5\u5177\u4e0d\u4e00\u5b9a\u4f1a\u63d0\u4f9b\u56fe\u5f62\u754c\u9762\uff0c\u4f46\u4e00\u5b9a\u4f1a\u63d0\u4f9b\u547d\u4ee4\u884c\u754c\u9762\u3002\u5b66\u4e60 CLI \u4e00\u5f00\u59cb\u786e\u5b9e\u6709\u4e9b\u96be\u5ea6\uff0c\u4f46\u53ea\u8981\u5b66\u4e86\uff0c\u5c31\u4f1a\u53d7\u76ca\u65e0\u7a77\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#_2","title":"\u8fd0\u884c\u4e0e\u7ec8\u7aef","text":"

\u5728 Windows \u4e0a\u5982\u4f55\u6253\u5f00 Terminal \u5462\uff1f

\u8fd0\u884c\u7a97\u53e3

\u4f7f\u7528 Win+R \u7ec4\u5408\u952e\uff0c\u5c06\u4f1a\u51fa\u73b0\u56fe\u4e2d\u7684\u7a97\u53e3\u3002\u53ef\u4ee5\u5728\u5176\u4e2d\u8f93\u5165\u547d\u4ee4\u8fd0\u884c\uff0c\u5373\u4f7f\u662f Windows XP \u90fd\u53ef\u4ee5\u4f7f\u7528\u3002

\u547d\u4ee4\u63d0\u793a\u7b26 CMD

\u5728\u8fd0\u884c\u7a97\u53e3\u4e2d\u8f93\u5165 cmd \u540e\u56de\u8f66\uff0c\u5c31\u4f1a\u51fa\u73b0\u547d\u4ee4\u63d0\u793a\u7b26\u3002\u547d\u4ee4\u63d0\u793a\u7b26\u662f Windows \u6700\u57fa\u672c\u7684 Shell\uff08\u4e0e Linux \u7684 bash \u540c\u7b49\u5730\u4f4d\uff09\uff0c\u4f46\u662f\u529f\u80fd\u53ca\u5176\u6709\u9650\uff0c\u4e00\u822c\u4e0d\u7528\u3002

Powershell

Powershell \u7b80\u79f0 pwsh\uff0c\u662f Windows \u7684\u65b0\u4e00\u4ee3\u547d\u4ee4\u89e3\u91ca\u5668\u3002\u5b83\u7684\u529f\u80fd\u5f3a\u5927\uff0c\u4f46\u8bed\u6cd5\u548c\u6211\u4eec\u5c06\u8981\u5b66\u4e60\u4e14\u6700\u5e38\u7528\u7684 Linux Shell \u5927\u4e0d\u76f8\u540c\u3002\u6211\u4eec\u5728 Windows \u4e0a\u7ecf\u5e38\u4f7f\u7528 pwsh\uff0c\u4f46\u4e0d\u7528\u82b1\u65f6\u95f4\u53bb\u5b66\u4e60\u5b83\u3002

Windows Terminal

\u8fd9\u662f Windows \u4e0a\u6700\u597d\u7684 Terminal\uff0c\u5bf9\u5404\u79cd Shell \u7684\u663e\u793a\u6548\u679c\u90fd\u652f\u6301\u7684\u5f88\u597d\u3002\u5728 Microsoft Store \u4e2d\u641c\u7d22 Terminal\uff0c\u51fa\u73b0\u56fe\u4e2d\u7684\u9009\u9879\uff0c\u7136\u540e\u9009\u62e9\u5b89\u88c5\u5373\u53ef\u3002\u5b83\u5bf9\u5e94\u4e8e macOS \u4e0a\u7684 iTerm\u3002\u4eca\u540e\u5b66\u4e60 ssh \u65f6\uff0c\u4f60\u8fd8\u53ef\u80fd\u4f1a\u63a5\u89e6\u5230 Termius\u3002

\u5728\u6bd4\u8f83\u65b0\u7248\u672c\u7684 Windows \u4e2d\uff0cWin \u952e\u6253\u5f00\u83dc\u5355\u4e4b\u540e\u8f93\u5165\u5b57\u7b26\u80fd\u591f\u641c\u7d22\u5230\u5bf9\u5e94\u7a0b\u5e8f\uff0c\u9664\u4e86\u5e38\u7528\u7684\u5e94\u7528\u7a0b\u5e8f\u4ee5\u5916\uff0c\u542f\u52a8 cmd.exe \u4e5f\u53ef\u4ee5\u8fd9\u6837\u8fdb\u884c\uff0c\u6548\u679c\u548c Win + R \u76f8\u540c\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#wsl","title":"WSL \u5b89\u88c5\u7b80\u5355\u5f15\u5bfc\uff08\u53ef\u9009\uff09","text":"

\u63a8\u8350\u88c5\u4e00\u88c5\uff0c\u5982\u679c\u4e3b\u529b\u673a\u662f Windows \u5728\u4ee5\u540e\u5c06\u5bf9 WSL \u6709\u8f83\u5927\u9700\u6c42

WSL\uff0c\u5168\u79f0 Windows Subsystem for Linux\uff08\u9002\u7528\u4e8e Linux \u7684 Windows \u5b50\u7cfb\u7edf\uff09\uff0c\u662f\u4e00\u9879\u5141\u8bb8\u5f00\u53d1\u8005\u4e0d\u4f9d\u9760\u5355\u72ec\u7684\u865a\u62df\u673a\u6216\u53cc\u542f\u52a8 (dual booting) \u800c\u5728 Windows \u4e0a\u8fd0\u884c Linux \u73af\u5883\u7684\u529f\u80fd\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#ubuntu","title":"\u5b89\u88c5\uff1a\u4ee5 Ubuntu \u4e3a\u4f8b","text":"

\u5728\u8fd9\u91cc\u4ee5\u5728 Windows11 \u4e0a\u5b89\u88c5 WSL2 Ubuntu \u4e3a\u4f8b\u4ecb\u7ecd\u6700\u7b80\u5355\u7684\u5b89\u88c5\u6d41\u7a0b\uff0c\u8be6\u7ec6\u7684\u4fe1\u606f\u53ef\u4ee5\u53c2\u8003\u5b98\u65b9\u6587\u6863 Install Linux on Windows with WSL \u6216\u8005\u5b83\u7684\u4e2d\u6587\u7248\u3002

Ubuntu \u662f Linux \u7684\u4e00\u79cd\u53d1\u884c\u7248\u672c\uff0c\u5728\u8fd9\u91cc\u5c31\u4e0d\u5bf9 Linux \u7684\u4f17\u591a\u53d1\u884c\u7248\u672c\u8fdb\u884c\u4ecb\u7ecd\u548c\u8bc4\u4ef7\u4e86\u3002\u6709\u80fd\u529b\u548c\u60f3\u6cd5\u7684\u540c\u5b66\u53ef\u4ee5\u81ea\u5df1\u5bf9\u7167\u6559\u7a0b\u5b89\u88c5\u5176\u4ed6\u53d1\u884c\u7248\uff0c\u6bd4\u5982\u5728\u7ec8\u7aef\u8f93\u5165 wsl --list --online \u53ef\u4ee5\u770b\u5230\u6240\u6709\u53ef\u4ee5\u9009\u62e9\u7684 Linux \u53d1\u884c\u7248

\u6ce8\u610f\u5b89\u88c5 WSL \u7684\u5148\u51b3\u6761\u4ef6\uff1aWindows \u7248\u672c\u4e0d\u4f4e\u4e8e Windows 10 20H2\uff08Build 19042\uff09\u6216\u8005 Windows 11\u3002\u5982\u679c\u7248\u672c\u592a\u8001\uff0c\u8bf7\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\uff0c\u5982\u679c\u65e0\u6cd5\u66f4\u65b0\u53ef\u4ee5\u8003\u8651\u91cd\u88c5\u7cfb\u7edf\u3002

\u53ef\u4ee5\u4f7f\u7528 winver \u547d\u4ee4\u67e5\u8be2 Windows \u7248\u672c\uff0cWin + R \u8f93\u5165 winver \u6216\u8005\u5728 Win \u952e\u51fa\u73b0\u7684\u83dc\u5355\u680f\u4e2d\u76f4\u63a5\u8f93\u5165 winver \u90fd\u53ef\u4ee5\u542f\u52a8\u3002\u65b0\u4e70\u7684\u7535\u8111\u53ef\u80fd Windows 11 \u5c45\u591a\uff0c\u5982\u679c\u662f Windows 10 \u7684\u7535\u8111\u7248\u672c\u663e\u793a\u53ef\u80fd\u662f 21H2\uff08\u64cd\u4f5c\u7cfb\u7edf\u5185\u90e8\u7248\u672c 19044.3086\uff09\uff0c\u8fd9\u6837\u4e5f\u662f\u7b26\u5408\u5148\u51b3\u6761\u4ef6\u7684\u3002

\u5728 Powershell\uff08\u7ba1\u7406\u5458\uff09\u4e2d\u76f4\u63a5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u81ea\u52a8\u5b89\u88c5\uff08\u6ce8\u610f\uff0c\u6bcf\u4e00\u884c\u547d\u4ee4\u5206\u522b\u6267\u884c\uff0c\u4e0d\u8981\u591a\u884c\u7c98\u8d34\u6267\u884c\uff09\uff1a

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart\ndism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart\nwsl --install\n

\u4e2d\u9014\u53ef\u80fd\u4f1a\u5f39\u51fa\u4e24\u4e2a\u7a97\u53e3\uff0c\u663e\u793a\u6b63\u5728\u4fee\u6539\u4ec0\u4e48\u4e1c\u897f\uff0c\u7edf\u7edf\u9009\u62e9\u201c\u662f\u201d\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5c06\u51fa\u73b0\u5982\u4e0b\u754c\u9762

\u8fd9\u6837\u5c31\u5b8c\u6210\u4e86 WSL2 Ubuntu \u7684\u5b89\u88c5\u3002

\u9519\u8bef\uff1a0x80370114

\u4f7f\u7528\u7ec8\u7aef\u7684\u4e00\u5927\u597d\u5904\u662f\u65b9\u4fbf\u6253\u5f00 WSL\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u70b9\u51fb Ubuntu 22.04.2 LTS \u6216\u8005\u4f7f\u7528 Ctrl + Shift + 5 \u7ec4\u5408\u952e\u5c31\u53ef\u4ee5\u65b9\u4fbf\u5730\u6253\u5f00 Ubuntu 22.04\u3002\u5f53\u7136\u8fd9\u662f\u56e0\u4e3a\u6211\u5b89\u88c5\u7684\u662f Ubuntu 22.04 \u7684\u7f18\u6545\uff0c\u5728\u4f60\u4eec\u7684\u7535\u8111\u4e2d\u663e\u793a\u7684\u5e94\u8be5\u5c31\u662f Ubuntu\u3002

\u5176\u4ed6 WSL \u7684\u4f7f\u7528\u65b9\u6cd5\u7559\u5f85\u4f60\u4eec\u6162\u6162\u63a2\u7d22\u4e86\uff0c\u5728\u6b64\u4e0d\u518d\u8d58\u8ff0\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#c","title":"\u5b89\u88c5 C \u8bed\u8a00\u7f16\u8bd1\u5668","text":"

\u5982\u679c\u5df2\u7ecf\u5b89\u88c5\u597d WSL\uff0c\u90a3\u4e48\u53ef\u4ee5\u8df3\u8fc7\u672c\u8282\uff0c\u56e0\u4e3a\u57fa\u672c\u4e0a\u4e0d\u9700\u8981\u5728 Windows \u4e0a\u518d\u5b89\u88c5\u7f16\u8bd1\u73af\u5883\u4e86\u3002

\u672c\u7bc7\u76f8\u5bf9\u6bd4\u8f83\u590d\u6742\uff0c\u5982\u679c\u5728\u672c\u7bc7\u914d\u7f6e\u9047\u5230\u96be\u4ee5\u89e3\u51b3\u7684\u56f0\u96be\uff0c\u800c\u4f5c\u4e1a/\u5b9e\u9a8c\u622a\u6b62\u65e5\u671f\u5feb\u8981\u5230\u4e86\uff0c\u53ef\u4ee5\u8df3\u8fc7\u672c\u7bc7\u5b89\u88c5 Dev-C++ \u8fdb\u884c\u4e34\u65f6\u5f00\u53d1\u3002

\u5199\u5b8c\u4e86 C \u8bed\u8a00\u4ee3\u7801\uff0c\u6211\u4eec\u9700\u8981\u8ba9\u5b83\u53d8\u6210\u80fd\u8dd1\u7684\u7a0b\u5e8f\uff0c\u8fd9\u5c31\u9700\u8981\u51c6\u5907 C \u8bed\u8a00\u7684\u7f16\u8bd1\u5668\u652f\u6301\u3002\u4ee5\u4e0b\u4e3b\u8981\u4ecb\u7ecd Windows \u7cfb\u7edf\u7684\u914d\u7f6e\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#gcc","title":"\u5c31\u51b3\u5b9a\u662f\u4f60\u4e86\uff0cgcc","text":"

\u81ea\u7531\u8f6f\u4ef6 (free software)\uff0c\u6839\u636e\u81ea\u7531\u8f6f\u4ef6\u57fa\u91d1\u4f1a\u5bf9\u5176\u7684\u5b9a\u4e49\uff0c\u662f\u4e00\u7c7b\u53ef\u4ee5\u4e0d\u53d7\u9650\u5236\u5730\u81ea\u7531\u4f7f\u7528\u3001\u590d\u5236\u3001\u7814\u7a76\u3001\u4fee\u6539\u548c\u5206\u53d1\u7684\uff0c\u5c0a\u91cd\u7528\u6237\u81ea\u7531\u7684\u8f6f\u4ef6\u3002\u2014\u2014\u7ef4\u57fa\u767e\u79d1

gcc\uff0c\u5168\u79f0 GNU Compiler Collection\uff0c\u8457\u540d\u7684\u81ea\u7531\u8f6f\u4ef6\uff0c\u88ab\u8bb8\u591a\u73b0\u4ee3\u7c7b Unix \u64cd\u4f5c\u7cfb\u7edf\u91c7\u7528\u4e3a\u6807\u51c6\u7f16\u8bd1\u5668\uff0c\u4f46\u662f Windows \u4e0a\u5e76\u4e0d\u76f4\u63a5\u652f\u6301\u3002\u6211\u4eec\u60f3\u8981\u5728 Windows \u7cfb\u7edf\u4e0a\u4f7f\u7528\uff0c\u4e00\u822c\u5f97\u4f9d\u8d56 MinGW \u7684 gcc\uff0ctdm-gcc \u4e5f\u662f\u57fa\u4e8e MinGW \u7684 gcc \u6765\u7684\u3002

\u6709\u80fd\u529b\u7684\u540c\u5b66\u63a8\u8350\u5728 Windows \u4e0a\u5f00\u542f WSL\uff0c\u4f7f\u7528 WSL \u8fdb\u884c C \u8bed\u8a00\u5f00\u53d1\u3002WSL \u53ef\u4ee5\u7406\u89e3\u4e3a\u5728 Windows \u7684\u7535\u8111\u4e2d\u6a21\u62df\u4e00\u4e2a Linux \u7684\u5c0f\u7cfb\u7edf\uff0c\u4ece\u800c\u80fd\u65b9\u4fbf\u5730\u63a7\u5236\u73af\u5883\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#windows-tdm-gcc","title":"Windows \u5c0f\u767d\u6559\u7a0b\u4e4b tdm-gcc","text":"

\u524d\u9762\u9009\u62e9\u4e86 WSL \u7684\u540c\u5b66\u53ef\u4ee5\u81ea\u884c\u914d\u7f6e\uff0c\u7136\u540e\u518d\u770b\u7b2c 3 \u8282\u3002Mac \u7528\u6237\u53ef\u4ee5\u76f4\u63a5\u770b\u7b2c 3 \u8282\u3002

\u53ef\u4ee5\u6309\u7167\u8001\u5e08\u7684\u89c6\u9891\u6559\u7a0b\u4e0b\u8f7d tdm-gcc\uff0c\u76ee\u524d\u6700\u65b0\u7248\u4e3a gcc 10.3.0\u3002

\u9700\u8981\u5224\u65ad\u81ea\u5df1\u7684 Windows \u662f 64 \u4f4d\u7cfb\u7edf\u8fd8\u662f 32 \u4f4d\u7cfb\u7edf\uff08\u73b0\u5728\u4e00\u822c\u90fd\u662f 64 \u4f4d\u7cfb\u7edf\uff09\u3002

Windows 11Windows 10

\u70b9\u51fb Win \u952e\uff0c\u8f93\u5165\u201c\u5173\u4e8e\u201d\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002\u6253\u5f00\u201c\u5173\u4e8e\u4f60\u7684\u7535\u8111\u201d\u540e\u5c31\u53ef\u4ee5\u770b\u5230\u7535\u8111\u662f\u4e0d\u662f 64 \u4f4d\u4e86\uff0c\u65b0\u7535\u8111\u4e00\u822c\u90fd\u662f 64 \u4f4d\u3002

\u684c\u9762\u627e\u5230\u201c\u6b64\u7535\u8111\u201d\uff0c\u53f3\u952e\u5c5e\u6027

\u53ef\u4ee5\u770b\u5230\u662f 64 \u4f4d\u7cfb\u7edf\u8fd8\u662f 32 \u4f4d\u7cfb\u7edf\u3002

64 \u4f4d\u7cfb\u7edf\u76f4\u63a5\u4e0b\u8f7d tdm64-gcc-10.3.0-2.exe \u5b89\u88c5\u5373\u53ef\uff0c32 \u4f4d\u5219\u9009\u62e9 tdm-gcc-10.3.0.exe\u3002

\u51c6\u5907\u5b89\u88c5\u3002\u5bf9\u4e8e\u96f6\u57fa\u7840\u7684\u540c\u5b66\uff0c\u7535\u8111\u91cc\u5e94\u8be5\u8fd8\u6ca1\u88c5\u8fc7 tdm-gcc\uff0c\u9009\u62e9 create \u5373\u53ef\u3002

\u63a5\u4e0b\u6765\u5c31\u662f\u6839\u636e 64/32 \u4f4d\u7cfb\u7edf\u9009\u62e9\u5bf9\u5e94\u7684\u7248\u672c

\u9009\u62e9\u5b89\u88c5\u8def\u5f84\uff0c\u63a8\u8350\u96f6\u57fa\u7840\u540c\u5b66\u9009\u62e9\u9ed8\u8ba4\u8def\u5f84\uff08\u5982 64 \u4f4d\u7684 C:\\TDM-GCC-64\uff09

\u63a5\u4e0b\u6765\u662f\u8981\u8ba4\u771f\u8003\u8651\u7684\u9875\u9762\u3002

\u5982\u679c\u5e0c\u671b\u7528\u66f4\u65b0\u7248\u672c\u7684 gcc \u53ef\u4ee5\u4f7f\u7528 winlibs \u7f16\u8bd1\u7684 mingw-gcc\uff0c\u6216\u8005\u4f60\u53ef\u4ee5\u81ea\u5df1\u9009\u62e9\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#gcc_1","title":"\u6d4b\u8bd5 gcc \u662f\u5426\u6b63\u786e\u5b89\u88c5","text":"WindowsWSLmacOS

\u5728\u547d\u4ee4\u63d0\u793a\u7b26/\u7ec8\u7aef\u4e2d\u8f93\u5165 gcc\uff0c\u5e94\u5f53\u51fa\u73b0\u5982\u4e0b\u4fe1\u606f\uff1a

gcc: fatal error: no input files\ncompilation terminated.\n

\u5982\u679c\u6ca1\u6709\uff0c\u53ef\u80fd\u662f\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5 gcc\uff0c\u6216\u8005\u4f60\u524d\u4e00\u6b65 Add to PATH \u6ca1\u6709\u6b63\u5e38\u8fdb\u884c\uff0c\u53ef\u80fd\u9700\u8981\u53c2\u7167 Windows \u4fee\u6539\u73af\u5883\u53d8\u91cf\u8fdb\u884c\u73af\u5883\u53d8\u91cf\u7684\u68c0\u67e5\u3002

\u547d\u4ee4\u63d0\u793a\u7b26/\u7ec8\u7aef\u4e2d\u8f93\u5165 gcc --version\uff0c\u5e94\u5f53\u51fa\u73b0\u7c7b\u4f3c\u5982\u4e0b\u7684\u4fe1\u606f\u3002

gcc.exe (tdm64-1) 9.2.0\nCopyright (C) 2019 Free Software Foundation, Inc.\nThis is free software; see the source for copying conditions.  There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n

\u6211\u7684\u7248\u672c\u663e\u793a\u662f 9.2.0\uff0c\u662f\u56e0\u4e3a\u88c5\u4e86\u65e7\u7248\u672c\u7684 tdm-gcc\uff0c\u4f60\u4eec\u7684\u663e\u793a\u5c06\u4f1a\u662f 10.3.0\u3002

\u5982\u4e0b\u547d\u4ee4\u5b89\u88c5 gcc\u3002\u5982\u679c\u9519\u8bef\uff0c\u5c1d\u8bd5 sudo apt-get update \u540e\u518d\u91cd\u65b0\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\u3002

sudo apt install gcc\n

\u7ec8\u7aef\u4e2d\u8f93\u5165 gcc\uff0c\u5e94\u5f53\u51fa\u73b0\u5982\u4e0b\u4fe1\u606f\uff1a

gcc: fatal error: no input files\ncompilation terminated.\n

\u7ec8\u7aef\u4e2d\u8f93\u5165 gcc --version\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u7c7b\u4f3c\u5982\u4e0b\u7684\u4fe1\u606f\uff1a

gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0\nCopyright (C) 2021 Free Software Foundation, Inc.\nThis is free software; see the source for copying conditions.  There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n

Mac \u7528\u6237\u76f4\u63a5\u4f7f\u7528 gcc -v \uff08\u6216\u8005 xcode-select --install\uff09\u4f1a\u63d0\u793a\u4f60\u5b89\u88c5\u5f00\u53d1\u8005\u5de5\u5177\uff0c\u7136\u540e\u5c31\u4f1a\u81ea\u52a8\u5b89\u88c5 XCode \u5728\u5185\u7684\u4e00\u7cfb\u5217\u5f00\u53d1\u652f\u6301\uff0c\u6700\u540e\u544a\u8bc9\u4f60\u4f60\u5b89\u88c5\u7684 gcc \u5176\u5b9e\u662f clang\uff0c\u672c\u8d28\u4e0a\u662f\u5b83\u5c06 gcc \u4f5c\u4e3a clang \u7684\u522b\u540d (alias) \u4e86\u3002

\u6210\u529f\u5b89\u88c5\u540e\uff0c\u7ec8\u7aef\u8f93\u5165 gcc \u4f1a\u51fa\u73b0\u5982\u4e0b\u4fe1\u606f\uff1a

clang: error: no input files\n

\u4f7f\u7528 gcc --version \u53ef\u80fd\u51fa\u73b0\u4ee5\u4e0b\u4fe1\u606f\uff1a

Apple clang version 14.0.3 (clang-1403.0.22.14.1)\nTarget: x86_64-apple-darwin22.6.0\nThread model: posix\nInstalledDir: /Library/Developer/CommandLineTools/usr/bin\n

gcc \u548c clang \u90fd\u662f C \u8bed\u8a00\u7f16\u8bd1\u5668\uff0c\u53ea\u662f\u7279\u6027\u4e0a\u5b58\u5728\u5dee\u5f02\u3002\u5728\u4f5c\u4e1a\u548c\u5b9e\u9a8c\u4e2d\uff0c\u4e00\u4e2a\u597d\u7684\u9075\u4ece\u6807\u51c6\u7684 C \u4ee3\u7801\uff0c\u7531\u4e0d\u540c\u7684\u7f16\u8bd1\u5668\u7f16\u8bd1\u540e\u4e0d\u5e94\u5f53\u4ea7\u751f\u4e0d\u540c\u7684\u8fd0\u884c\u7ed3\u679c\u3002\u56e0\u6b64\u5982\u679c\u4f60\u4f7f\u7528 clang \u7f16\u8bd1 C \u4ee3\u7801\u8fd0\u884c\u4e0d\u7b26\u5408\u9884\u671f\uff0c\u4ee3\u7801\u51fa\u95ee\u9898\u7684\u6982\u7387\u6bd4 clang \u7279\u6027\u51fa\u95ee\u9898\u7684\u6982\u7387\u5927\u5f88\u591a\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#windows","title":"Windows \u4fee\u6539\u73af\u5883\u53d8\u91cf","text":"

Windows \u7528\u6237\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u51fa\u73b0\u95ee\u9898\u4e86\u624d\u9700\u8981\u770b\u8fd9\u4e00\u5c0f\u8282

\u68c0\u67e5\u4e00\u4e0b\u73af\u5883\u53d8\u91cf\uff0cWin + R \u952e\u8f93\u5165 sysdm.cpl \u540e\u56de\u8f66\uff0c\u4f1a\u51fa\u73b0\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u754c\u9762\uff0c\u9009\u62e9\u201c\u9ad8\u7ea7\u201d\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a

\u6253\u5f00\u73af\u5883\u53d8\u91cf\uff0c\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u6216\u8005\u201c\u7528\u6237\u53d8\u91cf\u201d\u4e2d\u627e\u5230 PATH \u53d8\u91cf\uff0c\u5728\u5176\u4e2d\u589e\u52a0\u4e00\u9879 tdm-gcc \u7684\u8def\u5f84\u3002\u4f8b\u5982\u4f60\u5982\u679c\u9ed8\u8ba4\u5b89\u88c5 tdm-gcc\uff0c\u90a3\u4e48\u8def\u5f84\u53ef\u80fd\u5c31\u662f C:\\TDM-GCC-64\\bin\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#vscode","title":"VSCode \u5b89\u88c5\u4e0e\u914d\u7f6e","text":"

VSCode \u7684\u5168\u79f0\u662f Visual Studio Code\uff0c\u6ce8\u610f\u5b83\u548c Visual Studio \u5b8c\u5168\u662f\u4e24\u4e2a\u4e1c\u897f

\u4e0d\u5efa\u8bae\u5b89\u88c5 Visual Studio\uff0c\u9664\u975e\u4f60\u6e05\u695a\u4f60\u5b89\u88c5\u5b83\u662f\u4e3a\u4e86\u4ec0\u4e48

\u5728\u8fd9\u91cc\u4ec5\u4ecb\u7ecd Visual Studio Code \u7684\u5b89\u88c5\u3002\u9664\u4e86\u8001\u5e08\u7684\u89c6\u9891\u4e4b\u5916\uff0c\u5927\u5bb6\u5b89\u88c5\u914d\u7f6e\u65f6\u8fd8\u53ef\u4ee5\u53c2\u8003 GZTime \u7684\u6559\u7a0b\uff0c\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bf4\u8fd8\u4e0d\u9519\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#_3","title":"\u5b89\u88c5","text":"

VSCode \u76f4\u63a5\u4ece\u5b98\u7f51\u9009\u62e9\u81ea\u5df1\u5e73\u53f0\u5bf9\u5e94\u7684\u5b89\u88c5\u5305\u4e0b\u8f7d\u5c31\u884c

WindowsMac

Windows \u7684 exe \u5b89\u88c5\u53ef\u4ee5\u5168\u9009\u9ed8\u8ba4\u9009\u9879\u4e00\u8def Next\uff0c\u6bd4\u8f83\u719f\u6089\u7684\u540c\u5b66\u53ef\u4ee5\u81ea\u5b9a\u4e49\u9009\u9879\uff1a

Mac \u7684\u5305\u4e0b\u8f7d\u4e0b\u6765\u4e4b\u540e\u62d6\u5165 Application \u6587\u4ef6\u5939\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c

"},{"location":"programming/archive/23fall/lec1/pre/#_4","title":"\u63d2\u4ef6\u5b89\u88c5","text":"

\u6253\u5f00 VSCode \u540e\uff0c\u5728\u5de6\u4fa7\u7ad6\u680f\u5bfb\u627e\u4e0b\u9762\u8fd9\u4e2a\u56fe\u6807\uff1a

\u70b9\u51fb\u8fd9\u4e2a\u56fe\u6807\u5c31\u8fdb\u5165\u4e86\u63d2\u4ef6\u7ba1\u7406\u3002\u5efa\u8bae\u53ef\u4ee5\u5b89\u88c5\u4e0b\u9762\u4e24\u4e2a\u63d2\u4ef6\uff1a

\u5b89\u88c5\u6c49\u5316\u63d2\u4ef6\u540e\u53ef\u80fd\u9700\u8981\u4f60\u624b\u52a8\u5207\u6362\u663e\u793a\u8bed\u8a00\u3002Ctrl + Shift + P\uff0c\u51fa\u73b0\u7684\u641c\u7d22\u6846\u4e2d\u8f93\u5165 Configure\uff0c\u9009\u62e9 Configure Display Language\u3002

\u968f\u540e\u518d\u9009\u62e9\u201c\u4e2d\u6587 (\u7b80\u4f53)\u201d\u5c31\u53ef\u4ee5\u5b8c\u6210\u754c\u9762\u6c49\u5316\u4e86\u3002

\u82f1\u8bed\u57fa\u7840\u4e0d\u592a\u597d\u7684\u540c\u5b66\u6709\u56f0\u96be\u53ef\u4ee5\u4f7f\u7528\uff0c\u82f1\u8bed\u57fa\u7840\u6bd4\u8f83\u597d\u4ee5\u53ca\u60f3\u8981\u5728\u65e5\u5e38\u5b9e\u8df5\u4e2d\u5b66\u4e60\u82f1\u8bed\u7684\u540c\u5b66\u5efa\u8bae\u8df3\u8fc7\u8fd9\u4e00\u6b65\u3002

\u8fd9\u91cc\u53ea\u63d0\u4f9b\u6700\u57fa\u672c\u7684\u63d2\u4ef6\u548c\u4f7f\u7528\u793a\u4f8b\uff0c\u590d\u6742\u7684\u914d\u7f6e\u4e0e\u4f7f\u7528\u5927\u5bb6\u53ef\u4ee5\u53c2\u8003 GZTime \u7684\u6559\u7a0b

"},{"location":"programming/archive/23fall/lec1/pre/#vscode_1","title":"VSCode \u4f7f\u7528\u7684\u4e00\u4e2a\u7b80\u5355\u793a\u4f8b","text":"

\u8fd9\u91cc\u4e3a\u60f3\u8981\u5c3d\u5feb\u4e0a\u624b\u7684\u540c\u5b66\u63d0\u4f9b\u4e00\u4e2a\u7b80\u5355\u7684\u4f7f\u7528\u793a\u4f8b\u3002\u6253\u5f00 VSCode\uff08\u6253\u5f00\u65f6\u6ca1\u6709\u6307\u5b9a\u5de5\u4f5c\u76ee\u5f55\uff09\uff0c\u5c06\u4f1a\u51fa\u73b0\u5982\u4e0b\u7684\u7a97\u53e3\uff1a

\u5de5\u4f5c\u76ee\u5f55\uff0c\u6307\u67d0\u4e2a\u4e13\u95e8\u5b58\u653e\u4f60\u7528\u4e8e\u67d0\u4e2a\u76ee\u7684\u7684\u6587\u4ef6\u7684\u6587\u4ef6\u5939\u3002\u4f8b\u5982\u4f60\u53ef\u80fd\u4f1a\u5efa\u7acb\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u4e13\u95e8\u5b58\u653e\u6240\u6709\u4e0e\u7b2c\u4e00\u6b21\u4f5c\u4e1a\u76f8\u5173\u7684\u4ee3\u7801\u3001\u6587\u6863\u3001\u914d\u7f6e\u6587\u4ef6\u7b49\uff0c\u5728\u4f60\u4e3a\u5b8c\u6210\u7b2c\u4e00\u6b21\u4f5c\u4e1a\u800c\u5de5\u4f5c\u65f6\uff0c\u8fd9\u4e2a\u6587\u4ef6\u5939\u5c31\u662f\u4f60\u7684\u5de5\u4f5c\u76ee\u5f55

\u70b9\u51fb\u5de6\u4fa7\u7684 Open Folder\uff0c\u9009\u62e9\u4e00\u4e2a\u76ee\u5f55\u4f5c\u4e3a\u4f60\u7684\u5de5\u4f5c\u76ee\u5f55\uff0c\u4e00\u822c\u4f1a\u628a\u4f60\u8fd9\u4e2a\u7a97\u53e3\u6240\u8981\u5904\u7406\u7684\u6240\u6709\u6587\u4ef6\u653e\u7f6e\u5728\u8fd9\u91cc\u3002\u9876\u680f Terminal > New Terminal\uff08\u6216\u7ec8\u7aef > \u65b0\u5efa\u7ec8\u7aef\uff09\u6253\u5f00 VSCode \u7684\u5185\u90e8\u7ec8\u7aef\uff0c\u529f\u80fd\u5927\u81f4\u4e0e\u547d\u4ee4\u63d0\u793a\u7b26/\u7ec8\u7aef\u76f8\u540c\u3002

\u4e0b\u56fe\u5c31\u662f\u6253\u5f00\u4e86\u5de5\u4f5c\u76ee\u5f55\u5e76\u65b0\u5efa\u4e86\u7ec8\u7aef\u7684\u754c\u9762\u72b6\u6001\u3002

\u9f20\u6807\u79fb\u52a8\u5230\u5de5\u4f5c\u533a\uff0c\u6309 New File \u952e\u53ef\u4ee5\u65b0\u5efa\u6587\u4ef6\uff0c\u65c1\u8fb9\u6709\u65b0\u5efa\u6587\u4ef6\u5939\u6309\u952e\u3002\u5f53\u7136\uff0c\u76f4\u63a5\u5728\u5de6\u4fa7\u5de5\u4f5c\u76ee\u5f55\u53f3\u952e\u4e5f\u53ef\u4ee5\u65b0\u5efa\u6587\u4ef6/\u6587\u4ef6\u5939\u3002

\u521b\u5efa test.c\uff0c\u8f93\u5165 Hello World \u7684\u4ee3\u7801\u5e76\u4fdd\u5b58\u6587\u4ef6\u3002\u7136\u540e\u5728\u7ec8\u7aef\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5e76\u6267\u884c\uff1a

gcc test.c\n

\u5728\u4e0d\u540c\u7684\u7cfb\u7edf\u5c06\u4f1a\u751f\u6210\u4e0d\u540c\u7684\u7f16\u8bd1\u4ea7\u7269\u3002

WindowsWSL/macOS

\u5c06\u4f1a\u5728\u548c test.c \u540c\u76ee\u5f55\u4e0b\u751f\u6210 a.exe\uff0c\u968f\u540e\u5728\u7ec8\u7aef\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u6267\u884c

./a.exe\n

\u5c06\u4f1a\u5728\u548c test.c \u540c\u76ee\u5f55\u4e0b\u751f\u6210 a.out\uff0c\u968f\u540e\u5728\u7ec8\u7aef\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u6267\u884c

./a.out\n

\u4ee5\u4e0b\u5c55\u793a\u5728 macOS \u4e0a\u7684\u6267\u884c\u7ed3\u679c\uff1a

\u8fd9\u91cc\u6709\u51e0\u4e2a\u6ce8\u610f\u70b9\uff1a

gcc test.c -o hello.exe\n
"},{"location":"programming/archive/23fall/lec1/pre/#vscode-wsl","title":"VSCode + WSL\uff08\u53ef\u9009\uff09","text":"

\u524d\u9762\u9009\u62e9\u5b89\u88c5\u4e86 WSL \u7684\u4f7f\u7528 Windows \u4e3b\u529b\u673a\u7684\u540c\u5b66\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\uff0c\u975e\u5e38\u6709\u7528\u7684\u529f\u80fd

\u4ee5\u4e0b\u5f15\u5bfc\u4e3b\u8981\u6309\u7167 Microsoft \u7684\u5b98\u65b9\u6587\u6863\uff0c\u4e5f\u53ef\u4ee5\u53c2\u8003\u5176\u4e2d\u6587\u7248\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#vscode-wsl_1","title":"\u4ece VSCode \u8fde\u63a5\u5230 WSL","text":"

\u5b89\u88c5 WSL \u63d2\u4ef6\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a

\u6216\u8005\u4f60\u4e5f\u53ef\u4ee5\u50cf\u5b98\u65b9\u6587\u6863\u90a3\u6837\uff0c\u76f4\u63a5\u5b89\u88c5\u6574\u4e2a Remote Development \u6269\u5c55\u5305\uff1a

\u5176\u4e2d\u4e0d\u4ec5\u6709 WSL\uff0c\u8fd8\u5305\u62ec\u53e6\u5916\u4e09\u4e2a\u975e\u5e38\u6709\u7528\u7684\u8fdc\u7a0b\u5f00\u53d1\u63d2\u4ef6\u3002

\u5982\u679c\u9700\u8981\u5728\u672c\u7a97\u53e3\u8fde\u63a5\u5230 WSL\uff0c\u6216\u8fde\u63a5\u5230\u975e\u9ed8\u8ba4\u7684 WSL \u6240\u5b89\u88c5\u7684\u5176\u4ed6 Linux \u53d1\u884c\u7248\uff0c\u53ef\u4ee5\u9009\u62e9\u5176\u4ed6 WSL \u7684\u547d\u4ee4

\u6ce8\u610f\u4e0a\u56fe\u5de6\u4e0b\u89d2\u6240\u663e\u793a\u7684\u72b6\u6001\uff0c\u8868\u660e\u5df2\u7ecf\u8fde\u63a5\u5230 WSL \u6240\u5b89\u88c5\u7684 Ubuntu-22.04\uff0c\u63a5\u4e0b\u6765\u7684\u5f00\u53d1\u64cd\u4f5c\u548c\u4e0a\u4e00\u8282\u5c31\u533a\u522b\u4e0d\u5927\u4e86\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#wsl-vscode","title":"\u4ece WSL \u542f\u52a8 VSCode","text":"

\u786e\u4fdd\u4f60\u5df2\u7ecf\u5c06 VSCode \u6dfb\u52a0\u5230 PATH \u73af\u5883\u53d8\u91cf\u4e2d\u3002\u5982\u679c\u5df2\u7ecf\u6dfb\u52a0\uff0c\u90a3\u4e48\u76f4\u63a5\u5728 WSL \u7684\u547d\u4ee4\u884c\u4e2d\u4f60\u6240\u5e0c\u671b\u4f5c\u4e3a\u5de5\u4f5c\u76ee\u5f55\u7684\u4f4d\u7f6e\u6267\u884c

code .\n

\u5c31\u53ef\u4ee5\u6253\u5f00 VSCode\uff0c\u8fde\u63a5\u5230 WSL \u5e76\u4e14\u6253\u5f00\u8be5\u76ee\u5f55\u4f5c\u4e3a\u5de5\u4f5c\u76ee\u5f55\u3002. \u5728\u8fd9\u91cc\u8868\u793a\u5f53\u524d\u76ee\u5f55\u5373 pwd\uff0c\u5982\u679c\u5c06\u5b83\u66ff\u6362\u6210\u5176\u4ed6\u76ee\u5f55\u7684\u8def\u5f84\u4e5f\u662f\u53ef\u4ee5\u5c06\u5176\u6253\u5f00\u4f5c\u4e3a\u5de5\u4f5c\u76ee\u5f55\u7684\u3002

\u5982\u679c\u4f60\u8fd8\u672a\u5c06 VSCode \u6dfb\u52a0\u5230 PATH \u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u90a3\u8be5\u529f\u80fd\u5c06\u65e0\u6cd5\u4f7f\u7528\uff0c\u9700\u8981\u4f60\u624b\u52a8\u6dfb\u52a0 VSCode \u5230 PATH \u73af\u5883\u53d8\u91cf\u3002\u4f8b\u5982\u4f60\u7684 Windows \u7528\u6237\u540d\u662f ZTM\uff0c\u5e76\u628a VSCode \u5b89\u88c5\u5728\u9ed8\u8ba4\u76ee\u5f55\uff0c\u90a3\u4e48\u9700\u8981\u5c06 C:\\Users\\ZTM\\AppData\\Local\\Programs\\Microsoft VS Code\\bin \u52a0\u5165\u5230 PATH \u73af\u5883\u53d8\u91cf\uff0c\u53c2\u8003 Windows \u4fee\u6539\u73af\u5883\u53d8\u91cf\u7ae0\u8282\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/","title":"\u8bb2\u4e49\uff1aC \u8bed\u8a00\u7684\u7c7b\u578b\u7cfb\u7edf\u4e0e\u5185\u5b58\u6a21\u578b","text":"

\u65bd\u5de5\u4e2d

\u672c\u9875\u9762\u6b63\u5728\u65bd\u5de5\uff1a

Abstract

Tip

\u5728\u672c\u8282\u8bb2\u4e49\u4e2d\uff0c\u82e5\u65e0\u7279\u522b\u8bf4\u660e\uff0c\u6211\u4eec\u9ed8\u8ba4\u91c7\u7528 C99 \u6807\u51c6\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_1","title":"\u524d\u7f6e\uff1a\u6570\u3001\u8fdb\u5236\u4e0e\u6570\u636e","text":"

\u4f60\u53ef\u4ee5\u901a\u8fc7 %x \u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u6765\u6253\u5370\u5341\u516d\u8fdb\u5236\u6570\u3002

printf(\"%x\\n\", 20231029);\nprintf(\"%d\\n\", 0x20231029);\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_2","title":"\u5982\u4f55\u9605\u8bfb\u5b83\u4eec\uff1f","text":"

\u8fd9\u4e9b\u90fd\u662f\u201c\u5341\u201d\uff1a0b1010\uff0c0o12\uff0c0xa\uff0c10\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#ascii","title":"ASCII","text":"

\u6bcf\u4e2a\u5b57\u7b26\u5bf9\u5e94\u4e00\u4e2a\u6570\u5b57\uff0c\u5373\u5176 ASCII \u7801\u3002\u5982 A \u7684 ASCII \u7801\u4e3a 65\uff0ca \u7684 ASCII \u7801\u4e3a 97\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_3","title":"\u7c7b\u578b\u7cfb\u7edf","text":"

\u7c7b\u578b\u662f\u4e0e\u6570\u636e\u76f8\u5173\u7684\u5c5e\u6027\uff0c\u5b83\u51b3\u5b9a\u4e86\u6570\u636e\u7684\u5b58\u50a8\u65b9\u5f0f\u548c\u53ef\u8fdb\u884c\u7684\u64cd\u4f5c\u3002

\u53d8\u91cf\u662f\u6570\u636e\u7684\u8f7d\u4f53\uff0c\u5b83\u662f\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u7684\u4e00\u5757\u7a7a\u95f4\uff0c\u6709\u7c7b\u578b\u548c\u503c\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_4","title":"\u8ba1\u7b97\u673a\u5982\u4f55\u5b58\u50a8\u6570\u636e\uff1f","text":"

\u5728\u4e00\u53f0 s390x \u67b6\u6784\u7684\u8ba1\u7b97\u673a\u4e0a\uff1a

MAGIC_R(0x20231029);\n// =====\n// 0x20231029: 4 (0x4) byte(s)\n// 0000  20 23 10 29\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_5","title":"\u5927\u7aef\u5e8f\u4e0e\u5c0f\u7aef\u5e8f","text":"\u5927\u7aef\u548c\u5c0f\u7aef\u540d\u79f0\u7684\u6765\u6e90

\u6765\u6e90\u4e8e\u300a\u683c\u5217\u4f5b\u6e38\u8bb0\u300b\u4e2d\u7684\u5927\u5c0f\u7aef\u4e4b\u4e89\uff1a

\u6211\u4e0b\u9762\u8981\u544a\u8bc9\u4f60\u7684\u662f\uff0cLilliput \u548c Blefuscu \u8fd9\u4e24\u5927\u5f3a\u56fd\u5728\u8fc7\u53bb 36 \u4e2a\u6708\u91cc\u4e00\u76f4\u5728\u82e6\u6218\u3002\u6218\u4e89\u5f00\u59cb\u662f\u7531\u4e8e\u4ee5\u4e0b\u7684\u539f\u56e0\uff1a\u6211\u4eec\u5927\u5bb6\u90fd\u8ba4\u4e3a\uff0c\u5403\u9e21\u86cb\u524d\uff0c\u539f\u59cb\u7684\u65b9\u6cd5\u662f\u6253\u7834\u9e21\u86cb\u8f83\u5927\u7684\u4e00\u7aef\uff0c\u53ef\u662f\u5f53\u4eca\u7687\u5e1d\u7684\u7956\u7236\u5c0f\u65f6\u5019\u5403\u9e21\u86cb\uff0c\u4e00\u6b21\u6309\u53e4\u6cd5\u6253\u9e21\u86cb\u65f6\u78b0\u5de7\u5c06\u4e00\u4e2a\u624b\u6307\u5f04\u7834\u4e86\u3002\u56e0\u6b64\u4ed6\u7684\u7236\u4eb2\uff0c\u5f53\u65f6\u7684\u7687\u5e1d\uff0c\u5c31\u4e0b\u4e86\u4e00\u9053\u6555\u4ee4\uff0c\u547d\u4ee4\u5168\u4f53\u81e3\u6c11\u5403\u9e21\u86cb\u65f6\u6253\u7834\u9e21\u86cb\u8f83\u5c0f\u7684\u4e00\u7aef\uff0c\u8fdd\u4ee4\u8005\u91cd\u7f5a\u3002\u8001\u767e\u59d3\u4eec\u5bf9\u8fd9\u9879\u547d\u4ee4\u6781\u5176\u53cd\u611f\u3002\u5386\u53f2\u544a\u8bc9\u6211\u4eec\uff0c\u7531\u6b64\u66fe\u7ecf\u53d1\u751f\u8fc76\u6b21\u53db\u4e71\uff0c\u5176\u4e2d\u4e00\u4e2a\u7687\u5e1d\u9001\u4e86\u547d\uff0c\u53e6\u4e00\u4e2a\u4e22\u4e86\u738b\u4f4d\u3002\u8fd9\u4e9b\u53db\u4e71\u5927\u591a\u90fd\u662f\u7531 Blefuscu \u7684\u56fd\u738b\u5927\u81e3\u4eec\u717d\u52a8\u8d77\u6765\u7684\u3002\u53db\u4e71\u5e73\u606f\u540e\uff0c\u6d41\u4ea1\u7684\u4eba\u603b\u662f\u9003\u5230\u90a3\u4e2a\u5e1d\u56fd\u53bb\u5bfb\u6c42\u907f\u96be\u3002\u636e\u4f30\u8ba1\uff0c\u5148\u540e\u51e0\u6b21\u6709 11000 \u4eba\u60c5\u613f\u53d7\u6b7b\u4e5f\u4e0d\u80af\u53bb\u6253\u7834\u9e21\u86cb\u8f83\u5c0f\u7684\u4e00\u7aef\u3002\u5173\u4e8e\u8fd9\u4e00\u4e89\u7aef\uff0c\u66fe\u51fa\u7248\u8fc7\u51e0\u767e\u672c\u5927\u90e8\u8457\u4f5c\uff0c\u4e0d\u8fc7\u5927\u7aef\u6d3e\u7684\u4e66\u4e00\u76f4\u662f\u53d7\u7981\u7684\uff0c\u6cd5\u5f8b\u4e5f\u89c4\u5b9a\u8be5\u6d3e\u4efb\u4f55\u4eba\u4e0d\u5f97\u505a\u5b98\u3002\u201d

\u4e3b\u6d41\u67b6\u6784\uff08\u5982 x86\u3001AMD64\u3001ARM\uff09\u4f7f\u7528\u5c0f\u7aef\u5e8f\u3002\u4e00\u4e9b\u4e0d\u5e38\u89c1\u7684\u67b6\u6784\uff08\u5982 SPARC\uff09\u4f7f\u7528\u5927\u7aef\u5e8f\u3002\u7f51\u7edc\u534f\u8bae\u4f7f\u7528\u5927\u7aef\u5e8f\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_6","title":"\u5148\u6765\u7ec3\u7ec3\u624b","text":"

\u4f60\u5e94\u5f53\u5df2\u7ecf\u77e5\u9053\uff0c\u4e0d\u540c\u7c7b\u578b\u7684\u53d8\u91cf\u4e00\u822c\u5360\u636e\u4e0d\u540c\u7684\u5b57\u8282\u6570\u3002

int i = 0x12345678;\nMAGIC(i);\n\nlong long ll = 0xfedcba9876543210LL;\nMAGIC(ll);\n\ndouble d = 3.14159265358979323;\nMAGIC(d);\n\nfloat f = d;\nMAGIC(f);\n\nchar c = 'A';\nMAGIC(c);\n\nMAGIC_R('A');\n\nMAGIC_R((short)ll);\n\nMAGIC(\"Hello world! I am a l\" \"ong string.\");\n
\u5728\u5c0f\u7aef\u5e8f\u8ba1\u7b97\u673a\u4e0a\u53ef\u80fd\u7684\u8fd0\u884c\u7ed3\u679c
=====\ni: 4 (0x4) byte\n0000  78 56 34 12\n=====\nll: 8 (0x8) byte\n0000  10 32 54 76 98 ba dc fe\n=====\nd: 8 (0x8) byte\n0000  18 2d 44 54 fb 21 09 40\n=====\nf: 4 (0x4) byte\n0000  db 0f 49 40\n=====\nc: 1 (0x1) bytes\n0000  41\n=====\n'A': 4 (0x4) byte <!--(1)!-->\n0000  41 00 00 00\n=====\n(short)ll: 2 (0x2) byte\n0000  10 32\n=====\n\"Hello world! I am a l\" \"ong string.\": 33 (0x21) byte\n0000  48 65 6c 6c 6f 20 77 6f 72 6c 64 21 20 49 20 61\n0010  6d 20 61 20 6c 6f 6e 67 20 73 74 72 69 6e 67 2e\n0020  00\n
  1. \u5176\u7c7b\u578b\u4e3a int\uff0c\u6545\u5360\u7528 4 \u5b57\u8282\u3002
"},{"location":"programming/archive/23fall/lec2/lec2/#_7","title":"\u57fa\u672c\u7c7b\u578b","text":"

\u7c7b\u578b - cppreference.com

\u6574\u6570\u7c7b\u578b\uff1achar short int long long long

\u5176\u4e2d\uff0c\u9664\u4e86 char \u4ee5\u5916\u7684\u7c7b\u578b\u9ed8\u8ba4\u4e3a signed\uff0c\u5373\u6709\u7b26\u53f7\u6570\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cint \u5c31\u662f signed int\u3002\u5c06 signed \u6362\u4e3a unsigned\uff0c\u5c31\u5f97\u5230\u4e86\u65e0\u7b26\u53f7\u6570\u3002

\u90a3\u4e48 char \u5462\uff1f

char signed char unsigned char \u662f\u4e09\u4e2a\u4e0d\u540c\u7684\u7c7b\u578b\uff0c\u5c3d\u7ba1\u5728\u5927\u591a\u6570\u5b9e\u73b0\u4e2d\uff0cchar \u8868\u73b0\u4e3a\u6709\u7b26\u53f7\u6570\u3002

\u5b57\u7b26\u7c7b\u578b\u89e3\u60d1

\u6216\u8bb8\u4f60\u4f1a\u548c\u6211\u540c\u6837\u5bf9\u4ee5\u4e0b\u51e0\u4e2a\u95ee\u9898\u611f\u5230\u56f0\u60d1\uff1a

\u8fd9\u91cc\u5c06\u89e3\u91ca\u524d\u4e24\u4e2a\u95ee\u9898\uff0c\u7b2c\u4e09\u4e2a\u95ee\u9898\u4e0d\u505a\u8981\u6c42\uff0c\u6709\u5174\u8da3\u53ef\u4ee5\u53c2\u770b\u4e2d\u7684\u76f8\u5173\u5185\u5bb9\u3002

\u591a\u5b57\u7b26\u5e38\u91cf\uff08Multicharacter constants\uff09\u7ee7\u627f\u4e8e C \u8bed\u8a00\u7684\u524d\u8eab B \u8bed\u8a00\u3002\u5b83\u4eec\u7684\u4e3b\u8981\u7528\u9014\u662f\u7528\u4e8e\u7f16\u5199\u6c47\u7f16\u8bed\u8a00\uff0c\u56e0\u4e3a\u6c47\u7f16\u8bed\u8a00\u4e2d\u7684\u6307\u4ee4\u901a\u5e38\u662f\u591a\u5b57\u8282\u7684\u3002\u4f8b\u5982\uff0c'abcd' \u53ef\u4ee5\u7528\u4e8e\u8868\u793a\u4e00\u4e2a 32 \u4f4d\u7684\u6307\u4ee4\u3002

\u5728 C \u6807\u51c6\u4e2d\uff0c\u591a\u5b57\u7b26\u5e38\u91cf\u88ab\u5b9a\u4e49\u4e3a int \u7c7b\u578b\uff0c\u957f\u5ea6\u662f 4 \u4e2a\u5b57\u8282\u3002\u5728 C \u8bed\u8a00\u7684\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u591a\u5b57\u7b26\u5e38\u91cf\u901a\u5e38\u662f\u51fa\u4e8e\u8c03\u8bd5\u76ee\u7684\u800c\u5d4c\u5165\u7ed3\u6784\u4e2d\u7684\u9b54\u6570\uff08Magic Numbers\uff09\uff0c\u5c31\u50cf\u6709\u4e9b\u4eba\u4f1a\u4f7f\u7528 0xfeedbeef \u548c 0xdeadbeef \u800c\u4e0d\u662f NULL \u6765\u6807\u8bb0\u6307\u9488\u7684\u672a\u521d\u59cb\u5316\u548c\u5df2\u5220\u9664\u72b6\u6001\u3002\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f\uff0c\u5982\u679c\u7a0b\u5e8f\u51fa\u73b0\u4e86\u9519\u8bef\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6253\u5370\u51fa\u8fd9\u4e9b\u9b54\u6570\u6765\u5b9a\u4f4d\u9519\u8bef\u7684\u4f4d\u7f6e\u3002

\u6211\u4eec\u4f7f\u7528\u65f6\u5e94\u5f53\u907f\u514d\u5c06\u591a\u5b57\u7b26\u5e38\u91cf\u4ece int \u7c7b\u578b\u8f6c\u6362\u4e3a char \u7c7b\u578b\uff0c\u56e0\u4e3a\u8fd9\u4e00\u8f6c\u6362\u8fc7\u7a0b\u662f\u7531\u7f16\u8bd1\u5668\u5b9e\u73b0\u51b3\u5b9a\u7684\u3002\u6bd4\u5982 char a = 'ABCD'\uff0c\u5728 gcc\u3001clang\u3001msvc \u4e0a\u5747\u4e3a a = 'D'\uff0c\u4f46\u662f\u5728 armcc \u4e0a\u4e3a a = 'A'\u3002

\u56e0\u4e3a\u5b83\u4f1a\u8fd4\u56de EOF\uff0c\u800c EOF \u5728\u6807\u51c6\u4e2d\u5b9a\u4e49\u4e3a int \u7c7b\u578b\uff0c\u901a\u5e38\u4e3a (int)-1\u3002

This macro is an integer value that is returned by a number of narrow stream functions to indicate an end-of-file condition, or some other error situation.

\u4e3a\u4ec0\u4e48\u8981\u8fd9\u4e48\u5b9a\u4e49\uff1f\u4ece\u903b\u8f91\u4e0a\u8bf4\uff0cEOF \u5e94\u5f53\u4e0e\u4efb\u4f55\u4e00\u4e2a\u5b57\u7b26\u503c\u90fd\u4e0d\u540c\u3002(char)-1 \u4e5f\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u5b57\u7b26\uff08\u56e0\u4e3a\u5b83\u662f char \u7c7b\u578b\uff0c\u6839\u636e Latin-1 \u7f16\u7801\uff0cchar \u7c7b\u578b\u7684\u6bcf\u4e2a\u53ef\u80fd\u503c\u90fd\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\uff09\uff0c\u6240\u4ee5\u4e0d\u80fd\u7528\u4f5c EOF\uff0c\u5fc5\u987b\u4f7f\u7528 (int)-1\uff0c\u5b83\u4e0e\u524d\u8005\u5bbd\u5ea6\u4e0d\u540c\uff0c\u56e0\u6b64\u662f\u4e0d\u540c\u7684\u503c\u3002

\u8fd8\u8bb0\u5f97\u7684\u5728\u7c7b\u578b\u8f6c\u6362\u4e2d\u63d0\u5230\u7684\u6574\u5f62\u63d0\u5347\u5417\uff1f\u5982\u679c\u6211\u4eec\u8ba9 getchar() \u8fd4\u56de (char)-1\uff0c\u5f53\u51fd\u6570\u63a5\u6536\u5230 (char)-1 \u65f6\uff0c\u5b83\u4f1a\u6267\u884c\u4ece\u65e0\u7b26\u53f7\u6570\u5230\u6709\u7b26\u53f7\u6570\u7684\u8f6c\u6362\uff08\u5373\u4f7f\u5b9e\u73b0\u4e3a\u6709\u7b26\u53f7\u7684 char\uff09\uff0c\u4ece\u800c\u8fd4\u56de (int)255\uff0c\u8fd9\u4e0e EOF \u7684\u5b9a\u4e49\u4e0d\u7b26\u3002

\u53c2\u8003\u8d44\u6599\uff1a

\u6d6e\u70b9\u7c7b\u578b\uff1afloat double long double

\u590d\u6570\u7c7b\u578b

\u5728\u5176\u540e\u52a0\u4e0a _Complex \u5373\u4e3a\u590d\u6570\u7c7b\u578b\uff0c\u5982 double _Complex\u3002\u76f8\u540c\u7684\uff0c\u6709 _Imaginary\u3002

\u662f\u7684\uff0cC \u5728\u8bed\u8a00\u5c42\u9762\u4e0a\u652f\u6301\u590d\u6570\u548c\u865a\u6570\uff0c\u4f46\u5e76\u4e0d\u662f\u6240\u6709\u7684\u7f16\u8bd1\u5668\u90fd\u652f\u6301\u8fd9\u4e00\u7279\u6027\u3002\u4f8b\u5982\uff0cgcc \u548c clang \u76ee\u524d\u5747\u4e0d\u652f\u6301 _Imaginary\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_8","title":"\u5b9a\u957f\u6574\u6570\u7c7b\u578b\u4e0e\u5176\u4ed6\u6574\u6570\u7c7b\u578b","text":"

\u5728 stdint.h \u4e2d\u5b9a\u4e49\uff0c\u5982 int8_t uint8_t int16_t uint16_t int32_t uint32_t int64_t uint64_t\u3002

sizeof \u8fd0\u7b97\u7b26\u4e0e offsetof \u5b8f\u7684\u7ed3\u679c\uff1asize_t\uff0c\u8db3\u591f\u8868\u793a\u4efb\u4f55\u5bf9\u8c61\u7684\u5927\u5c0f\u3002\u5e38\u88ab\u5b9a\u4e49\u4e3a unsigned long\u3002

\u5728 stddef.h \u4e2d\u5b9a\u4e49\uff0cptrdiff_t \u8868\u793a\u4e24\u4e2a\u6307\u9488\u76f8\u51cf\u7684\u7ed3\u679c\u3002\u5e38\u88ab\u5b9a\u4e49\u4e3a long\u3002

\u5982\u4f55\u8f93\u51fa\u8fd9\u4e9b\u6574\u6570\u7c7b\u578b\uff1f

\u5728 inttypes.h \u4e2d\u5b9a\u4e49\u4e86\u4e00\u7cfb\u5217\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0c\u5982 PRId32 \u4e00\u822c\u5c55\u5f00\u4e3a \"d\"\uff0c\u800c PRIu64 \u53ef\u80fd\u5c55\u5f00\u4e3a \"llu\"\u3002

\u8fd9\u4e9b\u5b9a\u4e49\u5728\u4e0d\u540c\u7684\u5e73\u53f0\u4e0a\u53ef\u80fd\u6709\u6240\u4e0d\u540c\u3002\u4f7f\u7528\u8fd9\u4e9b\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u53ef\u4ee5\u4fdd\u8bc1\u5728\u4e0d\u540c\u5e73\u53f0\u4e0a\u8f93\u51fa\u6b63\u786e\u7684\u7ed3\u679c\uff08\u4e14\u4e0d\u4f1a\u5f15\u53d1\u7f16\u8bd1\u5668\u8b66\u544a\uff09\u3002

uint64_t i = 0xdeadbeefcafebabe;\nprintf(\"%\" PRIu64 \"\\n\", i); // \u5e94\u5f53\u5305\u542b inttypes.h\n

\u5bf9\u4e8e size_t \u548c ptrdiff_t\uff0c\u53ef\u4ee5\u4f7f\u7528 %zu \u548c %td\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_9","title":"\u7ed3\u6784\u4f53\u3001\u8054\u5408\u4f53\u3001\u679a\u4e3e\u7c7b\u578b","text":"

\u679a\u4e3e\u7c7b\u578b\u5b9e\u8d28\u4e0a\u662f\u6574\u6570\u7c7b\u578b\u3002\u5b83\u7684\u503c\u662f\u7531\u7f16\u8bd1\u5668\u81ea\u52a8\u5206\u914d\u7684\uff08\u4e00\u822c\u4ece 0 \u5f00\u59cb\uff09\uff0c\u4e5f\u53ef\u624b\u52a8\u6307\u5b9a\u3002

\u7ed3\u6784\u4f53\u7684\u5927\u5c0f\u662f\u5176\u6210\u5458\u5927\u5c0f\u7684\u603b\u548c\uff0c\u52a0\u4e0a\u5bf9\u9f50\u6240\u9700\u7684\u586b\u5145\u5b57\u8282\u3002

struct point {\n  int x;\n  long y;\n};\nstruct point p = {1234, -5678};\nMAGIC(p);\n\nunion un_t {\n  long l;\n  double d;\n};\nunion un_t un;\nun.d = 3.14159265358979323;\nMAGIC(un);\n\nenum en_t { ENA, ENB, ENC = 114514 };\nMAGIC_R(ENA);\nMAGIC_R(ENC);\n\nMAGIC_PTR(&p.x);\nMAGIC_PTR(&p.y);\nMAGIC_PTR(&un.l);\nMAGIC_PTR(&un.d);\n
\u5728\u5c0f\u7aef\u5e8f\u8ba1\u7b97\u673a\u4e0a\u53ef\u80fd\u7684\u8fd0\u884c\u7ed3\u679c
=====\np: 16 (0x10) byte\n0000  d2 04 00 00 00 00 00 00 d2 e9 ff ff ff ff ff ff\n=====\nun: 8 (0x8) byte\n0000  18 2d 44 54 fb 21 09 40\n=====\nENA: 4 (0x4) bytes\n0000  00 00 00 00\n=====\nENC: 4 (0x4) bytes\n0000  52 bf 01 00\n&p.x: 0x16d3cee18\n&p.y: 0x16d3cee20\n&un.l: 0x16d3cee10\n&un.d: 0x16d3cee10\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_10","title":"\u5b57\u7b26\u4e32\uff0c\u6570\u7ec4\uff0c\u51fd\u6570\uff0c\u6307\u9488\u7c7b\u578b","text":"

\u6570\u7ec4\u662f\u4e00\u7cfb\u5217\u76f8\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\u7684\u96c6\u5408\u3002\u6570\u7ec4\u7684\u5927\u5c0f\u662f\u5176\u5143\u7d20\u5927\u5c0f\u7684\u603b\u548c\u3002

int arr[] = { 0xbeef, 0xcafe, 0xdead, 0xface, 0xfeed };\nMAGIC(arr);\n\nchar str1[] = \"Hello world!\";\nconst char *str2 = \"Hello world!\";\nMAGIC(str1);\nMAGIC(str2);\n

\u4ee5 main \u51fd\u6570\u4e3a\u4f8b\uff0c\u5176\u6709\u4e24\u79cd\uff08\u6807\u51c6\u89c4\u5b9a\u7684\uff09\u5f62\u5f0f\uff1a

int main(void);                   // \u7c7b\u578b\u4e3a int(void)\nint main(int argc, char *argv[]); // \u7c7b\u578b\u4e3a int(int, char *[])\n

C \u6807\u51c6\u4e0d\u5141\u8bb8\u5bf9\u51fd\u6570\u7c7b\u578b\u5e94\u7528 sizeof \u8fd0\u7b97\u7b26\u3002

\u6240\u6709\u7684\u6307\u9488\u7c7b\u578b\u90fd\u62e5\u6709\u76f8\u540c\u7684\u5927\u5c0f\u3002\u6211\u4eec\u5c06\u5728\u540e\u9762\u7684\u7ae0\u8282\u4e2d\u8ba8\u8bba\u6307\u9488\u7c7b\u578b\u3002

\u6570\u7ec4\u5230\u6307\u9488\u9000\u5316

"},{"location":"programming/archive/23fall/lec2/lec2/#void","title":"void \u7c7b\u578b","text":"

void \u662f\u4e00\u4e2a\u4e0d\u5b8c\u6574\u7c7b\u578b\uff0c\u5373\u4e0d\u5b58\u5728 void \u7c7b\u578b\u7684\u53d8\u91cf\u3002\u5b83\u4f5c\u4e3a\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\uff0c\u8868\u793a\u51fd\u6570\u6ca1\u6709\u8fd4\u56de\u503c\u3002\u5b83\u4f5c\u4e3a\u51fd\u6570\u7684\u53c2\u6570\u7c7b\u578b\uff0c\u8868\u793a\u51fd\u6570\u4e0d\u63a5\u53d7\u53c2\u6570\u3002

void f(void) { /* \u5b9e\u73b0\u7565\u53bb */ }\nvoid g(void) {\n  return f(); // \u4ec5\u5f53 f \u7684\u8fd4\u56de\u7c7b\u578b\u4e3a void \u65f6\u624d\u80fd\u8fd9\u6837\u5199\n}\n
\u90a3\u4e48 void * \u5462\uff1f

void * \u662f\u4e00\u4e2a\u5b8c\u6574\u7c7b\u578b\uff0c\u5b83\u8868\u793a\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411\u672a\u77e5\u7c7b\u578b\u7684\u5bf9\u8c61\uff08\u5373\uff0c\u201c\u820d\u5f03\u201d\u4e86\u7c7b\u578b\u4fe1\u606f\u7684\u6307\u9488\uff09\u3002

\u4efb\u4f55\u7c7b\u578b\u7684\u6307\u9488\u5747\u53ef\u9690\u5f0f\u8f6c\u6362\u4e3a void * \u7c7b\u578b\uff0c\u4f46\u662f\u53cd\u8fc7\u6765\u4e0d\u884c\u3002\u8fd9\u662f\u56e0\u4e3a void * \u7c7b\u578b\u7684\u6307\u9488\u4e0d\u77e5\u9053\u6307\u5411\u7684\u5bf9\u8c61\u7684\u5927\u5c0f\uff0c\u56e0\u6b64\u4e0d\u80fd\u8fdb\u884c\u89e3\u5f15\u7528\u64cd\u4f5c\u3002

int i = 0x12345678;\nvoid *p = &i;\nprintf(\"%p\\n\", p);\nprintf(\"%d\\n\", *(int *)p);\n
\u4ec0\u4e48\u662f\u4e0d\u5b8c\u6574\u7c7b\u578b\uff1f

\u4e0d\u5b8c\u6574\u7c7b\u578b\u662f\u6307\u53ea\u77e5\u9053\u5176\u5b58\u5728\uff0c\u4f46\u65e0\u6cd5\u77e5\u9053\u5176\u5927\u5c0f\u7684\u7c7b\u578b\u3002\u6bd4\u5982\uff1a

struct incomp;\n

\u6211\u4eec\u53ea\u77e5\u9053 struct incomp \u5b58\u5728\uff0c\u4f46\u662f\u4e0d\u77e5\u9053\u5b83\u7684\u5927\u5c0f\uff08\u56e0\u4e3a\u6ca1\u6709\u7ed9\u51fa\u5176\u5b9a\u4e49\uff09\u3002\u56e0\u6b64\uff0cstruct incomp \u662f\u4e00\u4e2a\u4e0d\u5b8c\u6574\u7c7b\u578b\u3002\u4f46\u662f\u53ef\u4ee5\u58f0\u660e\u6307\u5411 struct incomp \u7c7b\u578b\u7684\u6307\u9488\u3002

void \u7c7b\u578b\u662f\u552f\u4e00\u53ef\u4f5c\u4e3a\u51fd\u6570\u8fd4\u56de\u7c7b\u578b\u7684\u4e0d\u5b8c\u6574\u7c7b\u578b\u3002\u8fd9\u662f C \u8bed\u6cd5\u7684\u4e00\u6761\u7279\u6b8a\u89c4\u5b9a\uff0c\u5176\u610f\u4e49\u5c31\u662f\u6807\u5b9a\u201c\u51fd\u6570\u6ca1\u6709\u8fd4\u56de\u503c\u201d\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#typedef","title":"\u4f7f\u7528 typedef \u4e3a\u73b0\u6709\u7684\u7c7b\u578b\u5b9a\u4e49\u522b\u540d","text":"
int a;\n

\u4f60\u5df2\u7ecf\u5f88\u719f\u6089\u8fd9\u6837\u7684\u58f0\u660e\u4e86\uff0c\u5bf9\u5427\uff1fa \u662f\u4e00\u4e2a int \u7c7b\u578b\u7684\u53d8\u91cf\u3002

typedef int a;\n

\u8fd9\u5c31\u662f\u8bf4\uff0ca \u73b0\u5728\u5c31\u662f int \u7684\u522b\u540d\u3002\u4f60\u53ef\u4ee5\u8fd9\u6837\u4f7f\u7528\u5b83\uff1a

a b; // \u7b49\u4ef7\u4e8e int b;\n

\u6211\u4eec\u4e4b\u524d\u63d0\u5230\u8fc7\u7684 size_t\u3001ptrdiff_t\u3001int8_t \u7b49\u7c7b\u578b\uff0c\u5c31\u662f\u901a\u8fc7 typedef \u5b9a\u4e49\u7684\u3002

\u8003\u8bd5\u4e2d\u8fd8\u4f1a\u8981\u6c42\u4f60\u9605\u8bfb\u4ee3\u7801\u7247\u6bb5\uff0c\u4e3a\u5f62\u53c2\u7b49\u4f4d\u7f6e\u586b\u5199\u7c7b\u578b\u58f0\u660e\u3002\u8bf7\u53c2\u8003\u5386\u5e74\u5377\u603b\u7ed3\u4e2d\u7684\u4f8b\u9898\u3002

C \u4e0e C++ \u7684 struct \u5e76\u4e0d\u5b8c\u5168\u4e00\u81f4

\u5bf9\u4e8e\u7ed3\u6784\u4f53

struct point {\n  int x;\n  int y;\n}\n

\u5728 C++ \u4e2d\uff0c\u6b64\u58f0\u660e\u5f15\u5165\u7684\u65b0\u7c7b\u578b\u540d\u4e3a point\uff0c\u800c\u5728 C \u4e2d\uff0c\u6b64\u58f0\u660e\u5f15\u5165\u7684\u65b0\u7c7b\u578b\u540d\u4e3a struct point\u3002point \u672c\u8eab\u4e0d\u662f\u4e00\u4e2a\u7c7b\u578b\u540d\u3002

\u4e0b\u9762\u7684\u5199\u6cd5\u662f\u5e38\u89c1\u7684\uff1a

typedef struct point point;\n

\u6b64\u5373\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7c7b\u578b\u540d point\uff0c\u5176\u4e3a struct point \u7684\u522b\u540d\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_11","title":"\u5185\u5b58\u6a21\u578b","text":"

\u5728 C \u8bed\u8a00\u7684\u5185\u5b58\u6a21\u578b\u4e2d\uff0c\u5b57\u8282\uff08byte\uff09\u662f\u6700\u5c0f\u7684\u53ef\u5bfb\u5740\u7684\u5185\u5b58\u5355\u5143\uff0c\u5176\u88ab\u5b9a\u4e49\u4e3a\u4e00\u7cfb\u5217\u8fde\u7eed\u7684\u4f4d\uff08bit\uff09\u3002\u53ef\u5bfb\u5740\u610f\u5473\u7740\u6bcf\u4e2a\u5b57\u8282\u90fd\u62e5\u6709\u5176\u7f16\u53f7\uff0c\u5373\u5730\u5740\u3002

MAGIC_PTR(&i);\nMAGIC_PTR(&ll);\nMAGIC_PTR(&d);\nMAGIC_PTR(&f);\n\nMAGIC_SIZED(f, 0x20);\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_12","title":"\u5730\u5740\u548c\u6307\u9488","text":"

\u5730\u5740\u662f\u4e00\u4e2a\u65e0\u7b26\u53f7\u6574\u6570\uff0c\u5b83\u8868\u793a\u5185\u5b58\u4e2d\u7684\u4e00\u4e2a\u5b57\u8282\u3002\u6307\u9488\u662f\u4e00\u4e2a\u53d8\u91cf\uff0c\u5176\u5b58\u50a8\u4e86\u4e00\u4e2a\u5730\u5740\u3002\u7531\u4e8e\u8fd9\u4e2a\u539f\u56e0\uff0c\u6240\u6709\u6307\u9488\u7c7b\u578b\u7684\u5927\u5c0f\u90fd\u662f\u76f8\u540c\u7684\u3002

MAGIC_R(&i);\nMAGIC_PTR(&i);\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_13","title":"\u5bf9\u8c61\u548c\u6807\u8bc6\u7b26","text":"

\u6bcf\u4e2a\u88ab\u5b58\u50a8\u7684\u503c\u90fd\u5360\u7528\u4e00\u5b9a\u7684\u7269\u7406\u5185\u5b58\uff0c\u8fd9\u6837\u7684\u4e00\u5757\u5185\u5b58\u79f0\u4e3a\u5bf9\u8c61\u3002\u5bf9\u8c61\u53ef\u4ee5\u50a8\u5b58\u4e00\u4e2a\u6216\u591a\u4e2a\u503c\u3002\u58f0\u660e\u53d8\u91cf\u65f6\uff0c\u521b\u5efa\u4e86\u4e00\u4e2a\u6807\u8bc6\u7b26\uff08identifier\uff09\uff0c\u5176\u4e0e\u5bf9\u8c61\u76f8\u5173\u8054\u3002

\u6240\u4ee5\uff0c\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\u65f6\u5b9e\u9645\u4e0a\u505a\u4e86\u4e24\u4ef6\u4e8b\uff1a

\u5bf9\u8c61\u7684\u5176\u4ed6\u542b\u4e49

\u201c\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u201d\u4e2d\u7684\u5bf9\u8c61\u6307\u7684\u662f\u201c\u7c7b\u5bf9\u8c61\u201d\u3002C \u8bed\u8a00\u4e2d\u6ca1\u6709\u201c\u7c7b\u5bf9\u8c61\u201d\u8fd9\u4e00\u6982\u5ff5\u3002

\u601d\u7ef4\u8bad\u7ec3\uff1a

int *psi = &i;\n\nMAGIC(i);\nMAGIC_R(*psi);\nMAGIC(psi);\nMAGIC_PTR(&i);\nMAGIC_PTR(&psi);\n
\u5728\u5c0f\u7aef\u5e8f\u8ba1\u7b97\u673a\u4e0a\u53ef\u80fd\u7684\u8fd0\u884c\u7ed3\u679c
=====\ni: 4 (0x4) bytes\n0000  78 56 34 12\n=====\n*psi: 4 (0x4) bytes\n0000  78 56 34 12\n=====\npsi: 8 (0x8) bytes\n0000  4c ae db 6f 01 00 00 00\n&i: 0x16fdbae4c\n&psi: 0x16fdbae08\n

\u6211\u4eec\u53ef\u4ee5\u89c2\u5bdf\u5230\u4ec0\u4e48\uff1f

\u5de6\u503c\u4e0e\u53f3\u503c

\u6307\u4ee3\u5bf9\u8c61\u7684\u8868\u8fbe\u5f0f\u88ab\u79f0\u4e3a\u5de6\u503c\u3002\u8fd9\u4e2a\u672f\u8bed\u6765\u81ea\u4e8e\u8d4b\u503c\u8bed\u53e5\uff0c\u56e0\u4e3a\u8d4b\u503c\u8bed\u53e5\u7684\u5de6\u8fb9\u5fc5\u987b\u662f\u4e00\u4e2a\u5bf9\u8c61\u3002

\u5982\u679c\u53ef\u4ee5\u4f7f\u7528\u5de6\u503c\u6539\u53d8\u5bf9\u8c61\u4e2d\u7684\u503c\uff0c\u90a3\u4e48\u79f0\u4e3a\u53ef\u4fee\u6539\u7684\u5de6\u503c\u3002

const char *pc = \"Good morning my neighbors\";\n

\u53c2\u8003\uff1a\u503c\u7c7b\u522b - cppreference.com

"},{"location":"programming/archive/23fall/lec2/lec2/#_14","title":"\u5185\u5b58\u7ba1\u7406","text":"

C \u7684\u5185\u5b58\u7ba1\u7406\u662f\u4e00\u5927\u75db\u70b9\uff0c\u56e0\u4e3a\u5b83\u672c\u8eab\u5e76\u4e0d\u63d0\u4f9b\u68c0\u67e5\u673a\u5236\uff0c\u4e00\u5207\u90fd\u4f9d\u8d56\u4e8e\u7a0b\u5e8f\u5458\u81ea\u5df1\u3002\u56e0\u6b64\uff0c\u597d\u597d\u638c\u63e1\u5185\u5b58\u7ba1\u7406\u5bf9\u4e8e\u5199\u51fa\u5b89\u5168\u3001\u7a33\u5b9a\u7684\u7a0b\u5e8f\u662f\u975e\u5e38\u5fc5\u8981\u7684\u3002

int *dangling() {\n  int i = 0xdeadbeef;\n  int *p = &i;\n  return p;\n}\n\nint main() {\n  int *pfi = dangling();\n  MAGIC(pfi);\n  MAGIC(*pfi);\n}\n

\u5728\u8fd9\u91cc pfi \u79f0\u4e3a\u60ac\u5782\u6307\u9488\uff08dangling pointer\uff09\uff0c\u5b83\u6307\u5411\u4e86\u4e00\u4e2a\u5df2\u7ecf\u88ab\u9500\u6bc1\u7684\u5bf9\u8c61\u3002\u4f7f\u7528\u60ac\u5782\u6307\u9488\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002

\u5e38\u89c1\u53d8\u5f0f

char *get_a_string() {\n  char str[] = \"Hello world!\";\n  return str;\n}\nint main() {\n  char *str = get_a_string();\n  printf(\"%s\\n\", str);\n}\n

\u95ee\u9898\u51fa\u5728\u54ea\uff1f

str \u4f5c\u4e3a\u4e00\u4e2a\u6570\u7ec4\uff0c\u5176\u751f\u547d\u5468\u671f\u5728 get_a_string \u51fd\u6570\u8fd4\u56de\u65f6\u7ed3\u675f\u3002

\u5b83\u4e0e\u4e0b\u9762\u7684\u7a0b\u5e8f\u6709\u4ec0\u4e48\u533a\u522b\uff1f

char *get_a_string() {\n  char *str = \"Hello world!\";\n  return str;\n}\nint main() {\n  char *str = get_a_string();\n  printf(\"%s\\n\", str);\n}\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_15","title":"\u5b58\u50a8\u671f\u3001\u4f5c\u7528\u57df\u548c\u94fe\u63a5","text":"

\u5b58\u50a8\u671f\u63cf\u8ff0\u5bf9\u8c61\uff0c\u8868\u660e\u5728\u5185\u5b58\u4e2d\u5b58\u50a8\u7684\u65f6\u95f4\u3002

\u4f5c\u7528\u57df\u548c\u94fe\u63a5\u6027\u63cf\u8ff0\u6807\u8bc6\u7b26\uff0c\u8868\u660e\u7a0b\u5e8f\u7684\u54ea\u4e9b\u90e8\u5206\u53ef\u4ee5\u4f7f\u7528\u5b83\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_16","title":"\u5b58\u50a8\u671f","text":"
#include <stdlib.h>\nint global;\nint main() {\n  int automatic;\n  int *allocated = malloc(sizeof(int));\n\n  MAGIC_PTR(&global);\n  MAGIC_PTR(&automatic);\n  MAGIC_PTR(allocated);\n}\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_17","title":"\u4f5c\u7528\u57df","text":"

\u4f5c\u7528\u57df - cppreference.com

"},{"location":"programming/archive/23fall/lec2/lec2/#_18","title":"\u5757\u4f5c\u7528\u57df","text":"Note

\u5728 C99 \u4e4b\u524d\uff0c\u5757\u4f5c\u7528\u57df\u7684\u53d8\u91cf\u5fc5\u987b\u5728\u5757\u7684\u5f00\u5934\u58f0\u660e\u3002

\u5728 C99\uff0c\u5757\u7684\u6982\u5ff5\u88ab\u653e\u5bbd\uff1a\u63a7\u5236\u8bed\u53e5\uff08\u6761\u4ef6\u3001\u5faa\u73af\uff09\u4e5f\u662f\u5757\uff08\u5373\u4f7f\u6ca1\u6709\u4f7f\u7528\u82b1\u62ec\u53f7\uff09\u3002\u6bd4\u5982\uff1a

for(int i = 0;;)\n  function();\n

i \u5177\u6709\u5757\u4f5c\u7528\u57df\uff0c\u662f\u5faa\u73af\u7684\u4e00\u90e8\u5206\u3002

\u66f4\u7cbe\u7ec6\u7684\u5b9a\u4e49\uff1a\u5faa\u73af\u4f53\u662f\u6574\u4e2a\u5faa\u73af\u7684\u5b50\u5757\u3002\u4f60\u53ef\u4ee5\u8fd9\u6837\u60f3\u5b83\uff1a

{\n  for(int i;;) {\n    int i;\n  }\n}\n

\u4e0a\u9762\u7684\u4e24\u4e2a\u540c\u540d\u53d8\u91cf i \u4e0d\u5728\u540c\u4e00\u4e2a\u5757\u4e2d\uff0c\u56e0\u6b64\u4e0d\u662f\u91cd\u590d\u5b9a\u4e49\u3002

Tip

\u540c\u540d\u7684\u53d8\u91cf\uff0c\u5185\u90e8\u8986\u76d6\u5916\u90e8\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_19","title":"\u51fd\u6570\u4f5c\u7528\u57df","text":"

goto \u8bed\u53e5\u7684\u6807\u7b7e\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5373\u4f7f\u6807\u7b7e\u5728\u5185\u5c42\u7684\u5757\u4e2d\uff0c\u5b83\u7684\u4f5c\u7528\u57df\u4e5f\u5ef6\u4f38\u81f3\u6574\u4e2a\u51fd\u6570\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_20","title":"\u51fd\u6570\u539f\u578b\u4f5c\u7528\u57df","text":"

\u51fd\u6570\u539f\u578b\u4e2d\u7684\u53d8\u91cf\u540d\u3002\u4ece\u5b9a\u4e49\u5904\u5230\u51fd\u6570\u539f\u578b\u7ed3\u675f\u3002

\u53ea\u5728\u4f60\u4f7f\u7528 VLA \u65f6\u9700\u8981\u6ce8\u610f\u8fd9\u4e00\u987a\u5e8f\uff1a

void use_VLA(int n, int m, ar[n][m]);\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_21","title":"\u6587\u4ef6\u4f5c\u7528\u57df","text":"

\u5728\u4efb\u4f55\u51fd\u6570\u5916\u5b9a\u4e49\u7684\u53d8\u91cf\u3002\u4ece\u5b9a\u4e49\u5904\u5230\u6587\u4ef6\u672b\u5c3e\u3002

\u8fd9\u6837\u7684\u53d8\u91cf\u79f0\u4e3a\u5168\u5c40\u53d8\u91cf\u3002

\u7ffb\u8bd1\u5355\u5143

\u4f60\u6240\u8ba4\u4e3a\u7684\u591a\u4e2a\u6587\u4ef6\u5bf9\u4e8e\u7f16\u8bd1\u5668\u6765\u8bf4\u53ef\u80fd\u662f\u4e00\u4e2a\u6587\u4ef6\u3002\u6bd4\u5982\u5934\u6587\u4ef6\uff1a\u9884\u5904\u7406\u65f6\uff0c\u5934\u6587\u4ef6\u88ab\u63d2\u5165\u3002\u5bf9\u4e8e\u7f16\u8bd1\u5668\u6765\u8bf4\uff0c\u5b83\u770b\u5230\u7684\u662f\u5355\u4e2a\u6587\u4ef6\u3002

\u8fd9\u6837\u7684\u5355\u4e2a\u6587\u4ef6\u79f0\u4e3a\u4e00\u4e2a\u7ffb\u8bd1\u5355\u5143\u3002\u6bcf\u4e2a\u7ffb\u8bd1\u5355\u5143\u5bf9\u5e94\u4e00\u4e2a\u6e90\u6587\u4ef6\u548c\u5b83 include \u7684\u6587\u4ef6\u3002

\u521a\u624d\u6211\u4eec\u8bf4\u7684\u6587\u4ef6\u4f5c\u7528\u57df\u5176\u5b9e\u662f\u5728\u6574\u4e2a\u7ffb\u8bd1\u5355\u5143\u53ef\u89c1\u3002

\u7531\u4e8e\u8bb2\u4e49\u4e2d\u6d89\u53ca\u5230\u7684\u5185\u5bb9\u8f83\u591a\uff0c\u65e0\u6cd5\u5728\u4e00\u8282\u8bfe\u5185\u5168\u90e8\u8bb2\u89e3\u3002\u540e\u7eed\u7684\u8bb2\u4e49\u5c06\u4f1a\u968f\u56de\u653e\u94fe\u63a5\u66f4\u65b0\u800c\u66f4\u65b0\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_22","title":"\u94fe\u63a5","text":""},{"location":"programming/archive/23fall/lec2/lec2/#_23","title":"\u9605\u8bfb\u548c\u64b0\u5199\u7c7b\u578b\u58f0\u660e","text":""},{"location":"programming/archive/23fall/lec2/pre/","title":"\u8bfe\u524d\uff1aMAGIC \u51fd\u6570","text":"

\u8bf7\u590d\u5236\u6b64\u4efd\u7a0b\u5e8f\u5230\u4f60\u7684\u7f16\u8f91\u5668\u4e2d\u3002\u6211\u4eec\u5c06\u4f1a\u76f4\u63a5\u5728\u8fd9\u4efd\u7a0b\u5e8f\u7684\u57fa\u7840\u4e0a\u8fdb\u884c\u6388\u8bfe\u3002

\u4e0d\u9700\u8981\u8bfb\u61c2\u5e76\u7406\u89e3\u8fd9\u6bb5\u7a0b\u5e8f\u7684\u610f\u4e49\u3002\u611f\u5174\u8da3\u7684\u540c\u5b66\u53ef\u81ea\u884c\u7814\u7a76\u3002

#define _STR0(x) #x\n#define _STR(x) _STR0(x)\n#define _MAGIC0(name, val, size) _magic_print((name), (const uint8_t *)(val), (size))\n#define MAGIC(v) _MAGIC0(_STR(v), (&v), sizeof(v));\n#define MAGIC_R(v)                      \\\n  ({                                    \\\n    __typeof__(v) _v = v;               \\\n    _MAGIC0(_STR(v), (&_v), sizeof(v)); \\\n  });\n#define MAGIC_SIZED(v, size) _MAGIC0(_STR(v), (&v), (size));\n#define MAGIC_PTR(v) fprintf(stderr, \"%s: %p\\n\", _STR(v), (void *)(v));\n\nstatic void _magic_print(const char *name, const uint8_t *ptr, size_t size) {\n  fprintf(stderr, \"=====\\n%s: %zu (%#zx) byte%s\", name, size, size, (\"s\") + (size == 1));\n  for (size_t i = 0; i < size; i++) {\n    if (i % 16 == 0)\n      fprintf(stderr, \"\\n%0*zx \", 4, i);\n    fprintf(stderr, \" %02hhx\", ptr[i]);\n  }\n  fprintf(stderr, \"\\n\");\n}\n\nint main() {\n  // start our journey here...\n  MAGIC_R(0x12345678);\n\n}\n
"},{"location":"programming/archive/23fall/lec3/lec3/","title":"\u8bb2\u4e49\uff1aI/O \u4e0e\u6587\u4ef6","text":"

\u5185\u5bb9\u63d0\u8981

"},{"location":"programming/archive/23fall/lec3/lec3/#c","title":"C \u7684\u8f93\u5165\u8f93\u51fa\u6a21\u578b","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_1","title":"\u7f13\u51b2","text":"

\u5e7f\u4e49\u7684\u7f13\u51b2\u533a\u662f\u5185\u5b58\u7a7a\u95f4\u7684\u4e00\u90e8\u5206\uff0c\u5728\u5185\u5b58\u4e2d\u9884\u7559\u4e86\u4e00\u5b9a\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c\u7528\u6765\u6682\u65f6\u4fdd\u5b58\u8f93\u5165\u548c\u8f93\u51fa\u7b49 I/O \u64cd\u4f5c\u7684\u4e00\u4e9b\u6570\u636e\uff0c\u8fd9\u4e9b\u9884\u7559\u7684\u7a7a\u95f4\u5c31\u53eb\u505a\u7f13\u51b2\u533a\uff1b\u800c buffer \u7f13\u51b2\u533a\u548c Cache \u7f13\u5b58\u533a\u90fd\u5c5e\u4e8e\u7f13\u51b2\u533a\u7684\u4e00\u79cd\u3002

buffer \u7f13\u51b2\u533a\u548c cache \u7f13\u5b58\u533a

C \u8bed\u8a00\u4e2d\uff0c\u7528\u6237\u8f93\u5165\u7684\u5b57\u7b26\u88ab\u6536\u96c6\u5e76\u50a8\u5b58\u5728\u7f13\u51b2\u533a\uff08buffer\uff09\u4e2d\uff0c\u6309\u4e0b Enter \u952e\u540e\u7a0b\u5e8f\u624d\u80fd\u4f7f\u7528\u7528\u6237\u8f93\u5165\u7684\u5b57\u7b26\u3002

\u4e0e\u4e4b\u5bf9\u5e94\u5730\uff0c\u65e0\u7f13\u51b2\u8f93\u5165\u7684\u7a0b\u5e8f\u80fd\u591f\u7acb\u5373\u4f7f\u7528\u7528\u6237\u8f93\u5165\u7684\u5185\u5bb9\u3002

stdin,stdout,stderr \u7684\u7f13\u51b2\u7c7b\u578b

Unix\u7ea6\u5b9astdin\u4e0estdout\u82e5\u4e0e\u7ec8\u7aef\u5173\u8054\u5219\u4e3a\u884c\u7f13\u51b2\uff0c\u800cstderr\u4e3a\u65e0\u7f13\u51b2\u3002

\u4e3a\u4ec0\u4e48\u8981\u6709\u7f13\u51b2\u533a\uff1f

\u867d\u7136\u7f13\u51b2\u8f93\u5165\u597d\u5904\u5f88\u591a\uff0c\u4f46\u662f\u67d0\u4e9b\u4ea4\u4e92\u5f0f\u7a0b\u5e8f\u4e5f\u9700\u8981\u65e0\u7f13\u51b2\u8f93\u5165\u3002\u4f8b\u5982\u5728\u6e38\u620f\u4e2d\uff0c\u73a9\u5bb6\u7684\u8f93\u5165\u9700\u8981\u7acb\u5373\u53cd\u5e94\u5728\u5c4f\u5e55\u4e0a\uff0c\u800c\u4e0d\u662f\u7b49\u5f85\u7528\u6237\u6309\u4e0b Enter \u952e\u3002

C \u6807\u51c6\u89c4\u5b9a\uff1a\u8f93\u5165\u662f\u7f13\u51b2\u7684\u3002\u4f60\u80fd\u89e3\u91ca\u4e3a\u4ec0\u4e48 C \u6807\u51c6\u8981\u89c4\u5b9a\u8f93\u5165\u662f\u7f13\u51b2\u7684\u5417\uff1f

\u4e3a\u4ec0\u4e48 C \u6807\u51c6\u89c4\u5b9a\u8f93\u5165\u662f\u7f13\u51b2\u7684\uff1f

\u4e00\u4e9b\u8ba1\u7b97\u673a\u4e0d\u5141\u8bb8\u65e0\u7f13\u51b2\u8f93\u5165\u3002ANSI\u6ca1\u6709\u63d0\u4f9b\u8c03\u7528\u65e0\u7f13\u51b2\u8f93\u5165\u7684\u6807\u51c6\u65b9\u5f0f\uff0c\u8fd9\u610f\u5473\u7740\u662f\u5426\u80fd\u8fdb\u884c\u65e0\u7f13\u51b2\u8f93\u5165\u53d6\u51b3\u4e8e\u8ba1\u7b97\u673a\u7cfb\u7edf\u3002

\u5982\u679c\u4f60\u7684\u8ba1\u7b97\u673a\u5141\u8bb8\u65e0\u7f13\u51b2\u8f93\u5165\uff0c\u90a3\u4e48\u4f60\u6240\u7528\u7684C\u7f16\u8bd1\u5668\u5f88\u53ef\u80fd\u4f1a\u63d0\u4f9b\u4e00\u4e2a\u65e0\u7f13\u51b2\u8f93\u5165\u7684\u9009\u9879\u3002\u4f8b\u5982\uff0c\u8bb8\u591aIBM PC\u517c\u5bb9\u673a\u7684\u7f16\u8bd1\u5668\u90fd\u4e3a\u652f\u6301\u65e0\u7f13\u51b2\u8f93\u5165\u63d0\u4f9b\u4e00\u7cfb\u5217\u7279\u6b8a\u51fd\u6570\uff0c\u5176\u539f\u578b\u5728conio.h\u4e2d\u3002\u5728Unix\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528iotcl()\u51fd\u6570\u6307\u5b9a\u5f85\u8f93\u5165\u7684\u7c7b\u578b\uff0c\u7136\u540e\u4f7f\u7528getchar()\u6267\u884c\u76f8\u5e94\u64cd\u4f5c\u3002\u5728ANSI C\u4e2d\uff0c\u7528setbuf()\u548csetbufv()\u63a7\u5236\u7f13\u51b2\uff0c\u4f46\u662f\u8fd9\u4e24\u4e2a\u51fd\u6570\u53ef\u80fd\u4e0d\u8d77\u4f5c\u7528\u3002

\u6211\u53ef\u4ee5\u66f4\u6539\u8f93\u5165\u65b9\u5f0f\u5417\uff1f

UNIX \u5e93\u4e2d\u6709 ioctl() \u51fd\u6570\u7528\u4e8e\u6307\u5b9a\u5f85\u8f93\u5165\u7684\u7c7b\u578b\uff0c\u4f46\u8fd9\u4e0d\u5c5e\u4e8e C \u6807\u51c6\u3002

ANSI C \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 setbuf() \u548c setvbuf() \u63a7\u5236\u7f13\u51b2\uff0c\u4f46\u53d7\u9650\u4e8e\u7cfb\u7edf\u7684\u8bbe\u7f6e\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_2","title":"\u6d41","text":"

C \u5e93\u63d0\u4f9b\u7684\u8f93\u5165\u8f93\u51fa\u65b9\u5f0f\u79f0\u4e3a\u6807\u51c6 I/O\uff0c\u5b83\u4eec\u662f\u5efa\u7acb\u5728\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u5e95\u5c42 I/O \u4e0a\u7684\u3002\u5e95\u5c42 I/O \u4e4b\u95f4\u5e38\u5e38\u4f1a\u6709\u4e00\u4e9b\u5dee\u5f02\uff1a

\u5404\u4e2a\u7cfb\u7edf\u7684\u6587\u4ef6\u5dee\u5f02

\u5dee\u5f02 UNIX Windows MacOS \u6362\u884c\u7b26 \\n LF \\r\\n CRLF \\n (\u8f83\u65e9\u7684 MacOS \u4f7f\u7528 \\r)LF \u6587\u4ef6\u7ed3\u675f\u7b26 ^D ^Z ^D

\u6ce8\uff1a\u5982 ^Z \u4ee3\u8868 Ctrl+Z\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8be5\u7ec4\u5408\u952e\u7ed3\u675f\u952e\u76d8\u8f93\u5165\u3002

\u6587\u4ef6\u7ed3\u5c3e\u4e5f\u4e0d\u4e00\u5b9a\u7531\u6587\u4ef6\u7ed3\u675f\u7b26\u6807\u8bb0\u3002\u4e8b\u5b9e\u4e0a\uff0cUNIX \u7cfb\u7edf\u50a8\u5b58\u6587\u4ef6\u5927\u5c0f\u4fe1\u606f\uff0c\u4f9d\u636e\u6587\u4ef6\u5927\u5c0f\u4fe1\u606f\u51b3\u5b9a\u6587\u4ef6\u672b\u5c3e\u3002

\u4ece\u6982\u5ff5\u4e0a\u770b\uff0cC \u5904\u7406\u7684\u662f\u6d41\u800c\u4e0d\u662f\u6587\u4ef6\u3002\u4e0d\u540c\u5c5e\u6027\u548c\u4e0d\u540c\u79cd\u7c7b\u7684\u8f93\u5165\uff0c\u7531\u5c5e\u6027\u66f4\u7edf\u4e00\u7684\u6d41\u6765\u8868\u793a\u3002\u6d41\u544a\u8bc9\u6211\u4eec\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u5904\u7406\u6587\u4ef6\u7684\u65b9\u5f0f\u6765\u5904\u7406\u952e\u76d8\u8f93\u5165\u3002

C \u8bed\u8a00\u4e2d I/O \u6d41\u7531File\u7c7b\u578b\u7684\u5bf9\u8c61\u8868\u793a\uff0c\u8be5\u5bf9\u8c61\u53ea\u80fd\u901a\u8fc7FILE*\u7c7b\u578b\u7684\u6307\u9488\u8bbf\u95ee\u53ca\u64cd\u4f5c\u3002\u6bcf\u4e2a\u6d41\u90fd\u4e0e\u5916\u90e8\u7684\u7269\u7406\u8bbe\u5907\u76f8\u5173\u8054\u3002

\u6d41

\u6d41\u5c31\u662f\u4e00\u7cfb\u5217\u8fde\u7eed\u7684\u5b57\u8282\u3002

\u6253\u5f00\u6587\u4ef6\u7684\u8fc7\u7a0b\u5c31\u662f\u628a\u6d41\u4e0e\u6587\u4ef6\u76f8\u5173\u8054\uff0c\u8bfb\u5199\u90fd\u901a\u8fc7\u6d41\u6765\u5b8c\u6210\u3002

getchar() \u548c scanf() \u7b49\u51fd\u6570\u8bfb\u53d6\u5230\u6587\u4ef6\u7ed3\u5c3e\u65f6\u4f1a\u8fd4\u56de\u4e00\u4e2a\u7279\u6b8a\u7684\u503c EOF\uff0c\u5728 stdio.h \u4e2d\u5b9a\u4e49\u4e86\uff1a

#define EOF (-1) \n
\u4f60\u80fd\u89e3\u91ca\u4e3a\u4ec0\u4e48\u8981\u628a\u5b83\u5b9a\u4e3a -1 \u5417\uff1f

The value of EOF is -1 because it has to be different from any return value from getchar that is an actual character. So getchar returns any character value as an unsigned char, converted to int, which will therefore be non-negative.

\u56e0\u6b64\uff0c\u5982\u679c\u4f60\u5728\u7ec8\u7aef\u4e2d\u8fdb\u884c\u8f93\u5165\uff0c\u53ef\u4ee5\u4f7f\u7528Ctrl+Z(Windows)\u6216\u8005Ctrl+D(unix-style systems)\u4f5c\u4e3aEOF\u7ed3\u675f\u8f93\u5165\u3002

\u7531\u4ee5\u4e0a\u4e24\u90e8\u5206\uff0c\u6211\u4eec\u53ef\u4ee5\u77e5\u9053\u5728 C \u7684\u952e\u76d8\u8f93\u5165\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u7528Enter\u5904\u7406\u7f13\u51b2\u533a\u4e2d\u7684\u5185\u5bb9\uff0c\u7528Ctrl+Z\u6216\u8005Ctrl+D\u7ed3\u675f\u8f93\u5165\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_3","title":"\u6807\u51c6\u6d41","text":"

\u5728\u6807\u51c6\u5934\u6587\u4ef6<stidio.h>\u4e2d\uff0c\u5b9a\u4e49\u4e86\u4e09\u4e2a\u6587\u672c\u6d41\u3002

#define stdin  /* \u7531\u5b9e\u73b0\u5b9a\u4e49 */\n#define stdout /* \u7531\u5b9e\u73b0\u5b9a\u4e49 */\n#define stderr /* \u7531\u5b9e\u73b0\u5b9a\u4e49 */\n

\u8fd9\u4e09\u4e2a\u6587\u672c\u6d41\u662f\u9884\u5b9a\u4e49\u7684\u3002\u8fd9\u4e9b\u6d41\u5728\u7a0b\u5e8f\u542f\u52a8\u65f6\u9690\u5f0f\u6253\u5f00\uff0c\u4e14\u4e3a\u65e0\u53d6\u5411\u7684\u3002

  1. \u4e0e\u6807\u51c6\u8f93\u5165\u6d41\u5173\u8054\uff0c\u7528\u4e8e\u8bfb\u53d6\u4f20\u7edf\u7684\u8f93\u5165\u3002\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u5f53\u4e14\u4ec5\u5f53\u80fd\u786e\u5b9a\u6d41\u4e0d\u5f15\u7528\u4ea4\u4e92\u5f0f\u8bbe\u5907\u65f6\u8be5\u6d41\u4e3a\u5b8c\u5168\u7f13\u51b2\u3002
  2. \u4e0e\u6807\u51c6\u8f93\u51fa\u6d41\u5173\u8054\uff0c\u7528\u4e8e\u5199\u5165\u4f20\u7edf\u7684\u8f93\u51fa\u3002\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u5f53\u4e14\u4ec5\u5f53\u80fd\u786e\u5b9a\u6d41\u4e0d\u5f15\u7528\u4ea4\u4e92\u5f0f\u8bbe\u5907\u65f6\u8be5\u6d41\u4e3a\u5b8c\u5168\u7f13\u51b2\u3002
  3. \u4e0e\u6807\u51c6\u9519\u8bef\u6d41\u5173\u8054\uff0c\u7528\u4e8e\u5199\u5165\u8bca\u65ad\u8f93\u51fa\u3002\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u8be5\u6d41\u4e0d\u4e3a\u5b8c\u5168\u7f13\u51b2\u3002

\u6587\u4ef6\u63cf\u8ff0\u7b26

\u5f53\u4e00\u4e2a\u7a0b\u5e8f\u6210\u529f\u5411\u64cd\u4f5c\u7cfb\u7edf\u8bf7\u6c42\u8bbf\u95ee\u4e00\u4e2a\u6253\u5f00\u7684\u6587\u4ef6, \u5185\u6838\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6307\u5411\u5185\u6838\u4e2d\u5168\u5c40\u6587\u4ef6\u8868(global file table)\u4e2d\u7684\u5165\u53e3\u70b9(entry)\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26. \u6587\u4ef6\u8868\u5165\u53e3\u70b9\u5305\u542b\u5982: \u6587\u4ef6\u7684inode(\u786c\u76d8\u4e2d\u7684\u4f4d\u7f6e), \u5b57\u8282\u504f\u79fb\u91cf(byte offset), \u4ee5\u53ca\u5bf9\u8fd9\u4e2a\u6570\u636e\u6d41\u7684\u8bbf\u95ee\u9650\u5236(\u53ea\u8bfb, \u53ea\u5199\u7b49)\u3002

\u6587\u4ef6\u63cf\u8ff0\u7b26: \u662f\u8ba1\u7b97\u673a\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u88ab\u6253\u5f00\u6587\u4ef6\u7684\u552f\u4e00\u6807\u8bc6. \u5b83\u7528\u6765\u63cf\u8ff0\u4e00\u79cd\u6570\u636e\u8d44\u6e90, \u4ee5\u53ca\u8fd9\u4e2a\u6570\u636e\u8d44\u6e90\u53ef\u4ee5\u5982\u4f55\u88ab\u8bbf\u95ee\u5230\u3002

\u5728 Unix \u7cfb\u7edf\u5f53\u4e2d, \u524d\u4e09\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b260, 1, 2 \u9ed8\u8ba4\u4e3a stdin stdout stderr

"},{"location":"programming/archive/23fall/lec3/lec3/#_4","title":"\u5b57\u7b26\u8f93\u5165\u8f93\u51fa","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_5","title":"\u91cd\u5b9a\u5411","text":"

\u5728\u5f00\u59cb\u4ecb\u7ecd\u5b57\u7b26\u8f93\u5165\u8f93\u51fa\u524d\uff0c\u5148\u4ecb\u7ecd\u7cfb\u7edf\u7684\u91cd\u5b9a\u5411\u3002

\u91cd\u5b9a\u5411\u662f\u6307\u6539\u53d8\u6807\u51c6\u8f93\u5165\u8f93\u51fa\u7684\u76ee\u7684\u5730\u3002\u5728 UNIX \u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528>\u548c<\u6765\u91cd\u5b9a\u5411\u8f93\u5165\u8f93\u51fa\u3002

\u4f8b\u5982\uff0cls > ls.txt \u5c06ls\u7684\u8f93\u51fa\u91cd\u5b9a\u5411\u5230ls.txt\u6587\u4ef6\u4e2d\uff0ccat < ls.txt\u5c06ls.txt\u6587\u4ef6\u7684\u5185\u5bb9\u91cd\u5b9a\u5411\u5230cat\u547d\u4ee4\u4e2d\u3002

\u91cd\u5b9a\u5411\u7684\u76ee\u7684\u5730\u53ef\u4ee5\u662f\u6587\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u662f\u5176\u4ed6\u7a0b\u5e8f\u3002

\u4f8b\u5982\uff0cls | cat\u5c06ls\u7684\u8f93\u51fa\u91cd\u5b9a\u5411\u5230cat\u547d\u4ee4\u4e2d\u3002

\u66f4\u8fdb\u4e00\u6b65\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528>>\u6765\u8ffd\u52a0\u8f93\u51fa\u91cd\u5b9a\u5411\uff0c<<\u6765\u8ffd\u52a0\u8f93\u5165\u91cd\u5b9a\u5411\u3002

\u7ed3\u5408\u4e0a\u4e00\u8282\u8bb2\u7684\u5185\u5bb9\uff0c\u4f60\u53ef\u4ee5\u8bf4\u51fa2>\u548c2>>\u7684\u4f5c\u7528\u5417\uff1f

"},{"location":"programming/archive/23fall/lec3/lec3/#_6","title":"\u65e0\u683c\u5f0f\u8f93\u5165/\u8f93\u51fa","text":"

\u5728\u5b57\u7b26 I/O \u4e2d\uff0c\u6211\u4eec\u5e38\u4f7f\u7528\u4ee5\u4e0b\u51fd\u6570\u6765\u5904\u7406\u5b57\u7b26\uff0c\u8fd9\u4e9b\u51fd\u6570\u4f4d\u4e8e<stdio.h>\u5934\u6587\u4ef6\u4e2d\u3002<wchar.h> \u5934\u6587\u4ef6\u63d0\u4f9b\u4e86\u5177\u6709\u5bbd\u5b57\u7b26\u8f93\u5165/\u8f93\u51fa\u529f\u80fd\u7684\u51fd\u6570\u3002

e.g.

echo_eof.c
/* echo_eof.c -- repeats input to end of file */\n#include <stdio.h>\nint main(void)\n{\n    int ch;\n\n    while ((ch = getchar()) != EOF)\n    putchar(ch);\n\n    return 0;\n}\n

\u7ed3\u5408\u91cd\u5b9a\u5411\u8fd0\u7b97\u7b26\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528echo_eof < echo_eof.c\u6765\u6d4b\u8bd5\u8be5\u7a0b\u5e8f\u3002

$ echo_eof < echo_eof.c\n$ echo_eof < echo_eof.c > echo_eof.txt\n$ echo_eof < echo_eof.c | cat\n

\u7a84\u5b57\u7b26\u65e0\u683c\u5f0f\u8f93\u5165\u8f93\u51fa\u51fd\u6570\uff0c\u5b9a\u4e49\u4e8e <stdio.h> \u5934\u6587\u4ef6\u4e2d\uff1a

\u529f\u80fd \u51fd\u6570 \u5931\u8d25\u8fd4\u56de\u503c int getchar(void) int getc(FILE *stream) int fgetc(FILE *stream) \u5355\u5b57\u7b26\u8f93\u5165 EOF char *fgets(char *s, int size, FILE *stream) char *gets_s( char *str, rsize_t n) \u5b57\u7b26\u4e32\u8f93\u5165 NULL int ungetc(int c, FILE *stream) \u653e\u56de\u6587\u4ef6\u6d41 EOF int putchar(int c) int putc(int c, FILE *stream) int fputc(int c, FILE *stream) \u5355\u5b57\u7b26\u8f93\u51fa EOF int puts(const char *s) int fputs(const char *s, FILE *stream) \u5b57\u7b26\u4e32\u8f93\u51fa EOF

\u6ce8\u610f

\u90a3\u4e48\u8fd9\u662f\u5426\u4f1a\u9020\u6210 EOF \u4e0d\u80fd\u88ab\u8bc6\u522b\uff0c\u800c\u662f\u88ab\u770b\u4f5c\u5b57\u7b26\u5462\uff1f
#define EOF (-1) // unsigned char\u8f6c\u6362\u6210int\u540e\uff0c\u503c\u90fd\u5927\u4e8e\u7b49\u4e8e0\n

\u5bbd\u5b57\u7b26\u8f93\u5165\u8f93\u51fa\u5b9a\u4e49\u4e8e <wchar.h> \u5934\u6587\u4ef6\u4e2d\uff0c\u533a\u522b\u5728\u4e8e\u5176\u4e00\u4e2a\u5b57\u7b26\u7684\u957f\u5ea6\u4e0d\u540c\u3002C \u8bed\u8a00\u4e2d\u6709\u4e00\u79cd\u7c7b\u578bwchar_t,\u5176\u957f\u5ea6\u53d6\u51b3\u4e8e\u7f16\u8bd1\u5668\uff1a

\u5728\u4f7f\u7528\u5bbd\u5b57\u7b26\u524d\uff0c\u9700\u8981\u5728\u5b57\u7b26\u548c\u5b57\u7b26\u4e32\u524d\u52a0\u4e0aL\u524d\u7f00\uff0c\u4f8b\u5982L'c'\u548cL\"string\"\uff0c\u672a\u52a0\u524d\u7f00\u7684\u5b57\u7b26\u548c\u5b57\u7b26\u4e32\u4e3a\u7a84\u5b57\u7b26\u3002 \u5bf9\u4e8e\u5bbd\u5b57\u7b26/\u5b57\u7b26\u4e32\u8bfb\u5199\u51fd\u6570\uff0c\u5176\u4f7f\u7528\u65b9\u6cd5\u4e0e\u7a84\u5b57\u7b26\u7c7b\u4f3c\u3002

\u529f\u80fd \u51fd\u6570 \u5931\u8d25\u8fd4\u56de\u503c int getwchar(void) int getwc(FILE *stream) int fgetwc(FILE *stream) \u5355\u5b57\u7b26\u8f93\u5165 EOF char *fgetws(char *s, int size, FILE *stream) \u5b57\u7b26\u4e32\u8f93\u5165 NULL int ungetwc(int c, FILE *stream) \u653e\u56de\u6587\u4ef6\u6d41 EOF int putwchar(int c) int fputwc(int c, FILE *stream)` \u5355\u5b57\u7b26\u8f93\u51fa EOF int fputws(const char *s, FILE *stream) \u5b57\u7b26\u4e32\u8f93\u51fa EOF"},{"location":"programming/archive/23fall/lec3/lec3/#_7","title":"\u683c\u5f0f\u5316\u8f93\u5165\u8f93\u51fa","text":"

\u5728\u6807\u5934<stdio.h>\u548c<wchar.h>\u4e2d\uff0c\u5b9a\u4e49\u4e86\u4e00\u7cfb\u5217\u683c\u5f0f\u5316\u8f93\u5165\u8f93\u51fa\u51fd\u6570\uff0c\u8fd9\u4e9b\u51fd\u6570\u53ef\u4ee5\u7528\u4e8e\u8bfb\u5199\u683c\u5f0f\u5316\u7684\u6570\u636e\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_8","title":"\u683c\u5f0f\u5b57\u7b26\u4e32","text":"

\u683c\u5f0f\u5b57\u7b26\u4e32const char *format\u7531\u666e\u901a\u591a\u5b57\u8282\u5b57\u7b26\uff08\u9664\u4e86%\uff09\u548c\u8f6c\u6362\u6307\u793a\u6784\u6210\uff0c\u524d\u8005\u88ab\u590d\u5236\u5230\u8f93\u51fa\u6d41\u800c\u65e0\u66f4\u6539\u3002\u6bcf\u4e2a\u8f6c\u6362\u6307\u793a\u62e5\u6709\u4e0b\u5217\u683c\u5f0f\uff1a

"},{"location":"programming/archive/23fall/lec3/lec3/#printf","title":"printf()\u4e2d\u8f6c\u6362\u8bf4\u660e\u7684\u610f\u4e49","text":"

\u8f6c\u6362\u8bf4\u660e\u5b9e\u9645\u4e0a\u662f\u5728\u5c06\u4ee5\u4e8c\u8fdb\u5236\u5b58\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u4e2d\u7684\u503c\u8f6c\u6362\u6210\u4e00\u4e9b\u5217\u5b57\u7b26\u4fbf\u4e8e\u663e\u793a\u3002\u8f6c\u6362\u5b9e\u9645\u4e0a\u662f\u4e00\u79cd\u7ffb\u8bd1\u8bf4\u660e\u3002

\u4f8b\u5982\uff1ad\uff1a\u5c06\u4e00\u4e2a\u6709\u7b26\u53f7\u7684\u5341\u8fdb\u5236\u6574\u6570\u8f6c\u6362\u6210\u5341\u8fdb\u5236\u6570\u3002

\u4e0b\u9762\u8ba8\u8bba\u51e0\u79cd\u8f6c\u6362\u8bf4\u660e\u7684\u60c5\u51b5\uff1a

  1. \u8f6c\u6362\u4e0d\u5339\u914d

    \u8f6c\u6362\u8bf4\u660e\u4e0e\u5f85\u6253\u5370\u7684\u503c\u4e0d\u5339\u914d\u53ef\u80fd\u5bfc\u81f4\u6570\u636e\u9519\u8bef\u6216\u8005\u51fa\u73b0\u672a\u5b9a\u4e49\u7684\u884c\u4e3a\u3002

    e.g.

    wrong_cnv.c

    #include <stdio.h>\n#define num 336\n#define b 65618\nint main(void)\n{\n    printf(\"num as short and unsigned short:  %hd %hu\\n\", num,num);\n    printf(\"-num as short and unsigned short: %hd %hu\\n\", -num,-num);\n    printf(\"num as int and char: %d %c\\n\", num, num);\n    printf(\"b as int, short, and char: %d %hd %c\\n\",b, b, b);\n\n    float n1 = 3.0;\n    double n2 = 3.0;\n    long n3 = 2000000000;\n    long n4 = 1234567890;\n    printf(\"%.1e %.1e %.1e %.1e\\n\", n1, n2, n3, n4);\n    printf(\"%ld %ld\\n\", n3, n4);\n    printf(\"%ld %ld %ld %ld\\n\", n1, n2, n3, n4);\n    return 0;\n}\n
    \u8be5\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c\u4e3a (\u7531\u4e8e\u5b9e\u73b0\u662f\u672a\u5b9a\u4e49\u7684\uff0c\u90e8\u5206\u7ed3\u679c\u56e0\u7cfb\u7edf\u548c\u7f16\u8bd1\u5668\u800c\u5f02)\uff1a
        num as short and unsigned short:  336 336\n    -num as short and unsigned short: -336 65200\n    num as int and char: 336 P\n    b as int, short, and char: 65618 82 R\n    3.0e+00 3.0e+00 2.0e+09 1.2e+09\n    2000000000 1234567890\n    0 1074266112 0 1074266112\n
    \u4f60\u80fd\u89e3\u91ca\u4e3a\u4ec0\u4e48\u4f7f\u7528%ld \u8f93\u51fa long \u7c7b\u578b\u7684\u503c\u65f6\uff0c\u4e5f\u4f1a\u51fa\u73b0\u9519\u8bef\u5417\uff1f

  2. printf()\u7684\u8fd4\u56de\u503c

    printf()\u51fd\u6570\u8fd4\u56de\u6253\u5370\u7684\u5b57\u7b26\u6570\uff0c\u82e5\u51fa\u73b0\u9519\u8bef\u5219\u8fd4\u56de\u8d1f\u503c\u3002

  3. \u6253\u5370\u957f\u7684\u5b57\u7b26\u4e32

    \u4e0d\u80fd\u5728\u53cc\u5f15\u53f7\u62ec\u8d77\u6765\u7684\u5b57\u7b26\u4e32\u4e2d\u95f4\u65ad\u884c\u3002

    e.g.

    longstrg.c
    #include <stdio.h>\nint main(void)\n{\n    printf(\"Here's one way to print a \");\n    printf(\"long string.\\n\");\n    printf(\"Here's another way to print a \\\n    long string.\\n\");\n    printf(\"Here's the newest way to print a \"\n    \"long string.\\n\"); /* ANSI C */\n    /*\n    printf(\"Here's wrong way to print a\n    long string.\\n\");\n    */\n    return 0;\n}\n
"},{"location":"programming/archive/23fall/lec3/lec3/#scanf","title":"scanf()","text":"

\u5728\u524d\u9762\u6211\u4eec\u4ecb\u7ecd\u4e86printf()\u4e2d\u7684\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u548c\u8f6c\u6362\u8bf4\u660e\uff0cscanf()\u4e2d\u4e5f\u6709\u7c7b\u4f3c\u7684\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u548c\u8f6c\u6362\u8bf4\u660e\u3002

\u590d\u6742\u7684\u4f7f\u7528\u65b9\u6cd5\u8bf7\u67e5\u9605scanf\u3002

\u4e0b\u9762\u4ecb\u7ecd\u4e00\u4e9bscanf()\u7684\u7279\u6027\uff1a

  1. scanf()\u8981\u5c06\u8bfb\u53d6\u7684\u5185\u5bb9\u5b58\u50a8\u5230\u5bf9\u5e94\u53d8\u91cf\u5730\u5740\u4e2d\uff0c\u800c\u4e0d\u662f\u53d8\u91cf\u540d\u3002\u56e0\u6b64\uff0cscanf()\u7684\u53c2\u6570\u5e94\u8be5\u662f\u53d8\u91cf\u7684\u5730\u5740\u3002

    e.g. scanf.c
    #include <stdio.h>\n#include <stdio.h>\nint main(void)\n{\n    int a;\n    float b;\n    char str[30];\n    int c[10];\n\n    scanf(\"%d %f\", &a, &b); // \u8bfb\u53d6\u6574\u6570\u548c\u6d6e\u70b9\u6570\n    scanf(\"%s\", str);       // \u8bfb\u53d6\u5b57\u7b26\u4e32\n    scanf(\"%d\", c);        // \u8bfb\u53d6\u6574\u6570\u6570\u7ec4\n    return 0;\n}\n
  2. scanf() \u51fd\u6570\uff0c\u9664\u4e86 %c \u4ee5\u5916\u7684\u8f6c\u6362\u8bf4\u660e\uff0c\u90fd\u4e0d\u4f1a\u8bfb\u53d6\u7a7a\u767d\u5b57\u7b26\uff08\u7a7a\u683c\u3001\u5236\u8868\u7b26\u548c\u56de\u8f66\uff09\u3002

    \u5178\u578b\u95ee\u9898\uff1a\u6362\u884c\u7b26\u95ee\u9898

    e.g.

    confusing_scanf.c
    #include <stdio.h>\nint main(void)\n{\n    char c[100] = {0};\n    scanf(\"%s\\n\",&c);\n    printf(\"%s\",c);\n}\n
  3. scanf()\u4e2d\u7684\u8f93\u5165\u8fc7\u7a0b

    \u5047\u8bbescanf()\u6839\u636e%d\u8f6c\u6362\u8bfb\u53d6\u4e00\u4e2a\u6574\u6570\uff0cscanf()\u51fd\u6570\u6bcf\u6b21\u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26\uff0c\u8df3\u8fc7\u6240\u6709\u7684\u7a7a\u767d\u5b57\u7b26\uff0c\u76f4\u5230\u9047\u5230\u7b2c\u4e00\u4e2a\u975e\u7a7a\u767d\u5b57\u7b26\u624d\u5f00\u59cb\u8bfb\u53d6\u3002scanf()\u5e0c\u671b\u627e\u5230\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u6216\u8005\u4e00\u4e2a\u7b26\u53f7\uff0c\u82e5\u627e\u5230\uff0c\u5219\u4f1a\u7ee7\u7eed\u5bfb\u627e\u4e0b\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u6216\u8005\u7b26\u53f7\uff0c\u76f4\u5230\u9047\u5230\u4e00\u4e2a\u975e\u6570\u5b57\u5b57\u7b26\uff0c\u6b64\u65f6scanf()\u4f1a\u5c06\u8bfb\u53d6\u7684\u5b57\u7b26\u653e\u56de\u8f93\u5165\u6d41\u4e2d\uff0c\u7136\u540e\u5c06\u8bfb\u53d6\u7684\u5b57\u7b26\u8f6c\u6362\u6210\u6574\u6570\u3002

    \u5982\u679c\u7b2c\u4e00\u4e2a\u975e\u7a7a\u767d\u5b57\u7b26\u4e0d\u662f\u6570\u5b57\u6216\u8005\u6b63\u8d1f\u53f7\uff0cscanf()\u4f1a\u505c\u5728\u90a3\u91cc\uff0c\u5e76\u628a\u5b57\u7b26\u653e\u56de\u8f93\u5165\u4e2d\uff0c\u4e0d\u4f1a\u628a\u503c\u8d4b\u7ed9\u76f8\u5e94\u53d8\u91cf\u3002C \u8bed\u8a00\u89c4\u5b9a\u4e86\u5728\u7b2c 1 \u4e2a\u51fa\u9519\u7684\u5730\u65b9\u505c\u6b62\u8bfb\u53d6\u8f93\u5165\u3002

    \u5982\u679c\u4f7f\u7528%s\u8f6c\u6362\u8bf4\u660e\uff0cscanf()\u4f1a\u8df3\u8fc7\u7a7a\u767d\u5f00\u59cb\u8bfb\u53d6\u9664\u7a7a\u767d\u4ee5\u5916\u7684\u6240\u6709\u5b57\u7b26\uff0c\u76f4\u5230\u9047\u5230\u7a7a\u767d\u5b57\u7b26\u4e4b\u540e\u5c06\u7a7a\u767d\u7b26\u91cd\u65b0\u653e\u56de\u8f93\u5165\u540e\u7ed3\u675f\u3002

  4. \u683c\u5f0f\u5b57\u7b26\u4e32\u4e2d\u7684\u666e\u901a\u5b57\u7b26

    scanf()\u4e2d\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u767d\u610f\u5473\u7740\u8df3\u8fc7\u4e0b\u4e00\u4e2a\u8f93\u5165\u9879\u524d\u7684\u6240\u6709\u7a7a\u767d\u3002

    \u9664\u4e86%c\u5176\u4ed6\u8f6c\u6362\u8bf4\u660e\u90fd\u4f1a\u81ea\u52a8\u8df3\u8fc7\u5f85\u8f93\u5165\u503c\u524d\u9762\u7684\u6240\u6709\u7a7a\u767d\u3002

    \u4ee5\u4e0b\u4ee3\u7801\u6709\u4ec0\u4e48\u533a\u522b\uff1f

    scanf(\"%d %d\", &n,&m);\nscanf(\"%d%d\", &n,&m);\n\nscanf(\"%c\", &c);\nscanf(\" %c\", &c);\n
  5. scanf()\u7684\u8fd4\u56de\u503c

    \u8bfb\u53d6\u6210\u529f\u5219\u8fd4\u56de\u8bfb\u53d6\u7684\u9879\u6570\u3002\u6ca1\u6709\u8bfb\u53d6\u4efb\u4f55\u9879\u5219\u8fd4\u56de 0\u3002\u5f53scanf()\u8bfb\u53d6\u5230\u6587\u4ef6\u672b\u5c3e\u5219\u8fd4\u56deEOF\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_9","title":"\u5b9e\u4f8b","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_10","title":"\u5b89\u5168\u7684\u8f93\u5165\u51fd\u6570","text":"

\u5199\u4e00\u4e2a\u5b89\u5168\u7684\u8f93\u5165\u51fd\u6570

\u4f17\u6240\u5468\u77e5\uff0cC\u8bed\u8a00\u7684gets\u51fd\u6570\u662f\u4e00\u4e2a\u975e\u5e38\u4e0d\u5b89\u5168\u7684\u51fd\u6570(\u8bf7\u53c2\u8003\u7cfb\u7edf\u77e5\u8bc6\u62fe\u90571)\uff0c\u5728C11\u4e2d\u88ab\u5f03\u7528\uff0c\u8f6c\u4e3agets_s()\u3002gets()\u6781\u6709\u53ef\u80fd\u9020\u6210\u7f13\u51b2\u533a\u6ea2\u51fa\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u5199\u4e00\u4e2a\u5b89\u5168\u7684\u8f93\u5165\u51fd\u6570\u3002

s_gets.c
char * s_gets(char* st, int n)\n{\n    char * ret_val;\n    int i = 0;\n\n    ret_val = fgets(st, n, stdin);\n    if (ret_val)\n    {\n        while (st[i] != '\\n' && st[i] != '\\0)\n            i++;\n        if (st[i] == '\\n')\n            st[i] = '\\0';\n        else //must have words[i] == '\\0'\n            while (getchar() != '\\n')\n                continue;\n    }\n    return ret_val;\n}\n

\u8fd9\u4e2a\u51fd\u6570\u6765\u81ea\u300aC Primer Plus\u300b\uff0c\u4e5f\u662f\u4e66\u4e2d 13 \u7ae0\u4ee5\u540e\u4e00\u76f4\u4f7f\u7528\u7684\u8f93\u5165\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u793a\u8303\u4e86\u5982\u4f55\u4f7f\u7528\u5b89\u5168\u7684 fgets() \u51fd\u6570\uff0c\u5e76\u5c06\u8f93\u5165\u7edf\u4e00\uff0c\u5e76\u5904\u7406\u5269\u4f59\u7684\u5b57\u7b26\u3002

\u5728\u6d89\u53ca\u884c\u7684\u8f93\u5165\u65f6\uff0c\u4e00\u5b9a\u8981\u6ce8\u610f\u7edf\u4e00\u884c\u7ed3\u5c3e\u7684\u5f62\u5f0f\u3002\u8fd9\u5bf9\u4e8e\u6362\u884c\u7b26\uff0c\u7279\u522b\u662f\u6587\u4ef6\u7ed3\u5c3e\u5904\u859b\u5b9a\u8c14\u7684\u6362\u884c\u7b26\uff0c\u6709\u5f88\u5927\u4f5c\u7528\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_11","title":"\u68c0\u67e5\u8f93\u5165","text":"

\u53ef\u4ee5\u4f7f\u7528scanf() \u7684\u8fd4\u56de\u503c\u6765\u68c0\u67e5\u8f93\u5165\u662f\u5426\u6b63\u786e\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_12","title":"\u6587\u4ef6\u7f16\u7801\u4e0e\u6587\u4ef6\u8f93\u5165\u8f93\u51fa","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_13","title":"\u57fa\u7840\u6982\u5ff5","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_14","title":"\u4ec0\u4e48\u662f\u6587\u4ef6\uff1f","text":"

\u7b80\u5355\u7684\u8bf4\uff0c\u6587\u4ef6\u662f\u5728\u786c\u76d8\u4e0a\u7684\u4e00\u6bb5\u5df2\u547d\u540d\u7684\u50a8\u5b58\u533a\u3002

\u5bf9\u64cd\u4f5c\u7cfb\u7edf\u800c\u8a00\uff0c\u6587\u4ef6\u66f4\u52a0\u590d\u6742\u3002\u6587\u4ef6\u662f\u5177\u6709\u7b26\u53f7\u540d\u7684\uff0c\u5728\u903b\u8f91\u4e0a\u5177\u6709\u5b8c\u6574\u610f\u4e49\u7684\u4e00\u7ec4\u76f8\u5173\u4fe1\u606f\u9879\u7684\u5e8f\u5217\u3002\u6587\u4ef6\u8fd8\u5305\u62ec\u4e86\u4e00\u4e9b\u989d\u5916\u6570\u636e\uff0c\u4fbf\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u786e\u5b9a\u6587\u4ef6\u7684\u79cd\u7c7b\u3002

c_file.c
#include<stdio.h>\n#include<string.h>\n\nint main(int argc, char *argv[]){\n    const char *str = \"ckc-agc programming lec3\";\n\n    FILE *fp1 = fopen(\"test1.txt\", \"wb+\");\n    FILE *fp2 = fopen(\"test2.txt\", \"w+\");\n    fprintf(fp1, \"%s\\n%s\\n\", str, argv[0]);\n    fprintf(fp2, \"%s\\n%s\\n\", str, argv[0]);\n    fwrite(str, sizeof(char), strlen(str), fp1);\n\n    // fseek(fp1, 0, SEEK_SET);\n    // fprintf(fp1, \"%s\\n\", \"SEEK_SET\");\n    fseek(fp1, 0, SEEK_END);\n    fprintf(fp1, \"%s\\n\", \"SEEK_END\");\n\n    rewind(fp1);\n    fprintf(fp1, \"%s\\n\", \"rewind\");\n\n    fclose(fp1);\n    fclose(fp2);\n}\n
file c_file.c\nfile c_file.o\nfile c_file\nobjdump -h -s -d c_file.o\nobjdump -h -s c_file\n

\u5bf9\u4e8e C \u8bed\u8a00\u6765\u8bf4\uff0cC \u628a\u6587\u4ef6\u770b\u4f5c\u8fde\u7eed\u7684\u5b57\u8282\uff0c\u6bcf\u4e2a\u5b57\u8282\u90fd\u80fd\u88ab\u5355\u72ec\u8bfb\u53d6\u3002\u8fd9\u4e0e UNIX \u73af\u5883\u4e2d\u7684\u6587\u4ef6\u7ed3\u6784\u76f8\u5bf9\u5e94\u3002\u4fbf\u4e8e\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\uff0cC \u63d0\u4f9b\u4e24\u79cd\u6587\u4ef6\u6a21\u5f0f\uff1a\u6587\u672c\u6a21\u5f0f\u548c\u4e8c\u8fdb\u5236\u6a21\u5f0f\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_15","title":"\u6587\u4ef6\u7f16\u7801","text":"

\u5b57\u7b26\u7f16\u7801\u662f\u628a\u5b57\u7b26\u96c6\u4e2d\u7684\u5b57\u7b26\u7f16\u7801\u4e3a\u6307\u5b9a\u96c6\u5408\u4e2d\u67d0\u4e00\u5bf9\u8c61\uff08\u4f8b\u5982\uff1abit \u6d41\uff09\uff0c\u4ee5\u4fbf\u6587\u672c\u5728\u8ba1\u7b97\u673a\u4e2d\u5b58\u50a8\u548c\u901a\u8fc7\u901a\u4fe1\u7f51\u7edc\u7684\u4f20\u9012\u3002

\u5e38\u89c1\u7684\u6587\u4ef6\u5b57\u7b26\u96c6/\u7f16\u7801\uff1a

\u73b0\u5728\u5728\u5185\u5b58\u4e2d\u901a\u5e38\u4ee5 UTF-16(Windows API \u5927\u91cf\u504f\u597d UTF-16 LE \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u4f5c\u4e3a\u53c2\u6570) \u6765\u50a8\u5b58\uff0c\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\u66ff\u6362\u4e3a UTF-8 \u7b49\u683c\u5f0f\uff0c\u53ef\u4ee5\u538b\u7f29\u7a7a\u95f4\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_16","title":"\u6587\u672c\u6a21\u5f0f\u548c\u4e8c\u8fdb\u5236\u6a21\u5f0f","text":"

\u6240\u6709\u6587\u4ef6\u7684\u5185\u5bb9\u90fd\u4ee5\u4e8c\u8fdb\u5236\u5f62\u5f0f\u5b58\u50a8\u3002\u4f46\u662f\uff0c\u5982\u679c\u6587\u4ef6\u6700\u521d\u4f7f\u7528\u4e8c\u8fdb\u5236\u7f16\u7801\u7684\u5b57\u7b26 (\u4f8b\u5982 ASCII \u7801) \u8868\u793a\u6587\u672c\uff0c\u8be5\u6587\u4ef6\u5c31\u662f\u6587\u672c\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u6587\u672c\u5185\u5bb9\u3002\u5982\u679c\u6587\u4ef6\u4e2d\u7684\u4e8c\u8fdb\u5236\u503c\u4ee3\u8868\u53ca\u5176\u8bed\u8a00\u4ee3\u7801\u6216\u6570\u503c\u6570\u636e\uff0c\u8be5\u6587\u4ef6\u662f\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u4e8c\u8fdb\u5236\u5185\u5bb9\u3002

Unix \u4f7f\u7528\u540c\u4e00\u79cd\u6587\u4ef6\u683c\u5f0f\u5904\u7406\u6587\u672c\u6587\u4ef6\u548c\u4e8c\u8fdb\u5236\u6587\u4ef6\u7684\u5185\u5bb9\u3002Unix \u76ee\u5f55\u4e2d\u6709\u4e00\u4e2a\u7edf\u8ba1\u6587\u4ef6\u5927\u5c0f\u7684\u8ba1\u6570\uff0c\u7a0b\u5e8f\u53ef\u4ee5\u6839\u636e\u8be5\u8ba1\u6570\u786e\u5b9a\u662f\u5426\u8bfb\u5230\u6587\u4ef6\u5c3e\u3002

C \u8bed\u8a00\u63d0\u4f9b\u4e24\u79cd\u8bbf\u95ee\u6587\u4ef6\u7684\u9014\u5f84\uff1a\u4e8c\u8fdb\u5236\u6a21\u5f0f\u548c\u6587\u672c\u6a21\u5f0f\u3002\u5728\u4e8c\u8fdb\u5236\u6a21\u5f0f\u4e2d\uff0c\u7a0b\u5e8f\u53ef\u4ee5\u8bbf\u95ee\u6587\u4ef6\u7684\u6bcf\u4e2a\u5b57\u8282\uff0c\u800c\u5728\u6587\u672c\u6a21\u5f0f\u4e2d\uff0c\u7a0b\u5e8f\u6240\u89c1\u7684\u5185\u5bb9\u548c\u6587\u4ef6\u7684\u5b9e\u9645\u5185\u5bb9\u4e0d\u540c\u3002\u7a0b\u5e8f\u4ee5\u6587\u672c\u6a21\u5f0f\u8bfb\u53d6\u6587\u4ef6\u65f6\uff0c\u628a\u672c\u5730\u73af\u5883\u8868\u793a\u7684\u884c\u672b\u5c3e\u6216\u6587\u4ef6\u7ed3\u5c3e\u6620\u5c04\u6210 C \u6a21\u5f0f\u3002

\u8fd9\u544a\u8bc9\u6211\u4eec\u6587\u672c\u548c\u4e8c\u8fdb\u5236\u6a21\u5f0f\u4e0d\u80fd\u968f\u610f\u6df7\u7528\uff0c\u5426\u5219\u53ef\u80fd\u4f1a\u51fa\u73b0\u6b63\u786e\u6027\u4e0a\u7684\u95ee\u9898\u3002

I/O \u7ea7\u522b

\u4e8b\u5b9e\u4e0a\u6211\u4eec\u9664\u4e86\u9009\u62e9\u5904\u7406\u6587\u4ef6\u7684\u6a21\u5f0f\uff0c\u8fd8\u80fd\u591f\u9009\u62e9I/O\u7684\u7ea7\u522b\u3002\u5e95\u5c42I/O\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684I/O\u670d\u52a1\u3002\u6807\u51c6\u9ad8\u7ea7I/O\u4f7f\u7528C\u5e93\u7684\u6807\u51c6\u5305\u548cstdio.h\u5934\u6587\u4ef6\u5b9a\u4e49\u3002\u6807\u51c6\u9ad8\u7ea7I/O\u4f7f\u7528\u5e95\u5c42I/O\u670d\u52a1\uff0c\u4f46\u662f\u5b83\u4eec\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7ea7\u522b\u7684\u63a5\u53e3\u3002\u56e0\u4e3a\u65e0\u6cd5\u4fdd\u8bc1\u6240\u6709\u7684\u64cd\u4f5c\u7cfb\u7edf\u90fd\u9002\u7528\u76f8\u540c\u7684\u5e95\u5c42I/O\u6a21\u578b\uff0cC\u6807\u51c6\u53ea\u652f\u6301\u6807\u51c6I/O\u5305\u3002

\u6807\u51c6\u6587\u4ef6

C\u7a0b\u5e8f\u4f1a\u81ea\u52a8\u6253\u5f003\u4e2a\u6587\u4ef6\uff0c\u5b83\u4eec\u88ab\u79f0\u4e3a\u6807\u51c6\u8f93\u5165\uff08standard input\uff09\u3001\u6807\u51c6\u8f93\u51fa\uff08standard output\uff09\u548c\u6807\u51c6\u9519\u8bef\u8f93\u51fa\uff08standard error output\uff09\u3002\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6807\u51c6\u8f93\u5165\u662f\u7cfb\u7edf\u7684\u666e\u901a\u8f93\u5165\u8bbe\u5907\uff0c\u901a\u5e38\u4e3a\u952e\u76d8\uff1b\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u662f\u7cfb\u7edf\u7684\u666e\u901a\u8f93\u51fa\u8bbe\u5907\uff0c\u901a\u5e38\u4e3a\u663e\u793a\u5c4f\u3002

\u901a\u5e38\uff0c\u6807\u51c6\u8f93\u5165\u4e3a\u7a0b\u5e8f\u63d0\u4f9b\u8f93\u5165\uff0c\u5b83\u662f getchar()\u548c scanf()\u4f7f\u7528\u7684\u6587\u4ef6\u3002\u7a0b\u5e8f\u901a\u5e38\u8f93\u51fa\u5230\u6807\u51c6\u8f93\u51fa\uff0c\u5b83\u662fputchar()\u3001puts()\u548cprintf()\u4f7f\u7528\u7684\u6587\u4ef6\u3002\u524d\u6587\u63d0\u5230\u7684\u91cd\u5b9a\u5411\u628a\u5176\u4ed6\u6587\u4ef6\u89c6\u4e3a\u6807\u51c6\u8f93\u5165\u6216\u6807\u51c6\u8f93\u51fa\u3002\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u63d0\u4f9b\u4e86\u4e00\u4e2a\u903b\u8f91\u4e0a\u4e0d\u540c\u7684\u5730\u65b9\u6765\u53d1\u9001\u9519\u8bef\u6d88\u606f\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f7f\u7528\u91cd\u5b9a\u5411\u628a\u8f93\u51fa\u53d1\u9001\u7ed9\u6587\u4ef6\u800c\u4e0d\u662f\u5c4f\u5e55\uff0c\u90a3\u4e48\u53d1\u9001\u81f3\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u7684\u5185\u5bb9\u4ecd\u7136\u4f1a\u88ab\u53d1\u9001\u5230\u5c4f\u5e55\u4e0a\u3002\u8fd9\u6837\u5f88\u597d\uff0c\u56e0\u4e3a\u5982\u679c\u628a\u9519\u8bef\u6d88\u606f\u53d1\u9001\u81f3\u6587\u4ef6\uff0c\u5c31\u53ea\u80fd\u6253\u5f00\u6587\u4ef6\u624d\u80fd\u770b\u5230\u3002

\u7406\u89e3\uff1a\u6807\u51c6I/O\u4e2d\u7528FILE\uff08\u6d41\uff09\u8868\u793a\u4e00\u4e2a\u6253\u5f00\u7684\u6587\u4ef6

"},{"location":"programming/archive/23fall/lec3/lec3/#_17","title":"\u6d41\u548c\u6587\u4ef6","text":"

C \u6807\u51c6\u662f\u8fd9\u6837\u63cf\u8ff0\u4e24\u79cd\u6d41\u7684\uff1a

\u5173\u4e8e\u6587\u4ef6\u52a8\u4f5c\uff1a

"},{"location":"programming/archive/23fall/lec3/lec3/#_18","title":"\u7c7b\u578b\u548c\u5b8f","text":"

\u5728 <stdio.h> \u4e2d\u6709\u5982\u4e0b\u4e0e\u6587\u4ef6\u76f8\u5173\u7684\u7c7b\u578b\u548c\u5b8f\uff1a

"},{"location":"programming/archive/23fall/lec3/lec3/#_19","title":"\u51fd\u6570","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_20","title":"\u6587\u4ef6\u64cd\u4f5c","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_21","title":"\u6587\u4ef6\u8bbf\u95ee","text":""},{"location":"programming/archive/23fall/lec3/lec3/#mode","title":"mode \u5b57\u7b26\u4e32\u7684\u542b\u4e49","text":"flag meaning r read w write (new or cut) a append (new or append) b binary + update

\u6ce8\u610f\u4e0a\u9762\u8bcd\u8bed\u7684\u542b\u4e49\uff0cupdate \u548c append \u80fd\u5199\u5165\u7684\u8303\u56f4\u5e94\u8be5\u662f\u4e0d\u540c\u7684\u3002

\u5bf9\u4e8e UNIX \u8fd9\u79cd\u53ea\u6709\u4e00\u79cd\u6587\u4ef6\u7c7b\u578b\u7684\u7cfb\u7edf\uff0c\u5e26 b \u4e0e\u5426\u7684\u6a21\u5f0f\u662f\u76f8\u540c\u7684\u3002 C11 \u4e2d\u65b0\u589e\u4e86 x\uff0c\u5e26\u8be5\u5b57\u6bcd\u7684\u5199\u6a21\u5f0f\u6253\u5f00\u5b58\u5728\u6587\u4ef6\u4f1a\u5931\u8d25\uff08\u76f8\u5f53\u4e8e\u52a0\u4e86\u4fdd\u62a4\uff09\uff0c\u4e14\u5141\u8bb8\u72ec\u5360\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_22","title":"\u683c\u5f0f\u5316\u8f93\u5165/\u8f93\u51fa","text":"

fprintf,fscanf,vfprintf,vprintf,vsprintf

"},{"location":"programming/archive/23fall/lec3/lec3/#_23","title":"\u5b57\u7b26\u8f93\u5165/\u8f93\u51fa","text":"

fgetc,fgets,fputc,fputs,getc,getchar,gets_s/(gets),putc,putchar,puts,ungetc

\u5176\u4e2d\uff0cfgetc() \u4e0e getc() \u8fd9\u7c7b\u51fd\u6570\u7684\u4e0d\u540c\u662f\u540e\u8005\u53ef\u80fd\u88ab\u5b9e\u73b0\u4e3a\u5b8f\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#io_1","title":"\u76f4\u63a5 I/O","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_24","title":"\u6587\u4ef6\u5b9a\u4f4d","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_25","title":"\u5176\u4ed6","text":"

\u4ee5\u4e0b\u4e24\u4e2a\u51fd\u6570\u7528\u4e8e\u5904\u7406\u66f4\u5927\u578b\u7684\u6587\u4ef6\uff08long \u65e0\u6cd5\u8868\u793a\u7684\u504f\u79fb\u503c\uff09

"},{"location":"programming/archive/23fall/lec3/pre/","title":"\u8bfe\u524d\uff1a\u4e00\u4e9b\u6837\u4f8b","text":"

\u628a\u8bb2\u4e49\u91cc\u7684\u5c0f\u7a0b\u5e8f\u548c\u547d\u4ee4\u884c\u8dd1\u4e00\u8dd1\uff0c\u601d\u8003\u4e00\u4e0b\u7559\u4e0b\u7684\u95ee\u9898\uff5e

  1. \u91cd\u5b9a\u5411\u8fd0\u7b97\u7b26

    echo_eof.c
    /* echo_eof.c -- repeats input to end of file */\n#include <stdio.h>\nint main(void)\n{\n    int ch;\n\n    while ((ch = getchar()) != EOF)\n    putchar(ch);\n\n     return 0;\n}\n
    echo_eof < echo_eof.c\necho_eof < echo_eof.c > echo_eof.txt\necho_eof < echo_eof.c | cat\n
  2. \u5173\u4e8e\u683c\u5f0f\u5316\u5b57\u7b26\u4e32

    printf.c
    #include <stdio.h>\n\nint main()\n{\n    // \u7c7b\u578b\n    printf(\"%5d\\n\", 1000);  // \u9ed8\u8ba4\u53f3\u5bf9\u9f50\uff0c\u5de6\u8fb9\u8865\u7a7a\u683c\n    printf(\"%-5d\\n\", 1000); // \u5de6\u5bf9\u9f50\uff0c\u53f3\u8fb9\u8865\u7a7a\u683c\n    printf(\"%+d %+d\\n\", 1000, -1000); // \u8f93\u51fa\u6b63\u8d1f\u53f7\n    printf(\"% d % d\\n\", 1000, -1000); // \u6b63\u53f7\u7528\u7a7a\u683c\u66ff\u4ee3\uff0c\u8d1f\u53f7\u8f93\u51fa\n    printf(\"%x %#x\\n\", 1000, 1000); // \u8f93\u51fa 0x\n    printf(\"%.0f %#.0f\\n\", 1000.0, 1000.0); // \u5f53\u5c0f\u6570\u70b9\u540e\u4e0d\u8f93\u51fa\u503c\u65f6\u4f9d\u7136\u8f93\u51fa\u5c0f\u6570\u70b9\n    printf(\"%g %#g\\n\", 1000.0, 1000.0); // \u4fdd\u7559\u5c0f\u6570\u70b9\u540e\u540e\u7684 0\n    printf(\"%05d\\n\", 1000); // \u524d\u9762\u8865 0\n\n    // \u5bbd\u5ea6\n    double a = 3.141592653589;\n    int x = 5;\n    printf(\"%.*f\", x, a);\n\n    // \u7cbe\u5ea6\n    printf(\"%.8d\\n\", 1000);           // \u4e0d\u8db3\u6307\u5b9a\u5bbd\u5ea6\u8865\u524d\u5bfc 0\uff0c\u6548\u679c\u7b49\u540c\u4e8e%06d\n    printf(\"%.8f\\n\", 1000.123456789); // \u8d85\u8fc7\u7cbe\u5ea6\uff0c\u622a\u65ad\n    printf(\"%.8f\\n\", 1000.123456);    // \u4e0d\u8db3\u7cbe\u5ea6\uff0c\u8865\u540e\u7f6e 0\n    printf(\"%.8g\\n\", 1000.123456);    // \u6700\u5927\u6709\u6548\u6570\u5b57\u4e3a 8 \u4f4d\n    printf(\"%.8s\\n\", \"abcdefghij\");   // \u8d85\u8fc7\u6307\u5b9a\u957f\u5ea6\u622a\u65ad\n\n    // \u7c7b\u578b\u957f\u5ea6\n    printf(\"%hhd\\n\", 'A');               // \u8f93\u51fa\u6709\u7b26\u53f7 char\n    printf(\"%hhu\\n\", 'A' + 128);         // \u8f93\u51fa\u65e0\u7b26\u53f7 char\n    printf(\"%hd\\n\", 32767);              // \u8f93\u51fa\u6709\u7b26\u53f7\u77ed\u6574\u578b short int\n    printf(\"%hu\\n\", 65535);              // \u8f93\u51fa\u65e0\u7b26\u53f7\u77ed\u6574\u578b unsigned short int\n    printf(\"%ld\\n\", 0x7fffffffffffffff); // \u8f93\u51fa\u6709\u7b26\u53f7\u957f\u6574\u578b long int\n    printf(\"%lu\\n\", 0xffffffffffffffff); // \u8f93\u51fa\u6709\u7b26\u53f7\u957f\u6574\u578b unsigned long int\n}\n
  3. \u5173\u4e8eprintf()

    wrong_cnv.c
    #include <stdio.h>\n#define num 336\n#define b 65618\nint main(void)\n{\n    printf(\"num as short and unsigned short:  %hd %hu\\n\", num,num);\n    printf(\"-num as short and unsigned short: %hd %hu\\n\", -mnum,-mnum);\n    printf(\"num as int and char: %d %c\\n\", num, num);\n    printf(\"b as int, short, and char: %d %hd %c\\n\",b, b, b);\n\n    float n1 = 3.0;\n    double n2 = 3.0;\n    long n3 = 2000000000;\n    long n4 = 1234567890;\n    printf(\"%.1e %.1e %.1e %.1e\\n\", n1, n2, n3, n4);\n    printf(\"%ld %ld\\n\", n3, n4);\n    printf(\"%ld %ld %ld %ld\\n\", n1, n2, n3, n4);\n    return 0;\n}\n

    \u8be5\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c\u4e3a (\u7531\u4e8e\u5b9e\u73b0\u662f\u672a\u5b9a\u4e49\u7684\uff0c\u90e8\u5206\u7ed3\u679c\u56e0\u7cfb\u7edf\u548c\u7f16\u8bd1\u5668\u800c\u5f02)\uff1a

    num as short and unsigned short:  336 336\n-num as short and unsigned short: -336 65200\nnum as int and char: 336 P\nb as int, short, and char: 65618 336 R\n3.0e+00 3.0e+00 2.0e+09 1.2e+09\n2000000000 1234567890\n0 1074266112 0 1074266112\n

    \u4f60\u80fd\u89e3\u91ca\u4e3a\u4ec0\u4e48\u4f7f\u7528%ld \u8f93\u51fa long \u7c7b\u578b\u7684\u503c\u65f6\uff0c\u4e5f\u4f1a\u51fa\u73b0\u9519\u8bef\u5417\uff1f

  4. \u5173\u4e8escanf()

    confusing_scanf.c
    #include <stdio.h>\nint main(void)\n{\n    char c[100] = {0};\n    scanf(\"%s\\n\",&c);\n    printf(\"%s\",c);\n}\n

    \u8fd9\u4e2a\u7a0b\u5e8f\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u5947\u602a\uff1f

  5. \u6587\u4ef6

    c_file.c
    #include<stdio.h>\n#include<string.h>\n\nint main(int argc, char *argv[]){\n    const char *str = \"ckc-agc programming lec3\";\n\n    FILE *fp1 = fopen(\"test1.txt\", \"wb+\");\n    FILE *fp2 = fopen(\"test2.txt\", \"w+\");\n    fprintf(fp1, \"%s\\n%s\\n\", str, argv[0]);\n    fprintf(fp2, \"%s\\n%s\\n\", str, argv[0]);\n    fwrite(str, sizeof(char), strlen(str), fp1);\n\n    // fseek(fp1, 0, SEEK_SET);\n    // fprintf(fp1, \"%s\\n\", \"SEEK_SET\");\n    fseek(fp1, 0, SEEK_END);\n    fprintf(fp1, \"%s\\n\", \"SEEK_END\");\n\n    rewind(fp1);\n    fprintf(fp1, \"%s\\n\", \"rewind\");\n\n    fclose(fp1);\n    fclose(fp2);\n}\n
    file c_file.c\nfile c_file.o\nfile c_file\nobjdump -h -s -d c_file.o\nobjdump -h -s c_file\n
"},{"location":"programming/archive/23fall/lec4/after/","title":"\u8bfe\u540e\u6269\u5c55\uff1aC \u6807\u51c6\u5e93\u7684\u5b9e\u73b0","text":"

\u65bd\u5de5\u4e2d

\u672c\u9875\u9762\u6b63\u5728\u7f16\u8f91\u4e2d\u3002

"},{"location":"programming/archive/23fall/lec4/after/#c_1","title":"\u540e\u534a\uff1aC \u6807\u51c6\u5e93\u7684\u5b9e\u73b0","text":"

\u6742\u8c08\uff1a\u4e3a\u4ec0\u4e48\u8981\u5b66\u4e60 C \u6807\u51c6\u5e93\uff1f

\u7406\u8bba\u4e0a\uff0c\u5b66\u4e60\u5b8c\u4efb\u4f55\u7f16\u7a0b\u8bed\u8a00\u7684\u57fa\u672c\u8bed\u6cd5\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u7528\u5b83\u6765\u7f16\u7a0b\u89e3\u51b3\u4efb\u4f55\u5b9e\u9645\u95ee\u9898\u4e86\u3002\u4f46\u662f\uff0c\u8bed\u8a00\u6240\u884d\u751f\u51fa\u7684\u4efb\u4f55\u80fd\u63d0\u9ad8\u751f\u4ea7\u529b\u7684\u5e93\uff0c\u5176\u91cd\u8981\u6027\u5f80\u5f80\u4f1a\u8fdc\u8fdc\u8d85\u8fc7\u8be5\u8bed\u8a00\u672c\u8eab\u3002\u5b66\u4e60\u4e00\u95e8\u8bed\u8a00\u5e76\u5b66\u4e60\u5176\u5e93\u7684\u5b9e\u73b0\uff0c\u8fd9\u6837\u624d\u80fd\u719f\u7ec3\u5730\u9a7e\u9a6d\u8bed\u8a00\u5de5\u5177\uff0c\u4e86\u89e3\u5e93\u6240\u63d0\u4f9b\u7684\u529f\u80fd\u548c\u5c40\u9650\u6027\uff0c\u8fdb\u800c\u5728\u7279\u5b9a\u7684\u5e94\u7528\u8981\u6c42\u4e0b\u6269\u5c55\u5e93\u3002

\u5c3d\u7ba1 C \u8bed\u8a00\u53ca\u5176\u6240\u9644\u5e26\u7684\u6807\u51c6\u5e93\u4e2d\u9690\u85cf\u7740\u592a\u591a\u7684\u6666\u6da9\u9677\u9631\uff0c\u4f46\u6211\u4eec\u4e0d\u5f97\u4e0d\u82b1\u5927\u529b\u6c14\u201c\u8fc7\u5206\u94bb\u7814\u201d\u5b83\u3002\u5b66\u4e60 C \u6807\u51c6\u5e93\u672c\u8eab\u7684\u5b9e\u73b0\uff0c\u5c31\u662f\u5b66\u4e60 C \u8bed\u8a00\u6700\u597d\u7684\u6559\u6750\uff0c\u56e0\u4e3a\u5176\u5b9e\u73b0\u8fc7\u7a0b\u5c06\u4f1a\u628a\u4f7f\u7528 C \u8bed\u8a00\u7f16\u5199\u5177\u6709\u5de5\u4e1a\u5f3a\u5ea6\u7684\u5065\u58ee\u4ee3\u7801\u6240\u9700\u7684\u6280\u5de7\u5c55\u73b0\u5f97\u6dcb\u6f13\u5c3d\u81f4\u3002

C \u6807\u51c6\u5e93\u53ef\u4ee5\u5206\u4e3a 3 \u7ec4\u3002\u5982\u4f55\u6b63\u786e\u548c\u719f\u7ec3\u5730\u4f7f\u7528\u5b83\u4eec\uff0c\u53ef\u4ee5\u76f8\u5e94\u5730\u533a\u5206\u51fa 3 \u79cd\u5c42\u6b21\u7684 C \u7a0b\u5e8f\u5458\uff1a

\u53ef\u4ee5\u770b\u5230\uff0cC \u7a0b\u5e8f\u8bbe\u8ba1\u8fd9\u95e8\u8bfe\u7a0b\u5bf9\u5927\u5bb6\u7684\u8981\u6c42\u5c31\u662f\u300c\u5408\u683c\u7a0b\u5e8f\u5458\u300d\u3002\u6211\u4eec\u5728\u8bfe\u7a0b\u4e2d\u7684\u6781\u5c11\u90e8\u5206\u4ee3\u7801\u4f1a\u770b\u89c1 <assert.h> \u548c <time.h>\uff0c\u8fd9\u4e24\u4e2a\u5e93\u4e5f\u4f1a\u5bf9\u4f60\u7684\u7f16\u7a0b\u6709\u6240\u5e2e\u52a9\uff0c\u4f18\u79c0\u7684\u540c\u5b66\u53ef\u4ee5\u4ee5\u300c\u719f\u7ec3\u7a0b\u5e8f\u5458\u300d\u6765\u8981\u6c42\u81ea\u5df1\u3002\u4eca\u540e\u5927\u591a\u6570\u540c\u5b66\u6216\u8bb8\u90fd\u4f1a\u8f6c\u5411\u5b66\u4e60 C++\uff0c\u5927\u6982\u53ea\u6709\u505a\u5b89\u5168\u3001\u7cfb\u7edf\u3001\u5d4c\u5165\u5f0f\u4e4b\u7c7b\u7684\u540c\u5b66\u4f1a\u9700\u8981\u505a\u5230\u300c\u4f18\u79c0\u7a0b\u5e8f\u5458\u300d\u7684\u5730\u6b65\u3002

\u5b66\u4e60 C \u6807\u51c6\u5e93\u524d\u4f60\u5e94\u8be5\u5177\u5907\u7684\u77e5\u8bc6

\u5b66\u4e60 C \u6807\u51c6\u5e93\u65f6\uff0c\u6211\u4eec\u4f1a\u63a5\u89e6\u5230\u5f88\u591a C \u6807\u51c6\u4e2d\u7684\u89c4\u8303\u6027\u7684\u4e25\u8c28\u5730\u8bed\u53e5\uff0c\u521d\u8bfb\u65f6\u53ef\u80fd\u8ba9\u4f60\u89c9\u5f97\u975e\u5e38\u62d7\u53e3\u548c\u96be\u4ee5\u7406\u89e3\uff0c\u8ba9\u6211\u4eec\u6765\u8bfb\u51e0\u6761\u3002

"},{"location":"programming/archive/23fall/lec4/after/#c_2","title":"\u6742\u9879\uff1aC \u6807\u51c6\u5bf9\u5e93\u7684\u5b9e\u73b0\u8981\u6c42","text":"

\u5728\u4f7f\u7528\u65f6\u4e0d\u5fc5\u5728\u610f\uff0c\u4f46\u9700\u8981\u77e5\u9053\u7684\u4e00\u4e2a\u70b9\u662f\uff1a\u6807\u51c6\u5e93\u4e2d\u7684\u67d0\u4e9b\u51fd\u6570\u53ef\u80fd\u88ab\u4f5c\u4e3a\u5b8f\u5b9e\u73b0\u4e86\u3002\u4f46\u65e0\u8bba\u5982\u4f55\uff0c\u6807\u51c6\u5e93\u4e00\u5b9a\u4f1a\u63d0\u4f9b\u4e00\u4e2a\u51fd\u6570\u7248\u672c\u7684\u5b9e\u73b0\u3002

\u5982\u679c\u4e00\u4e2a\u51fd\u6570\u65e2\u63d0\u4f9b\u4e86\u5b8f\u7248\u672c\u53c8\u63d0\u4f9b\u4e86\u51fd\u6570\u7248\u672c\uff0c\u4f60\u77e5\u9053\u5982\u4f55\u4f7f\u7528\u6307\u5b9a\u7684\u7248\u672c\u5417\uff1f

\u4f8b\u5982\uff0c\u5bf9\u4e8e\u4ee5\u4e0b\u4e24\u79cd\u7248\u672c\uff0c\u4f60\u77e5\u9053\u4f60\u5728\u4f7f\u7528\u7684\u662f\u5b8f\u8fd8\u662f\u51fd\u6570\u5417\uff1f

#define isalnum(c) ...\nint isalnum(int c);\n

\u6807\u51c6\u5e93\u4e2d\u7684\u4e00\u4e9b\u51fd\u6570\uff0c\u53ef\u80fd\u540c\u65f6\u63d0\u4f9b\u4e86\u5b8f\u548c\u51fd\u6570\u7684\u7248\u672c\u3002

atoi() \u7684\u4f7f\u7528\u65b9\u5f0f

  1. \u53ef\u80fd\u751f\u6210\u4e00\u4e2a\u5b8f\u51fd\u6570\uff1a
    #include <stdlib.h>\nconst char *str;\ni = atoi(str);\n
  2. \u751f\u6210\u4e00\u4e2a\u5b9e\u9645\u51fd\u6570\u5f15\u7528\uff1a
    #include <stdlib.h>\n#undef atoi\nconst char *str;\ni = atoi(str);\n
    \u6216\u8005
    #include <stdlib.h>\nconst char *str;\ni = (atoi)(str);\n
"},{"location":"programming/archive/23fall/lec4/after/#stdioh","title":"<stdio.h> \u7684\u5b9e\u73b0\uff1a\u7cfb\u7edf\u8c03\u7528\u4e0e\u5185\u6838\u7f16\u7a0b","text":"

\u5728\u6211\u4e2a\u4eba\u770b\u6765\uff0c<stdio.h> \u7684\u5b9e\u73b0\u6700\u5177\u6311\u6218\u6027\u3002\u4f60\u9700\u8981\u5bf9\u5b9e\u73b0\u5bf9\u5e94\u7684\u64cd\u4f5c\u7cfb\u7edf\u6709\u4e00\u5b9a\u7684\u4e86\u89e3\uff0c\u624d\u80fd\u7f16\u5199\u51fa\u5b8c\u5584\u7684\u4ee3\u7801\u3002

\u672c\u8282\u4ee5 UNIX \u548c POSIX \u89c4\u8303\u7684\u7cfb\u7edf\u8c03\u7528\u4e3a\u51c6\u3002

\u4e00\u4e9b\u5386\u53f2\u7684\u80cc\u666f\uff1a\u6587\u4ef6\u3001\u8bbe\u5907\u548c ioctl
  1. \u6df7\u4e71\u7684\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf

\u6216\u8bb8\u4f60\u5f88\u96be\u60f3\u8c61\uff0cUNIX \u4e4b\u524d\u7684\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf\u4e3a\u6587\u4ef6\u8d4b\u4e88\u4e86\u5f88\u591a\u7c7b\u578b\u4e0a\u7684\u6982\u5ff5\u548c\u3001\u4f5c\u4e86\u5f88\u591a\u533a\u5206\uff0c\u800c\u4e0d\u662f\u6211\u4eec\u73b0\u5728\u6240\u5e7f\u6cdb\u63a5\u53d7\u7684\u300c\u6587\u4ef6\u5c31\u662f\u4e00\u7cfb\u5217\u8fde\u7eed\u7684\u5b57\u8282\u300d\u7684\u6982\u5ff5\u3002\u8fd9\u8fb9\u6709\u4e00\u6bb5\u63cf\u8ff0\uff0c\u4f60\u53ef\u4ee5\u770b\u770b\uff1a

Typically source code was a distinguished type, different from data. Compilers could read source, compiled programs could read and write 'data.' Thus the creation and inspection of Fortran programs was often walled off from the creation and inspection of other files, with completely different ways to edit and print them. This ruled out the use of programs to generate (or even simply copy) Fortran programs.

  1. \u4e0d\u7edf\u4e00\u7684\u6587\u672c\u8868\u793a\u548c\u8bbe\u5907\u4ea4\u4e92

\u65e9\u671f\u7a0b\u5e8f\u7684\u8f93\u5165\u8f93\u51fa\u65e0\u6cd5\u72ec\u7acb\u4e8e\u8bbe\u5907\u3002\u6bd4\u5982\uff0c\u5728\u4e0a\u4e2a\u4e16\u7eaa 60 \u5e74\u4ee3\u7684 FORTRAN IV \u4e2d\uff0c\u5728\u78c1\u5e26\u673a\u4e0a\u9700\u8981\u7528 READ INPUT TAPE 5\uff0c\u8bfb\u53d6\u78c1\u76d8\u4e0a\u9700\u8981\u7528 READ INPUT DISK 1\u3002\u8fd9\u6837\u7684\u4ee3\u7801\u5728\u4e0d\u540c\u7684\u8bbe\u5907\u4e0a\u9700\u8981\u4fee\u6539\uff0c\u975e\u5e38\u4e0d\u65b9\u4fbf\u3002UNIX \u5c06\u8fd9\u4e9b\u6df7\u4e71\u7684\u8bbe\u5907\u4ea4\u4e92\u5c01\u88c5\u5728\u8bbe\u5907\u5904\u7406\u7a0b\u5e8f\u4e2d\u3002\u5728 UNIX \u7cfb\u7edf\u770b\u6765\uff0c\u5916\u56f4\u8bbe\u5907\u6709\u4e09\u79cd\u7c7b\u578b\uff1a\u5b57\u7b26\u8bbe\u5907\uff08Character devices\uff09\u3001\u5757\u8bbe\u5907\uff08Block devices\uff09\u548c\u7f51\u7edc\u8bbe\u5907\uff08Network devices\uff09\u3002\u8fd9\u4e09\u79cd\u8bbe\u5907\u90fd\u88ab\u62bd\u8c61\u4e3a\u6587\u4ef6\uff0c\u4f7f\u7528\u7edf\u4e00\u7684\u6587\u4ef6\u64cd\u4f5c\u63a5\u53e3\u3002

\u5728 Ken Thompson \u4e3a UNIX \u8bbe\u8ba1\u7edf\u4e00\u7684\u5185\u90e8\u6587\u672c\u5f62\u5f0f\u524d\uff0c\u6587\u672c\u8868\u793a\u4e5f\u662f\u5341\u5206\u6df7\u4e71\u7684\u3002\u7ed3\u675f\u4e00\u884c\u662f\u4f7f\u7528\u56de\u8f66\u8fd8\u662f\u56de\u8f66\u52a0\u6362\u884c\uff0c\u8fd8\u662f\u6362\u884c\u7b26\uff0c\u8fd8\u662f\u66f4\u795e\u5947\u7684\u5b57\u7b26\uff1f\u7ec8\u7aef\u80fd\u4e0d\u80fd\u8bc6\u522b\u548c\u5c55\u5f00\u5236\u8868\u7b26\uff1f\u600e\u6837\u7528\u952e\u76d8\u6807\u5fd7\u6587\u4ef6\u7ed3\u675f\uff1f\u8fd9\u4e9b\u95ee\u9898\u7684\u7b54\u6848\u548c\u7ec8\u7aef\u7684\u751f\u4ea7\u5382\u5546\u4e00\u6837\u591a\u3002UNIX \u4f7f\u7528\u7cfb\u7edf\u8c03\u7528 ioctl \u6765\u8bbe\u7f6e\u4e00\u4e2a\u8bbe\u5907\u7684\u5404\u79cd\u53c2\u6570\uff0c\u8d1f\u8d23\u5bf9\u5185\u90e8\u6362\u884c\u7ea6\u5b9a\u548c\u5404\u79cd\u7ec8\u7aef\u4e4b\u95f4\u7684\u9700\u8981\u8f6c\u6362\u7684\u5b57\u7b26\u8fdb\u884c\u5904\u7406\u3002

UNIX Devices Drivers

\u9884\u5907\u77e5\u8bc6\uff1aUNIX \u7cfb\u7edf\u8c03\u7528

"},{"location":"programming/archive/23fall/lec4/lec4/","title":"\u7b80\u660e C \u6807\u51c6\u5e93","text":"

\u6458\u8981

\u8003\u8651\u5230\u8bfe\u7a0b\u6559\u5b66\u8fdb\u5ea6\uff0c\u672c\u8282\u8bfe\u4e0d\u518d\u8bb2\u89e3 C \u6807\u51c6\u5e93\u7684\u5b9e\u73b0\u3002

\u672c\u6b21\u8f85\u5b66\u7684\u76ee\u7684\u662f\uff1a

\u4ece\u5386\u5e74\u5377\u6765\u770b\uff0c\u5bf9\u6807\u51c6\u5e93\u7684\u8003\u5bdf\u5185\u5bb9\u4ec5\u9650\u4e8e\u4e0b\u9762\u7684\u8fd9\u4e9b\u5e93\uff0c\u672c\u8282\u8bfe\u4e5f\u4ec5\u53d9\u8ff0\u4e0b\u9762\u8fd9\u4e9b\u5e93\uff1a

"},{"location":"programming/archive/23fall/lec4/lec4/#c_1","title":"\u5bfc\u5f15\uff1aC \u6807\u51c6\u5e93\uff0c\u5b66\u4e9b\u4ec0\u4e48\uff1f","text":""},{"location":"programming/archive/23fall/lec4/lec4/#_1","title":"\u4e3a\u4ec0\u4e48\u8981\u5b66\u6807\u51c6\u5e93\uff1f","text":"

\u6709\u4e00\u4e2a\u7c97\u6d45\u7684\u7406\u7531\uff0c\u5c31\u662f\u56fe\u65b9\u4fbf\u3002\u5047\u8bbe\u6709\u4e0b\u9762\u8fd9\u4e2a\u58f0\u660e\u5728 main \u51fd\u6570\u4e2d\u6570\u7ec4\uff1a

int a[100];\n

\u6211\u4eec\u77e5\u9053\uff0c\u8fd9\u4e2a\u6570\u7ec4\u4e0d\u4f1a\u88ab\u521d\u59cb\u5316\u3002\u5982\u679c\u60f3\u8981\u628a\u8fd9\u4e2a\u6570\u7ec4\u5168\u90e8\u7f6e\u4e3a 0\uff0c\u4f60\u4f1a\u600e\u4e48\u5199\u5462\uff1f

\u9996\u5148\u4f1a\u6709\u7684\u60f3\u6cd5\u80af\u5b9a\u662f\uff1a

for (int i = 0; i < 100; ++i)\n    a[i] = 0;\n

\u5176\u5b9e\u6807\u51c6\u5e93\u63d0\u4f9b\u4e86\u4e00\u4e2a\u51fd\u6570 memset\uff0c\u7528\u6765\u8bbe\u7f6e\u4e00\u6bb5\u5185\u5b58\u7684\u503c\uff1a

memset(a, 0, sizeof(a));\n

\u662f\u4e0d\u662f\u5f88\u65b9\u4fbf\u5462\uff1f

\u518d\u6765\u4e00\u4e2a\u4f8b\u5b50\uff0c\u628a\u8f93\u5165\u4e2d\u6240\u6709\u7684\u5c0f\u5199\u5b57\u6bcd\u8f6c\u6362\u6210\u5927\u5199\u5b57\u6bcd\u3002\u5047\u8bbe\u8f93\u5165\u5df2\u7ecf\u5b58\u50a8\u5728 char \u6570\u7ec4 str \u4e2d\uff0c\u6839\u636e\u73b0\u6709\u7684\u77e5\u8bc6\uff0c\u4f60\u4f1a\u4e0d\u4f1a\u8fd9\u6837\u5199\uff1a

for(int i = 0; i < strlen(str); ++i)\n    if ('a' <= str[i] && str[i] <= 'z')\n        str[i] -= 'a' - 'A';\n

\u5176\u5b9e\u6807\u51c6\u5e93\u63d0\u4f9b\u4e86\u5224\u65ad\u5b57\u7b26\u5927\u5c0f\u5199\u7684\u51fd\u6570\uff0c\u4e5f\u63d0\u4f9b\u4e86\u8f6c\u6362\u5927\u5c0f\u5199\u7684\u51fd\u6570\uff1a

for(int i = 0; i < strlen(str); ++i)\n    if (islower(str[i]))\n        str[i] = toupper(str[i]);\n

\u4e0b\u9762\u7684\u8fd9\u6bb5\u4ee3\u7801\uff0c\u662f\u4e0d\u662f\u6bd4\u4e0a\u9762\u7684\u4ee3\u7801\u7b80\u6d01\uff0c\u5e76\u4e14\u4e00\u773c\u770b\u8fc7\u53bb\u5c31\u80fd\u660e\u767d\u610f\u601d\u5462\uff1f

\u603b\u800c\u8a00\u4e4b\uff0cC \u6807\u51c6\u5e93\u529f\u80fd\u5f3a\u5927\uff0c\u5b83\u7684\u91cd\u8981\u6027\u548c\u8bed\u8a00\u672c\u8eab\u4e00\u6837\u3002\u5b66\u4f1a\u4f7f\u7528\u6807\u51c6\u5e93\uff0c\u8ba9\u4f60\u5c11\u9020\u8f6e\u5b50\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3001\u7b80\u6d01\u6027\u548c\u6b63\u786e\u6027\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_2","title":"\u6807\u51c6\u5e93\u91cc\u6709\u4ec0\u4e48\uff1f","text":"

\ud83d\udca1\u5728\u4f60\u7684\u5370\u8c61\u4e2d\uff0c\u6807\u51c6\u5e93\u662f\u4ec0\u4e48\u6837\u7684\uff1f\u91cc\u9762\u6709\u4ec0\u4e48\u4e1c\u897f\uff1f

\u6bcf\u4e00\u4e2a\u6807\u51c6\u5e93\u4f1a\u5b9a\u4e49\u8fd9\u4e9b\u5185\u5bb9\uff1a

\u51e0\u4e2a\u8033\u719f\u80fd\u8be6\u7684\u4f8b\u5b50\uff0c\u4f60\u80fd\u8bf4\u8bf4\u5b83\u4eec\u662f\u4ec0\u4e48\u5417\uff1f

\u63a5\u4e0b\u6765\u7684\u6bcf\u4e00\u8282\u662f\u4e00\u4e2a\u6807\u51c6\u5e93\uff0c\u4f1a\u5206\u4e3a\u80cc\u666f\u3001\u5185\u5bb9\u3001\u4f7f\u7528\u4e09\u4e2a\u90e8\u5206\u3002\u5176\u4e2d\u300c\u80cc\u666f\u300d\u90e8\u5206\u4f1a\u4ecb\u7ecd\u4e00\u4e9b\u524d\u7f6e\u77e5\u8bc6\uff0c\u300c\u5185\u5bb9\u300d\u90e8\u5206\u4f1a\u4ecb\u7ecd\u6807\u51c6\u5e93\u4e2d\u7684\u5185\u5bb9\uff0c\u300c\u4f7f\u7528\u300d\u90e8\u5206\u4f1a\u4ecb\u7ecd\u4e00\u4e9b\u4f7f\u7528\u7684\u4f8b\u5b50\u3002\u300c\u5185\u5bb9\u300d\u6a21\u5757\u4e2d\u4ee3\u7801\u6bb5\u5185\u88ab\u6ce8\u91ca\u6389\u7684\u5185\u5bb9\uff0c\u8868\u793a\u4e0d\u4f5c\u8981\u6c42\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_3","title":"\u80cc\u666f\u77e5\u8bc6","text":"

\u4e3a\u4e86\u80fd\u8ddf\u4e0a\u63a5\u4e0b\u6765\u7684\u5185\u5bb9\uff0c\u786e\u8ba4\u4e00\u4e0b\u5927\u5bb6\u90fd\u6709\u7684\u77e5\u8bc6\uff1a

"},{"location":"programming/archive/23fall/lec4/lec4/#ctypeh","title":"<ctype.h>","text":"

\u5934\u6587\u4ef6 <ctype.h> \u58f0\u660e\u4e86\u51e0\u4e2a\u53ef\u4ee5\u7528\u4e8e\u8bc6\u522b\u548c\u8f6c\u6362\u5b57\u7b26\u7684\u51fd\u6570\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#ascii","title":"\u80cc\u666f\uff1aASCII \u5b57\u7b26\u96c6","text":"

ASCII \u5b57\u7b26\u96c6\u4e2d\u7684\u6570\u5b57\u548c\u5b57\u6bcd\u5927\u5bb6\u5e94\u8be5\u90fd\u5f88\u719f\u4e86\uff0c\u8fd9\u8fb9\u518d\u5bf9\u4e24\u7c7b\u5927\u5bb6\u63a5\u89e6\u6bd4\u8f83\u5c11\u7684\u5b57\u7b26\u5206\u7c7b\u7b80\u5355\u505a\u4e2a\u4ecb\u7ecd\u3002

\u5c0f\u63d0\u793a

\u4f60\u771f\u7684\u9700\u8981\u53bb\u8bb0\u8fd9\u4e9b\u5b57\u7b26\u7684\u7f16\u7801\u5417\uff1f

\u9009\u62e9\u586b\u7a7a\u4e4b\u7c7b\u7684\u9898\u76ee\u53ef\u80fd\u4f1a\u8003\u5230\uff0c\u4f46\u4e5f\u662f\u6709\u6280\u5de7\u7684\u3002\u4f60\u6700\u591a\u9700\u8981\u8bb0\u5fc6\u7684\u662f\u5927\u5c0f\u5199\u5b57\u6bcd\u4e4b\u95f4\u76f8\u5dee 32\uff0c\u4f46\u53ea\u8981\u9898\u76ee\u4e0d\u662f\u8ba9\u4f60\u5fc5\u987b\u586b\u6570\u5b57\uff0c\u4f60\u5c31\u53ef\u4ee5\u7528 'a' - 'A' \u6765\u4ee3\u66ff\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_4","title":"\u5185\u5bb9","text":"

\u8fd9\u4e2a\u5934\u6587\u4ef6\u4e2d\u53ea\u6709\u51fd\u6570\uff0c\u6ca1\u6709\u7279\u522b\u7684\u7c7b\u578b\u548c\u5b8f\u3002

\u8fd9\u4e9b\u51fd\u6570\u7684\u610f\u4e49\u548c\u7528\u6cd5\u975e\u5e38\u663e\u7136\uff0c\u56e0\u6b64\u6211\u4e5f\u4e0d\u505a\u6ce8\u91ca\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_5","title":"\u4f7f\u7528","text":"

<ctype.h> \u4e2d\u7684\u51fd\u6570\u5bf9 ASCII \u5b57\u7b26\u5927\u81f4\u4f5c\u4e86\u5982\u4e0b\u5212\u5206\uff1a

\u63a7\u5236\u5b57\u7b26\u90a3\u4e9b\u4e0d\u7528\u7ba1\uff0c\u4e0d\u8981\u6c42\u7684\u51fd\u6570\u4e0d\u7528\u7ba1\u3002\u53ea\u8981\u8bb0\u5f97 isspace \u548c isblank \u7684\u533a\u522b\u5c31\u884c\u4e86\u3002

isspace \u548c isblank \u7684\u533a\u522b

"},{"location":"programming/archive/23fall/lec4/lec4/#ctypeh_1","title":"<ctype.h> \u7684\u5b9e\u73b0\uff1a\u5b8f\u4e0e\u4f4d\u8fd0\u7b97","text":"

\u9605\u8bfb\u672c\u8282\u9700\u8981\u5177\u5907\u7684\u77e5\u8bc6

\u77e5\u9053\u53ef\u4ee5\u7528\u4f4d\u6765\u6807\u5fd7\u67d0\u4e9b\u72b6\u6001\u3002\u4e0e\u6216\u975e\u7b49\u4f4d\u8fd0\u7b97\u7684\u6982\u5ff5\u3002

\u77e5\u9053\u5b8f\u51fd\u6570\u662f\u600e\u4e48\u5c55\u5f00\u7684\u3002

\u4e0d\u77e5\u9053\uff1f\u901f\u901a\u4e00\u4e0b\uff01

\u9996\u5148\u4f60\u5e94\u8be5\u5bf9\u4e8c\u8fdb\u5236\u6709\u4e00\u5b9a\u6982\u5ff5\u3002\u5047\u5982\u6211\u4eec\u6709 4 \u4e2a\u4e8c\u8fdb\u5236\u4f4d 0000\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u7528\u5b83\u6765\u6807\u8bb0 4 \u79cd\u72b6\u6001\u3002\u6211\u4eec\u4e0d\u59a8\u8bbe\uff1a

\uff08\u6ce8\u610f\uff0c\u6700\u53f3\u4fa7\u7684\u4f4d\u662f\u6700\u4f4e\u4f4d\uff0c\u6700\u5de6\u4fa7\u7684\u4f4d\u662f\u6700\u9ad8\u4f4d\u3002\uff09

\u90a3\u4e48\u5bf9\u4e8e\u5b57\u7b26 c\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u4e8c\u8fdb\u5236\u4e32 1010 \u6765\u8868\u793a\u5b83\u7684\u5c5e\u6027\u3002

\u4f7f\u7528\u4f4d\u8fd0\u7b97\u548c\u63a9\u7801\u53ef\u4ee5\u5224\u65ad\u5c5e\u6027\u3002\u6bd4\u5982\uff0c\u6211\u4eec\u8981\u5224\u65ad\u4e00\u4e2a\u5b57\u7b26\u662f\u5426\u662f\u6570\u5b57\uff0c\u628a\u5b83\u7684\u4e32\u4e0e\u63a9\u7801 0001 \u8fdb\u884c\u4e0e\u8fd0\u7b97\u3002\u56e0\u4e3a 0001 \u4e2d\u524d\u4e09\u4f4d\u90fd\u662f 0\uff0c\u7ed3\u679c\u80af\u5b9a\u4e5f\u662f 0\u3002\u800c\u6700\u540e\u4e00\u4f4d\u662f 1\uff0c\u7ed3\u679c\u5c06\u7531\u53c2\u4e0e\u8fd0\u7b97\u7684\u4e32\u51b3\u5b9a\u3002\u63a9\u7801\u4e2d\u7684\u524d\u4e09\u4f4d\u597d\u50cf\u628a\u90a3\u4e9b\u65e0\u5173\u7684\u4f4d\u201c\u63a9\u76d6\u201d\u6389\u4e86\u3002\u6700\u540e\u7ed3\u679c\u5982\u679c\u662f\u96f6\uff0c\u90a3\u4e48\u5c31\u8bf4\u660e\u4e0d\u5177\u6709\u8be5\u5c5e\u6027\uff1b\u5982\u679c\u975e\u96f6\uff0c\u5c31\u8bf4\u660e\u5177\u6709\u8be5\u5c5e\u6027\u3002

\u63a5\u4e0b\u6765\u662f\u5b8f\u3002\u5b8f\u662f\u7eaf\u7cb9\u7684\u5b57\u7b26\u66ff\u6362\u3002\u5982\u679c\u5b8f\u4f7f\u7528\u4e86\u5706\u62ec\u53f7\uff0c\u90a3\u4e48\u5b83\u5c31\u662f\u4e00\u4e2a\u51fd\u6570\u5b8f\uff1a

#define MEAN(X, Y) (((X) + (Y)) / 2)\n

\u90a3\u4e48\u53ea\u8981\u7f16\u8bd1\u5668\u770b\u5230\u4ee3\u7801\u4e2d\u6709 MEAN \u540e\u8ddf\u4e00\u4e2a\u5706\u62ec\u53f7\uff0c\u5c31\u4f1a\u5f00\u59cb\u5339\u914d\u548c\u66ff\u6362\u3002\u6bd4\u5982\uff0cMEAN(1, 2) \u5c06\u88ab\u66ff\u6362\u4e3a (((1) + (2)) / 2)\u3001MEAN(a, b) \u5c06\u88ab\u66ff\u6362\u4e3a (((a) + (b)) / 2)\u3002

\ud83e\udd1a\u505c\u4e00\u505c\uff0c\u5148\u522b\u770b\u4e0b\u9762\u7684\u5185\u5bb9\u3002\u601d\u8003\u4e00\u4e0b\uff0c\u4f60\u4f1a\u600e\u4e48\u5b9e\u73b0\u4e0a\u9762\u7684\u90a3\u4e9b\u51fd\u6570\uff1f

\u4f60\u4f1a\u4e0d\u4f1a\u5728\u60f3\u8fd9\u6837\u7684\u4ee3\u7801\uff1a

int isalnum(int c)\n    { /* test for alphanumeric character */\n    return (('0' <= c && c <= '9') ||\n            ('a' <= c && c <= 'z') ||\n            ('A' <= c && c <= 'Z'));\n    }\n

<ctype.h> \u4e2d\u7684\u51fd\u6570\u901a\u5e38\u4f7f\u7528\u5b8f\u6765\u5b9e\u73b0\u3002\u4f7f\u7528\u5b8f\u5b9e\u73b0\u65f6\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u56e0\u7d20\uff1a

<ctype.h> \u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e2a\u67e5\u627e\u8868 _Ctype\uff0c\u4e24\u4e2a\u6620\u5c04\u8868 _Tolower \u548c _Toupper\u3002\u6bcf\u4e2a\u5b57\u7b26\u90fd\u88ab\u7f16\u5165\u67e5\u627e\u8868\u4e2d\uff0c\u4f7f\u7528\u4f4d\u8fd0\u7b97\u5c31\u80fd\u5224\u65ad\u51fa\u5b57\u7b26\u7684\u7c7b\u578b\u3002

ctype.h
#define _DI 0x20 /* '0'-'9' */\n#define _LO 0x10 /* 'a'-'z' */\n#define _UP 0x02 /* 'A'-'Z' */\n#define _XA 0x200 /* 'a'-'z', 'A'-'Z' */\nextern const short *_Ctype, *_Tolower, *_Toupper;\n#define isalnum(c) (_Ctype[(int)(c)] & (_DI|_LO|_UP|_XA))\n#define tolower(c) _ToLower[(int)(c)]\n

\u8bfb\u4e00\u4e0b\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u60f3\u8c61\u4e00\u4e0b _Ctype \u8fd9\u4e2a\u67e5\u627e\u8868\u7684\u6837\u5b50\u3002

\u8003\u8003\u4f60\uff0c\u5bf9\u4e8e ASCII \u5b57\u7b26\u96c6\uff0c\u8fd9\u4e2a\u67e5\u627e\u8868\u6709\u591a\u5927\uff1f

\u4f60\u80fd\u60f3\u4e00\u60f3\u6620\u5c04\u8868\u7684\u5b9e\u73b0\u5417\uff1f

\u540c\u6837\uff0c\u7ed9\u51fa\u51fd\u6570\u7248\u672c\u7684\u5b9e\u73b0\uff1a

isalnum.c
#include <ctype.h>\n\nint isalnum(int c)\n    { /* test for alphanumeric character */\n    return (_Ctype[c] & (_DI|_LO|_UP|_XA));\n    }\n

\u4e0b\u9762\u4e24\u5e45\u56fe\u5206\u522b\u5c55\u793a\u4e86 _Ctype \u548c _Toupper \u7684\u6837\u5b50\uff1a

_Ctype

_Toupper

\u975e\u5e38\u5730\u7b80\u5355\uff0c\u5bf9\u5427\uff1f\u8fd9\u53ef\u6bd4 'a' <= c && c <= 'z' \u8fd9\u6837\u7684\u5224\u65ad\u8981\u5feb\u5f97\u591a\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#mathh","title":"<math.h>","text":""},{"location":"programming/archive/23fall/lec4/lec4/#_6","title":"\u80cc\u666f\u77e5\u8bc6\uff1a\u51fd\u6570\u7684\u5b9a\u4e49\u57df\u4e0e\u503c\u57df","text":"

\u8fd8\u8bb0\u5f97 double \u8868\u793a\u7684\u8303\u56f4\u5417\uff1f

\u4ece\u4e0a\u56fe\u4f60\u53ef\u4ee5\u770b\u5230\uff0c\u6d6e\u70b9\u6570\u6240\u80fd\u8868\u793a\u7684\u6570\u503c\uff0c\u5b9e\u9645\u4e0a\u662f\u6570\u8f74\u4e0a\u7684\u4e00\u4e2a\u4e2a\u70b9\u3002\u6bd5\u7adf\u53ea\u6709 64 \u4e2a bit \u561b\uff0c\u53ea\u80fd\u7f16\u7801\u6709\u9650\u4e2a\u70b9\u3002

double \u7c7b\u578b\uff088 \u5b57\u8282 IEEE \u6d6e\u70b9\u6570\uff09\u6240\u80fd\u8868\u793a\u7684\u6781\u9650\u503c\u4e3a\uff1a

\u6211\u4eec\u90fd\u77e5\u9053\u6570\u5b66\u51fd\u6570\u6709\u5b9a\u4e49\u57df\u548c\u503c\u57df\uff0c<math.h> \u4e2d\u7684\u51fd\u6570\u4e5f\u6709\uff0c\u53ea\u662f\u5927\u5bb6\u5e73\u5e38\u4f7f\u7528\u7684\u65f6\u5019\u53ef\u80fd\u4e0d\u592a\u5173\u6ce8\u7f62\u4e86\u3002

\u56e0\u4e3a\u6211\u4eec\u6ca1\u6709\u5b66 C \u7684\u9519\u8bef\u5904\u7406\uff0c\u6240\u4ee5\u6211\u4eec\u4e0d\u77e5\u9053\u600e\u4e48\u6355\u83b7\u8fd9\u4e9b\u9519\u8bef\u3002\u6709\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u5b66\u4e60 <error.h> \u4e2d\u7684\u5185\u5bb9\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_7","title":"\u5185\u5bb9","text":""},{"location":"programming/archive/23fall/lec4/lec4/#_8","title":"\u4f7f\u7528","text":""},{"location":"programming/archive/23fall/lec4/lec4/#stringh","title":"<string.h>","text":""},{"location":"programming/archive/23fall/lec4/lec4/#_9","title":"\u80cc\u666f\u77e5\u8bc6\uff1a\u5b57\u7b26\u4e32","text":"

\u5b57\u7b26\u4e32\u548c\u5b57\u7b26\u6570\u7ec4\u4e00\u5b9a\u8981\u533a\u522b\u5f00\u6765\u3002\u5b57\u7b26\u4e32\u662f\u4ee5\u7a7a\u5b57\u7b26 \\0 \u7ed3\u5c3e\u7684\u5b57\u7b26\u6570\u7ec4\u3002

char name[13] = \"StudyTonight\";\nchar name[10] = {'c','o','d','e','\\0'};\n

<string.h> \u7684\u51fd\u6570\u53ea\u8d1f\u8d23\u64cd\u4f5c\u5b57\u7b26\u4e32\uff0c\u4e0d\u8d1f\u8d23\u64cd\u4f5c\u5b57\u7b26\u6570\u7ec4\uff01

\u8fd8\u8bb0\u5f97\u6570\u7ec4\u4f20\u5165\u51fd\u6570\u7684\u65f6\u5019\u4f1a\u9000\u5316\u6210\u6307\u9488\u5417\uff1f\u51fd\u6570\u65e0\u6cd5\u83b7\u77e5\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u56e0\u6b64\u7a7a\u5b57\u7b26\u662f\u5e2e\u52a9\u51fd\u6570\u5224\u65ad\u5b57\u7b26\u4e32\u7ed3\u675f\u3001\u907f\u514d\u8d8a\u754c\u7684\u552f\u4e00\u65b9\u6cd5\u3002

\u5f53\u7136\uff0cstrn \u7cfb\u5217\u51fd\u6570\u63d0\u4f9b\u4e86\u6307\u5b9a\u957f\u5ea6\u7684\u53c2\u6570\u3002

\u4f60\u80fd\u60f3\u8d77\u54ea\u4e9b\u4e1c\u897f\u662f\u5b57\u7b26\u4e32\u5417\uff1f

"},{"location":"programming/archive/23fall/lec4/lec4/#_10","title":"\u5185\u5bb9","text":""},{"location":"programming/archive/23fall/lec4/lec4/#_11","title":"\u4f7f\u7528","text":"

\u4f7f\u7528\u524d\uff0c\u81ea\u5df1\u8ba1\u7b97\u5b57\u7b26\u4e32\u957f\u5ea6\u548c\u5269\u4f59\u7a7a\u95f4\uff0c\u8fd9\u662f\u7f16\u7a0b\u8005\u7684\u8d23\u4efb\u3002\u6216\u8005\u4f7f\u7528\u5e26 n \u7684\u51fd\u6570\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#stdlibh","title":"<stdlib.h>","text":"

\u5934\u6587\u4ef6 <stdlib.h> \u662f\u4e00\u4e2a\u5927\u6742\u70e9\uff0c\u4e3a\u4e86\u5b9a\u4e49\u548c\u58f0\u660e\u90a3\u4e9b\u6ca1\u6709\u660e\u663e\u5f52\u5c5e\u7684\u5b8f\u548c\u51fd\u6570\u3002\u6211\u4eec\u4ec5\u4ecb\u7ecd\u5e38\u7528\u7684\u90e8\u5206\uff1a\u6574\u5f62\u6570\u5b66\u3001\u7b97\u6cd5\u3001\u6587\u672c\u8f6c\u6362\u3001\u73af\u5883\u63a5\u53e3\u548c\u5b58\u50a8\u5206\u914d\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_12","title":"\u80cc\u666f\uff1a\u6307\u9488\u7684\u6982\u5ff5","text":"

\u8bf7\u5148\u9605\u8bfb\u6307\u9488\u7b14\u8bb0\u3002

\u8fd9\u91cc\u518d\u5f3a\u8c03\u4e00\u4e0b\u58f0\u660e\u548c malloc \u7684\u533a\u522b\uff1a

\u4f60\u80fd\u89e3\u91ca\u4e00\u4e0b\u58f0\u660e\u7684\u65f6\u5019\u5185\u5b58\u53d1\u751f\u4e86\u4ec0\u4e48\u53d8\u52a8\u5417\uff1f

\u4e0b\u9762\u7684\u4ee3\u7801\u6bb5\uff0c\u6bcf\u4e00\u884c\u6267\u884c\u65f6\uff0c\u53d1\u751f\u4e86\u4ec0\u4e48\uff1f\u6709\u5185\u5b58\u88ab\u5206\u914d\u5417\uff1f

int p;\nint *q;\nq = &p;\nq = (int *)malloc(sizeof(int));\n

\u6709\u4e00\u4f4d\u540c\u5b66\u5199\u51fa\u4e86\u4e0b\u9762\u8fd9\u6837\u9519\u8bef\u7684\u4ee3\u7801\uff0c\u4f60\u80fd\u6307\u51fa\u9519\u8bef\u5417\uff1f

// \u4e00\u4e2a\u9519\u8bef\u7684\u94fe\u8868\u5934\u63d2\u5165\u51fd\u6570\nstruct Node* create_linked_list() {\n    struct Node* head = NULL;\n    struct Node* current = (struct Node*)malloc(sizeof(struct Node));\n    while (1) {\n        int data;\n        printf(\"\u8bf7\u8f93\u5165\u8282\u70b9\u503c\uff08\u8f93\u5165-1\u9000\u51fa\uff09\uff1a\");\n        scanf(\"%d\", &data);\n        if (data == -1) {\n            break;\n        }\n        current->data = data;\n        current->next = NULL;\n        if (head == NULL) {\n            head = current;\n        } else {\n            head->next = current;\n        }\n    }\n    return head;\n}\n
"},{"location":"programming/archive/23fall/lec4/lec4/#_13","title":"\u5185\u5bb9","text":""},{"location":"programming/archive/23fall/lec4/lec4/#_14","title":"\u4f7f\u7528","text":""},{"location":"programming/archive/23fall/lec4/lec4/#stdioh","title":"<stdio.h>","text":"

\u5173\u4e8e\u6587\u4ef6\u8f93\u5165\u8f93\u51fa......

\u8fd9\u8fb9\u5217\u51fa\u4e86\u6587\u4ef6\u8f93\u5165\u8f93\u51fa\u7684\u5185\u5bb9\uff0c\u7ed9\u5927\u5bb6\u590d\u4e60\u7684\u65f6\u5019\u53c2\u8003\u7528\u3002\u54b1\u4eec\u8fd9\u8282\u8bfe\u4e0d\u8bb2\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_15","title":"\u80cc\u666f\u77e5\u8bc6\uff1a\u6d41","text":"\u80cc\u666f\u6545\u4e8b\uff1a\u65e9\u671f\u8ba1\u7b97\u673a\u6df7\u4e71\u7684\u8f93\u5165\u8f93\u51fa\u6a21\u578b

\u65e9\u671f\u7a0b\u5e8f\u7684\u8f93\u5165\u8f93\u51fa\u65e0\u6cd5\u72ec\u7acb\u4e8e\u8bbe\u5907\u3002\u6bd4\u5982\uff0c\u5728\u4e0a\u4e2a\u4e16\u7eaa 60 \u5e74\u4ee3\u7684 FORTRAN IV \u4e2d\uff0c\u5728\u78c1\u5e26\u673a\u4e0a\u9700\u8981\u7528 READ INPUT TAPE 5\uff0c\u8bfb\u53d6\u78c1\u76d8\u4e0a\u9700\u8981\u7528 READ INPUT DISK 1\u3002\u8fd9\u6837\u7684\u4ee3\u7801\u5728\u4e0d\u540c\u7684\u8bbe\u5907\u4e0a\u9700\u8981\u4fee\u6539\uff0c\u975e\u5e38\u4e0d\u65b9\u4fbf\u3002UNIX \u7cfb\u7edf\u5c06\u8fd9\u4e9b\u6df7\u4e71\u7684\u8bbe\u5907\u4ea4\u4e92\u5c01\u88c5\u5728\u8bbe\u5907\u5904\u7406\u7a0b\u5e8f\u4e2d\u3002\u5728 UNIX \u7cfb\u7edf\u770b\u6765\uff0c\u5916\u56f4\u8bbe\u5907\u6709\u4e09\u79cd\u7c7b\u578b\uff1a\u5b57\u7b26\u8bbe\u5907\uff08Character devices\uff09\u3001\u5757\u8bbe\u5907\uff08Block devices\uff09\u548c\u7f51\u7edc\u8bbe\u5907\uff08Network devices\uff09\u3002\u8fd9\u4e09\u79cd\u8bbe\u5907\u90fd\u88ab\u62bd\u8c61\u4e3a\u6587\u4ef6\uff0c\u4f7f\u7528\u7edf\u4e00\u7684\u6587\u4ef6\u64cd\u4f5c\u63a5\u53e3\u3002

\u5728 Ken Thompson \u4e3a UNIX \u8bbe\u8ba1\u7edf\u4e00\u7684\u5185\u90e8\u6587\u672c\u5f62\u5f0f\u524d\uff0c\u6587\u672c\u8868\u793a\u4e5f\u662f\u5341\u5206\u6df7\u4e71\u7684\u3002\u7ed3\u675f\u4e00\u884c\u662f\u4f7f\u7528\u56de\u8f66\u8fd8\u662f\u56de\u8f66\u52a0\u6362\u884c\uff0c\u8fd8\u662f\u6362\u884c\u7b26\uff0c\u8fd8\u662f\u66f4\u795e\u5947\u7684\u5b57\u7b26\uff1f\u7ec8\u7aef\u80fd\u4e0d\u80fd\u8bc6\u522b\u548c\u5c55\u5f00\u5236\u8868\u7b26\uff1f\u600e\u6837\u7528\u952e\u76d8\u6807\u5fd7\u6587\u4ef6\u7ed3\u675f\uff1f\u8fd9\u4e9b\u95ee\u9898\u7684\u7b54\u6848\u548c\u7ec8\u7aef\u7684\u751f\u4ea7\u5382\u5546\u4e00\u6837\u591a\u3002UNIX \u4f7f\u7528\u7cfb\u7edf\u8c03\u7528 ioctl \u6765\u8bbe\u7f6e\u4e00\u4e2a\u8bbe\u5907\u7684\u5404\u79cd\u53c2\u6570\uff0c\u8d1f\u8d23\u5bf9\u5185\u90e8\u6362\u884c\u7ea6\u5b9a\u548c\u5404\u79cd\u7ec8\u7aef\u4e4b\u95f4\u7684\u9700\u8981\u8f6c\u6362\u7684\u5b57\u7b26\u8fdb\u884c\u5904\u7406\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_16","title":"\u6d41\u7684\u6982\u5ff5","text":"

\u5404\u79cd\u8f93\u5165\u8f93\u51fa\u8bbe\u5907\u5b9e\u5728\u662f\u592a\u591a\u4e86\uff08\u7ec8\u7aef\u3001\u78c1\u5e26\u9a71\u52a8\u5668\u3001\u7ed3\u6784\u5316\u5b58\u50a8\u8bbe\u5907......\uff09\u3002\u4e3a\u4e86\u7edf\u4e00\u6982\u5ff5\uff0cC \u8bed\u8a00\u4e2d\u7684\u8f93\u5165\u548c\u8f93\u51fa\u8bbe\u5907\u5168\u90fd\u548c\u903b\u8f91\u6570\u636e\u6d41\u76f8\u5bf9\u5e94\u3002

\u6d41\u5c31\u662f\u5b57\u7b26\u5e8f\u5217\u3002

\u4e0d\u7ba1\u7cfb\u7edf\u3001\u786c\u4ef6\u662f\u600e\u4e48\u5b9e\u73b0\u7684\u3002\u8f93\u5165\u8f93\u51fa\u5230\u4e86 C \u7a0b\u5e8f\u8fd9\u91cc\uff0c\u5c31\u7edf\u4e00\u4e3a\u903b\u8f91\u4e0a\u7684\u6d41\u4e86\u3002

\u6d41\u5173\u8054\u5230\u4e00\u4e2a\u7279\u5b9a\u7684\u6587\u4ef6\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_17","title":"\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6","text":"

\u8ba1\u7b97\u673a\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u53ef\u4ee5\u5206\u4e3a\u4e24\u7c7b\uff1a

\u4e8c\u8fdb\u5236\u6587\u4ef6\u5b58\u50a8\u7684\u5185\u5bb9\u6bd4\u8f83\u590d\u6742\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4e0d\u6562\u968f\u610f\u53d8\u52a8\u3002\u4f46\u6587\u672c\u6587\u4ef6\u5185\u5bb9\u7b80\u5355\uff0c\u5404\u7c7b\u64cd\u4f5c\u7cfb\u7edf\u65e9\u5c31\u6709\u4e86\u81ea\u5df1\u7684\u5904\u7406\u65b9\u5f0f\u3002

\u5373\u4f7f\u5230\u4eca\u5929\uff0c\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u5904\u7406\u6587\u672c\u6587\u4ef6\u7684\u65b9\u5f0f\u4ecd\u7136\u5177\u6709\u5dee\u5f02\u3002

\u5dee\u5f02 UNIX Windows MacOS \u6362\u884c\u7b26 \\n LF \\r\\n CRLF \\n (\u8f83\u65e9\u7684 MacOS \u4f7f\u7528 \\r)LF \u6587\u4ef6\u7ed3\u675f\u7b26 ^DCtrl+D ^ZCtrl+Z ^DCtrl+D

\u90fd\u662f\u5386\u53f2\u7684\u9505\uff01

\u751a\u81f3\u6709\u7684\u64cd\u4f5c\u7cfb\u7edf\u8fd9\u6837\u5904\u7406\u6587\u672c\u6587\u4ef6\uff1a

"},{"location":"programming/archive/23fall/lec4/lec4/#_18","title":"\u6d41\u7684\u7c7b\u578b","text":"

C \u8bed\u8a00\u63d0\u4f9b\u4e24\u79cd\u6d41\uff1a\u6587\u672c\u6d41\u548c\u4e8c\u8fdb\u5236\u6d41\u3002

\u4e3e\u4e2a\u4f8b\u5b50

\u8fd9\u662f\u4e00\u4e2a MS-DOS \u4e0a\u7684\u6587\u672c\u6587\u4ef6\u3002\u5982\u679c\u4f5c\u4e3a\u4e8c\u8fdb\u5236\u6d41\u6253\u5f00\uff0c\u7a0b\u5e8f\u4f1a\u770b\u89c1\u4ee5\u4e0b\u5b57\u8282\uff1a

Rebecca clutched the\\r\\n\njewel-encrusted scarab\\r\\n\nto her heaving bosom.\\r\\n\n^Z\n

\u5982\u679c\u4f5c\u4e3a\u6587\u672c\u6d41\u6253\u5f00\uff0c\u7a0b\u5e8f\u4f1a\u770b\u89c1\u4ee5\u4e0b\u5b57\u8282\uff1a

Rebecca clutched the\\n\njewel-encrusted scarab\\n\nto her heaving bosom.\\n\n
"},{"location":"programming/archive/23fall/lec4/lec4/#_19","title":"\u5185\u5bb9","text":""},{"location":"programming/archive/23fall/lec4/lec4/#_20","title":"\u4f7f\u7528","text":"

\u4ee5\u4e0b\u662f\u8bfe\u5185\u5185\u5bb9\uff0c\u4ec5\u5217\u51fa\uff0c\u4e0d\u505a\u8be6\u7ec6\u4ecb\u7ecd\uff1a

\u4e0b\u9762\u5bf9\u51e0\u4e2a\u77e5\u8bc6\u70b9\u4f5c\u4e00\u70b9\u89c4\u8303\u4ecb\u7ecd\uff1a

\u8f6c\u6362\u8bf4\u660e

\u89c4\u8303\u7684\u8bf4\u660e\u8bf7\u770b\u8fd9\u91cc\uff1a

printf \u7684\u8f6c\u6362\u8bf4\u660e

\u8f6c\u6362\u8bf4\u660e\u4e2d\uff0c% \u540e\u9762\u8981\u8ddf 4 \u4e2a\u7ec4\u6210\u90e8\u5206\u3002\u9664\u4e86\u6700\u540e\u4e00\u4e2a\u90e8\u5206\uff0c\u5176\u4ed6\u90fd\u662f\u53ef\u9009\u7684\uff1a

%[\u6807\u5fd7][\u6700\u5c0f\u5b57\u6bb5\u5bbd\u5ea6][.\u7cbe\u5ea6][h/l/L]\u6307\u5b9a\u8f6c\u6362\u7c7b\u578b\u7684\u5b57\u7b26\n

\u4e3e\u4e2a\u4f8b\u5b50

scanf \u7684\u8f6c\u6362\u8bf4\u660e

\u666e\u904d\u8bef\u533a

\u9488\u5bf9\u540c\u5b66\u4eec\u666e\u904d\u7684\u8bef\u533a\u505a\u51e0\u70b9\u5f3a\u8c03\u8bf4\u660e\uff1a

\u8f93\u5165\u8f93\u51fa\u51fd\u6570\u7684\u8fd4\u56de\u503c

\u5927\u5bb6\u5e73\u5e38\u4f7f\u7528\u53ef\u80fd\u4e0d\u592a\u5173\u6ce8\u3002\u4f46\u8fd8\u662f\u6709\u8003\u5bdf\u7684\u53ef\u80fd\uff1a

\u6587\u4ef6\u5b9a\u4f4d\uff08\u4e0d\u505a\u4ecb\u7ecd\uff09 "},{"location":"programming/archive/23fall/lec5/lec5/","title":"\u6307\u9488\u53ca\u94fe\u8868\u76f8\u5173\u77e5\u8bc6\u70b9\u590d\u4e60","text":"

\u6458\u8981

\u8003\u8651\u5230\u672c\u6b21\u8f85\u5b66\u65f6\u95f4\u5df2\u8fd1\u671f\u672b\uff0c\u539f\u5148\u5b89\u6392\u7684\u4ecb\u7ecd\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u5185\u5bb9\u5df2\u7ecf\u4e0d\u592a\u5408\u9002\uff0c\u56e0\u6b64\u672c\u6b21\u8f85\u5b66\u65f6\u95f4\u5c06\u4e3b\u8981\u4ecb\u7ecd\u671f\u672b\u8003\u8bd5\u7684\u90e8\u5206\u91cd\u70b9\u77e5\u8bc6\uff0c\u4ee5\u8bb2\u89e3\u6307\u9488\u4e0e\u94fe\u8868\u4e3a\u4e3b\u3002

\u672c\u6b21\u8f85\u5b66\u7684\u4e3b\u8981\u5185\u5bb9\uff1a

\u5176\u4e2d\u6211\u4eec\u8f85\u5b66\u5b66\u957f\u5199\u7684\u4e13\u9898\u7b14\u8bb0 \u2014\u2014 \u4e13\u9898\u7b14\u8bb0 - \u6307\u9488\u6982\u89c8 \u5df2\u7ecf\u5bf9\u6307\u9488\u8fdb\u884c\u4e86\u8be6\u7ec6\u7684\u4ecb\u7ecd\u3002\u672c\u6b21\u8f85\u5b66\u4e0d\u4f1a\u6df1\u6316\u6307\u9488\u7684\u5185\u5b58\u6a21\u578b\u7b49\u7ec6\u8282\uff0c\u4e3b\u8981\u662f\u9488\u5bf9\u5386\u5e74\u5377\u9898\u76ee\uff0c\u4ee5\u53ca\u8f85\u5b66\u7fa4\u4e2d\u540c\u5b66\u4eec\u6240\u95ee\u7684\u6307\u9488\u76f8\u5173\u7684\u95ee\u9898\uff0c\u8fdb\u884c\u4ee5\u5907\u8003\u4e3a\u76ee\u7684\u7684\u590d\u4e60\u3002

"},{"location":"programming/archive/23fall/lec5/lec5/#_2","title":"\u6307\u9488\u7684\u57fa\u672c\u64cd\u4f5c","text":""},{"location":"programming/archive/23fall/lec5/lec5/#_3","title":"\u6307\u9488\u7684\u58f0\u660e","text":"

\u58f0\u660e\u4e00\u4e2a\u6307\u9488\uff1a

VariableType *pointerName;\n

\u5176\u4e2d VariableType \u4e3a\u6307\u9488\u6307\u5411\u7684\u53d8\u91cf\u7c7b\u578b\uff0cpointerName \u4e3a\u6307\u9488\u7684\u540d\u79f0\u3002

\u4f8b\u5982\uff1aint *p; \u58f0\u660e\u4e86\u4e00\u4e2a\u6307\u5411 int \u7c7b\u578b\u53d8\u91cf\u7684\u6307\u9488\uff0c\u6307\u9488\u7684\u540d\u79f0\u4e3a p\u3002

\u6ce8\u610f

\u9650\u5b9a\u7b26\u5bf9\u6307\u9488\u7684\u9650\u5b9a

\u9650\u5b9a\u7b26\u5728 C \u8bed\u8a00\u4e2d\u7528\u4e8e\u9650\u5b9a\u53d8\u91cf\u7684\u7c7b\u578b\uff0c\u6700\u5e38\u7528\u7684\u4e3a const \u9650\u5b9a\u7b26\u3002

\u5728\u6307\u9488\u58f0\u660e\u4e2d\uff0c\u9650\u5b9a\u7b26\u51fa\u73b0\u7684\u4f4d\u7f6e\u51b3\u5b9a\u4e86\u9650\u5b9a\u7b26\u662f\u5bf9\u6307\u9488\u672c\u8eab\u7684\u9650\u5b9a\uff0c\u8fd8\u662f\u5bf9\u6307\u9488\u6307\u5411\u7684\u53d8\u91cf\u7684\u9650\u5b9a\u3002

int n;\nconst int * pc = &n; // pc \u662f\u6307\u5411 const int \u7684\u975e const \u6307\u9488\n// *pc = 2; // \u9519\u8bef\uff1a\u4e0d\u80fd\u901a\u8fc7\u4e0d\u5e26\u8f6c\u578b\u7684 pc \u4fee\u6539 n\npc = NULL; // OK\uff1apc \u81ea\u8eab\u53ef\u4fee\u6539\n\nint * const cp = &n; // cp \u662f\u4e00\u4e2a\u6307\u5411\u975e const \u7684 int \u7684 const \u6307\u9488\n*cp = 2; // OK\uff1a\u901a\u8fc7 cp \u4fee\u6539 n\n// cp = NULL; // \u9519\u8bef\uff1acp \u81ea\u8eab\u4e0d\u80fd\u4fee\u6539\n

\u5927\u4f53\u53ea\u9700\u8981\u8bb0\u4f4f\uff1a\u9650\u5b9a\u7b26\u4f1a\u5bf9\u7d27\u968f\u5176\u540e\u7684\u5bf9\u8c61\u8fdb\u884c\u9650\u5b9a\u5373\u53ef\u3002

\u8fdb\u9636\u4e00\u70b9\u7684\u4f8b\u5b50\uff1a

int * const * pcp = &cp; // \u6307\u5411\u6307\u5411\u975e const \u7684 int \u7684 const \u6307\u9488\u7684\u975e const \u6307\u9488\n
"},{"location":"programming/archive/23fall/lec5/lec5/#_4","title":"\u591a\u7ea7\u6307\u9488\u7684\u58f0\u660e","text":"

\u5bf9\u591a\u7ea7\u6307\u9488\u7684\u58f0\u660e\uff0c\u53ef\u4ee5\u7528\u9012\u5f52\u7684\u65b9\u5f0f\u7406\u89e3\u3002

\u5bf9\u4e8e\u6307\u5411 int \u7c7b\u578b\u7684\u4e00\u7ea7\u6307\u9488\uff0c\u5176 VariableType \u4e3a int\uff1b\u5bf9\u4e8e\u4e8c\u7ea7\u6307\u9488 int **p\uff0c\u5373\u6307\u5411\u6307\u5411 int \u7c7b\u578b\u7684\u6307\u9488\u7684\u6307\u9488\uff0c\u5176 VariableType \u4e3a int *\u3002

\u4f8b

int var = 1;\nint *p1 = &var;\nint **p = &p;\n

\u4ed6\u4eec\u7684\u6307\u5411\u5173\u7cfb\u662f\uff1a

(int **)p -> (int *)p1 -> (int)var\n
"},{"location":"programming/archive/23fall/lec5/lec5/#_5","title":"\u6307\u9488\u6570\u7ec4\u4e0e\u6570\u7ec4\u6307\u9488","text":"

\u5f88\u5bb9\u6613\u641e\u6df7\uff0c\u9700\u8981\u6280\u5de7\u6765\u8bc6\u522b\u3002

\u6bd4\u5982\u4e0b\u9762\u4e24\u6761\u58f0\u660e\uff1a

char *p[10]; // \u5927\u5c0f\u4e3a 10 \u7684\u6570\u7ec4\uff0c\u6570\u7ec4\u5143\u7d20\u662f\u6307\u5411 char \u7c7b\u578b\u7684\u6307\u9488\n\nchar (*p)[10]; // \u6307\u9488\uff0c\u6307\u5411\u5927\u5c0f\u4e3a 10 \u7684 char \u6570\u7ec4\n

\u7262\u8bb0\u987a\u65f6\u9488\u87ba\u65cb\u6cd5\u5219\uff08Clockwise/Spiral Rule\uff09\uff08\u8be6\u89c1\u8f85\u5b66\u7fa4\u7fa4\u6587\u4ef6\u4e2d\u7684\u201c\u6d45\u8c08 C \u8bed\u8a00\u7684\u6570\u636e\u7c7b\u578b.pdf\u201d\uff09\u3002

\u4e8e\u662f\uff0c\u4e0a\u9762\u7684\u4e24\u6761\u58f0\u660e\u5c31\u53ef\u4ee5\u516c\u5f0f\u5316\u5730\u89e3\u91ca\uff1a

\u4e0a\u4e00\u8282\u7684\u591a\u7ea7\u6307\u9488\u58f0\u660e\u540c\u6837\u53ef\u4ee5\u7528\u8fd9\u4e2a\u6cd5\u5219\u8fdb\u884c\u89e3\u91ca\u3002

"},{"location":"programming/archive/23fall/lec5/lec5/#_6","title":"\u6307\u9488\u7684\u4f7f\u7528","text":""},{"location":"programming/archive/23fall/lec5/lec5/#_7","title":"\u6307\u9488\u7684\u89e3\u5f15\u7528","text":"

\u89e3\u5f15\u7528\u8fd0\u7b97\u7b26 * \u7684\u4e00\u822c\u5f62\u5f0f\u4e3a\uff1a

* \u6307\u9488\u8868\u8fbe\u5f0f\n

\u7ed3\u679c\u4e3a\u6307\u4ee3\u88ab\u6307\u5411\u5bf9\u8c61\u7684\u5de6\u503c\u8868\u8fbe\u5f0f\uff0c\u5373\u53ef\u4ee5\u88ab\u8d4b\u503c\u3002

\u8bb0\u4f4f a[b] \u7b49\u4ef7\u4e8e *(a + b)\u3002\u8fd9\u4e2a trick \u5728\u4e00\u4e9b\u9898\u76ee\u4e2d\u5f88\u6709\u7528\u3002

\u4f8b\u9898

Given the declaration: int a[3][3]={1,2,3,4,5,6,7,8,9}; , the value of a[-1][5] is _____.

Answer

\u89e3\u7b54\u6765\u81ea\uff1axg \u2014\u2014 \u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66\u5e38\u95ee\u9898\u76ee\u53ca\u89e3\u6790 v1.1.pdf

a[-1] \u7b49\u4ef7\u4e8e *(a - 1)\uff0ca - 1 \u4f1a\u4ee5 3 \u4e2a int \u4e3a\u5355\u4f4d\u5411\u5de6\u79fb\u52a8\uff0c\u5373

    0 0 0 1 2 3 4 5 6 7 8 9\n    ^\n    |\np = *(a - 1)\n

\u4ee4 p = *(a - 1)\uff0c\u5219\u8981\u6c42\u7684\u503c\u53d8\u4e3a p[5]\uff0c\u7b49\u4ef7\u4e8e *(p + 5)\u3002\u5c06\u4e0a\u8ff0\u6307\u9488\u53f3\u79fb 5 \u4e2a int \u5355\u4f4d\uff0c\u5f97\u5230 3\u3002

\u91ce\u6307\u9488

\u5f53\u6307\u9488\u58f0\u660e\u65f6\u672a\u521d\u59cb\u5316\uff0c\u4e14\u8fd8\u672a\u88ab\u8d4b\u503c\uff0c\u5219\u8fd9\u4e2a\u6307\u9488\u6307\u5411\u65e0\u6cd5\u786e\u5b9a\uff0c\u88ab\u79f0\u4e3a \u91ce\u6307\u9488\u3002

\u91ce\u6307\u9488\u53ef\u80fd\u6307\u5411\u4efb\u610f\u5185\u5b58\uff0c\u5bf9\u5176\u8fdb\u884c\u8bbf\u95ee\u53ef\u80fd\u4f1a\u5bfc\u81f4\u975e\u6cd5\u5185\u5b58\u8bbf\u95ee\uff0c\u4ea7\u751f\u6bb5\u9519\u8bef\u3002

\u5728\u8003\u9898\u4e2d\uff0c\u5c1d\u8bd5\u8bbf\u95ee\u91ce\u6307\u9488\u662f\u9519\u8bef\u7684\u64cd\u4f5c\u3002\u5728\u81ea\u5df1\u5199\u4ee3\u7801\u65f6\u4e5f\u7edd\u4e0d\u80fd\u51fa\u73b0\u91ce\u6307\u9488\u8bbf\u95ee\u3002

\u4f8b\u9898

For the declarations: char *s, str[10]; , statement _____ is completely correct.

A. strcpy(s, \"hello\");

B. str=\"hello\"+1

C. s=*&(str+1)

D. s=str+1

\u9009\u9879 A \u5c31\u662f\u7ecf\u5178\u7684\u91ce\u6307\u9488\u8bbf\u95ee\u3002

"},{"location":"programming/archive/23fall/lec5/lec5/#_8","title":"\u53d6\u5740\u64cd\u4f5c","text":"

\u53d6\u5740\u8fd0\u7b97\u7b26 & \u65e9\u5728\u5927\u5bb6\u5b66\u4e60\u8f93\u5165\u8f93\u51fa\u7684\u65f6\u5019\u5c31\u5df2\u7ecf\u63a5\u89e6\u8fc7\u4e86\u3002\u5728\u4f7f\u7528 scanf \u5bf9 int \u7b49\u7c7b\u578b\u7684\u53d8\u91cf\u8fdb\u884c\u8bfb\u5165\u7684\u65f6\u5019\uff0c\u4f7f\u7528\u7684\u662f\u5982\u4e0b\u5f62\u5f0f\uff1a

int a;\nscanf(\"%d\", &a);\n

\u8fd9\u91cc\u7684 & \u5bf9 a \u8fdb\u884c\u53d6\u5740\u64cd\u4f5c\uff0c\u5bf9 a \u7684\u5730\u5740\u800c\u4e0d\u662f a \u7684\u503c\u8fdb\u884c\u8bfb\u5165\u3002

\u4e00\u822c\u5730\uff0c\u53d6\u5740\u8fd0\u7b97\u7b26\u6709\u5982\u4e0b\u51e0\u79cd\u5f62\u5f0f\uff1a

\u89e3\u5f15\u7528\u4e0e\u53d6\u5740\u64cd\u4f5c\u7684\u5e94\u7528

\u8f93\u5165\u4e00\u4e2a 64 \u4f4d\u65e0\u7b26\u53f7\u6574\u6570 x\uff0c\u6c42 x \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u7684 01 \u4e32\u6240\u8868\u793a\u7684 double \u7c7b\u578b\u53d8\u91cf\u7684\u503c\u3002

Answer
unsigned long long x;\nscanf(\"%llu\", &x);\nprintf(\"%lf\\n\", *((double *)&x));\n
"},{"location":"programming/archive/23fall/lec5/lec5/#_9","title":"\u901a\u8fc7\u6307\u9488\u8fdb\u884c\u6210\u5458\u8bbf\u95ee","text":"

\u5bf9\u4e8e\u7ed3\u6784\u4f53\u7c7b\u578b\u7684\u6307\u9488\uff0cC \u8bed\u8a00\u63d0\u4f9b\u4e86\u4e00\u4e2a\u8fd0\u7b97\u7b26 ->\uff0c\u7528\u4e8e\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u7ed3\u6784\u4f53\u6210\u5458\u3002

struct Point { int x, y; }; // \u5b9a\u4e49\u7ed3\u6784\u4f53 Point\nstruct Point point = { 1, 2 }; // \u5b9a\u4e49\u7ed3\u6784\u4f53\u53d8\u91cf point\n\nstruct Point *p = &point; // p \u6307\u5411 point \u7ed3\u6784\u4f53\np->x = 3; // \u901a\u8fc7\u6307\u9488 p \u8bbf\u95ee\u7ed3\u6784\u4f53\u6210\u5458 x\n// \u7b49\u4ef7\u4e8e (*p).x = 3;\n
"},{"location":"programming/archive/23fall/lec5/lec5/#_10","title":"\u6570\u7ec4\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362","text":"

\u9690\u5f0f\u8f6c\u6362

\u6570\u7ec4\u5230\u6307\u9488\u8f6c\u6362

\u4efb\u4f55\u6570\u7ec4\u7c7b\u578b\u7684\u5de6\u503c\u8868\u8fbe\u5f0f\uff0c\u5728\u7528\u4e8e\u5f02\u4e8e\u4e0b\u5217\u8bed\u5883\u65f6

\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u975e\u5de6\u503c\u6307\u9488\u7684\u8f6c\u6362\u3002

\u2014\u2014 cppreference-\u9690\u5f0f\u8f6c\u6362

\u7b80\u5355\u6765\u8bf4\uff1a\u7262\u8bb0\u6570\u7ec4\u540d \u4e0d\u7b49\u4e8e \u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u7684\u6307\u9488\uff0c\u5f53\u6570\u7ec4\u540d\u88ab\u53d6\u5740\u8fd0\u7b97\u7b26 & \u4f5c\u7528\uff0c\u6216\u8005\u4f5c\u4e3a sizeof \u7684\u64cd\u4f5c\u6570\u65f6\uff0c\u4e0d\u4f1a\u53d1\u751f\u9690\u5f0f\u8f6c\u6362\u3002

\u8fd9\u91cc\u8981\u6ce8\u610f\u7684\u4e00\u70b9\u662f\uff0c\u5c06\u6570\u7ec4\u4f5c\u4e3a\u53c2\u6570\u4f20\u7ed9\u51fd\u6570\u65f6\uff0c\u51fd\u6570\u7684\u5f62\u53c2\u53ea\u80fd\u662f\u6307\u9488\uff0c\u800c\u4e0d\u80fd\u662f\u6570\u7ec4\uff0c\u6b64\u65f6\u6570\u7ec4\u540d\u4f1a\u53d1\u751f\u9690\u5f0f\u8f6c\u6362\u3002

\u6570\u7ec4\u7c7b\u578b\u7528\u4e8e\u51fd\u6570\u5f62\u53c2

\u5f53\u6570\u7ec4\u7c7b\u578b\u7528\u4e8e\u51fd\u6570\u5f62\u53c2\u5217\u8868\u65f6\uff0c\u5b83\u4f1a\u8f6c\u6362\u6210\u5bf9\u5e94\u7684\u6307\u9488\u7c7b\u578b\uff1aint f(int a[2])\u3001int f(int a[])\u3001int f(int *a) \u58f0\u660e\u540c\u4e00\u4e2a\u51fd\u6570\u3002

\u56e0\u4e3a\u51fd\u6570\u5b9e\u9645\u53c2\u6570\u7c7b\u578b\u4e3a\u6307\u9488\u7c7b\u578b\uff0c\u4f7f\u7528\u6570\u7ec4\u5b9e\u53c2\u7684\u51fd\u6570\u8c03\u7528\u4f1a\u8fdb\u884c\u4e00\u4e2a\u6570\u7ec4\u5230\u6307\u9488\u8f6c\u6362\uff1b\u88ab\u8c03\u7528\u51fd\u6570\u65e0\u6cd5\u83b7\u5f97\u5b9e\u53c2\u6570\u7ec4\u7684\u5927\u5c0f\uff0c\u5fc5\u987b\u663e\u5f0f\u4f20\u9012\u3002

\u89c1 \u6bcf\u65e5\u4e00\u9898-29\u3002

Warning

\u53ea\u6709\u6570\u7ec4\u7c7b\u578b\u7528\u4e8e\u51fd\u6570\u5f62\u53c2\u5217\u8868\u65f6\uff0ca[] \u548c *a \u624d\u662f\u7b49\u4ef7\u7684\u3002

\u6bd4\u5982\u4f7f\u7528\u5b57\u7b26\u4e32\u5e38\u91cf\u521d\u59cb\u5316\u5b57\u7b26\u4e32\uff1a

\u521b\u5efa\u6307\u5411\u5b57\u7b26\u4e32\u5e38\u91cf\u7684\u6307\u9488\uff0c\u5185\u5bb9\u4e0d\u80fd\u66f4\u6539\uff0c

char *s = \"hello\"; // s \u7c7b\u578b\u4e3a char * \uff0c\u6307\u5411\u5b57\u7b26\u4e32\u5e38\u91cf\ns = \"he11o\"; // OK\n

\u521b\u5efa char \u6570\u7ec4\uff0c\u5185\u5bb9\u88ab\u5b57\u7b26\u4e32\u5e38\u91cf\u521d\u59cb\u5316\uff0c\u5185\u5bb9\u53ef\u4ee5\u66f4\u6539\uff0c

char s[] = \"hello\"; // s \u7c7b\u578b\u4e3a char [6] \uff0c\u6570\u7ec4\u5185\u5bb9\u662f \"hello\\0\" \u7684\u62f7\u8d1d\n// s[] = \"he11o\"; // wrong\n

Question

\u4e0b\u5217\u4ee3\u7801\u7684 val_x \u548c val_y \u7684\u7c7b\u578b\u4e00\u6837\u5417\uff1f

int a[10], *p = a;\nType1 val_x = &a;\nType2 val_y = &p;\n

Question

\u4e0b\u5217\u4ee3\u7801\u7684 size_x \u548c size_y \u5927\u5c0f\u4e00\u6837\u5417\uff1f

int a[10], *p = a;\nsize_t size_x = sizeof a;\nsize_t size_y = sizeof p;\n
"},{"location":"programming/archive/23fall/lec5/lec5/#_11","title":"\u6307\u9488\u7684\u503c\u4e0e\u6307\u9488\u7684\u5730\u5740","text":"

\u6307\u9488\u7684\u503c\uff0c\u53c8\u79f0\u4e3a\u6307\u9488\u6240\u6307\u5411\u7684\u5185\u5b58\u533a\u3002

\u5728\u8ba1\u7b97\u673a\u4e2d\uff0c\u5185\u5b58\u4e2d\u7684\u6240\u6709\u5b57\u8282\u90fd\u62e5\u6709\u4e00\u4e2a\u552f\u4e00\u7f16\u53f7\uff0c\u4e5f\u5373\u5185\u5b58\u5730\u5740\u3002\u6307\u9488\u6307\u5411\u67d0\u4e00\u6570\u636e\u7684\u5730\u5740\uff0c\u5373\u6307\u9488\u53d8\u91cf\u5b58\u50a8\u4e86\u8fd9\u4e2a\u6570\u636e\u7684\u5185\u5b58\u5730\u5740\u7684\u7f16\u53f7\u3002

\u6307\u9488\u6240\u5360\u7684\u5b57\u8282\u6570

\u73b0\u5728\u4e00\u822c\u7684\u8ba1\u7b97\u673a\u57fa\u672c\u90fd\u662f 64 \u4f4d\u7cfb\u7edf\uff0c\u4f7f\u7528 64 \u4f4d\u957f\u7684\u5185\u5b58\u5730\u5740\uff0c\u5373\u5185\u5b58\u5730\u5740\u7684\u7f16\u53f7\u662f\u4e00\u4e2a 64 \u4f4d\u6574\u6570\u3002\u5728 64 \u4f4d\u7cfb\u7edf\u4e2d\u4f7f\u7528 sizeof \u8fd0\u7b97\u7b26\u6c42\u6307\u9488\u7684\u5927\u5c0f\u65f6\uff0c\u5f97\u5230\u7684\u7ed3\u679c\u4e3a 8\u3002

\u6ce8\u610f\uff0c\u4e00\u822c\u6765\u8bf4\u65e0\u6cd5\u9884\u6d4b\u5730\u5740\u7684\u503c\uff0c\u56e0\u4e3a\u5185\u5b58\u5730\u5740\u53d6\u51b3\u4e8e\u7cfb\u7edf\u7684\u5185\u5b58\u5206\u914d\u60c5\u51b5\u3002\u4f46\u90e8\u5206\u60c5\u51b5\u4e0b\u53ef\u4ee5\u786e\u5b9a\u5185\u5b58\u5730\u5740\u7684\u76f8\u5bf9\u4f4d\u7f6e\uff0c\u6bd4\u5982\u540c\u4e00\u6570\u7ec4\u4e2d\u5143\u7d20\u5728\u5185\u5b58\u4e2d\u8fde\u7eed\u3002

\u6b64\u5916\uff0c\u6307\u9488\u540c\u6837\u4e5f\u662f\u4e00\u4e2a\u5728\u5185\u5b58\u4e2d\u6709\u5bf9\u5e94\u5b58\u50a8\u7a7a\u95f4\u7684\u53d8\u91cf\uff0c\u4e5f\u6709\u81ea\u5df1\u7684\u5185\u5b58\u5730\u5740\u3002\u5728\u6307\u9488\u7684\u5185\u5b58\u5730\u5740\u4e2d\uff0c\u5b58\u50a8\u7684\u5185\u5bb9\u662f\u5176\u6307\u5411\u7684\u5185\u5bb9\u7684\u5185\u5b58\u5730\u5740\u3002

\u7c7b\u6bd4\u7406\u89e3

\u5047\u5982\u6709\u4e00\u4e2a\u5f88\u957f\u7684\u6570\u7ec4\uff0c\u5b58\u50a8\u4e86\u4e00\u4e9b\u6570\u636e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u4e0b\u6807\u53bb\u8bbf\u95ee\u6570\u636e\u3002\u5c06\u6570\u7ec4\u4e0b\u6807\u5f53\u4f5c\u6570\u636e\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u53ef\u4ee5\u4ece\u6570\u7ec4\u4e2d\u7684\u67d0\u4e00\u4f4d\u7f6e\u53bb\u8bbf\u95ee\u5176\u5b58\u50a8\u7684\u6570\u7ec4\u4e0b\u6807\u7684\u4f4d\u7f6e\u7684\u6570\u636e\uff0c\u8fd9\u5c31\u53ef\u4ee5\u770b\u4f5c\u662f\u7b80\u5355\u7684\u6307\u9488\u3002

\u4e0b\u6807    31       32       33       34      ...     X\narr   data0    data1    data2    data3    ....    32\n                 ^                                |\n                 +--------------------------------+\n

Question

\u90a3\u4e48\u5c31\u6709\u540c\u5b66\u95ee\u4e86\uff1a\u65e2\u7136\u6307\u9488\u7684\u503c\u662f 64 \u4f4d\u6574\u6570\uff0c\u90a3\u80fd\u7528\u5173\u7cfb\u8fd0\u7b97\u7b26\u6bd4\u8f83\u5927\u5c0f\u5417\uff1f

\u7b54\u6848\u662f\uff1a\u90e8\u5206\u60c5\u51b5\u4e0b\u53ef\u4ee5\u3002

\u5173\u7cfb\u8fd0\u7b97\u7b26\u8fdb\u884c\u6307\u9488\u6bd4\u8f83

\u6839\u636e cppreference-\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff0c\u5f53\u8fdb\u884c\u6307\u9488\u6bd4\u8f83\u7684\u65f6\u5019\uff0c\u6709\u4ee5\u4e0b\u8981\u6c42\uff1a

\u4e24\u6307\u9488\u5fc5\u987b\u662f\u517c\u5bb9\u7c7b\u578b\u7684\u6307\u9488\u3002\u4e14\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u4e4b\u4e00\uff1a

\u9664\u6b64\u4e4b\u5916\uff0c\u6307\u9488\u7684\u6bd4\u8f83\u7ed3\u679c\u662f\u672a\u5b9a\u4e49\u7684\u3002

\u6307\u9488\u7684\u8ba1\u7b97

\u6d89\u53ca\u6307\u9488\u7684\u52a0\u51cf\u53ea\u6709\u4e24\u79cd\u60c5\u51b5\uff1a

\u4f8b\u9898

\u4ee5\u4e0b\u4ee3\u7801\u7684\u8f93\u51fa\u4e3a _____\u3002

int a[] = {1, 2, 3, 4, 5};\nint *p = a, *q = &a[2];\nprintf(\"%lu\\n\", q - p);\n
"},{"location":"programming/archive/23fall/lec5/lec5/#_12","title":"\u4e00\u4e9b\u9898\u76ee","text":"

\u9898\u76ee 1

The following code fragment will output _____.

char *week[]={\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"}, **pw=week;\nchar c1, c2;\nc1 = (*++pw)[1];\nc2 = *++pw[1];\nprintf(\"%c#%c#\", c1, c2);\n
Answer
       \"Mon\\0\"   \"Tue\\0\"   \"Wed\\0\"   \"Thu\\0\"   \"Fri\\0\"   \"Sat\\0\"   \"Sun\\0\"\n        ^         ^         ^         ^         ^         ^         ^\n        |         |         |         |         |         |         |\nweek: week[0]   week[1]   week[2]   week[3]   week[4]   week[5]   week[6]\n        ^\n        |\n       pw\n

\u9898\u76ee 2

For definitions:

char s[2][3] = {\"ab\", \"cd\"}, *p = (char *)s;\n

the expression _____ is correct and its value is equivalent to the element s[1][1].

A. *(s + 3)

B. *s + 2

C. p[1][1]

D. *++p + 2

Answer
s:    \"ab\\0\"     \"cd\\0\"\n      ^\n      |\ns(\u9690\u5f0f\u8f6c\u6362)(char *[3])\n\ns:    \"ab\\0\"     \"cd\\0\"\n       ^\n       |\n  p = (char *)s\n
"},{"location":"programming/archive/23fall/lec5/lec5/#_13","title":"\u94fe\u8868","text":""},{"location":"programming/archive/23fall/lec5/lec5/#_14","title":"\u57fa\u7840\u77e5\u8bc6\u548c\u603b\u7ed3","text":"

\u94fe\u8868\u662f\u4e00\u79cd\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u901a\u8fc7\u8282\u70b9\u7684\u5f62\u5f0f\u5b58\u50a8\u6570\u636e\u3002\u6bcf\u4e2a\u8282\u70b9\u5305\u542b\u6570\u636e\u90e8\u5206\u548c\u6307\u5411\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684\u6307\u9488\u3002\u94fe\u8868\u53ef\u4ee5\u662f\u5355\u5411\u7684\u4e5f\u53ef\u4ee5\u662f\u53cc\u5411\u7684\uff0c\u6211\u4eec\u5148\u770b\u770b\u5355\u5411\u94fe\u8868\uff1a

\u5355\u5411\u94fe\u8868\u7684\u4e00\u79cd\u5b9a\u4e49\u65b9\u5f0f

typedef struct Node {\n    int data;\n    struct Node* next;\n} Node;\n

\u597d\u4e86\uff0c\u6211\u4eec\u5df2\u7ecf\u628a\u94fe\u8868\u7ed9\u5b9a\u4e49\u51fa\u6765\u4e86\u3002\u4f46\u662f\u4f60\u4f1a\u597d\u5947\uff0c\u6211\u4eec\u4e0d\u662f\u53ea\u5b9a\u4e49\u51fa\u4e86\u8282\u70b9\u5417\uff1f\u600e\u4e48\u5df2\u7ecf\u5b9a\u4e49\u5b8c\u4e86\uff1f\u4e8b\u5b9e\u4e0a\uff0c\u8fd9\u51e0\u4e4e\u5c31\u5df2\u7ecf\u662f\u94fe\u8868\u7684\u5b8c\u6574\u7ed3\u6784\u4e86\u2014\u2014\u56e0\u4e3a\u94fe\u8868\u5c31\u662f\u7b80\u5355\u7684\u94fe\u8868\u8282\u70b9\u7684\u4e32\u8054\u3002

\u5927\u5bb6\u90fd\u5df2\u7ecf\u77e5\u9053\u4e86\u94fe\u8868\u7684\u7ed3\u6784\uff0c\u662f\u7c7b\u4f3c\u4e8e\u4e0b\u9762\u8fd9\u6837\u7684\uff1a

\u6240\u4ee5\uff0c\u94fe\u8868\u5176\u5b9e\u5c31\u662f\u4ee5\u4e0b\u7684\u4e1c\u897f\u7684\u7ed3\u5408\uff1a

\u6211\u4eec\u600e\u4e48\u77e5\u9053\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u662f\u4ec0\u4e48\u5462\uff1f\u6211\u4eec\u89c4\u5b9a\uff0c\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u6307\u5411\u7684\u4f4d\u7f6e\u5c31\u662f NULL\uff0c\u4e5f\u5c31\u662f 0\u3002\u8fd9\u6837\uff0c\u53ea\u8981\u5224\u65ad\u8282\u70b9\u7684 .next \u662f\u5426\u662f NULL\uff0c\u5c31\u53ef\u4ee5\u77e5\u9053\u8fd9\u4e2a\u8282\u70b9\u662f\u4e0d\u662f\u5c3e\u8282\u70b9\u4e86\u3002\u597d\u4e86\uff0c\u6240\u4ee5\u6211\u4eec\u53ea\u9700\u8981\u82e5\u5e72\u4e2a Node\uff0c\u7136\u540e\u5c06\u4ed6\u4eec\u4e32\u8054\u2014\u2014\u4e5f\u5c31\u662f\u901a\u8fc7 next \u8fde\u63a5\uff0c\u5c31\u5f97\u5230\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u94fe\u8868\u3002

\u63a5\u4e0b\u6765\u8ba9\u6211\u4eec\u56de\u5fc6\u4e00\u4e0b\u94fe\u8868\u7684\u5404\u79cd\u64cd\u4f5c\u7684\u5b9e\u73b0\u5427\uff01\u4e0d\u8fc7\u5927\u5bb6\u5728\u5e73\u65f6\u505a\u9898\u7684\u65f6\u5019\u5e94\u8be5\u90fd\u611f\u89c9\u5230\u4e86\uff0c\u94fe\u8868\u6709\u5f88\u591a\u5f88\u591a\u96be\u4ee5\u7422\u78e8\u7684\u7ec6\u8282\u548c\u7279\u6b8a\u60c5\u51b5\uff01\u600e\u4e48\u529e\u5462\uff1f\u51b7\u9759\u4e0b\u6765\u603b\u7ed3\uff0c\u65e0\u975e\u5c31\u662f\u8fd9\u51e0\u79cd\uff1a

\u8fd9\u4e9b\u60c5\u51b5\u5982\u679c\u6ca1\u6709\u8003\u8651\u6e05\u695a\uff0c\u5f88\u53ef\u80fd\u5728\u5199\u4ee3\u7801\u7684\u8fc7\u7a0b\u4e2d\u51fa\u73b0 segmentation fault\uff0c\u4e5f\u5c31\u662f\u6bb5\u9519\u8bef\u3002\u8fd9\u6781\u5927\u6982\u7387\u662f\u56e0\u4e3a\uff0c\u4f60\u8bbf\u95ee\u4e86 NULL \u4f4d\u7f6e\u7684\u4e00\u4e9b\u4fe1\u606f\u3002\u6bd4\u5982\u5f53\u524d\u8282\u70b9\u6307\u9488 p \u6307\u5411\u4e86 NULL\uff0c\u4f46\u662f\u4f60\u5374\u8bbf\u95ee\u4e86 p->data \u6216\u8005 p->next\uff0c\u5c31\u4f1a\u62a5\u9519\u4e86\u3002

"},{"location":"programming/archive/23fall/lec5/lec5/#_15","title":"\u5355\u5411\u94fe\u8868\u7684\u5404\u79cd\u7ecf\u5178\u64cd\u4f5c","text":"

\u521b\u5efa\u4e00\u4e2a\u8282\u70b9 p\uff0c\u5176\u6743\u503c\u4e3a w\uff0c\u5e76\u8fd4\u56de\u8fd9\u4e2a\u8282\u70b9\u7684\u6307\u9488

\u53ea\u9700\u8981\u4f7f\u7528 malloc \u5373\u53ef\u3002

Node *create(int w){\n    Node* newNode = (Node*)malloc(sizeof(Node));\n    newNode->next = NULL;\n    newNode->data = w;\n    return newNode;\n}\n

\u4e00\u4e2a\u7ec6\u8282

\u6ce8\u610f\uff0cmalloc \u51fd\u6570\u5185\u90e8\u9700\u8981\u5f00\u7684\u8282\u70b9\u5927\u5c0f\u662f sizeof(Node) \u800c\u4e0d\u662f sizeof(Node*)\uff0c\u60f3\u60f3\u4e3a\u4ec0\u4e48\uff1f

\u5728\u94fe\u8868\u7684\u5934\u90e8/\u5c3e\u90e8\u63d2\u5165\u4e00\u4e2a\u8282\u70b9 p\uff0c\u5e76\u8fd4\u56de\u65b0\u94fe\u8868\u7684\u5934\u90e8

\u5148\u770b\u5934\u90e8\u63d2\u5165\u3002

\u9996\u5148\uff0c\u7279\u6b8a\u60c5\u51b5 \\(1\\)\uff0c\u539f\u5148\u94fe\u8868\u662f\u7a7a\u7684\uff0c\u90a3\u80af\u5b9a\u662f\u628a head \u8d4b\u503c\u4e3a\u65b0\u8282\u70b9\u561b\u3002

\u53d1\u73b0\u53ea\u5269\u4e0b\u7279\u6b8a\u60c5\u51b5 \\(2\\)\uff0c\u90a3 head \u4e5f\u8981\u8d4b\u503c\u4e3a\u65b0\u8282\u70b9\uff0c\u7136\u540e\u65b0\u8282\u70b9\u8fde\u5411\u8001 head \u3002

Node *insertAtHead(Node* head, Node* p) {\n    if (!head) return p; // \u53ef\u4ee5\u53d1\u73b0\uff0c\u8fd9\u53e5\u8bdd\u4e0d\u5199\u4e5f\u6ca1\u6709\u5f71\u54cd \n    p->Next = head;\n    return p;\n}\n

\u4e00\u4e2a\u7ec6\u8282

\u4e3a\u4ec0\u4e48 if \u91cc\u662f !head\uff1f

\u7136\u540e\u662f\u5c3e\u90e8\u63d2\u5165\u3002\u9996\u5148\u8fd8\u662f\u7279\u6b8a\u60c5\u51b5 \\(1\\)\uff0c\u5904\u7406\u5b8c\u4ee5\u540e\u53ea\u5269\u4e0b\u7279\u6b8a\u60c5\u51b5 \\(3\\) \uff0c\u90a3\u4e48\u6211\u4eec\u53ea\u9700\u8981\u627e\u5230\u5c3e\u8282\u70b9\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u63d2\u5165\u4e86\uff0c\u6700\u540e\u8fd4\u56de\u7684\u4e5f\u53ea\u662f\u539f\u672c\u7684 head\u3002

Node *insertAtEnd(Node* head, Node* p) {\n    if (!head) return p;\n    Node* last = head;\n    while (last->next) {\n        last = last->next;\n    }\n    last->next = p;\n    return head;\n}\n

\u5220\u9664\u6743\u503c\u4e3a key \u7684\u8282\u70b9\uff0c\u5982\u679c\u6709\u591a\u4e2a\uff0c\u5219\u5220\u9664\u6700\u9760\u8fd1\u5f00\u5934\u7684\uff0c\u6ca1\u6709\u5219\u4e0d\u5220\u9664\uff0c\u8fd4\u56de\u65b0\u94fe\u8868\u7684\u5934\u90e8

\u6700\u7e41\u7410\u6700\u590d\u6742\u7684\u4e00\u4e2a\u64cd\u4f5c\uff0c\u4e5f\u662f\u65b0\u624b\u7684\u5669\u68a6\u3002\u4e0d\u8fc7\u6309\u7167\u4e09\u6b65\u8d70\u5c31\u597d\u4e86\u3002

\u5148\u5904\u7406\u4e00\u4e0b\u7279\u6b8a\u60c5\u51b5 \\(1\\) \u3002

Node *deleteNode(Node* head, int key) {\n    if (!head) return NULL;\n}\n

\u7136\u540e\u60c5\u51b5 \\(2\\) \u5462\uff0c\u5934\u7ed3\u70b9\u4f1a\u53d1\u751f\u53d8\u5316\u3002

Node *deleteNode(Node* head, int key) {\n    if (!head) return NULL;\n    if (head->data == key){\n        node* tmp = head->next; //\u8fd9\u4e48\u505a\u662f\u56e0\u4e3a free \u4ee5\u540e\uff0chead->next \u5c31\u4e0d\u80fd\u83b7\u53d6\u4e86\u3002\n        free(head);\n        return tmp;\n    }\n}\n

\u5269\u4e0b\u60c5\u51b5 \\(3\\) \u8fd8\u8981\u7279\u6b8a\u5224\u65ad\u3002\u6211\u4eec\u5148\u627e\u5230\u8981\u5220\u9664\u7684\u4f4d\u7f6e\u3002\u56de\u5fc6\u4e00\u4e0b\u5220\u9664\u7684\u8fc7\u7a0b\uff0c\u6211\u4eec\u9700\u8981\u8bb0\u5f55\u5f53\u524d\u9700\u8981\u88ab\u5220\u9664\u7684\u8282\u70b9\u7684\u6307\u9488 prev\uff1a

Node *deleteNode(Node* head, int key) {\n    if (!head) return NULL;\n    if (head->data == key){\n        node* temp = head->next; //\u8fd9\u4e48\u505a\u662f\u56e0\u4e3a free \u4ee5\u540e\uff0chead->next \u5c31\u4e0d\u80fd\u83b7\u53d6\u4e86\u3002\n        free(head);\n        return tmp;\n    }\n    node* temp = head, prev = NULL;\n    while (temp && temp->data != key) {\n        prev = temp;\n        temp = temp->next;\n    }\n    if (!temp) return head;\n    prev->next = temp->next; //\u4e8b\u5b9e\u4e0a\u76f4\u63a5\u5220\u9664\u5c31\u597d\u4e86\uff0c\u4e0d\u9700\u8981\u5173\u7cfb\u60c5\u51b5 3 \u4e86\uff0c\u4e0d\u8fc7\u7279\u5224\u4e00\u4e0b\u4e5f\u4e0d\u9519\u3002\n    free(temp);\n    return head;\n}\n

\u6ce8\u610f\uff01

\u7406\u8bba\u8003\u8bd5\u5199\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u4e00\u5b9a\u4e0d\u8981\u5fd8\u8bb0 free \u88ab\u5220\u9664\u7684\u8282\u70b9\uff01\uff01\uff01\u5c0f\u5fc3\u6263\u5206\uff01\uff01\uff01

\u4e0a\u673a\u4e0d free \u5012\u662f\u6ca1\u5173\u7cfb\uff08\u6307\u8fd8\u80fd\u901a\u8fc7\uff09\uff0c\u4f46\u8fd8\u662f\u5efa\u8bae\u517b\u6210\u826f\u597d\u7684\u4e60\u60ef\uff0c\u9632\u6b62\u5185\u5b58\u6cc4\u6f0f\uff01

"},{"location":"programming/archive/23fall/lec5/lec5/#_16","title":"\u53cc\u5411\u94fe\u8868","text":"

\u5176\u5b9e\u6ca1\u4ec0\u4e48\u53ef\u4ee5\u8bb2\u7684\uff0c\u4e5f\u5c31\u662f\u5728 struct \u7684\u5b9a\u4e49\u4e2d\u52a0\u5165\u4e86 prev\uff0c\u53ef\u4ee5\u8ba9\u6211\u4eec\u65b9\u4fbf\u7684\u83b7\u53d6\u4e0a\u4e00\u4e2a\u8282\u70b9\u7684\u6307\u9488\uff0c\u8fd9\u6837\u5220\u9664\u8fc7\u7a0b\u4e2d\u5c31\u4e0d\u9700\u8981\u5355\u72ec\u5f00\u53d8\u91cf\u8bb0\u5f55\u4e86\u3002

\u53cc\u5411\u94fe\u8868\u7684\u4e00\u79cd\u5b9a\u4e49\u65b9\u5f0f

typedef struct Node {\n    int data;\n    struct Node* prev, next;\n} Node;\n

\u7279\u522b\u7684\uff0c\u5934\u7ed3\u70b9\u7684 prev \u662f NULL\u3002

\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u9898\u5427~

\u9898\u76ee 3

To delete p from a doubly linked list, we must do:

A. p->prev=p->prev->prev; p->prev->next=p;

B. p->next->prev=p; p->next=p->next->next;

C. p->prev->next=p->next; p->next->prev=p->prev;

D. p->next=p->prev->prev; p->prev=p->next->next;

Answer

C.

"},{"location":"programming/archive/23fall/lec5/lec5/#_17","title":"\u6808\u548c\u961f\u5217","text":"

\u8fd9\u4e00\u90e8\u5206\u7684\u5185\u5bb9\u76f8\u4fe1\u5927\u5bb6\u5728\u8bfe\u4e0a\u5df2\u7ecf\u6709\u5f88\u597d\u7684\u7406\u89e3\u4e86\uff0c\u4f46\u662f\u4f1a\u51fa\u4e00\u4e9b\u548c\u94fe\u8868\u7ed3\u5408\u7684\u6709\u96be\u5ea6\u7684\u7406\u8bba\u9898\u548c\u7f16\u7a0b\u9898\uff0c\u6240\u4ee5\u7b80\u5355\u5e26\u8fc7\u4e00\u4e0b\uff1a

\u901a\u5e38\u9898\u76ee\u4f1a\u4f7f\u7528\u5355\u5411\u94fe\u8868\u6765\u5b9e\u73b0\u6808\u548c\u961f\u5217\u3002\u4e0d\u8fc7\u5f88\u591a\u9898\u76ee\u5176\u5b9e\u4f1a\u4e0d\u544a\u8bc9\u4f60\uff0c\u94fe\u8868\u54ea\u4e00\u6bb5\u8868\u793a\u6808\u9876\uff0c\u54ea\u4e00\u6bb5\u8868\u793a\u961f\u5934\uff0c\u54ea\u4e00\u6bb5\u8868\u793a\u961f\u5c3e\u3002

\u4e00\u4e2a\u95ee\u9898

\u5982\u679c\u662f\u53cc\u5411\u94fe\u8868\u5176\u5b9e\u6ca1\u6709\u8fd9\u4e48\u591a\u70e6\u607c\uff0c\u4f46\u662f\u73b0\u5728\u662f\u5355\u5411\u7684\u3002\u600e\u4e48\u5224\u65ad\u94fe\u8868\u7684\u5934\u4ee3\u8868\u6808/\u961f\u5217\u7684\u54ea\u4e2a\u90e8\u5206\u5462\uff1f

\u6808\u9876\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u6211\u4eec\u53ea\u9700\u8981\u8bb0\u5f55\u4e00\u4e0b\u94fe\u8868\u7684\u5934\u6307\u9488 head\uff0c\u5728\u4e0a\u9762\u64cd\u4f5c\uff0c\u53ef\u4ee5\u76f4\u63a5\u5b8c\u6210\u5bf9\u6808\u7684\u6a21\u62df\uff0c\u6240\u4ee5\u94fe\u8868\u7684\u5934\u4ee3\u8868\u6808\u9876\u3002

\u90a3\u961f\u5217\u5462\uff1f\u6211\u4eec\u4e0d\u59a8\u8bd5\u4e00\u4e0b\uff0c\u5047\u8bbe\u94fe\u8868\u5934\u90e8\u4ee3\u8868\u961f\u5c3e\uff0c\u90a3\u4e48\u961f\u5217\u7684\u5165\u961f\u64cd\u4f5c\u5f88\u597d\u5b9e\u73b0\uff0c\u4f46\u662f\uff0c\u51fa\u961f\u9700\u8981\u5728\u94fe\u8868\u5c3e\u90e8\u8fdb\u884c\u64cd\u4f5c\u3002\u6709\u4e00\u4e2a\u5f88\u76f4\u89c2\u7684\u65b9\u6cd5\u5c31\u662f\u540c\u65f6\u8bb0\u5f55\u5e76\u7ef4\u62a4\u94fe\u8868\u7684\u5c3e\u6307\u9488 tail\uff0c\u4f46\u662f\uff0c\u5220\u9664\u7684\u8bdd\uff0c\u6211\u4eec\u9700\u8981\u77e5\u9053\u5c3e\u6307\u9488\u7684\u524d\u9a71\u8282\u70b9...

\u6240\u4ee5\u4e00\u4e9b\u9898\u76ee\u7684\u5b9e\u73b0\uff0c\u9ed8\u8ba4\u4e86\u94fe\u8868\u7684\u5934\u90e8\u4ee3\u8868\u961f\u5934\u3002\u770b\u4e00\u4e0b\u8fd9\u4e2a\u9898\u76ee\uff1a

\u9898\u76ee 4

Represent a queue by a singly linked list. Given the current status of the linked list as 1->2->3 where x->y means y is linked after x. Now if 4 is enqueued and then a dequeue is done, the resulting status must be:

A. 1->2->3

B. 2->3->4

C. 4->1->2

D. the solution is not unique

Answer

B.

\u8fd9\u91cc\u9700\u8981\u989d\u5916\u63d0\u4e00\u4e2a\u53eb\u505a\u5faa\u73af\u961f\u5217\u7684\u4e1c\u897f\u3002\u5b83\u662f\u961f\u5217\u7684\u4e00\u79cd\u53d8\u4f53\uff0c\u901a\u5e38\u4f7f\u7528\u6570\u7ec4\u6765\u5b9e\u73b0\uff0c\u7528\u6765\u8282\u7ea6\u961f\u5217\u7684\u7a7a\u95f4\u3002\u5faa\u73af\u961f\u5217\u662f\u628a\u987a\u5e8f\u961f\u5217\u9996\u5c3e\u76f8\u8fde\uff0c\u628a\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u8868\u4ece\u903b\u8f91\u4e0a\u770b\u6210\u4e00\u4e2a\u73af\u3002\u901a\u5e38\u7528\u4e24\u4e2a\u53d8\u91cf\u4ee3\u8868\u5f53\u524d\u5faa\u73af\u961f\u5217\u5b58\u50a8\u7684\u7a7a\u95f4\uff1a\u4e00\u4e2a\u662f\u5c3e rear\uff0c\u4e00\u4e2a\u662f\u5934front\u3002\u4e0d\u8fc7\u8fd9\u4e2a\u662f\u5f00\u533a\u95f4\u8fd8\u662f\u95ed\u533a\u95f4\u5462\uff0c\u8fd8\u5f97\u770b\u5177\u4f53\u5b9e\u73b0\u65b9\u5f0f\u548c\u9898\u5e72\u8981\u6c42\uff0c\u5927\u5bb6\u6700\u597d\u7ffb\u7ffb\u8001\u5e08\u7684 PPT\uff0c\u770b\u770b\u4e0a\u8bfe\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff0c\u4e07\u4e00\u9898\u76ee\u6ca1\u6709\u7ed9\u51fa\u5b9e\u73b0\u65b9\u5f0f\u5c31\u6309\u7167\u8001\u5e08\u8bb2\u7684\u4e3a\u4e3b\u5427\u3002

\u9898\u76ee 5

Suppose that an array of size 6 is used to store a circular queue, and the values of front and rear are 0 and 4, respectively. Now after 2 dequeues and 2 enqueues, what will the values of front and rear be?

A. 2 and 0

B. 2 and 2

C. 2 and 4

D. 2 and 6

Answer

A.

\u5173\u4e8e\u7f16\u7a0b\u90e8\u5206\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u8fd9\u4e2a\u6bcf\u65e5\u4e00\u9898\u3002

"},{"location":"programming/common/faq/","title":"\u5e38\u89c1\u95ee\u9898","text":"

\u8fd9\u91cc\u5206\u6a21\u5757\u6c47\u603b\u4e86\u7a0b\u8bbe\u8f85\u5b66\u7fa4\u4e2d\u7684\u5e38\u89c1\u95ee\u9898\u53ca\u5176\u89e3\u7b54\u3002

"},{"location":"programming/common/faq/#_2","title":"\u57fa\u672c\u6570\u636e\u7c7b\u578b\u3001\u8fd0\u7b97\u7b26\u3001\u8868\u8fbe\u5f0f\u548c\u8bed\u53e5","text":"\u6709\u5e03\u5c14\u7c7b\u578b\u5417\uff1f

Author\uff1a\u6731\u5b9d\u6797

\u5e03\u5c14\u7c7b\u578b\u7684\u5386\u53f2\uff1a

\u56e0\u6b64\uff0c\u4ece C23 \u4ee5\u540e\uff0c\u6211\u4eec\u7ec8\u4e8e\u6709\u4e86 bool \u7c7b\u578b\u3002bool\u3001true\u3001false \u5168\u90fd\u6210\u4e3a\u4e86 C \u7684\u5173\u952e\u5b57\u3002

\u5173\u4e8e\u5e03\u5c14\u7c7b\u578b\u7684\u4f7f\u7528\uff1a

\u6d6e\u70b9\u6570\u662f\u5982\u4f55\u5b58\u50a8\u7684\uff1f\u4e3a\u4ec0\u4e48\u5b83\u4e0d\u7cbe\u786e\uff1f

Author\uff1a\u6731\u5b9d\u6797

\u4e0b\u9762\u7684\u5185\u5bb9\u6765\u81ea\u300a\u8ba1\u7b97\u673a\u79d1\u5b66\u5bfc\u8bba\u300b\uff0c\u8bf7\u5b8c\u6574\u9605\u8bfb\u4ee5\u4e86\u89e3\u6d6e\u70b9\u6570\u7684\u5b58\u50a8\u65b9\u5f0f\u3002

\u5982\u679c\u4f60\u8bfb\u5b8c\u4e86\u4e0a\u9762\u7684\u5185\u5bb9\uff0c\u4f60\u5e94\u8be5\u80fd\u7406\u89e3\u6d6e\u70b9\u6570\u5b58\u50a8\u4e0d\u7cbe\u786e\u7684\u539f\u56e0\uff1a

\u6709\u4e00\u4e2a\u7ecf\u5178\u7684\u4f8b\u5b50\uff1a0.1 + 0.2 == 0.3 \u662f\u9519\u7684\u3002\u8fd9\u4e00\u4f8b\u5b50\u5728\u6bcf\u65e5\u4e00\u9898\u4e2d\u4e5f\u6709\u63d0\u53ca\u3002\u90a3\u4e48\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5462\uff1f\u53ea\u8981\u5c06\u8bef\u5dee\u63a7\u5236\u5728\u4e00\u5b9a\u8303\u56f4\u5185\u5373\u8ba4\u4e3a\u6b63\u786e\uff0c\u6bd4\u5982\uff1a

if(fabs(a - b) < 1e-6) {\n  // a \u548c b \u76f8\u7b49\n}\n
"},{"location":"programming/common/faq/#_3","title":"\u6570\u7ec4\u3001\u5b57\u7b26\u4e32","text":""},{"location":"programming/common/faq/#_4","title":"\u5faa\u73af\u3001\u5206\u652f\u548c\u8df3\u8f6c","text":""},{"location":"programming/common/faq/#_5","title":"\u51fd\u6570\u3001\u6807\u51c6\u5e93\u4e0e\u9884\u5904\u7406\u5668","text":""},{"location":"programming/common/faq/#io","title":"\u6587\u4ef6 I/O","text":""},{"location":"programming/common/faq/#_6","title":"\u6307\u9488\u3001\u5b58\u50a8\u7c7b\u522b\u3001\u94fe\u63a5\u548c\u5185\u5b58\u7ba1\u7406","text":""},{"location":"programming/common/faq/#_7","title":"\u7ed3\u6784\u548c\u5176\u4ed6\u6570\u636e\u5f62\u5f0f","text":""},{"location":"programming/common/daily/2023/","title":"2023-2024","text":"

\u4e3a\u4e86\u8ba9\u540c\u5b66\u4eec\u9002\u5e94\u671f\u672b\u8003\u8bd5\uff0c\u6bcf\u65e5\u4e00\u9898\u7684\u9898\u9762\u90fd\u5c06\u4f7f\u7528\u82f1\u6587\u63cf\u8ff0\u3002

"},{"location":"programming/common/daily/2023/#december","title":"December","text":""},{"location":"programming/common/daily/2023/#10-i-love-pointer","title":"\u300c10\u300d I Love pointer","text":"

What is the output of the following program on a 64-bit system?

    char str[3][10]={\"\",\"ILoveCKC\",\"ILoveZJU\"};\n    printf(\"%lu#%lu\\n\",strlen(str[0]),sizeof(str[0]));\n    printf(\"%lu#%lu\\n\",strlen(str),sizeof(str));\n    printf(\"%d#%c\\n\",str[1][-10],str[1][10]); // Don't write this in your own code.\n    printf(\"%s\\n\",(**str == (*(str + 1) + 8)[1] ? \"True\" : \"False\"));\n    printf(\"%s\",&str[1][9] == &((*(str + 1) + 8)[1]) ? \"True\" : \"False\");\n
Answer
    0#10\n    0#30\n    0#I\n    True\n    True\n
  1. strlen(str[0]) returns the length of the string pointed to by str[0], which is 0. sizeof(str[0]) returns the size of the array str[0], which is 10.
  2. strlen(str) returns the length of the string pointed to by str, which is 0. sizeof(str) returns the size of the array str, which is 30. In fact, str[0]'s value is same as str's value.
  3. str[1][-10] is equivalent to *(str[1] - 10) which is equivalent to **(str + 1 * 10 - 10) which is equivalent to ** str. So str[1][-10]'s value is '\\0'. str[1][10] is equivalent to *(str[1] + 10) which is equivalent to **(str + 1 * 10 + 10) which is equivalent to ** (str + 20) So str[1][10]'s value is 'I'.
  4. (*(str + 1) + 8)[1] is the same as str[1][9]. So **str == (*(str + 1) + 8)[1] is true.

\u4f9b\u9898\u4eba\uff1a\u80e1\u80b2\u73ae

"},{"location":"programming/common/daily/2023/#9-sizeof-all-in-one","title":"\u300c9\u300d sizeof All in One","text":"

What is the output of the following program on a 64-bit system?

char str[][3] = {'L', 'o', 'v', 'e', 'C', 'K', 'C'};\nprintf(\"%d \", (int)sizeof(str));\nprintf(\"%d \", (int)sizeof(&str));\nprintf(\"%d \", (int)sizeof(*str));\nprintf(\"%d \", (int)sizeof(str + 1));\nprintf(\"%d \", (int)sizeof(*str + 1));\nprintf(\"%d \", (int)sizeof(*(str + 1)));\nprintf(\"%d\", (int)sizeof(*(*(str + 1) + 1)));\n
Answer

9 8 3 8 8 3 1.

This is a comprehensive problem combining sizeof and pointer.

  1. When the object is an array name, the return value is the total size of the whole array. At initialization, the third row of the array will be filled to a 1-D array of length 3 automatically: char str[][3] = {{'L', 'o', 'v'}, {'e', 'C', 'K'}, {'C', '\\0', '\\0'}};. Therefore the value of sizeof(str) equals to 3 * 3 * 1 = 9 since sizeof(char) = 3.
  2. In the expression &str, & represents the address-of operator and the return value is the address of the entire array. That, of course, can be regarded as a pointer and hence sizeof(&str) equals 8 (Bytes), the size of a pointer on a 64-bit system.
  3. Now let's focus on str. We know that str is an array of char [3]. In the view of pointer, str is also a pointer to the first element (Note that the element here is an array of length 3). Hence *str is equivalent to str[0] which is an 1D array of length 3. So the output of sizeof(*str) is 3 * 1 = 3.
  4. In the previous discussion we know that str is a pointer to array of length 3 (char (*)[3] actually), so str + 1 is also a pointer and the output is 8.
  5. *str (equivalent to str[0]), will be converted to int * when added by 1. Therefore *str + 1 is a pointer to str[0][1] and 8 will be output again.
  6. From discussion 3 and 4 it's not difficult to find *(str + 1) an array of length 3 (str[1]), so 3 is the answer.
  7. *(*(str + 1) + 1) is classical equivalence of str[1][1]. Therefore sizeof(*(*(str + 1) + 1)) equals to sizeof(char), namely 1.

\u4f9b\u9898\u4eba\uff1a\u5f90\u82e5\u79ba

"},{"location":"programming/common/daily/2023/#8-j-lost","title":"\u300c8\u300d J lost","text":"

Given the following program:

void xqc(char c[], int i);\n\nint main(void) {\n    char c[] = \"I am a Man of Fortune\";\n    char d[] = \"and I must seek my Fortune\";\n\n    xqc(c + 1, ~1694);\n    xqc(d - ~3, -65);\n    printf(\"%s, %s\\n\", c, d);\n}\n\nvoid xqc(char c[], int i) {\n    c = c - 1;\n    c[0] = ' ';\n    c[1] = (i & 1) + 'I';\n}\n

Which of the following is correct?

A. This program fails to compile, because you cannot assign to an array in line 13.

B. Because of the call-by-value, function xqc cannot modify the character arrays in function main.

C. Change 1694 in line 7 to 1994, and the result of the program is the same.

D. This program outputs I am a Man of Fortune, and J must seek my Fortune.

Answer

C.

A: Inside function xqc, c is a pointer type char * rather than an array type, because when an array type is used in a function parameter list, it actually is the corresponding pointer type. Therefore, the assignment in line 13 is valid, and it means \"to move the pointer c one position backward\".

B: The function xqc can modify the character arrays in function main, because it takes the address of the character arrays as parameters. The function xqc can modify the contents of the character arrays through the pointers.

C: The ~ operator is the bitwise NOT operator. The ~1694 is equivalent to -1695. The ~3 is equivalent to -4. Therefore, the calls to function xqc are equivalent to:

xqc(c + 1, -1695);\nxqc(d - -4, -65);\n

And i & 1 gets the last bit of i. Both -1695 and -65 are odd numbers, so i & 1 is 1, and the character 1 + 'I', which is 'J', is assigned. Changing 1694 to 1994 does not change the result of the program, because ~1994 is -1995, and -1995 is also an odd number.

D: This program outputs \u00a0Jam a Man of Fortune, and J must seek my Fortune.

Tip

You don't need to calculate the exact value of ~1694. All you need to know is that the last bit of 1694 is 0 (since it is an even number), and the bitwise NOT operator will reverse that last bit. Therefore, ~1694 is an odd number, and i & 1 is 1. Ditto for ~1994.

\u4f9b\u9898\u4eba\uff1a\u674e\u82f1\u7426

"},{"location":"programming/common/daily/2023/#7-the-difference-between-strlen-and-sizeof","title":"\u300c7\u300d The difference between strlen and sizeof","text":"
#include <stdio.h>\n#include <string.h>\nint main()\n{\n char arr1[] = \"abcd\";\n char arr2[] = {'a', 'b', 'c', 'd'};\n printf(\"%d\\n\", sizeof(arr1));\n printf(\"%d\\n\", sizeof(arr2));\n printf(\"%d\\n\", strlen(arr1));\n printf(\"%d\\n\", strlen(arr2));\n return 0;\n}\n

What are the results?

A. 4, 4, 4, 4 B. 5, 4, 4, 4 C. 4, 4, 4, indeterminable D. 5, 4, 4, indeterminable Answer

D.

arr1 has \\0 at the end, but arr2 doesn't.

The sizeof operator returns the size of its operand in bytes. In this case, the size of arr1 is 5, because it contains 4 characters and a null character \\0. The size of arr2 is 4, because it contains just 4 characters. The \\0 is absent in arr2.

The strlen function returns the length of the string, that is, the number of characters in the string before the null character \\0. In this case, the length of arr1 is 4, because it contains 4 characters before the null character \\0. But the length of arr2 is indeterminable, because it does not contain a null character \\0. The strlen function will continue to read memory until it finds a null character \\0, resulting totally random result. If there is no null character \\0 in the memory, the behavior is undefined.

\u4f9b\u9898\u4eba\uff1a\u534e\u5c55\u8f89\uff0c\u674e\u82f1\u7426

"},{"location":"programming/common/daily/2023/#6-stack-and-queue-adapted-from-fds-mid-term-exam","title":"\u300c6\u300d Stack and Queue (adapted from FDS mid-term exam)","text":"

Given an empty stack S and an empty queue Q. Push elements {1, 2, 3, 4, 5, 6, 7} one by one onto S. If each element that is popped from S is enqueued onto Q immediately, and if the dequeue sequence is {3, 2, 4, 6, 7, 5, 1}, then the minimum size of S should be:

A. 5 B. 4 C. 3 D. 7 Answer

C.

Stack is LIFO (Last In, First Out), queue is FIFO (First In, First Out). So dequeue sequence of queue is also the enqueue sequence. If enqueue sequence of Q is {3, 2, 4, 6, 7, 5, 1}, all operation of stack S must be the following:

In the process, there are at most 3 nodes in stack S, so the minimum size of S should be 3.

\u4f9b\u9898\u4eba\uff1a\u59da\u96ea\u6d9b

"},{"location":"programming/common/daily/2023/#5-monotonic-stacks","title":"\u300c5\u300d Monotonic stacks","text":"

Monotonic stacks are a specialized version of the standard stack data structure, designed to maintain elements in a pre-defined sorted order. Unlike regular stacks, which allow push and pop operations without any constraints, monotonic stacks enforce an order - either increasing or decreasing - on the elements. This means that elements are either strictly increasing or strictly decreasing from the top to the bottom of the stack.

The core operations of a monotonic stack, namely push, are modified to maintain the stack\u2019s order. During a push operation, elements that break the monotonic property are removed from the stack before the new element is added.

For example, now we have a decreasing monotonic stack, where elements closer to the top have the smaller values:

[5,4,2,1]\n       ^\n       |\n       top\n

We push a data with the value \\(3\\), and because \\(1,2\\) is smaller than \\(3\\), we remove them. And finally it will be:

[5,4,3]\n     ^\n     |\n     top\n

Now, your task is to create an decreasing monotonic stack in the C language.

typedef struct Node {\n    int data;\n    struct Node* next;\n} Node;\n\ntypedef struct Stack {\n    Node* top;\n} Stack;\n\nStack* createStack() {\n    Stack* stack = (Stack*)malloc(sizeof(Stack));\n    /* (1) */;\n    return stack;\n}\n\nvoid push(Stack* stack, int data) {\n    while (/* (2) */) {\n        Node* temp = stack->top;\n        stack->top = temp->next;\n        /* (3) */;\n    }\n    Node* newNode = (Node*)malloc(sizeof(Node));\n    newNode->data = data;\n    /* (4) */;\n    stack->top = newNode;\n}\n\nint pop(Stack* stack) {\n    if (isEmpty(stack)) {\n        printf(\"Stack is empty\\n\");\n        return -1;\n    }\n    Node* temp = stack->top;\n    int popped = temp->data;\n    stack->top = temp->next;\n    free(temp);\n    return popped;\n}\n
Answer

\u5355\u8c03\u6808\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u6808\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd\u4e25\u683c\u5c0f\u4e8e\u6216\u5927\u4e8e\u5b83\u4e0b\u9762\u7684\u5143\u7d20\u3002\u5927\u5bb6\u5728\u540e\u7eed\u7684\u8bfe\u7a0b\u4e2d\u6709\u53ef\u80fd\u4f1a\u63a5\u89e6\u5230\u4ed6\u7684\u4e00\u4e9b\u5e94\u7528\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u9010\u4e00\u770b\u770b\u8fd9\u4e9b\u9898\u76ee\u600e\u4e48\u586b\u5199\uff1a

\u7b2c\u4e00\u7a7a\uff1a\u8fd9\u91cc\u9700\u8981\u521d\u59cb\u5316\u6808\u9876\u5143\u7d20\u3002\u7531\u4e8e\u6808\u662f\u7a7a\u7684\uff0c\u6240\u4ee5\u6808\u9876\u5e94\u8be5\u8bbe\u7f6e\u4e3a NULL\u3002

stack->top = NULL;\n

\u7b2c\u4e8c\u7a7a\uff1a\u8fd9\u662f\u6700\u96be\u7684\u4e00\u7a7a\u3002\u6839\u636e\u9898\u610f\uff0c\u8fd9\u4e00\u5c42\u5faa\u73af\u7684\u76ee\u7684\u662f\uff1a\u79fb\u9664\u6240\u6709\u5c0f\u4e8e\u6216\u7b49\u4e8e\u65b0\u5143\u7d20\u7684\u6808\u9876\u5143\u7d20\uff0c\u4ee5\u7ef4\u6301\u6808\u7684\u5355\u8c03\u6027\u3002\u4f46\u662f\u8fd8\u6709\u4e00\u79cd\u60c5\u51b5\uff1a\u5982\u679c\u6808\u672c\u8eab\u662f\u7a7a\u7684\uff0c\u6216\u8005\u6240\u6709\u5143\u7d20\u90fd\u6bd4\u65b0\u5143\u7d20\u5c0f\uff0c\u90a3\u5fc5\u987b\u5f97\u9000\u51fa\u5faa\u73af\u3002

while (stack->top != NULL && stack->top->data <= data)\n

\u7b2c\u4e09\u7a7a\uff1a\u4e0d\u5927\u5bb9\u6613\u60f3\u5230\u3002\u5728\u79fb\u9664\u6808\u9876\u5143\u7d20\u540e\uff0c\u5e94\u8be5\u91ca\u653e\u8be5\u8282\u70b9\u5360\u7528\u7684\u5185\u5b58\u3002

free(temp);\n

\u4e3a\u4ec0\u4e48\u51fa\u8fd9\u4e2a\uff1f\u56e0\u4e3a wk \u660e\u786e\u8bf4\u8fc7\uff0c\u8003\u8bd5\u8003\u8fd9\u4e2a\u586b\u7a7a\uff0c\u4e0d\u5199 free \u5c31\u5c11 2 \u5206\uff0c\u6240\u4ee5\u51fa\u4e86\u8fd9\u4e2a\u7a7a\u6765\u8ba9\u5927\u5bb6\u6ce8\u610f\u3002

\u7b2c\u56db\u7a7a\uff1a\u8fd9\u91cc\u9700\u8981\u5c06\u65b0\u8282\u70b9\u7684 next \u6307\u9488\u6307\u5411\u4e4b\u524d\u7684\u6808\u9876\u5143\u7d20\uff0c\u7136\u540e\u5c06\u6808\u9876\u6307\u9488\u6307\u5411\u65b0\u8282\u70b9\uff0c\u8fd9\u6837\u65b0\u8282\u70b9\u5c31\u6210\u4e3a\u4e86\u65b0\u7684\u6808\u9876\u3002

newNode->next = stack->top;\n

\u4f9b\u9898\u4eba\uff1a\u8c22\u96c6

"},{"location":"programming/common/daily/2023/#4-command-line-arguments","title":"\u300c4\u300d Command Line Arguments","text":"

If you run the following command in the terminal:

./a.out this is a test\n

Please describe what will the program see in argv and argc.

Answer

argv is an array of pointers to strings, and argc is the number of strings in argv. The argv array contains the following strings:

argv[0] = \"./a.out\"\nargv[1] = \"this\"\nargv[2] = \"is\"\nargv[3] = \"a\"\nargv[4] = \"test\"\n

The argc is 5, because there are 5 strings in argv.

The argv array is terminated by a null pointer, so argv[5] is a null pointer.

For more information about argv and argc, see cppreference-argc, argv.

\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797

"},{"location":"programming/common/daily/2023/#3-sizeof-struct","title":"\u300c3\u300d sizeof struct","text":"

Consider the following code fragment:

struct A {\n    char a[10];\n    int b;\n\n};\ntypedef struct A A;\n\nstruct B {\n    char *a;\n    int b;\n};\ntypedef struct B* B;\n

What is the value of sizeof(A) and sizeof(B)?

Answer

sizeof(A) is 16, and sizeof(B) is 8 (on a 64-bit modern system).

The sizeof operator returns the size of its operand in bytes. The size of a structure type is as large as the sum of the sizes of its members.

You may think the size of A is 14, because the size of char[10] is 10, and the size of int is 4. However, to improve performance of memory access, C standard allows the compiler to add padding bytes after each member of a structure, and the padding strategy is implementation specific. A common strategy is to align each member to the size of its type, that is to say, make their memory address to be a multiple of the size of the member. For example, on a 64-bit system, the address of a 4-byte integer must be a multiple of 4.

Therefore, The size of A is 16. The compiler will add 2 padding bytes after char[10], to make the address of int a multiple of 4 in struct A.

The size of B is 8, because B is a pointer and the size of pointer is 8. The size of type to which B points does not affect the size of B. Notice that type B is not equivalent to type struct B.

For more information about sizeof operator, see cppreference-sizeof.

\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797\u3001\u5b59\u5146\u6c5f

"},{"location":"programming/common/daily/2023/#2-print-non-printable-characters","title":"\u300c2\u300d Print Non-printable Characters","text":"

Write a program to convert unprintable characters (characters with ASCII codes between 0x00~0x1f and 0x7f) in the input string to hexadecimal format for output.

Requirements:

Sample Input:

Hello\nWorld!\n

Sample Output:

Hello\\0x0aWorld!\n
Answer
#include <stdio.h>\n#include <ctype.h>\n\nconst char* hex_digits = \"0123456789abcdef\";\n\nint main(void) {\n    char temp;\n    while((temp = getchar()) != EOF) {\n        if (isprint(temp)) {\n            putchar(temp);\n        } else {\n            putchar('\\\\');\n            putchar('0');\n            putchar('x');\n            putchar(hex_digits[temp >> 4]);\n            putchar(hex_digits[temp & 0xf]);\n        }\n    }\n    return 0;\n}\n

If you are not familiar with bitwise operations, the 14th and 15th lines in the above code fragment can be written in a more understandable form:

putchar(hex_digits[temp / 16]);\nputchar(hex_digits[temp % 16]);\n

\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797

"},{"location":"programming/common/daily/2023/#1-hello-cat","title":"\u300c1\u300d Hello, Cat","text":"

After executing the following code fragment, the output should be __.

#include <stdio.h>\n#include <string.h>\nint main()\n{\n    char s1[10] = \"Hello\\0Ow<\";\n    char s2[10] = \"world\";\n    char *s3 = s1 + 2;\n    char *s4 = s2 + 3;\n    strcat(s3, s4);\n    printf(\"%s, %s; %s, %s.\\n\", s1, s2, s3, s4);\n    return 0;\n}\n

A. Hello, world; llold, ld.

B. Hello, world; lloldw<, ld.

C. Hellold, world; llold, ld.

D. Helloldw<, world; lloldw<, ld.

Answer

C.

The strcat function appends a copy of the string pointed to by s4 to the end of the string pointed to by s3. The s3 and s4 pointers point to the third character of s1 and the fourth character of s2, respectively. Therefore, the strcat function appends the string \"ld\" to the end of the string \"Hellold\", resulting in \"Helloldld\", and the printf function prints \"Hellold, world; llold, ld.\".

When the strcat function appends the string \"ld\" after \"Hello\", it overwrites the null character '\\0' at the end of the string \"Hello\" and write a new null character '\\0' at the end of the string \"Helloldld\". Therefore, the character w and < after the null character '\\0' in s1 are not printed.

\u4f9b\u9898\u4eba\uff1a\u90d1\u4fca\u8fbe

"},{"location":"programming/common/daily/2023/#november","title":"November","text":""},{"location":"programming/common/daily/2023/#30-basic-doubly-linked-list","title":"\u300c30\u300d Basic Doubly Linked List","text":"

Please fill in the blanks to complete the following code fragment.

#include <stdio.h>\n#include <stdlib.h>\n\ntypedef struct Node {\n    int data;\n    struct Node *prev, *next;\n} Node;\ntypedef struct Node *List;\n\nList createEmptyList() {\n    List list = (List)malloc(sizeof(Node));\n    list->prev = list->next = NULL;\n    return list;\n}\n\nvoid insertFront(List list, int data) {\n    Node *node = (Node *)malloc(sizeof(Node));\n    node->data = data;\n    node->prev = /* 1 */;\n    node->next = /* 2 */;\n    list->next->prev = /* 3 */;\n    list->next = /* 4 */;\n}\n\nint main(){\n    List list = createEmptyList();\n    insertFront(list, 1);\n    insertFront(list, 2);\n    insertFront(list, 3);\n    for (Node *node = /* 5 */; node != NULL; node = node->next)\n        printf(\"%d \", node->data);\n    return 0;\n}\n
Answer
  1. list
  2. list->next
  3. node
  4. node
  5. list->next

Notice this is a doubly linked list with a dummy node. The dummy node is a special node that does not store any data. It is used to simplify the implementation of the linked list. In this case, the dummy node is list.

The insertFront function inserts a new node with data at the front of the list. The new node is inserted between the dummy node and the first node of the list. The insertFront function takes two steps:

  1. Create a new node and set its data to data.
  2. Insert the new node between the dummy node and the first node of the list.

If you want to iterate over the list, you should start from the first node of the list, which is list->next.

\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797

"},{"location":"programming/common/daily/2023/#29-soyo-size","title":"\u300c29\u300d Soyo Size","text":"

On a 64-bit machine, the output of the following code fragment is __.

void print_soyo(char soyo[]) {\n    printf(\"%lu\\n\", sizeof(soyo));\n}\n\nint main() {\n    char soyo[] = \"Soyosan\\0Love\";\n    print_soyo(soyo);\n    return 0;\n}\n
A. 13 B. 7 C. 8 D. 4 Answer

C.

When an array type is used in a function parameter list, it is transformed to the corresponding pointer type: int f(int a[]) and int f(int *a) declare the same function. See cppreference-Array to pointer conversion for more information.

So the parameter soyo in function print_soyo is actually a pointer, and the size of a pointer is variable depending on the architecture. On a 64-bit machine, the size of a pointer is 8 bytes, and on a 32-bit machine, the size of a pointer is 4 bytes. Therefore, the output of this program is 8.

\u4f9b\u9898\u4eba\uff1a\u82cf\u715c\u7a0b

"},{"location":"programming/common/daily/2023/#28-naughty-pointer","title":"\u300c28\u300d Naughty Pointer","text":"

The following code fragment prints out __.

int a[2][3] = {1, 2, 3, 4, 5, 6};\nint(*p)[3] = *a + 1;\nprintf(\"%d\", *(*(p + 1) + 1));\n
Answer

6.

Obviously, the type of p is declared as int (*)[3], which is a pointer to an array of 3 integers. We know that in the initializer, a will be converted to a pointer to its first element, so *a is equivalent to a[0], which is an array of 3 integers. Then, the type of *a will be converted from int [3] to int * again. Therefore, adding 1 to *a will make it point to the next integer, which is a[0][1].

You may notice that the type of *a + 1 is not the same as pointer p. In fact, its type is casted to int (*)[3] when assigned to p. Trying to figure out the \"meaning\" of p now may become more difficult. Instead, just remember the value of pointer p is the address of a[0][1].

Now consider the expression *(*(p + 1) + 1). First, since the type of p is int (*)[3], adding 1 to p will make it point to the next array of 3 integers; that is to say, the value of p will be the address of the third integer after a[0][1], which is a[1][1]. So *(p + 1) is just equivalent to &a[1][1]. Then, adding 1 to *(p + 1) will make it point to the next integer, which is a[1][2]. Thus, the value of *(*(p + 1) + 1) is a[1][2], which is 6.

\u4f9b\u9898\u4eba\uff1a\u5b59\u5146\u6c5f

"},{"location":"programming/common/daily/2023/#27-i-love-scanf","title":"\u300c27\u300d I Love scanf","text":"

After entering the following inputs, does the program operate normally? If it does, what should be the output?

int a;\nchar c1, c2;\nchar s[7];\nscanf(\"%d%c %c%s\\n\", &a, &c1, &c2, s);\nprintf(\"%d#%c#%c#%s\", a, c1, c2, s);\n
#input: there is no space after the last character\n20231127\n ckc-agc\ndaily_problem\n
Answer

The program operates normally and the output is:

20231127#\n#c#kc-agc\n

The scanf function reads input from the standard input stream, which is usually the keyboard. The format string of scanf is \"%d%c %c%s\\n\". The first %d matches the integer 20231127, the second %c matches the character '\\n' because %c won't miss any character including ' ' and '\\n'. The space in formatting string will ignore every blank character, so the third %c matches the character 'c', and the fourth %s matches the string \"kc-agc\", whose length is 7. When you print \\n after line2, scanf will not stop, because '\\n' in formatting string will ignore every blank character. So until you enter a non-blank character and use enter to send it to the program from buffer, scanf will stop.

\u4f9b\u9898\u4eba\uff1a\u80e1\u80b2\u73ae

"},{"location":"programming/common/daily/2023/#26-broken-strcpy","title":"\u300c26\u300d Broken strcpy()","text":"

Does this strcpy() implementation do its job?

void my_strcpy(char *s, const char *t) {\n    do {\n        *s++ = *t++;\n    } while (*t);\n}\n
Answer

No, it's broken. This implementation does not terminate the string pointed to by s. To correctly copy a string, the character used in assignment must be the same character used in loop condition.

What does that mean? Suppose t = \"Hello\", then:

See the problem? The null byte '\\0' is not copied to s, therefore it's left unterminated. Any attempt to use s as a string will result in undefined behavior.

Worse still, what happens if t is an empty string i.e. t = \"\"?

\u4f9b\u9898\u4eba\uff1a\u674e\u82f1\u7426

"},{"location":"programming/common/daily/2023/#25-i-love-strcat","title":"\u300c25\u300d I Love Strcat","text":"

The following code fragment prints out __.

#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nvoid my_strcat(char *s1, char *s2, char *s3) {\n    size_t len1 = strlen(s1);\n    size_t len2 = strlen(s2);\n    s3 = malloc(len1 + len2 + 1);\n    memcpy(s3, s1, len1);\n    memcpy(s3 + len1, s2, len2);\n    s3[len1 + len2] = 0;\n    printf(\"%s\\n\", s3);\n}\n\nint main() {\n    char s1[] = \"I love \";\n    char s2[] = \"cats!\";\n    char s3[] = \"\";\n    my_strcat(s1, s2, s3);\n    printf(\"%s\\n\", s3);\n}\n

A. I love cats!\\n\\n

B. \\n\\n

C. \\nI love cats!\\n

D. I love cats!\\nI love cats!\\n

Answer

A.

The function my_strcat is supposed to concatenate s1 and s2 and store the result in s3. However, the function does not work as expected. The problem lies in the line s3 = malloc(len1 + len2 + 1);. The function my_strcat takes s3 as a parameter, which is a pointer to a char array. When the function is called, the value of s3 is copied to the function's local variable s3. Therefore, the malloc function allocates memory for the local variable s3, not the original s3 in main. The memory allocated for the local variable s3 is not used after the function returns, so it is a memory leak. The original s3 in main is not modified, so it is still an empty string.

You may think that the problem can be solved by simply deleting the line s3 = malloc(len1 + len2 + 1);. However, this will cause another problem. s3 is initialized as an empty string, which means that it is a pointer to a char array with only one element, the null character \\0. The memory allocated for s3 is not enough to store the concatenated string. Therefore, this will cause a buffer overflow.

\u4f9b\u9898\u4eba\uff1a\u6885\u654f\u70ab

"},{"location":"programming/common/daily/2023/#24-pointer-array","title":"\u300c24\u300d Pointer Array","text":"

The output of the following code fragment is __.

#include <stdio.h>\nint main()\n{\n char* a[] = { \"the\",\"one\",\"is\",\"unknown\" };\n char** pa = a;\n pa++;\n printf(\"%c%s\\n\", *(*pa + 1), *pa);\n return 0;\n}\n
A. none B. tone C. tthe D. nis Answer

A.

a[] is an array of pointers, which stores the addresses of three strings, and pa points to the address of the first element of a, as shown below:

Pointer operations take precedence over addition, so *(*pa + 1) equals to n.

In summary, the code fragment prints out none.

\u4f9b\u9898\u4eba\uff1a\u534e\u5c55\u8f89

"},{"location":"programming/common/daily/2023/#23-typedef-and-string","title":"\u300c23\u300d typedef and String","text":"

The preprocessing of this program is as follows:

#define MAX_SIZE 10000\n\ntypedef struct Bookcase{\n    char* book[10];\n} *PtrToBookcase;\n\ntypedef PtrToBookcase Lib_data_base[MAX_SIZE];\n

After executing the following code fragment, the output should be __.

Lib_data_base library;\n*(library) = (PtrToBookcase)malloc(sizeof(struct Bookcase));\n(*library)->book[0] = \"C Programming Book\";\nfor(int i = 0; i < 3; i++)\n    printf(\"%.2s\\n\", library[0]->book[0] + strlen(library[0]->book[0]) - i - 1));\nfree(library[0]);\n
Answer

Output is:

k\nok\noo\n

The address pointed to by library[0]->book[0] plus (strlen(library[0]->book[0])-i-1) * sizeof(char) will be eventually passed to %.2s and placed into the output stream.

Thus, when i=0, i=1, and i=2, the strings passed to %.2s are \"k\\0\", \"ok\\0\", and \"ook\\0\", respectively. Among these, the length of the third string \"ook\\0\" exceeds 2, so only the first two characters \"oo\" will be output.

This question involves multiple concepts, primarily focusing on both the proper usage of typedef and issues related to pointer output with char* in C. The analysis will be divided into two parts: typedef and char*. If you are already familiar with typedef, you can directly skip this section.

typedef

In the C language, typedef is used to create new names for existing data types.

When using typedef, errors can occur in the specification of its usage. One common misunderstanding is to interpret typedef (type_name) (new_name), which is correct only in a few cases, such as typedef int Integer.

However, the correct understanding should be: if you need to redefine a type, first write the declaration statement of that type: type variable_name, then replace variable_name with the alias you want, and finally add typedef in front of the entire statement.

For example, after int array[10], where the type of the variable array is int [10], you can rename array to the alias IntegerList and add typedef at the front, resulting in typedef int IntegerList[10].

After this, you can directly use the alias IntegerList to define variables of type int [10], such as IntegerList a;, which is equivalent to decelaration: int a[10].

Returning to the question, let's analyze the two typedef statements in the question.

The first one creates an alias for a structure variable. If we initially want to declare a variable of type struct Bookcase*, we would write it like this:

struct Bookcase {\n    char* book[10];\n} *Bookcase1;\n

Following the rules of typedef, replace the variable name Bookcase1 with the alias PtrToBookcase and add typedef at the beginning of the entire statement, resulting in the form seen in the question:

typedef struct Bookcase {\n    char* book[10];\n} *PtrToBookcase;\n

This statement means giving an alias, PtrToBookcase, to the type struct Bookcase*.

The second typedef is very similar to the example we mentioned earlier, typedef int IntegerList[10];. It first declares PtrToBookcase Ptr1[MAX_SIZE], then replaces the variable name Ptr1 with the alias Lib_data_base, and adds typedef at the front. Therefore, its meaning is to give an alias, Lib_data_base, to the type PtrToBookcase [MAX_SIZE]. Consequently, the subsequent Lib_data_base library actually creates an array of PtrToBookcase, named library, with MAX_SIZE elements.

char*

After understanding typedef, let's now explore the issue related to string output in this program. There are two potentially confusing elements in this code: %.2s and library[0]->book[0]+strlen(library[0]->book[0])-i-1.

%.2s is relatively straightforward: It is used to control the output of strings. %s would directly output the characters stored at the memory location pointed to by a char* type pointer and all characters in consecutive memory until encountering the '\\0' character. The additional .2 in %.2s is used to limit the length of the output string. If the string length is less than or equal to 2, it will be output normally. If it exceeds 2, only the first two characters will be output.

library[0]->book[0]+strlen(library[0]->book[0])-i-1 involves operations on a char* type pointer. library[0]->book[0] is a char* type pointer. Adding n to it effectively shifts the pointer to a position n * sizeof(char) bytes forward from the current address. Subtracting n from it shifts the pointer to a position n * sizeof(char) bytes backward from the current address.

\u4f9b\u9898\u4eba\uff1a\u59da\u96ea\u6d9b

"},{"location":"programming/common/daily/2023/#october","title":"October","text":""},{"location":"programming/common/daily/2023/#29-precedence","title":"\u300c29\u300d Precedence","text":"

The output of the following code fragment is __.

int x = 1, y = 2;\nprintf(\"%d\\n\", y << 1 - 1 > 2 || !(x++ > --y) ? x : y);\n
Answer

The answer is 2.

Several operators appear in this problem, listed in order of operation precedence from top to bottom:

See more about operator precedence at cppreference.com.

Knowing this, let's break down the expression from the innermost to the outermost parts.

  1. 1 - 1 evaluates to 0, and y << 0 has the value 2.
  2. 2 > 2 is false, thus the value of the Logical OR depends on the right part.
  3. x++ assigns the value of x (1) to the expression and then increments x by 1, making x equal to 2.
  4. --y decreases the value of y (2) by 1, so y becomes 1.
  5. x++ > --y is equivalent to 1 > 1, which is false, so this part equals 0.
  6. !(x++ > --y) negates false, so this part equals 1, making the condition of the Ternary conditional true.
  7. Since x has the value of 2 and y has the value of 1, the output will be 2.

\u4f9b\u9898\u4eba\uff1a\u5f90\u82e5\u79ba

"},{"location":"programming/common/daily/2023/#27-or-in-switch","title":"\u300c27\u300d Or in switch","text":"

What will happen when compiling and executing the following code fragment with input 5?

char ch;\nscanf(\"%c\", &ch);\nswitch (ch) {\n    case 0 || 2 || 4 || 6 || 8:\n        printf(\"even digit \");\n    case 1 || 3 || 5 || 7 || 9:\n        printf(\"odd digit \");\n    default:\n        printf(\"not a digit \");\n}\n

A. It will print odd digit.

B. It will print odd digit not a digit.

C. It will print not a digit.

D. It cannot be compiled.

Answer

D.

The compiler will tell you that case label value has already appeared in this switch. There are many problems in this code fragment, and the most important one is that 0 || 2 || 4 || 6 || 8 will not behave as expected in case statement. It will be evaluated as 1 because 0 || 2 || 4 || 6 || 8 is equivalent to ((((0 || 2) || 4) || 6) || 8). The result of 0 || 2 is 1, so the result of 0 || 2 || 4 is 1, and so on. Therefore, the case statement will be evaluated as case 1. The same problem exists in case 1 || 3 || 5 || 7 || 9, which will also be evaluated as case 1. The correct way to write this code fragment is:

char ch;\nscanf(\"%c\", &ch);\nswitch (ch) {\n    case '0': case '2': case '4': case '6': case '8':\n        printf(\"even digit \"); break;\n    case '1': case '3': case '5': case '7': case '9':\n        printf(\"odd digit \"); break;\n    default:\n        printf(\"not a digit \");\n}\n

For more information about switch statement, see cppreference-Switch statement.

\u4f9b\u9898\u4eba\uff1a\u90d1\u4fca\u8fbe

"},{"location":"programming/common/daily/2023/#26-bitwize-operator","title":"\u300c26\u300d Bitwize Operator","text":"

Which of the following options can achieve a swapping effect for pair(*,*)? Note that ^ represents XOR operation. For binary numbers, 0 XOR 0 = 0, 0 XOR 1 = 1, 1 XOR 0 = 1, 1 XOR 1 = 0.

A. (x, y): x ^= y ^= x ^= y;

B. (a[x], a[y]): a[x] ^= a[y] ^= a[x] ^= a[y];

C. (x, y): x -= y += x -= y;

D. (a[x], a[y]): a[x] -= a[y] += a[x] -= a[y];

Answer

A.

\u4f9b\u9898\u4eba\uff1a\u7a0b\u6615\u5b87

"},{"location":"programming/common/daily/2023/#25-eternal-binary-search","title":"\u300c25\u300d Eternal Binary-Search","text":"

After executing the following code fragment, the output should be __.

int ok[50000];\nfor (int i = 0; i <= 19268; ++i) ok[i] = 1;\nfor (int i = 19269; i <= 49999; ++i) ok[i] = 0;\nint l = 0, r = 49999;\nwhile (l < r){\n    int mid = (l + r) / 2;\n    if (ok[mid]) l = mid;\n    else r = mid - 1;\n}\nprintf (\"the ok_maximum is %d\", l);\n
Answer

In fact, this code fragment has no output because it is stuck in an endless loop. Let's see what happens: At first the code executes perfectly, l increasing and r decreasing constantly. However, when the value of r-l reduce to 1, the value of l and r will never change again. That's because mid equals to l and ok[mid] is true (Think about it. why?), so l = mid will be execute, again and again with no value change.

Binary Search is a very simple, common and useful algorithm that you will learn soon. However, when using Binary Search, it is easy to write a wrong code. It is said that only 10% of the programmers can write a exactly correct code. Hence, you need to pay special attention to this algorithm. A small change can possibly change the code correctness. For example, modifying the int mid = (l + r) / 2; to int mid = (l + r + 1) / 2; makes the code correct.

\u4f9b\u9898\u4eba\uff1a\u90d1\u6db5\u6587

"},{"location":"programming/common/daily/2023/#24-nested-switch-confusing-default-and-break","title":"\u300c24\u300d Nested switch, Confusing default and break","text":"

After executing the following code fragment, the output should be __.

int x = 1, y = 1;\nswitch (x) {\n    case 1:\n        switch (y) {\n            default:\n                printf(\"three \");\n            case 1:\n                printf(\"one \");\n            case 2:\n                printf(\"two \");\n                break;\n        }\n    case 2: case 3:\n        printf(\"four \");\n        break;\n    default:\n        printf(\"five \");\n}\n
Answer

one two four

The syntax of switch statement is:

switch (expression) {\n    case constant-expression:\n        statements\n    case constant-expression:\n        statements\n    default:\n        statements\n}\n

The expression must have an integral or enumerated type, or be of a class type in which the class has a single conversion function to an integral or enumerated type. The constant-expression for each case must be a constant expression of the same type as the expression, and no two of the constant expressions associated with the same switch statement shall have the same value after conversion.

The switch statement evaluates expression, then looks for the case constant-expression whose value is equal to the value of expression (after conversion). If such a case is found, the statements following that case are executed until a break statement is encountered. If no case is found whose value is equal to the value of the expression, and if there is a default label, the statements following the default label are executed. Otherwise, the statements of the switch statement are skipped.

If some case labels are not followed by break statements, the execution of the switch statement falls through to the next case label. You can use this behavior to execute multiple statements for a particular case label or to execute statements for more than one case label.

\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797

"},{"location":"programming/common/daily/2023/#23-prefix-or-postfix","title":"\u300c23\u300d Prefix OR Postfix","text":"

After executing the following code fragment, the value of variable x is __.

int x;\nfor (x = 0; x-- < 9 || ++x < 10; ++x) {\n    x++;\n}\n
Answer

11

  1. The result of the increment and decrement operators

    Increment and decrement operators have postfix form x++ (or x--), and prefix form ++x (or --x).

    • The result of the postfix forms is the value of x.
    • The result of the prefix forms is the value of x + 1 for ++x (or x - 1 for --x).

    For more information, see cppreference-Increment/decrement operators

  2. Logical OR ||

    The logical OR expression has the form lhs || rhs, in which rhs is only evaluated if lhs compares equal to \u200b0\u200b.

    For more information, see cppreference-Logical operators

When x < 9, each loop will cause x to increase by 1. Note that only x-- < 9 is evaluated in each loop now.

Now x is equal to 9 before the cond-expression of the for loop. First, x-- < 9 is evaluated, which compares equal to 0, and causes x to decrease by 1. Then x is equal to 8 and ++x < 10 is evaluated, which compares equal to 1 and causes x to increase by 1. Loop continues.

Then, x is equal to 11 before the cond-expression of the for loop. Now x-- < 9 and ++x < 10 both compare equal to 0, so the loop ends. x firstly decreases by 1 and then increases by 1, so the final value of x is 11.

\u4f9b\u9898\u4eba\uff1a\u82cf\u715c\u7a0b

"},{"location":"programming/common/daily/2023/#22-string-comparison","title":"\u300c22\u300d String Comparison","text":"

What's wrong with this code snippet?

char a[] = {\"abcd\"};\nchar b[] = {\"abcd\"};\nchar c[] = {\"ABCD\"};\n\nif(a > b) printf(\"[1] YES\\n\");\nelse printf(\"[1] NO\\n\");\nif(a > c) printf(\"[2] YES\\n\");\nelse printf(\"[2] NO\\n\");\n
Answer

Actually, the output of this program is unpredictable.

  1. To compare two strings, you should use strcmp function in <string.h> header file. Learn how to use the function by yourself.
  2. In the code snippet above, a, b and c are all arrays of char, so a > b and a > c are actually comparing the addresses of these arrays. You may think that the array declared later has a larger address, but this is not always true. It depends on the design of the architecture that the stack grows towards higher memory addresses or towards lower memory addresses. So the output of this program is unpredictable. For more information on this, see StackOverflow: Is the order of memory addresses of successively declared variables always descending?

\u4f9b\u9898\u4eba\uff1a\u6768\u7433\u73a5

"},{"location":"programming/common/daily/2023/#21-addition","title":"\u300c21\u300d Addition","text":"

After executing the following code fragment, the output should be __.

double a = 0.1, b = 0.2;\nif (a + b == 0.3)\n    printf(\"Equal.\\n\");\nelse\n    printf(\"Not equal.\\n\");\n
Answer

Not equal.

In C (and many other programming languages), floating-point arithmetic is not always exact due to the way numbers are represented in binary. This means that sometimes, tiny errors can be introduced and accumulated when performing mathematical operations on floating-point numbers.

In this case, when adding 0.1 and 0.2 together, the result is not precisely 0.3 due to these inaccuracies. Thus, directly comparing floating-point numbers with == can lead to unexpected results.

To deal with such issues in real programs, check if the difference between two floating-point numbers is smaller than a tiny threshold.

For more information about floating-point numbers, search for IEEE 754.

\u4f9b\u9898\u4eba\uff1a\u5b59\u5146\u6c5f

"},{"location":"programming/common/daily/2023/#20-bad-for","title":"\u300c20\u300d Bad for","text":"

After executing the following code fragment, the output should be __.

unsigned int x , y; // 'int' occupies 4 bytes\nfor (x = 2, y = 1; x = y; y++)\n    ;\nprintf(\"%d\", x-1);\n
Hint

Review Oct.\u300c18\u300d & \u300c16\u300d may help you get right answer.

Answer

-1.

Notice that the condition of for is x = y, not x == y. So for loop will terminate until y = 0. You should consider overflow in unsigned int variable.

When we execute ++ for unsigned int y in for loop, we will get 0x111...1(\\(2^{32}-1\\)) as the max unsigned int, and then we will get 0x00...0 as 0 because of overflow. So x gets the value of y(0) and terminates for. In printf, x-1 is 0x11...1. When you use %d to print, it will be considered as a signed interger, so the answer is -1, not \\(2^{32}-1\\).

\u4f9b\u9898\u4eba\uff1a\u80e1\u80b2\u73ae

"},{"location":"programming/common/daily/2023/#19-isprime","title":"\u300c19\u300d IsPrime?","text":"

What's wrong with this code snippet?

int d;\nscanf(\"%d\", &d);\n\n// determine if d is a prime number\nfor (int i = 2; i <= d; i++) {\n  if (d % i == 0) {\n    printf(\"%d is a composite\\n\", d);\n    exit(0);\n  }\n}\nprintf(\"%d is a prime\\n\", d);\n
Answer

Notice the condition of the for loop: i <= d, which means i will eventually be equal to d. Therefore d % i == 0 evaluates to 1, reporting composite for every input greater than 1.

\u4f9b\u9898\u4eba\uff1a\u674e\u82f1\u7426

"},{"location":"programming/common/daily/2023/#18-bad-if-else","title":"\u300c18\u300d Bad if-else","text":"

After executing the following code fragment, the output is __.

int x = 0;\nint y = -2;\nif(x > 0) y = 1;\nelse if(x < 0) y = -1;\nelse if(x = 0) y = 0;\nprintf(\"%d\", y);\n
A. 1 B. 0 C. -1 D. -2 Answer

D.

Notice that the condition of if in line 5 is x = 0, not x == 0. The former means \"0 is assigned to x\", and then the if sentence won't be executed since it is equivalent to if(0). Thus the value of y is its initial value, -2.

\u4f9b\u9898\u4eba\uff1a\u6885\u654f\u70ab

"},{"location":"programming/common/daily/2023/#17-character","title":"\u300c17\u300d Character","text":"

Given: char c = '@';, the value of expression 'A' <= c <= 'Z' is __.

Answer

1.

To solve this problem you do not need to remember ASCII code. This problem is about operator precedence. The expression 'A' <= c <= 'Z' is equivalent to (('A' <= c) <= 'Z'). No matter what the value of c is, the expression ('A' <= c) will be evaluated to 1 or 0, which is less than 'Z'. Therefore, the value of the expression 'A' <= c <= 'Z' is 1.

But in other problems you may need to remember some key ASCII codes:

Character ASCII Code '0' 48 'A' 65 'a' 97

Upper case is prior to lower case. The difference between 'A' and 'a' is 32. So if you want to convert a lowercase letter to uppercase, you can use c - 32. Or an easier way: c - 'a' + 'A'.

\u6765\u81ea\uff1aC \u5927 13 \u5e74\u671f\u672b

"},{"location":"programming/common/daily/2023/#16-overflow","title":"\u300c16\u300d Overflow","text":"

For code below:

unsigned short sht = 0;\nsht--;\n

What will be the value of sht after the execution?

A. -1 B. 65535 C. 32767 D. 65536 Answer

B.

Remember that unsigned short is an unsigned integer type, so it will not be negative. Instead, it will be the largest value of unsigned short type. The largest value of unsigned short type is 65535, because unsigned short is 16-bit long.

\u6765\u81ea\uff1aC \u5927 13 \u5e74\u671f\u672b

"},{"location":"programming/common/exam/","title":"\u5386\u5e74\u5377","text":"

\u5386\u5e74\u5377\u5178\u578b\u9898\u76ee\u7b54\u7591\u96c6\u6b63\u5728\u6574\u7406\u4e2d\u3002

"},{"location":"programming/common/exam/#_2","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u4e0e\u7b97\u6cd5\u57fa\u7840","text":"

\u6682\u65e0

"},{"location":"programming/common/exam/#_3","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u57fa\u7840\u4e0e\u5b9e\u9a8c","text":"

\u6682\u65e0

"},{"location":"programming/common/exam/#2013-20182020","title":"\u3010\u5df2\u505c\u5f00\u3011\u7a0b\u5e8f\u8bbe\u8ba1\u57fa\u7840\uff082013-2018+2020\uff09","text":"

\u8be5\u8bfe\u7a0b\u5df2\u4e8e 2022-2023 \u5b66\u5e74\u505c\u5f00\u3002

\u5e74\u4efd \u8bd5\u5377 \u7b54\u6848 2013 \u8bd5\u5377 \u7b54\u6848 2014 \u8bd5\u5377 \u7b54\u6848 2015 \u8bd5\u5377 \u7b54\u6848 2016 \u8bd5\u5377 \u7b54\u6848 2017 \u8bd5\u5377 \u7b54\u6848 2018 \u8bd5\u5377 \u7b54\u6848 2020 \u6a21\u62df\u5377 1 \u53ca\u7b54\u6848 \u6a21\u62df\u5377 2 \u53ca\u7b54\u6848 \u6a21\u62df\u5377 3 \u53ca\u7b54\u6848"},{"location":"programming/common/exam/#c-2013-2019","title":"\u3010\u5df2\u505c\u5f00\u3011C \u7a0b\u5e8f\u8bbe\u8ba1\u4e13\u9898\uff082013-2019\uff09","text":"

\u8be5\u8bfe\u7a0b\u5df2\u4e8e 2022-2023 \u5b66\u5e74\u505c\u5f00\u3002

\u5e74\u4efd \u8bd5\u5377 \u7b54\u6848 2013 \u8bd5\u5377 \u7b54\u6848 2014 \u8bd5\u5377 \u7b54\u6848 2015 \u8bd5\u5377 \u7b54\u6848 2016 \u8bd5\u5377 \u7b54\u6848 2017 \u8bd5\u5377 \u7b54\u6848 2018 \u8bd5\u5377 \u7b54\u6848 2019 \u8bd5\u5377 \u7b54\u6848"},{"location":"programming/common/exam/exam/","title":"\u5386\u5e74\u5377\u7ecf\u5178\u9898\u76ee\u89e3\u6790","text":""},{"location":"programming/common/exam/exam/#_2","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u57fa\u7840\u5e38\u95ee\u9898\u76ee\u96c6\u53ca\u89e3\u6790","text":"

C \u8bed\u8a00\u6742\u9879 \u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66\u5e38\u95ee\u9898\u76ee\u96c6\u53ca\u89e3\u6790 - \u9e64\u7fd4\u4e07\u91cc\u7684\u7b14\u8bb0\u672c \u662f @\u9e64\u7fd4\u4e07\u91cc 2022 \u5e74\u4e3a\u7afa\u9662\u8f85\u5b66\u73ed\u6574\u7406\u7684\u7a0b\u5e8f\u8bbe\u8ba1\u57fa\u7840\u5e38\u89c1\u95ee\u9898\u76ee\u96c6\u53ca\u89e3\u6790\u3002

"},{"location":"programming/common/exam/exam/#_3","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u4e13\u9898\u5386\u5e74\u5377\u7ecf\u5178\u9898\u76ee\u89e3\u6790","text":"

\u56fe\u5f62\u5e93\u76f8\u5173\u5185\u5bb9\u5df2\u4e0d\u518d\u51fa\u73b0\u5728\u8bfe\u7a0b\u4e2d

\u76ee\u524d\uff0c\u8bfe\u6539\u5df2\u7ecf\u5220\u53bb\u4e86\u56fe\u5f62\u5e93\u76f8\u5173\u5185\u5bb9\uff0c\u8fd9\u90e8\u5206\u5185\u5bb9\u4e0d\u4f1a\u518d\u51fa\u73b0\u5728\u6559\u5b66\u548c\u8003\u8bd5\u4e2d\uff0c\u6211\u4eec\u4e5f\u4f1a\u9010\u6b65\u5c06\u5176\u79fb\u9664\u3002

"},{"location":"programming/common/exam/exam/#_4","title":"\u7b97\u6cd5\u590d\u6742\u5ea6\u5206\u6790","text":""},{"location":"programming/common/exam/exam/#_5","title":"\u540e\u7f00\u8868\u8fbe\u5f0f","text":"

\u8fd9\u4e1c\u897f\u524d\u4e24\u4e09\u5e74\u90fd\u8003\u4e86\uff0c\u9700\u8981\u4e86\u89e3\u4e00\u4e0b\u3002\u5173\u4e8e\u8868\u8fbe\u5f0f\u6811\u7684\u76f8\u5173\u5185\u5bb9\u8bf7\u53c2\u89c1\uff1a

\u5728\u524d\u7f00\u3001\u4e2d\u7f00\u3001\u540e\u7f00\u8868\u8fbe\u5f0f\u4e4b\u95f4\u8fdb\u884c\u8f6c\u6362\u7684\u6700\u597d\u65b9\u6cd5\u662f\u5c06\u5176\u60f3\u8c61\u6210\u4e00\u4e2a\u6811\u72b6\u7ed3\u6784\u3002

\u503c\u5f97\u4e00\u63d0\u7684\u662f\u540e\u7f00\u8868\u8fbe\u5f0f\u5177\u6709\u51e0\u4e2a\u65b9\u4fbf\u7684\u6027\u8d28\uff1a

"},{"location":"programming/common/exam/exam/#2020-2021","title":"2020-2021 \u5e74\u5377","text":"

\u6ce8\u610f\u8fd9\u91cc\u7684 typedef struct{char * name;} *T; \u628a T \u5b9a\u4e49\u4e3a struct{char * name;}*; \u7684\u522b\u540d\u3002\u4e0b\u4e00\u4e2a\u8bed\u53e5\u5373\u58f0\u660e\u53d8\u91cf t \u4e3a\u8be5\u7c7b\u578b\u3002

\u51fd\u6570\u540d\u3001\u6570\u7ec4\u540d\u90fd\u4e0d\u662f\u6307\u9488\u54e6\uff0c\u867d\u7136\u5b83\u4eec\u5e38\u5e38\u9000\u5316\u6210\u6307\u9488\u3002

C \u8bed\u8a00\u4e2d\u4e00\u5171\u6709 5 \u4e2a\u5b58\u50a8\u7c7b\u522b\u9650\u5b9a\u7b26\uff0c\u8bf7\u56de\u5fc6\u5b83\u4eec\u7684\u4f5c\u7528\uff1a

\u5176\u5b9e typedef \u6309\u8bed\u6cd5\u529f\u80fd\u4e5f\u88ab\u5206\u5728\u8fd9\u4e00\u7c7b\uff0c\u6211\u4eec\u4e0d\u7ba1\u5b83\u3002

\u5728\u4efb\u4f55\u58f0\u660e\u4e2d\uff0c\u53ea\u80fd\u540c\u65f6\u5b58\u5728\u6700\u591a\u4e00\u4e2a\u5b58\u50a8\u7c7b\u522b\u9650\u5b9a\u7b26\u3002\u8fd9\u4e0e const\u3001volatile\u3001restrict \u7b49\u7c7b\u578b\u9650\u5b9a\u7b26\u4e0d\u540c\uff0c\u5b83\u4eec\u53ef\u4ee5\u540c\u65f6\u5b58\u5728\u3002

\u89c1 2019 \u5e74\u9009\u62e9\u9898 6

\u8fd9\u79cd\u9898\u901a\u7528\u7684\u65b9\u6cd5\u5c31\u662f\u6bcf\u4e2a\u9009\u9879\u5c1d\u8bd5\u4e00\u904d\u3002\u53ea\u8981\u5bf9\u6808\u3001\u961f\u5217\u64cd\u4f5c\u719f\u6089\u7684\u8bdd\uff0c\u4e00\u4e2a\u4e2a\u8bd5\u5f88\u5feb\u5c31\u51fa\u6765\u4e86\u3002

\u5982\u679c\u4f60\u7684\u7b54\u6848\u548c\u53c2\u8003\u7b54\u6848\u4e0d\u4e00\u6837\uff0c\u4e5f\u662f\u6709\u5bf9\u7684\u53ef\u80fd\u7684\uff0c\u5c31\u50cf\u4e2d\u7f00\u8868\u8fbe\u5f0f\u90a3\u6837\uff0c\u4e8c\u5143\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\u6570\u662f\u53ef\u4ee5\u6362\u5e8f\u7684\uff08

\u6ce8\u610f\u8fd9\u9053\u9898\u4e2d\u7684 ^ \u8fd0\u7b97\u7b26\u7684\u53f3\u7ed3\u5408\u95ee\u9898\uff0c\u52a0\u4e0a\u62ec\u53f7\u540e\u53d8\u6210 d^(e^f) \u800c\u4e0d\u662f (d^e)^f\uff0c\u8f6c\u6362\u6210\u540e\u7f00\u8868\u8fbe\u5f0f\u53ea\u80fd\u662f def^^\uff0c\u800c fed^^ \u4e4b\u7c7b\u7684\u5168\u662f\u9519\u7684\u3002

\u89c1\u5e38\u89c1\u95ee\u9898 - \u7b97\u6cd5\u590d\u6742\u5ea6

\u5f15\u7528\u4e00\u4e0b ztgg \u7684\u89e3\u91ca\uff1a

\u5982\u679c\u7b2c\u4e00\u4e2a while \u5faa\u73af\u8bfb\u4e0d\u61c2\u4e00\u5b9a\u8981\u627e\u540c\u5b66/\u8001\u5e08\u95ee\u6e05\u695a\u634f\uff0c\u961f\u5217\u7684\u4f7f\u7528\u662f\u5f88\u57fa\u672c\u7684\u3002\u8bf7\u601d\u8003\u8fd9\u4e2a while \u5faa\u73af\u4e3a\u4ec0\u4e48\u9700\u8981\u9010\u4e2a malloc() \u5462\uff1f

\u4e2d\u95f4\u90a3\u4e2a while \u5faa\u73af\u6709\u70b9\u8ff7\u60d1\u3002\u5b83\u5176\u5b9e\u53ea\u662f\u5728\u5c06 eQueue \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u653e\u5230 dQueue \u65f6\u540c\u65f6\u628a\u540e\u9762\u4e00\u4e2a\u5143\u7d20\u6362\u5230\u961f\u5c3e\u53bb\u3002\u7406\u89e3\u5230\u8fd9\u91cc\u5c31\u80fd\u505a\u5bf9\u5566\u3002

\u8fd9\u51e0\u4e2a\u7a7a\u90fd\u9700\u8981\u82b1\u4e00\u4f1a\u513f\u65f6\u95f4\u6765\u63a8\u65ad\u7684\uff1a

\u60f3\u8c61\u4e00\u4e2a\u89e3\u8c1c\u573a\u666f\uff1a\u5982\u679c\u4f60\u548c\u4f60\u7684\u670b\u53cb\u8d70\u5728\u4e00\u6761\u8def\u4e0a\uff0c\u4f60\u4eec\u8981\u600e\u4e48\u505a\u624d\u80fd\u5224\u65ad\u6709\u6ca1\u6709\u9047\u5230\u9b3c\u6253\u5899\uff08\u5373\u5728\u539f\u8def\u7ed5\u5708\uff09 \uff1f

\u7b54\u6848\u5f88\u7b80\u5355\uff1a\u4e00\u4e2a\u4eba\u8d70\u5feb\u70b9\uff0c\u4e00\u4e2a\u4eba\u8d70\u6162\u70b9\u3002\u5982\u679c\u8fd9\u6761\u8def\u6709\u5c3d\u5934\uff0c\u5148\u8d70\u7684\u4eba\u4e00\u5b9a\u4f1a\u5148\u5230\u8fbe\u5c3d\u5934\uff1b\u5982\u679c\u6ca1\u6709\u5230\u8fbe\u5c3d\u5934\uff0c\u90a3\u4e48\u4ed6\u4e00\u5b9a\u4f1a\u91cd\u65b0\u770b\u89c1\u4f60\u3002

LoopDetect() \u51fd\u6570\u7684\u601d\u8def\u4e5f\u7c7b\u4f3c\uff1a\u4f7f\u7528\u4e24\u4e2a\u6307\u9488 fast \u548c late\uff0cfast \u6bcf\u6b21\u6b65\u8fdb\u4e24\u4e2a\u8282\u70b9\uff0clate \u6bcf\u6b21\u6b65\u8fdb\u4e00\u4e2a\u8282\u70b9\u3002\u6700\u540e\u7ec8\u6b62\u65f6\u53ea\u6709\u4e24\u79cd\u6761\u4ef6\uff1afast \u65e0\u6cd5\u7ee7\u7eed\u6b65\u8fdb\u6216 fast \u5728\u524d\u8fdb\u7684\u8def\u4e0a\u770b\u89c1 late\u3002\u524d\u8005\u8868\u660e\u6ca1\u6709\u5faa\u73af\uff0c\u540e\u8005\u8868\u660e\u6709\u5faa\u73af\u3002

\u770b\u5230\u8fd9\u9053\u9898\u4f60\u6709\u6ca1\u6709\u60f3\u8d77\u5b57\u7b26\u4e32\u53bb\u7a7a\u683c\u7684\u4e00\u4e2a\u4f8b\u7a0b\uff1f

char *a;\nfor(int i = 0, j = 0; i < length; i++){\n    if(a[i] != ' ')\n        a[j++] = a[i];\n}\n

\u6709\u5e8f\u6570\u7ec4\u53bb\u91cd\u4e0e\u8fd9\u4e2a\u7b97\u6cd5\u4e5f\u6709\u4e9b\u7c7b\u4f3c\uff0c\u53ea\u662f\u6bd4\u8f83\u6761\u4ef6\u6362\u6210 a[i]!=a[j] \u4e86\u800c\u5df2\u3002

"},{"location":"programming/common/exam/exam/#2019-2020","title":"2019-2020 \u5e74\u5377","text":"

\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1a\u4f5c\u4e3a\u51fd\u6570\u4f5c\u4e3a\u5f62\u53c2\uff0c\u4f1a\u81ea\u52a8\u9000\u5316\u6210\u51fd\u6570\u6307\u9488\uff0c\u5c31\u50cf\u6570\u7ec4\u540d\u4f5c\u4e3a\u5f62\u53c2\u81ea\u52a8\u9000\u5316\u6210\u6307\u9488\u90a3\u6837\u3002\u8fd9\u53e5\u8bdd\u5728\u4e0b\u9762\u7684\u82f1\u6587\u90e8\u5206\u63d0\u5230\u4e86\u3002

The type of a function is determined using the following rules. [...] After determining the type of each parameter, any parameter of type \u201carray of T\u201d or of function type T is adjusted to be \u201cpointer to T\u201d. [...]

As mentioned in dcl.fct of the working draft (emphasis mine):

The type of a function is determined using the following rules. [...] After determining the type of each parameter, any parameter of type \u201carray of T\u201d or of function type T is adjusted to be \u201cpointer to T\u201d. [...]

Because of that, the following function:

void f(void());\n

Has the same type of:

void f(void(*)());\n

Thus the definitions below are identical:

void f(void(g)());\nvoid f(void(*g)());\n

Correct me if I'm wrong, AFAIK function names are pointers just like array names so in the first example you are passing function object and compiler does implicit conversion, in the second example you are directly passing function pointer which is explicit conversion.

\u540c\u6837\u4f9d\u636e\u4e0a\u9762\u7684\u8bb2\u89e3\u80fd\u591f\u9009\u51fa\u6b63\u786e\u7b54\u6848

\u6211\u89c9\u5f97 D \u9879\u7684\u8868\u8ff0\u672c\u6765\u5c31\u5f88\u6df7\u4e71\u3002\u51fd\u6570\u53c2\u6570\u5982\u679c\u4e3a void \u5c31\u8868\u793a\u51fd\u6570\u4e0d\u63a5\u6536\u53c2\u6570\uff0c\u8fd9\u5c31\u662f void \u5173\u952e\u5b57\u7684\u4f5c\u7528\uff0c\u800c\u4e0d\u662f\u9009\u9879\u4e2d\u8bf4\u7684\u4ec0\u4e48\u201c\u51fd\u6570\u6709\u4e00\u4e2a void \u7c7b\u578b\u7684\u53c2\u6570\u201d\u3002

\u8bf7 WK \u73ed\u540c\u5b66\u4e00\u5b9a\u8981\u53bb\u770b\u8f85\u5b66\u7fa4\u91cc\u5176\u4ed6\u8001\u5e08\u7684\u56fe\u5f62\u5e93\u8bfe\u4ef6

\u5982\u679c\u7a0b\u5e8f\u4ee3\u7801\u6709\u9519\uff0c\u5c31\u52c7\u6562\u5730\u5199\u201c\u8be5\u6bb5\u7a0b\u5e8f\u53ef\u80fd\u8fd0\u884c\u5931\u8d25\u201d\u3002

\u6ce8\u610f\uff0c\u5408\u5e76\u6570\u7ec4\u7684\u65f6\u5019\u90e8\u5206\u53bb\u91cd\u4e86\u3002\u5982\u679c\u79bb\u5f00\u4e86\u7b2c\u4e00\u4e2a while \u5faa\u73af\uff0c\u5219\u4e0d\u4f1a\u53bb\u91cd\u3002

\u8ba9\u6211\u4eec\u770b main() \u51fd\u6570\u7684\u7b2c\u4e00\u884c\u7684\u8868\u8fbe\u5f0f\uff1a

WK \u73ed\u540c\u5b66\u5e94\u5f53\u8865\u5145\u9605\u8bfb libgraphics \u5e93\u4e2d\u7684\u4e00\u4e9b\u5185\u5bb9\uff0c\u6211\u4eec\u76f4\u63a5\u8bfb\u6e90\u7801\u5427\uff1a

\u7b2c 15 \u7a7a\u6709\u610f\u601d\uff0cFreeBlock(PopStack(stack)) \u7684\u5d4c\u5957\u5199\u6cd5\u3002

\u8fd9\u7c7b\u7b97\u6cd5\u8bbe\u8ba1\u9898\u76ee\uff0c\u600e\u4e48\u7b80\u6d01\u600e\u4e48\u6765\uff0c\u4ee5 OI \u7801\u98ce\u53bb\u5199\u662f\u6700\u5408\u9002\u7684\u3002\u4e0d\u8981\u8bd5\u56fe\u5f04\u5b8c\u5584\u7684\u4ea4\u4e92\uff0c\u90a3\u662f\u6d6a\u8d39\u65f6\u95f4\u3002

\u4ee5\u4e0b\u662f\u6211\u81ea\u5df1\u505a\u7684\u65f6\u5019\u5199\u7684\uff0c\u4f5c\u4e3a\u4e00\u4e2a\u4e0d\u597d\u7684\u53c2\u8003\uff08

\u7406\u89e3\u9519\u9898\u610f\u4e86\uff0c\u539f\u6765 order \u4e0d\u662f\u65b9\u5411\u800c\u662f\u5206\u5f62\u6b21\u5e8f\u3002

\u5c31\u7528\u6807\u7b54\u7684\u65b9\u6cd5\uff0c\u5c06\u5076\u6570\u8282\u70b9\u79fb\u52a8\u5230\u53e6\u4e00\u4e2a\u94fe\u8868\uff0c\u518d\u5408\u5e76\u4e24\u4e2a\u94fe\u8868\u3002

"},{"location":"programming/common/exam/exam/#2018-2019","title":"2018-2019 \u5e74\u5377","text":"

\u50cf\u8fd9\u79cd\u9012\u5f52\u8ba1\u7b97\uff0c\u5c31\u8001\u8001\u5b9e\u5b9e\u628a\u51fd\u6570\u9012\u5f52\u5c55\u5f00\u5427\u3002\u5c55\u5f00\u8fc7\u7a0b\u4e2d\u8bb0\u5f97\u4f9d\u6b21\u8bb0\u4e0b\u5df2\u7ecf\u8ba1\u7b97\u5b8c\u7684 f(0)\u3001f(1) \u7b49\u503c\uff0c\u65b9\u4fbf\u540e\u7eed\u8ba1\u7b97\u3002

\u8fd9\u9053\u9898\u6211\u7684\u60f3\u6cd5\u633a\u5947\u8469\u7684\uff0c\u6211\u662f\u60f3\u53ea\u8981\u5168\u90e8\u6392\u5e8f\u4e00\u904d \\(O(N\\log N)\\)\uff0c\u7136\u540e\u7528 \\(O(1)\\) \u7684\u65f6\u95f4\u68c0\u67e5\u4e00\u4e0b\u5934\u3001\u4e2d\u95f4\u3001\u5c3e\u90e8\u7684\u5143\u7d20\u4e0d\u5c31\u597d\u4e86\u5417\uff08doge

\u524d\u7f00\u9012\u589e\u8fd0\u7b97\u7b26\u5148\u9012\u589e\u518d\u4f7f\u7528\u3002

\u672c\u9898\u82f1\u6587\u6709\u70b9\u70eb\u5634\uff0c\u6211\u7ffb\u8bd1\u4e00\u4e0b\uff1a

\u4e3a\u4e86\u7528\u7c7b\u4f3c T p \u7684\u65b9\u5f0f\u58f0\u660e\u4e00\u4e2a\u6307\u9488 p\uff0c\u8bf7\u5199\u51fa\u590d\u5408\u7c7b\u578b T \u7684\u5b9a\u4e49\u3002p \u662f\u4e00\u4e2a\u51fd\u6570\u7684\u6307\u9488\uff0c\u8be5\u51fd\u6570\u63a5\u6536 (char *, double) \u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a int *\u3002

\u8bfb\u61c2\u9898\u76ee\u5269\u4e0b\u7684\u5c31\u4e0d\u7528\u8bf4\u5566\u3002

\u6ce8\u610f\uff1axx-bit system\uff08n \u4f4d\u7cfb\u7edf\uff09\u6307\u7684\u662f\u8fd9\u4e2a\u7cfb\u7edf\u7684\u6307\u9488\u957f\u5ea6\u6709 \\(n\\) \u6bd4\u7279\uff0c\\(8\\) \u6bd4\u7279\u4e3a\u4e00\u4e2a\u5b57\u8282\u3002\u6545\u672c\u9898\u7684\u6240\u6709\u6307\u9488\u90fd\u662f \\(4\\) \u5b57\u8282\u3002

\u4ee5\u4e0b\u662f\u5404\u7c7b\u578b\u7684\u5927\u5c0f\uff1a

\u4ece\u4e0a\u9762\u518d\u6b21\u770b\u5230\uff0c\u6570\u7ec4\u540d\u5e76\u4e0d\u80fd\u7b80\u5355\u88ab\u770b\u4f5c\u6307\u9488\uff0c\u5b83\u8fd8\u5305\u542b\u6570\u7ec4\u7684\u7c7b\u578b\u4fe1\u606f\u3002

\u8fd9\u9053\u9898\u7b54\u6848\u611f\u89c9\u6709\u70b9\u95ee\u9898\u554a\u3002\u53cd\u6b63\u53ea\u8981\u77e5\u9053\u8fd4\u56de\u7684\u65f6\u5019 p \u6307\u5411 \\(2\\) \u8fd9\u4e2a\u8282\u70b9\u5c31\u7b97\u5bf9\u4e86\uff0c\u9898\u76ee\u8bf4 node \u90a3\u5e94\u8be5\u4e0d\u7528\u5427\u540e\u9762\u7684\u8282\u70b9\u90fd\u5199\u51fa\u6765\u5427\u3002

\u8fd9\u4e2a\u51fd\u6570\u5408\u5e76\u4e86\u4e24\u4e2a\u94fe\u8868\uff0c\u6309\u5347\u5e8f\u5408\u5e76\u3002

HEAD \u662f\u4e00\u4e2a\u4e34\u65f6\u4f7f\u7528\u7684\u54d1\u8282\u70b9\u3002

\u8c03\u7528\u540e\uff0c\u539f\u6765\u7684\u4e24\u4e2a\u6307\u9488\u6307\u7684\u4f4d\u7f6e\u4e0d\u53d8\uff0cl1 \u4ecd\u7136\u6307\u5411 \\(1\\) \u8fd9\u4e2a\u8282\u70b9\u3002\u4f46\u8282\u70b9\u4e4b\u95f4\u7684\u8fde\u63a5\u53d8\u4e86\uff0c\u8fd9\u65f6 l1 \u540e\u9762\u94fe\u4e0a\u4e86\u4ece l2 \u5408\u5e76\u8fdb\u6765\u7684\u5176\u4ed6\u8282\u70b9\u3002\u6240\u4ee5\u53ef\u4ee5\u770b\u4f5c\u201c\u94fe\u8868\u201d l1 \u53d1\u751f\u4e86\u6539\u53d8\u3002

\u8fd9\u662f\u4e00\u4e2a\u53cc\u5411\u7684\u6808\u3002\u6bcf\u6b21\u5165/\u51fa\u6808\u65f6\uff0c\u9700\u8981\u7528 Tag \u53c2\u6570\u6307\u5b9a\u662f\u54ea\u4e00\u5934\u3002\u4ece\u6570\u7ec4\u7684\u89d2\u5ea6\u6765\u770b\uff0cTop1 \u662f\u5de6\u8fb9\uff08\u5934\u90e8\uff09\u90a3\u5934\uff0cTop2 \u662f\u53f3\u8fb9\uff08\u5c3e\u90e8\uff09\u90a3\u5934\u3002

\u8bfb\u8fd9\u79cd\u9898\u65f6\uff0c\u6211\u63a8\u8350\u5148\u8bfb main() \u4e2d\u7684\u5185\u5bb9\uff0c\u5373\u89c2\u5bdf\u9898\u76ee\u7ed9\u7684\u6570\u636e\u7ed3\u6784\u662f\u600e\u4e48\u88ab\u4f7f\u7528\u7684\u3002\u7136\u540e\u4e0d\u660e\u767d\u7684\u5730\u65b9\u518d\u53bb\u770b\u5177\u4f53\u5b9e\u73b0\u7684\u4ee3\u7801\uff0c\u5176\u4ed6\u90e8\u5206\u5c31\u4e00\u70b9\u90fd\u4e0d\u7528\u770b\u3002\u6bd4\u5982\u8fd9\u9053\u9898\uff1a

\u8fd9\u4e2a\u4e1c\u897f\uff0c\u4fdd\u9669\u8d77\u89c1\u63a8\u8350\u624b\u5de5\u6a21\u62df\uff0c\u800c\u4e14\u624b\u5de5\u6a21\u62df\u51e0\u6b21\u540e\u4f60\u5c31\u77e5\u9053\u8fd9\u4e2a\u51fd\u6570\u5728\u5e72\u561b\u4e86\u3002

\u5176\u5b9e\u8fd9\u4e2a\u51fd\u6570\u7684\u4f5c\u7528\u662f\uff1a\u8c03\u7528\u540e\u4fdd\u8bc1\u6570\u7ec4 a[k] \u5de6\u4fa7\u7684\u5143\u7d20\u90fd\u6bd4 a[k] \u5c0f\uff0c\u53f3\u4fa7\u90fd\u6bd4 a[k] \u5927\u3002\u6700\u540e\u8fd4\u56de a[k] \u4e0a\u7684\u5143\u7d20\u3002\u4f46\u4e0d\u4f1a\u4fdd\u8bc1\u5176\u4ed6\u5143\u7d20\u4e4b\u95f4\u7684\u76f8\u5bf9\u987a\u5e8f\u3002

\u5177\u4f53\u7684\u64cd\u4f5c\u5c31\u662f\uff1a\u6bcf\u8f6e\u5faa\u73af\u628a\u7b2c a[k] \u4f4d\u7f6e\u4e0a\u7684\u5143\u7d20\u63d0\u51fa\u6765\u4f5c\u4e3a x\uff0c\u7136\u540e\u7528 i \u548c j \u5206\u522b\u4ece\u5de6\u53f3\u904d\u5386\u5e76\u4ea4\u6362\u4e24\u4fa7\u4e0d\u7b26\u5408\u8981\u6c42\u7684\u6570\u3002\u4ea4\u6362\u5b8c\u6210\u540e\uff0c\u6570\u7ec4\u4e2d\u6bd4 x \u5c0f\u7684\u6570\u90fd\u5728\u76f8\u5bf9\u5de6\u8fb9\u7684\u4f4d\u7f6e\uff0c\u6bd4 x \u5927\u7684\u6570\u90fd\u5728\u76f8\u5bf9\u53f3\u8fb9\u7684\u4f4d\u7f6e\u3002

\u5982\u679c\u4f60\u5bf9\u5feb\u6392\u6bd4\u8f83\u719f\u6089\uff0c\u90a3\u4e48\u8fd9\u5c31\u662f\u201c\u5982\u679c\u76ee\u6807\u4f4d\u7f6e\u4e0d\u5728\u7684\u4e00\u8fb9\u76f4\u63a5\u820d\u5f03\u201d\u7684\u5feb\u6392\u3002\u76f8\u5f53\u4e8e\u672c\u6765\u5feb\u6392\u533a\u95f4\u5f62\u6210\u4e00\u9897\u6811\uff0c\u4f46\u662f\u73b0\u5728\u5c31\u53ea\u8d70\u4e00\u6761\u8def\uff0c\u53ea\u6392 a[k] \u6240\u5728\u7684\u90a3\u4e9b\u533a\u95f4\u5957\u3002

\u672c\u8d28\u4e0a\u8fd8\u662f\u7528\u6570\u7ec4\u5b9e\u73b0\u5faa\u73af\u961f\u5217\uff0c\u53ea\u4e0d\u8fc7\u672c\u9898\u8fdb\u884c\u4e86\u6bd4\u8f83\u5b8c\u5584\u7684\u5c01\u88c5\u3002

\u5982\u679c\u8fd8\u4e0d\u77e5\u9053\u5faa\u73af\u961f\u5217\u662f\u4ec0\u4e48\u4e1c\u897f\uff0c\u53bb\u7f51\u4e0a\u641c\u4e00\u641c\u3002\u5faa\u73af\u961f\u5217\u7684\u8981\u70b9\u5c31\u662f\uff1a\u6240\u6709\u52a0\u6cd5\u64cd\u4f5c\u5168\u90e8\u8981\u5957\u4e0a\u4e00\u6b21\u53d6\u6a21\u64cd\u4f5c\u3002\u672c\u9898\u6ce8\u610f\u4e00\u4e0b\u95f4\u63a5\u6210\u5458\u8fd0\u7b97\u7b26 -> \u7684\u4f7f\u7528\u3002

\u6b64\u5916\u5faa\u73af\u961f\u5217\u7684 rear \u4e5f\u6709\u4e0d\u540c\u5b9e\u73b0\u65b9\u6cd5\uff0c\u5728\u672c\u9898\u4e2d\uff0c\u5b83\u6807\u5fd7\u961f\u5217\u5c3e\u90e8\u7684\u540e\u4e00\u4e2a\u5143\u7d20\uff0c\u4e5f\u5c31\u662f\u4e0b\u4e00\u4e2a\u5143\u7d20\u5e94\u8be5\u63d2\u5165\u7684\u5730\u65b9\uff1b\u5728\u53e6\u4e00\u4e9b\u5b9e\u73b0\u4e2d\uff0c\u5b83\u76f4\u63a5\u6807\u5fd7\u961f\u5217\u5c3e\u90e8\u7684\u5143\u7d20\u3002\u6bd4\u5982\u5982\u679c\u672c\u9898\u5728\u521b\u5efa\u6570\u7ec4\u7684\u65f6\u5019 Q->rear = maxsize - 1\uff0c\u8fd9\u4e9b\u7a7a\u5e94\u8be5\u4f5c\u600e\u6837\u7684\u6539\u53d8\u5462\uff1f

\u53c2\u89c1\u5e38\u89c1\u95ee\u9898 - \u56fe\u5f62\u5e93 - \u8ba1\u65f6\u5668

\u60f3\u8c61\u8fd9\u6837\u4e00\u4e2a\u60c5\u5883\uff1a\u8fd8\u662f\u60f3\u8c61\u4f60\u548c\u4f60\u7684\u670b\u53cb\u7ad9\u5728\u9898\u76ee\u6240\u793a\u7684\u4e24\u4e2a\u94fe\u8868\u7684\u8d77\u59cb\u5904\u3002\u8fd9\u4e24\u4e2a\u94fe\u8868\u6709\u53ef\u80fd\u76f8\u4ea4\uff0c\u4f60\u4eec\u60f3\u8981\u5c3d\u5feb\u627e\u5230\u4f1a\u5408\u70b9\uff0c\u600e\u4e48\u529e\u5462\uff1f\u800c\u4e14\u4e00\u4e2a\u6709\u7528\u7684\u4fe1\u606f\u662f\uff0c\u4f60\u4eec\u90fd\u77e5\u9053\u81ea\u5df1\u79bb\u7ec8\u70b9\u8fd8\u6709\u591a\u8fdc\u3002

\u5982\u679c\u76f8\u4ea4\uff0c\u4f60\u4eec\u80af\u5b9a\u6709\u516c\u5171\u5b50\u94fe\u8868\u3002\u5269\u4e0b\u4e0d\u540c\u7684\u90e8\u5206\u5c31\u662f\u4f60\u4eec\u5404\u81ea\u5b50\u94fe\u8868\u7684\u957f\u5ea6\u3002\u56e0\u6b64\uff0c\u4f60\u4eec\u5e94\u5f53\u5148\u76f8\u5bf9\u7ec8\u70b9\u5bf9\u9f50\u5f7c\u6b64\u7684\u4f4d\u7f6e\uff0c\u4f7f\u81ea\u5df1\u5269\u4f59\u7684\u5b50\u94fe\u8868\u7684\u7684\u957f\u5ea6\u76f8\u7b49\u3002\u63a5\u4e0b\u6765\u4ee5\u76f8\u540c\u7684\u901f\u5ea6\u524d\u8fdb\uff0c\u5982\u679c\u4f60\u4eec\u5728\u67d0\u5904\u4f1a\u5408\u4e86\uff0c\u90a3\u4e48\u8fd9\u4e00\u5b9a\u662f\u516c\u5171\u5b50\u94fe\u8868\u7684\u8d77\u59cb\u5904\u3002

\u53c2\u7b54\u4e2d\uff0clPtr \u6307\u5411\u8f83\u957f\u7684\u94fe\u8868\uff0csPtr \u6307\u5411\u8f83\u77ed\u7684\u94fe\u8868\uff0cnumLeftNodes \u5c31\u662f\u4e24\u94fe\u8868\u8282\u70b9\u6570\u7684\u5dee\u503c\uff0clPtr=lPtr->next \u7684 for \u5faa\u73af\u5c31\u662f\u5728\u5bf9\u9f50\u4e24\u4eba\u7684\u4f4d\u7f6e\u3002

\u5faa\u73af\u7ec8\u6b62\u7684\u6761\u4ef6\u662f\uff1a\u5176\u4e2d\u67d0\u4eba\u8d70\u5230\u4e86\u5c3d\u5934 NULL\uff0c\u6216\u4e24\u4eba\u76f8\u9047 lPtr==sPtr\u3002\u8fd4\u56de\u6700\u7ec8\u4f4d\u7f6e\u5373\u53ef\u3002

\u8fd9\u9898\u7b80\u5355\uff0c\u4e0d\u4f5c\u89e3\u6790\u3002\u53c2\u7b54\u4e2d\u6f0f\u4e86\u68c0\u67e5 minPos == rh \u7684\u60c5\u51b5\uff0c\u60f3\u60f3\u8fd9\u6837\u4f1a\u9020\u6210\u4ec0\u4e48\u540e\u679c\uff1f

"},{"location":"programming/common/exam/exam/#2017-2018","title":"2017-2018 \u5e74\u5377","text":"

\u8fd9\u9053\u9898\u65f6\uff0c\u6211\u9009\u7684\u662f D \u9879\u3002\u56e0\u4e3a\u6211\u8bb0\u5fc6\u4e2d\u7684\u5192\u6ce1\u6392\u5e8f\u662f\u8fd9\u6837\u7684\uff1a

void bubble_sort(int *arr, int len) {\n int i, j, tmp;\n for (i = 0; i < len - 1; i++) {\n     for (j = len - 1; j > i; j--) {//Bubble\n         if (arr[j] < arr[j - 1]) {\n             tmp = arr[j];\n             arr[j] = arr[j - 1];\n             arr[j - 1] = tmp;\n         }\n     }\n }\n}\n

\u4e0a\u9762\u8fd9\u6837\u7684\u5199\u6cd5\u5bf9\u4e8e\u4efb\u4f55\u60c5\u51b5\u7684\u590d\u6742\u5ea6\u90fd\u662f \\(O(n^2)\\)\u3002\u4f46\u662f\u5192\u6ce1\u6392\u5e8f\u666e\u904d\u4f1a\u4f5c\u8fd9\u6837\u7684\u4f18\u5316\uff1a

\u56e0\u6b64\u53ef\u4ee5\u5728\u5916\u5faa\u73af\u5f00\u5934\u6dfb\u52a0 bool flag = 0;\uff0c\u7ed3\u5c3e\u6dfb\u52a0 if(!flag)break;\uff0c\u4ea4\u6362\u64cd\u4f5c\u4e2d\u6dfb\u52a0 flag=true \u5373\u53ef\u5c06\u6700\u4f18\u60c5\u51b5\u4f18\u5316\u81f3 \\(O(n)\\)\u3002

\u5148\u60f3\u60f3\u81ea\u5df1\u4f1a\u600e\u4e48\u8c03\u7528\u8fd9\u4e2a fun \u51fd\u6570\u624d\u80fd\u5f97\u5230 void \u7c7b\u578b\uff1a

\u5f97\u5230\u4e86\u7b54\u6848\uff1avoid (*fun(int))(int)\u3002

\u5176\u5b9e\u8fd9\u662f\u4e00\u4e2a\u7ecf\u5178\u7684\u7b97\u6cd5\uff1a\u6240\u6709\u8fde\u7eed\u5b50\u5217\u5143\u7d20\u7684\u548c\u4e2d\u6700\u5927\u8005\u3002\u5728\u7f51\u4e0a\u53ef\u4ee5\u641c\u5230\u5f88\u591a\u8be5\u7b97\u6cd5\u7684\u539f\u7406\u4ecb\u7ecd\uff0c\u8bf7\u53bb\u770b\u4e00\u770b\uff0c\u770b\u5b8c\u5c31\u80fd\u7acb\u523b\u660e\u767d\u8fd9\u6bb5\u4ee3\u7801\u4e86\u3002

thisp \u88ab\u653e\u7f6e\u5728\u6700\u5927\u5b50\u5217\u7684\u5f00\u5934\uff0cmaxp \u88ab\u653e\u7f6e\u5728\u6700\u5927\u5b50\u5217\u7684\u672b\u5c3e\u3002

\u57fa\u4e8e\u6bd4\u8f83\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u5927\u6982\u90fd\u80fd\u4f18\u5316\u5230\u6700\u4f18\u60c5\u51b5\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u5427\uff1f

\u8fd9\u9898\u86ee\u5751\u7684\uff0c\u6211\u770b\u4e86\u597d\u4e00\u4f1a\u513f\u624d\u660e\u767d\u7b2c (7)(8) \u7a7a\u5728\u5e72\u561b\u3002\u5b83\u5176\u5b9e\u5c31\u662f\u5148\u628a\u524d\u9762\u7684\u9ad8\u6b21\u9879\u63d0\u516c\u56e0\u5f0f\uff0c\u7136\u540e\u5728\u9010\u6b65\u5411\u540e\u6c42\u548c\u7684\u8fc7\u7a0b\u7ed9\u5b83\u6574\u4f53\u4e58\u4e0a \\(x\\)\u3002\u6bd4\u5982 \\(3x^4+2x^2+1\\) \u53ef\u4ee5\u8fd9\u6837\u8ba1\u7b97\uff1a

\u8fd9\u6837\u505a\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u51cf\u5c11\u4e86\u8ba1\u7b97\u4e58\u79ef\u7684\u6b21\u6570\u3002

\u540c\u6837\u6ce8\u610f -> \u8fd0\u7b97\u7b26\u7684\u4f7f\u7528\u3002

"},{"location":"programming/common/exam/exam/#2016-2017","title":"2016-2017 \u5e74\u5377","text":"

\u6ce8\u610f\u9898\u76ee\u4e2d\u8bf4\u660e\u4e86\u6808\u9876\u6307\u9488\u4f4d\u4e8e N\uff0c\u8fd9\u4e2a\u6808\u662f\u4ece\u6570\u7ec4\u7684\u5c3e\u90e8\u5f00\u59cb\u7d2f\u79ef\u7684\u3002

\u7b80\u5355\u51fd\u6570\u6307\u9488\uff0c\u76f4\u63a5\u8fd9\u6837\u8bb0\uff1atypedef \u8fd4\u56de\u7c7b\u578b (*\u65b0\u540d\u5b57)(\u53c2\u6570\u5217\u8868)

\u548c\u524d\u4e00\u5e74\u7684\u4f8f\u5112\u6392\u5e8f\u6709\u70b9\u50cf\uff0c\u6709\u5e8f\u60c5\u51b5\u4e5f\u662f\u4e00\u904d\u8fc7\uff0c\u6700\u4f18\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u662f \\(O(n)\\)\u3002

\u8fc7\u7a0b\u4e2d\uff0c\u8be5\u94fe\u8868\u987a\u5e8f\u88ab\u91cd\u65b0\u6392\u5217\u3002\u6bd4 x \u5c0f\u7684\u8282\u70b9\u4f9d\u6b21\u79fb\u52a8\u5230 root \u4e3a\u9996\u7684\u5e26\u54e8\u5175\u94fe\u8868\u4e2d\uff0c\u5927\u7684\u4f9d\u6b21\u79fb\u52a8\u5230 pivot \u4e3a\u9996\u7684\u54e8\u5175\u94fe\u8868\u4e2d\uff0c\u6700\u540e\u5c06\u4e24\u4e2a\u94fe\u8868\u5408\u5e76\uff0c\u8fd4\u56de\u5408\u5e76\u540e\u7684\u94fe\u8868\u3002

\u672c\u9898\u5176\u5b9e\u5c31\u662f\u5728\u4ece\u5c0f\u5230\u8fbe\u6c42\u56e0\u6570\u3001\u7ea6\u53bb\u8fd9\u4e2a\u56e0\u6570\u3001\u6c42\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u56e0\u6570...\u3002\u6a21\u62df\u4e00\u904d\u5373\u53ef\u3002

\u6392\u5e8f\u539f\u7406\u9898\u76ee\u5df2\u7ecf\u8bb2\u6e05\u695a\u4e86\uff0c\u8fd9\u91cc\u8bb2\u4e00\u4e0b\u5faa\u73af\u4e2d\u51e0\u4e2a\u53d8\u91cf\u7684\u4f5c\u7528\uff1a

\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0c\u8fd9\u4e24\u4e2a\u94fe\u8868\u90fd\u662f\u96c6\u5408\uff0c\u8fd9\u610f\u5473\u7740\u5176\u4e2d\u7684\u5143\u7d20\u90fd\u662f\u552f\u4e00\u7684\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u8003\u8651\u91cd\u590d\u5143\u7d20\u7684\u60c5\u51b5\uff0c\u4e0d\u9700\u8981\u5b8c\u6574\u904d\u5386 \\(A\\)\u3002

"},{"location":"programming/common/exam/exam/#2015-2016","title":"2015-2016 \u5e74\u5377","text":"

\u5b8f\u5c55\u5f00\u53ea\u662f\u7b80\u5355\u7684\u6587\u672c\u66ff\u6362\u3002

\u4ece\u4e0a\u9762\u7684\u5c55\u5f00\u4e2d\u6211\u4eec\u770b\u5230\uff0c\u5b8f\u51fd\u6570\u7684\u5c55\u5f00\u987a\u5e8f\u5e76\u4e0d\u91cd\u8981\u3002\u6700\u7ec8\u7ed3\u679c\u5e94\u5f53\u4e00\u81f4\u3002

"},{"location":"programming/common/notes/funcptr/","title":"\u51fd\u6570\u6307\u9488\u8ba4\u8bfb","text":"

\u9996\u5148\uff0c\u8ba9\u6211\u4ecb\u7ecd\u4e00\u4e0b\u4e24\u4e2a\u60f9\u4eba\u559c\u7231\u7684\u5c0f\u5bb6\u4f19\u3002

int function(int arg)\n{\n    return 2 * arg;\n}\n

\u4e00\u822c\u901a\u8fc7\u51fd\u6570\uff0c\u7c7b\u578b\u662f int (int)\u3002

int (*func_ptr)(int);\n

\u829d\u58eb\u4ec0\u4e48\uff1f\u829d\u58eb\u51fd\u6570\u6307\u9488\uff0c\u7c7b\u578b\u662f int (*)(int)\u3002

\u90a3\u4e48\uff0c\u8fd9\u4e24\u4e2a\u5c0f\u5bb6\u4f19\u80fd\u5e72\u4ec0\u4e48\u5462\uff1f

func_ptr = &function;\nfunc_ptr = function;\n

\u524d\u8005\u662f\u4ec0\u4e48\uff1f\u6307\u9488\u3002\u6ca1\u9519\uff0c\u5e73\u5e73\u65e0\u5947\u7684\u53d6\u5730\u5740\u64cd\u4f5c\uff0c\u6d12\u6d12\u6c34\u5566\u3002 \u540e\u8005\u662f\u4ec0\u4e48\uff1f\u6211\u4eec\u77e5\u9053\u6307\u9488\u7684\u503c\u5b9e\u9645\u4e0a\u662f\u67d0\u5757\u5185\u5b58\u5730\u5740\uff0c\u4e0d\u8003\u8651\u5947\u6280\u6deb\u5de7\u7684\u8bdd\uff0c\u5c06\u6240\u6307\u5bf9\u8c61\u7684\u503c\u8d4b\u503c\u7ed9\u6307\u9488\u662f\u6ca1\u6709\u610f\u4e49\u7684\u3002\u4f46\u662f\uff0c\u5c06\u51fd\u6570\u6307\u4ee3\u5668 function \u8d4b\u503c\u7ed9\u51fd\u6570\u6307\u9488 func_ptr\uff0c\u5374\u6ca1\u6709\u4ea7\u751f\u4efb\u4f55\u95ee\u9898\u3002

\u574f\u4e86\uff0c\u81ea\u52a8\u64ad\u653e\u5988\u5988\u751f\u7684\uff0c\u5927\u8111\u8981\u6253\u9ad8\u7aef\u5c40\u4e86\u3002\u4e0d\u8fc7\u4f60\u5148\u522b\u6025\uff0c\u8fd9\u4e2a\u770b\u8d77\u6765\u4e0d\u77e5\u6240\u4e91\u7684\u8d4b\u503c\u8bed\u53e5\uff0c\u5176\u5b9e\u4e0e\u524d\u8005\u5b8c\u5168\u7b49\u6548\u3002C \u6807\u51c6\u662f\u4ec1\u6148\u7684\uff0c\u5b83\u4e0d\u5fcd\u5fc3\u770b\u5230\u88ab\u51fd\u6570\u7ed5\u6655\u7684\u521d\u5b66\u8005\u9762\u5bf9\u9519\u8bef\u7684\u89e3\u5f15\u7528\u4e0d\u77e5\u6240\u63aa\uff0c\u4e8e\u662f\u89c4\u5b9a\u4e86\u51fd\u6570\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u3002

\u4efb\u4f55\u51fd\u6570\u6307\u4ee3\u5668\u8868\u8fbe\u5f0f\uff0c\u5728\u7528\u4e8e\u5f02\u4e8e\u4e0b\u5217\u8bed\u5883\u65f6

\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u8868\u8fbe\u5f0f\u6240\u6307\u4ee3\u51fd\u6570\u7684\u6307\u9488\u7684\u8f6c\u6362\u3002

\u8fd9\u91cc function \u7ecf\u8fc7\u4e00\u6b21\u9690\u5f0f\u8f6c\u6362\u53d8\u6210 &function\u3002\u8fd9\u4e00\u6b65\u8f6c\u6362\u5e76\u4e0d\u6539\u53d8\u503c\uff0c\u800c\u7c7b\u578b\u4ece int (int) \u53d8\u6210 int (*)(int) \u4e86\u3002\u4e5f\u5c31\u662f\u5b9e\u9645\u4e0a\u5728\u7f16\u8bd1\u5668\u770b\u6765\uff0c\u7b2c\u4e8c\u884c\u5c31\u662f\u7b2c\u4e00\u884c\u3002

\u73b0\u5728\u4f60\u5df2\u7ecf\u5bf9\u51fd\u6570\u548c\u51fd\u6570\u6307\u9488\u6709\u4e86\u4e00\u5b9a\u4e86\u89e3\uff0c\u8ba9\u6211\u4eec\u770b\u4e00\u770b\u4e0b\u9762\u8fd9\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u628a\u6211\u4eec\u5df2\u7ecf\u5b66\u5230\u7684\u77e5\u8bc6\u8fd0\u7528\u5230\u5b9e\u8df5\u4e2d\u5427\u3002

\u8bf7\u89e3\u91ca\u4ee5\u4e0b\u4ee3\u7801\u7684\u4f5c\u7528\uff1a

// \u8bd5\u8bd5\u770b\uff01:)\n(*(void(*)())0)();\n

\u597d\u5427\uff0c\u8fd9\u6837\u7684\u8868\u8fbe\u5f0f\u6216\u8bb8\u5bf9\u4f60\u6765\u8bf4\u4e3a\u65f6\u5c1a\u65e9\u3002\u6211\u4eec\u6362\u4e9b\u7b80\u5355\u70b9\u7684\u4f8b\u5b50\u3002

function(20);\n(function)(20);\n(*&function)(20);\n(&function)(20);\n(*function)(20);\n(***********function)(20); // \u4e0d\u7528\u6570\u4e86\uff0c11 \u4e2a\n

\u5148\u4e0d\u7ba1\u7b2c\u516d\u4e2a\u662f\u4ec0\u4e48\u4e1c\u897f\uff0c\u6211\u4eec\u770b\u770b\u524d\u4e94\u4e2a\u3002

\u7b2c\u4e00\u4e2a\u4e0d\u80fd\u518d\u719f\u6089\u4e86\uff0c\u4e00\u4e2a\u4eba\u755c\u65e0\u5bb3\u7684\u51fd\u6570\u8c03\u7528\u3002

\u7b2c\u4e8c\u4e2a\u770b\u7740\u548c\u7b2c\u4e00\u4e2a\u5dee\u4e0d\u591a\u2026\u2026\uff1f\u6ca1\u9519\uff0c\u76f8\u4fe1\u81ea\u5df1\uff0c\u5b83\u4eec\u5b8c\u5168\u4e00\u6837\u3002

\u7b2c\u4e09\u4e2a\u5462\uff1f\u6ca1\u9519\uff0c\u53d6\u5730\u5740\u518d\u89e3\u5f15\u7528\uff0c\u9664\u4e86\u51fa\u9898\u6ca1\u6709\u7528\u3002\u8fde\u7f16\u8bd1\u5668\u90fd\u4f1a\u6beb\u4e0d\u72b9\u8c6b\u5730\u4f18\u5316\u6389\u3002

\u7b2c\u56db\u4e2a\u5f00\u59cb\u5947\u602a\u4e86\u8d77\u6765\u3002\u7f3a\u5931\u7684\u89e3\u5f15\u7528\u5e76\u975e\u7c97\u5fc3\u5927\u610f\uff0c\u5b83\u8c61\u5f81\u7740\u6211\u4eec\u73a9\u8f6c\u6307\u9488\u7684\u81ea\u4fe1\u4e0e\u60ec\u610f\uff0c\u4ee5\u53ca\u634d\u536b\u6307\u9488\u5730\u4f4d\u7684\u51b3\u5fc3\u3002\u9274\u4e8e C \u6807\u51c6\u5141\u8bb8\u901a\u8fc7\u51fd\u6570\u6307\u9488\u8c03\u7528\u51fd\u6570\uff0c\u7f16\u8bd1\u5668\u5bf9\u6b64\u4e5f\u6ca1\u4ec0\u4e48\u610f\u89c1\u3002

\u7b2c\u4e94\u4e2a\u6362\u4e86\u79cd\u6298\u78e8\u65b9\u5f0f\u3002\u806a\u660e\u5982\u4f60\u65e9\u5df2\u6599\u5230\u6700\u540e\u7684\u7ed3\u679c\u3002\u4f46\u662f\u4e3a\u4ec0\u4e48\uff1f\u5f15\u8a00\u5b9a\u771f\uff0c\u9274\u5b9a\u4e3a\u9690\u5f0f\u8f6c\u6362\u60ef\u7684\u3002\u56de\u5fc6\u4e00\u4e0b\u51fd\u6570\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\uff0c*function \u7b49\u6548\u4e8e *&function\uff0c\u8fd9\u4e0b\u770b\u61c2\u4e86\u3002

\u73b0\u5728\u7b2c\u516d\u4e2a\u4f60\u5e94\u8be5\u4e5f\u80fd\u7406\u89e3\u4e86\u3002\u6bcf\u6b21\u5c1d\u8bd5\u5bf9 function \u89e3\u5f15\u7528\uff0c\u90fd\u4f1a\u8feb\u4f7f\u7f16\u8bd1\u5668\u5c06\u5b83\u8f6c\u6362\u4e3a\u51fd\u6570\u6307\u9488\uff0c\u4ee5\u6ee1\u8db3\u4f60\u5bf9\u4ee3\u7801\u98ce\u683c\u7684\u5947\u602a\u7656\u597d\u3002

\u8fd8\u662f\u770b\u770b\u8fdc\u5904\u7684 func_ptr \u5427\u5bb6\u4eba\u4eec\u3002

(*func_ptr)(20);\nfunc_ptr(20);\n(****func_ptr)(20);\n(&func_ptr)(20);\n

\u7b2c\u4e00\u4e2a\uff0c\u7b80\u5355\u6613\u61c2\u7684\u6307\u9488\u89e3\u5f15\u7528\uff0c\u76f8\u5f53\u4e8e\u4e0a\u9762\u7684\u7b2c\u4e8c\u4e2a\u3002

\u7b2c\u4e8c\u4e2a\uff0c\u4eba\u755c\u65e0\u5bb3\u7684\u51fd\u6570\u6307\u9488\u8c03\u7528\u51fd\u6570\uff0c\u76f8\u5f53\u4e8e\u4e0a\u9762\u7684\u7b2c\u56db\u4e2a\u3002

\u7b2c\u4e09\u4e2a\uff0c\u51fd\u6570\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u53d1\u751f\u4e86\u6574\u6574\u4e09\u56de\u554a\u4e09\u56de\uff0c\u7c7b\u4f3c\u4e0a\u9762\u7684\u7b2c\u516d\u4e2a\u3002

\u7b2c\u56db\u4e2a\uff0c\u7f16\u8bd1\u5668\u8ddf\u4f60\u7206\u4e86\u3002\u600e\u4e48\u4f1a\u662f\u5462\uff1f\u6211\u4eec\u4e0d\u59a8\u62c6\u5f00\u770b\u770b\uff1a

int (*func_ptr)(int) = &function;    // \u8fd9\u662f\u4e4b\u524d\u7684\nint (**second_ptr)(int) = &func_ptr; // \u8fd9\u662f\u6211\u4eec\u6b63\u5728\u505a\u7684\nsecond_ptr(20);                      // \u6211\u4eec\u60f3\u8fd9\u6837\n

\u5728\u8fd9\u91cc\uff0csecond_ptr \u5df2\u7ecf\u662f\u4e2a\u4e8c\u7ea7\u6307\u9488\u4e86\u3002\u51fd\u6570\u5230\u51fd\u6570\u6307\u9488\uff08\u5b83\u662f\u4e2a\u4e00\u7ea7\u6307\u9488\uff09\u7684\u8f6c\u6362\u8fc7\u7a0b\u4e2d\uff0c\u5730\u5740\u503c\u662f\u4e0d\u4f1a\u6539\u53d8\u7684\uff0c\u5c31\u662f\u8fd9\u4e2a\u51fd\u6570\u7684\u53ef\u6267\u884c\u4ee3\u7801\u6240\u5728\u7684\u4f4d\u7f6e\u3002\u95ee\u9898\u5728\u4e8e\uff0c\u4e8c\u7ea7\u6307\u9488\u7684\u503c\u4e0d\u662f function \u7684\u5730\u5740\uff0c\u800c\u662f func_ptr \u8fd9\u4e2a\u53d8\u91cf\u7684\u5730\u5740\u3002\u8fd9\u8fd8\u5f97\u4e86\uff0c\u9a97\u81ea\u5df1\u53ef\u4ee5\uff0c\u9a97\u5144\u5f1f\u4e5f\u5c31\u7b97\u4e86\uff0c\u7f16\u8bd1\u5668\u53ef\u4e0d\u5403\u4f60\u8fd9\u5957\u3002

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u518d\u770b\u70b9\u4e0d\u592a\u4e00\u6837\u7684\uff1a

int func_two(int a, int f(int arg))\n{\n    return 3 * f(a);\n}\n

\u8fd9\u662f\u4ec0\u4e48\uff1f\u51fd\u6570\uff0c\u8c03\u7528\u4e00\u4e0b\uff1a

// function \u5982\u4e0a\u6587\u5b9a\u4e49\nint function(int arg);\n\nint a = 1;\nint b = func_two(a, function);\n

\u76f8\u4fe1\u806a\u660e\u7684\u4f60\u5df2\u7ecf\u731c\u5230\u4e86\uff0cb \u7684\u503c\u5c31\u662f 6\u3002\u6865\u8c46\u9ebb\u888b\uff0c\u597d\u50cf\u6709\u54ea\u91cc\u4e0d\u592a\u5bf9\u52b2\u3002func_two \u7684\u4e24\u4e2a\u53c2\u6570\u7c7b\u578b\u5206\u522b\u662f int \u548c int (int)\uff0c\u4f46\u662f\u8c03\u7528\u65f6\u5374\u4f20\u5165\u4e86\u4e00\u4e2a\u51fd\u6570\u6307\u9488\uff08\u8fd8\u8bb0\u5f97\u9690\u5f0f\u8f6c\u6362\u5417\uff1f\uff09\uff0c\u8fd9\u5374\u6ca1\u6709\u4ea7\u751f\u4efb\u4f55\u95ee\u9898\u3002\u8fd9\u53c8\u662f\u4ec0\u4e48\u64cd\u4f5c\uff1f

\u53c8\u662f\u9690\u5f0f\u8f6c\u6362\uff1fBingo\uff01\u4e0d\u8fc7\u9700\u8981\u6ce8\u610f\u53d1\u751f\u9690\u5f0f\u8f6c\u6362\u7684\u4f4d\u7f6e\u3002func_two \u7684\u7b2c\u4e8c\u4e2a\u5f62\u53c2\u5b9e\u9645\u4e0a\u662f int (*)(int) \uff0c\u800c\u975e\u5b57\u9762\u4e0a\u7684 int (int)\u3002\u8fd9\u5c31\u548c void f(int a[]) \u5b9e\u9645\u4e0a\u662f void f(int *a) \u4e00\u6837\uff0c\u540c\u6837\u662f\u51fa\u4e8e\u8282\u7ea6\u8d44\u6e90\u7684\u8003\u8651\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u7f16\u8bd1\u5668\u773c\u4e2d\u7684 func_two \u662f int func_two(int a, int (*f)(int)\u3002\u641e\u6e05\u695a\u8fd9\u4e00\u70b9\uff0c\u5176\u4f59\u90e8\u5206\u4e5f\u5c31\u987a\u7406\u6210\u7ae0\u4e86\u3002

\u7ecf\u8fc7\u7ec3\u4e60\uff0c\u4f60\u5e94\u8be5\u5df2\u7ecf\u53ef\u4ee5\u770b\u51fa\uff0c\u4ece\u51fd\u6570\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u89c4\u5b9a\u51fa\u53d1\uff0c\u7406\u89e3\u4e0a\u8ff0\u60c5\u666f\u5e76\u975e\u96be\u4e8b\u3002\u5bf9\u51fd\u6570\u6307\u9488\u7684\u754f\u60e7\uff0c\u5f80\u5f80\u662f\u56e0\u4e3a\u4e0d\u719f\u6089\u8f6c\u6362\u89c4\u5219\uff0c\u6216\u53d7\u590d\u6742\u7684\u58f0\u660e\u8bed\u6cd5\u5e72\u6270\u3002\u56e0\u6b64\uff0c\u63d0\u9ad8\u8bc6\u522b\u7c7b\u578b\u7684\u719f\u7ec3\u5ea6\uff0c\u8db3\u4ee5\u8ba9\u4f60\u81ea\u4fe1\u8fd0\u7528\u51fd\u6570\u6307\u9488\u3002

"},{"location":"programming/common/notes/pointers/","title":"\u6307\u9488\u6982\u89c8","text":"

\u4f60\u53ef\u80fd\u5df2\u7ecf\u542c\u8bf4\u8fc7\uff0cC \u8bed\u8a00\u662f\u8d34\u8fd1\u5e95\u5c42\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u8fd9\u662f\u56e0\u4e3a\uff0cC \u8bed\u8a00\u672a\u5bf9\u8ba1\u7b97\u673a\u786c\u4ef6\u4f5c\u8fc7\u591a\u62bd\u8c61\uff0c\u5b83\u65b9\u4fbf\u800c\u53c8\u7075\u6d3b\u7684\u8bed\u8a00\u7279\u6027\u4e3a\u4e0e\u786c\u4ef6\u4ea4\u4e92\u63d0\u4f9b\u4e86\u6781\u5927\u4fbf\u5229\u3002

\u6307\u9488\u662f C \u8bed\u8a00\u7684\u6838\u5fc3\u7279\u6027\u4e4b\u4e00\uff0c\u5b83\u7684\u7075\u6d3b\u6027\u4e0e\u5f3a\u5927\u6027\uff0c\u4f7f\u5f97 C \u8bed\u8a00\u6210\u4e3a\u4e0e\u786c\u4ef6\u4ea4\u4e92\u7684\u9996\u9009\u8bed\u8a00\u3002\u4f46\u662f\uff0c\u6307\u9488\u4e5f\u662f C \u8bed\u8a00\u4e2d\u6700\u5bb9\u6613\u5f15\u53d1\u9519\u8bef\u7684\u7279\u6027\u4e4b\u4e00\uff0c\u5b83\u8981\u6c42\u4f7f\u7528\u8005\u6b63\u786e\u7406\u89e3\u5185\u5b58\u6a21\u578b\uff0c\u5e76\u5bf9\u6307\u9488\u7684\u4f7f\u7528\u4e25\u52a0\u7ea6\u675f\u3002

\u672c\u6587\u5c06\u5c3d\u91cf\u5168\u9762\u5730\u8bb2\u89e3\u6307\u9488\u7684\u5b9a\u4e49\u4e0e\u7279\u6027\uff0c\u5e76\u68b3\u7406\u90e8\u5206\u4f7f\u7528\u6280\u5de7\u3002\u5728\u6b64\u4e4b\u524d\uff0c\u4e3a\u4e86\u51c6\u786e\u7406\u89e3\u6307\u9488\uff0c\u6211\u4eec\u9700\u8981\u5148\u4e86\u89e3 C \u8bed\u8a00\u7684\u5185\u5b58\u6a21\u578b\u4e0e\u5bf9\u8c61\u6a21\u578b\u3002

\u9605\u8bfb\u63d0\u793a

\u7a0b\u7b97\u8bfe\u7a0b\u4e2d\u5b66\u4e60\u7684 C \u8bed\u8a00\u8bed\u6cd5\u5747\u5728 C99 \u6807\u51c6\u89c4\u5b9a\u7684\u8303\u56f4\u5185\u3002\u4e0b\u6587\u4e2d\uff0c\u5982\u679c\u672a\u4f5c\u989d\u5916\u8bf4\u660e\uff0c\u6240\u6709\u5185\u5bb9\u5747\u57fa\u4e8e C99 \u6807\u51c6\u3002

\u4e0b\u6587\u4e2d\u90e8\u5206\u63d0\u793a\u9ed8\u8ba4\u88ab\u6298\u53e0\u3002\u6b64\u7c7b\u63d0\u793a\u4e3a\u62d3\u5c55\u5185\u5bb9\uff0c\u5bf9\u77e5\u8bc6\u79ef\u7d2f\u4e0e\u7406\u89e3\u80fd\u529b\u6709\u4e00\u5b9a\u8981\u6c42\uff0c\u4f46\u6709\u52a9\u4e8e\u7406\u89e3\u4e00\u4e9b\u7ec6\u8282\u95ee\u9898\uff0c\u8bf7\u914c\u60c5\u9605\u8bfb\u3002

"},{"location":"programming/common/notes/pointers/#_2","title":"\u5e95\u5c42\u6982\u5ff5","text":""},{"location":"programming/common/notes/pointers/#_3","title":"\u5185\u5b58\u6a21\u578b","text":"

\u5185\u5b58\u6a21\u578b

\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5176\u6bcf\u4e2a\u5b57\u8282\u7684\u7d22\u5f15\u3001\u503c\u4e0e\u5185\u5b58\u5730\u5740\u3002

\uff08\u5355\u51fb\u56fe\u7247\u53ef\u653e\u5927\uff09

\u5728 C \u8bed\u8a00\u7684\u5185\u5b58\u6a21\u578b\u4e2d\uff0c\u5b57\u8282\uff08Byte\uff09\u5b9a\u4e49\u4e3a\u4e00\u7cfb\u5217\u8fde\u7eed\u7684\u4f4d\uff08bit\uff09\uff0c\u662f\u5185\u5b58\u7684\u6700\u5c0f\u53ef\u5bfb\u5740\u5355\u5143\u3002\u5728\u51e0\u4e4e\u6240\u6709\u73b0\u4ee3\u8ba1\u7b97\u673a\u4e0a\uff0c\u4e00\u4e2a\u5b57\u8282\u7684\u957f\u5ea6\u90fd\u662f 8 \u4f4d\uff0c\u6211\u4eec\u7684\u8ba8\u8bba\u4e5f\u57fa\u4e8e\u8fd9\u4e00\u6807\u51c6\u3002

\u6240\u8c13\u201c\u53ef\u5bfb\u5740\u201d\u6307\u7684\u662f\u5185\u5b58\u4e2d\u7684\u6240\u6709\u5b57\u8282\u90fd\u62e5\u6709\u4e00\u4e2a\u552f\u4e00\u7f16\u53f7\uff0c\u4e5f\u5373\u5185\u5b58\u5730\u5740\u3002\u4e60\u60ef\u4e0a\uff0c\u5185\u5b58\u5730\u5740\u7531\u957f\u5ea6\u4e00\u5b9a\u7684\u3001\u4ece 0 \u5f00\u59cb\u9012\u589e\u7684\u65e0\u7b26\u53f7\u6574\u6570\u8868\u793a\uff0c\u5176\u957f\u5ea6\u7531\u64cd\u4f5c\u7cfb\u7edf\u51b3\u5b9a\u3002

\u5e38\u89c1\u67b6\u6784\u4e2d\u5185\u5b58\u5730\u5740\u7684\u957f\u5ea6

\u6211\u4eec\u7ecf\u5e38\u63a5\u89e6\u7684\u5904\u7406\u5668\u67b6\u6784\u4e2d\uff0cx86\uff08\u53c8\u79f0 IA-32\uff09\u67b6\u6784\u4f7f\u7528 32 \u4f4d\u957f\u7684\u5185\u5b58\u5730\u5740\uff0cx86-64\uff08\u53c8\u79f0 x64\u3001AMD64\u3001Intel 64\uff09\u4e0e ARM64\uff08\u53c8\u79f0 AArch64\uff09\u67b6\u6784\u4f7f\u7528 64 \u4f4d\u957f\u7684\u5185\u5b58\u5730\u5740\u3002\u5bb9\u6613\u770b\u51fa\uff0cx86 \u67b6\u6784\u652f\u6301\u7684\u6700\u5927\u5185\u5b58\u7a7a\u95f4\u53ea\u6709 4 GB\uff0c\u800c\u540e\u4e24\u4e2a\u67b6\u6784\u652f\u6301\u7684\u6700\u5927\u5185\u5b58\u7a7a\u95f4\u5219\u8fdc\u8d85\u524d\u8005\u3002

"},{"location":"programming/common/notes/pointers/#_4","title":"\u5bf9\u8c61","text":"

C \u8bed\u8a00\u5c06\u7a0b\u5e8f\u4f7f\u7528\u7684\u6570\u636e\u62bd\u8c61\u4e3a\u5bf9\u8c61\uff0c\u5b83\u88ab\u5b9a\u4e49\u4e3a\u6267\u884c\u73af\u5883\u4e2d\u5185\u5b58\u7684\u4e00\u4e2a\u533a\u57df\uff0c\u5176\u5185\u5bb9\u53ef\u4ee5\u8868\u793a\u7279\u5b9a\u7c7b\u578b\u7684\u503c\u3002\u6839\u636e\u6570\u636e\u7c7b\u578b\u4e0e\u957f\u5ea6\u7684\u4e0d\u540c\uff0c\u4e00\u4e2a\u5bf9\u8c61\u53ef\u5360\u636e\u4e00\u4e2a\u6216\u591a\u4e2a\u5b57\u8282\uff0c\u6211\u4eec\u79f0\u8d77\u59cb\u5b57\u8282\u7684\u5185\u5b58\u5730\u5740\u4e3a\u8be5\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u3002

\u6bcf\u4e2a\u5bf9\u8c61\u53ef\u4ee5\u7528 memcpy \u590d\u5236\u5230 unsigned char[n] \u7c7b\u578b\u7684\u5bf9\u8c61\u4e2d\uff0c\u6211\u4eec\u79f0\u751f\u6210\u7684\u6570\u7ec4\u5185\u5bb9\u4e3a\u5bf9\u8c61\u8868\u793a\u3002\u65b9\u4fbf\u8d77\u89c1\uff0c\u6211\u4eec\u901a\u5e38\u4ee5\u5341\u516d\u8fdb\u5236\u6574\u6570\u5e8f\u5217\u5f62\u5f0f\u5c55\u793a\u5bf9\u8c61\u8868\u793a\uff0c\u6bcf\u4e24\u4f4d\u5341\u516d\u8fdb\u5236\u6570\u4ee3\u8868\u4e00\u4e2a\u5b57\u8282\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0cint \u7c7b\u578b\u5e38\u91cf 1 \u5728\u5c0f\u7aef\u5e8f\u8ba1\u7b97\u673a\u4e0a\u7684\u5bf9\u8c61\u8868\u793a\u4e3a 0x01 00 00 00\u3002

\u53e6\u5916\uff0c\u5bf9\u8c61\u8868\u793a\u548c\u503c\u5e76\u4e0d\u8981\u6c42\u4e00\u4e00\u5bf9\u5e94\uff0c\u4e24\u4e2a\u503c\u76f8\u7b49\u7684\u5bf9\u8c61\u53ef\u4ee5\u62e5\u6709\u4e0d\u540c\u7684\u5bf9\u8c61\u8868\u793a\u3002

\u9664\u4e86\u76f4\u63a5\u4f7f\u7528\u5b57\u9762\u91cf\uff08\u5e38\u91cf\u7684\u4e00\u79cd\uff09\u521b\u5efa\u5bf9\u8c61\u5916\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u58f0\u660e\u8bed\u53e5\u521b\u5efa\uff0c\u5e76\u4e3a\u5176\u5206\u914d\u4e00\u4e2a\u6807\u8bc6\u7b26\uff0c\u4ee5\u63a9\u76d6\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u4e0e\u8bbf\u95ee\u5185\u5b58\u5730\u5740\u7684\u7ec6\u8282\u8fc7\u7a0b\uff0c\u5e76\u589e\u5f3a\u7a0b\u5e8f\u53ef\u8bfb\u6027\u3002

\u6807\u8bc6\u7b26

C \u6807\u51c6\u5b9a\u4e49\uff0c\u6807\u8bc6\u7b26\u662f\u6570\u5b57\u3001\u4e0b\u5212\u7ebf\u3001\u5c0f\u5199\u53ca\u5927\u5199\u62c9\u4e01\u5b57\u6bcd\u7684\u4efb\u610f\u957f\u5ea6\u5e8f\u5217\uff08\u4e0d\u8ba8\u8bba Unicode \u5b57\u7b26\uff09\u3002\u5408\u6cd5\u7684\u6807\u8bc6\u7b26\u5fc5\u987b\u4ee5\u975e\u6570\u5b57\u5b57\u7b26\u5f00\u59cb\uff0c\u4ee5\u533a\u522b\u4e8e\u6574\u6570\u5e38\u91cf\u6216\u6d6e\u70b9\u5e38\u91cf\u3002

\u6807\u8bc6\u7b26\u80fd\u6307\u4ee3\u4e0b\u5217\u7c7b\u578b\u7684\u5b9e\u4f53\uff1a

\u5b8f\u540d\u6216\u5b8f\u5f62\u53c2\u540d\u4ee5\u5916\u7684\u6bcf\u4e2a\u6807\u8bc6\u7b26\u90fd\u62e5\u6709\u4f5c\u7528\u57df\uff0c\u5e76\u53ef\u4ee5\u62e5\u6709\u94fe\u63a5\u3002\u76f8\u540c\u7684\u6807\u8bc6\u7b26\u53ef\u4ee5\u5728\u7a0b\u5e8f\u7684\u76f8\u5f02\u70b9\u6307\u4ee3\u76f8\u5f02\u5b9e\u4f53\u3002

\u5173\u952e\u5b57\u4e5f\u5c5e\u4e8e\u6807\u8bc6\u7b26\uff0c\u4f46\u5b83\u4eec\u88ab\u4fdd\u7559\uff0c\u4e0d\u53ef\u5728\u7a0b\u5e8f\u4e2d\u58f0\u660e\u3002\u4ee5\u4e00\u4e2a\u6216\u591a\u4e2a\u4e0b\u5212\u7ebf\u5f00\u59cb\u7684\u6807\u8bc6\u7b26\u4e5f\u4e0d\u5e94\u5728\u7a0b\u5e8f\u4e2d\u51fa\u73b0\uff1b\u6839\u636e\u7ea6\u5b9a\uff0c\u8fd9\u4e9b\u6807\u8bc6\u7b26\u5e94\u7531\u5e93\u7684\u5185\u90e8\u5b9e\u73b0\u4f7f\u7528\u3002\u53e6\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u6807\u8bc6\u7b26\u88ab\u6307\u5b9a\u4fdd\u7559\uff0c\u6b64\u5904\u4e0d\u518d\u5c55\u5f00\u3002

\u533a\u5206\u5bf9\u8c61\u6982\u5ff5

\u5982\u679c\u4f60\u5b66\u4e60\u8fc7\u6216\u5c06\u8981\u5b66\u4e60\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\uff0c\u8bf7\u4e25\u683c\u533a\u5206\u4e0d\u540c\u8bed\u8a00\u4e2d\u7684\u5bf9\u8c61\u6982\u5ff5\uff0c\u5c24\u5176\u662f\u9762\u5411\u5bf9\u8c61\u8bed\u8a00\u4e2d\u7684\u201c\u5bf9\u8c61\u201d\u3002

\u56e0\u6b64\uff0c\u58f0\u660e\u4e00\u4e2a\u53d8\u91cf\u5b9e\u9645\u4e0a\u5305\u62ec\u4e24\u6b65\uff1a\u9996\u5148\uff0c\u4e3a\u5bf9\u8c61\u7533\u8bf7\u4e00\u5757\u5bf9\u5e94\u5927\u5c0f\u7684\u5185\u5b58\u7a7a\u95f4\uff1b\u5176\u6b21\uff0c\u5c06\u6807\u8bc6\u7b26\u4e0e\u5bf9\u8c61\u76f8\u5173\u8054\u3002

\u5f53\u7a0b\u5e8f\u5c1d\u8bd5\u8bfb\u53d6\u6216\u4fee\u6539\u5bf9\u8c61\u7684\u5185\u5bb9\u65f6\uff0c\u6211\u4eec\u79f0\u7a0b\u5e8f\u8bbf\u95ee\u4e86\u8be5\u5bf9\u8c61\u6216\u8be5\u5185\u5b58\u5730\u5740\u3002

"},{"location":"programming/common/notes/pointers/#_5","title":"\u57fa\u672c\u8bed\u6cd5","text":""},{"location":"programming/common/notes/pointers/#_6","title":"\u6307\u9488\u7c7b\u578b","text":"

\u4e00\u822c\u800c\u8a00\uff0c\u63d0\u5230\u201c\u6307\u9488\u201d\u65f6\uff0c\u6211\u4eec\u5b9e\u9645\u8ba8\u8bba\u7684\u662f\u6307\u9488\u7c7b\u578b\u5bf9\u8c61\u3002

C \u6807\u51c6\u5bf9\u6307\u9488\u7c7b\u578b\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a

A pointer type may be derived from a function type, an object type, or an incomplete type, called the referenced type. A pointer type describes an object whose value provides a reference to an entity of the referenced type. A pointer type derived from the referenced type \\(T\\) is sometimes called \"pointer to \\(T\\)\".

C \u8bed\u8a00\u4e2d\uff0c\u6307\u9488\u7c7b\u578b\u4e0e\u5176\u4ed6\u7c7b\u578b\u62e5\u6709\u76f8\u540c\u7684\u5bf9\u8c61\u6a21\u578b\uff0c\u6307\u9488\u7c7b\u578b\u7684\u5bf9\u8c61\u540c\u6837\u9700\u8981\u7533\u8bf7\u5185\u5b58\u7a7a\u95f4\u4ee5\u5b58\u50a8\u503c\u3002\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\uff0c\u6307\u9488\u7c7b\u578b\u5bf9\u8c61\u7684\u503c\u4e3a\u201c\u53e6\u4e00\u4e2a\u5bf9\u8c61\u7684\u5f15\u7528\u201d\uff0c\u4e5f\u5373\u5176\u5185\u5b58\u5730\u5740\u3002\u6211\u4eec\u79f0\u6307\u9488\u7c7b\u578b\u7684\u5bf9\u8c61\u6307\u5411\u88ab\u5f15\u7528\u5bf9\u8c61\u3002

\u6307\u9488\u7c7b\u578b\u662f\u4e00\u79cd\u6d3e\u751f\u7c7b\u578b\uff0c\u8fd9\u610f\u5473\u7740\u5b8c\u6574\u7684\u6307\u9488\u7c7b\u578b\u5305\u62ec\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u7c7b\u578b\u3002\u7531\u4e8e\u5728\u5185\u5b58\u4e2d\u6240\u6709\u6570\u636e\u5747\u4ee5\u4e00\u7cfb\u5217\u8fde\u7eed\u4f4d\u7684\u5f62\u5f0f\u5b58\u50a8\uff0c\u4e3a\u6b63\u786e\u8bfb\u53d6\u6570\u636e\uff0c\u8fd9\u79cd\u989d\u5916\u7684\u8bb0\u5f55\u663e\u7136\u662f\u5fc5\u8981\u7684\u3002

\u76f8\u5bf9\u5e94\u5730\uff0c\u4e0d\u540c\u6307\u9488\u7c7b\u578b\u95f4\u662f\u5426\u517c\u5bb9\uff0c\u53d6\u51b3\u4e8e\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u7c7b\u578b\u662f\u5426\u517c\u5bb9\u3002

"},{"location":"programming/common/notes/pointers/#_7","title":"\u58f0\u660e","text":"

\u6307\u9488\u7c7b\u578b\u5bf9\u8c61\u7684\u58f0\u660e\u8bed\u6cd5\u5982\u4e0b\uff1a

type-specifier * qualifiers declarator\n

\u5176\u4e2d\uff0ctype-specifier \u4e3a\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u7c7b\u578b\uff0cqualifiers \u4e3a\u5bf9\u6307\u9488\u7c7b\u578b\u5bf9\u8c61\u7684\u9650\u5b9a\uff0cdeclarator\u4e3a\u6307\u9488\u7c7b\u578b\u5bf9\u8c61\u7684\u6807\u8bc6\u7b26\uff08\u540d\u79f0\uff09\u3002

\u6b63\u786e\u6dfb\u52a0\u9650\u5b9a\u4e0e\u5b58\u50a8\u7c7b\u578b\u8bf4\u660e

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u53ea\u6709\u51fa\u73b0\u5728 * \u4e0e\u6807\u8bc6\u7b26\u4e4b\u95f4\u7684\u9650\u5b9a\u624d\u4f1a\u88ab\u8d4b\u4e88\u6307\u9488\u7c7b\u578b\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 char * const p; \u58f0\u660e\u4e86\u4e00\u4e2a\u7c7b\u578b\u4e3a char * \u7684\u3001\u503c\u4e0d\u53ef\u53d8\u7684\u6307\u9488 p\uff0c\u5b83\u6307\u5411\u7684\u5bf9\u8c61\u7c7b\u578b\u4e3a char\uff0c\u503c\u53ef\u901a\u8fc7\u6307\u9488 p \u6539\u53d8\uff1b\u800c\u8bed\u53e5 const char * p; \u58f0\u660e\u4e86\u4e00\u4e2a\u7c7b\u578b\u4e3a const char * \u7684\u3001\u503c\u53ef\u53d8\u7684\u6307\u9488 p\uff0c\u5b83\u6307\u5411\u7684\u5bf9\u8c61\u7c7b\u578b\u4e3a const char\uff0c\u503c\u4e0d\u53ef\u901a\u8fc7\u6307\u9488 p \u6539\u53d8\u3002

\u53e6\u5916\uff0c\u5b58\u50a8\u7c7b\u578b\u8bf4\u660e\u7b26\u5e76\u6ca1\u6709\u7c7b\u4f3c\u7684\u8bed\u4e49\uff0c\u5b83\u5fc5\u987b\u7f6e\u4e8e * \u4e4b\u524d\u3002\u4ece\u8bed\u6cd5\u4e0a\u8bf4\uff0c\u5b83\u4eec\u5c5e\u4e8e\u8bf4\u660e\u7b26\u800c\u975e\u9650\u5b9a\u7b26\uff0c\u4e0d\u5e94\u7f6e\u4e8e * \u4e0e\u6807\u8bc6\u7b26\u4e4b\u95f4\uff1b\u4ece\u8bed\u4e49\u4e0a\u6765\u8bf4\uff0c\u8bb0\u5f55\u88ab\u5f15\u7528\u5bf9\u8c61\u7c7b\u578b\u7684\u76ee\u7684\u662f\u4ece\u76ee\u6807\u5185\u5b58\u5730\u5740\u6b63\u786e\u8bfb\u53d6\u6570\u636e\uff0c\u800c\u4e86\u89e3\u6307\u5411\u5bf9\u8c61\u7684\u5b58\u50a8\u7c7b\u578b\u5bf9\u8fd9\u4e00\u76ee\u7684\u6beb\u65e0\u5e2e\u52a9\u3002

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u58f0\u660e\u4e2d * \u53ea\u5bf9\u76f4\u63a5\u7ed3\u5408\u7684\u6807\u8bc6\u7b26\u751f\u6548\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5982\u679c\u901a\u8fc7\u8bed\u53e5 int * a, b; \u58f0\u660e\u53d8\u91cf a \u4e0e b\uff0c\u90a3\u4e48\u53ea\u6709 a \u4f1a\u88ab\u8ba4\u5b9a\u4e3a\u6307\u9488\u7c7b\u578b\u3002

\u5728\u58f0\u660e\u6307\u5411\u67d0\u4e9b\u7c7b\u578b\u5bf9\u8c61\u7684\u6307\u9488\u65f6\uff0c\u53ef\u901a\u8fc7\u62ec\u53f7\u4f7f * \u4f18\u5148\u4e0e\u6807\u8bc6\u7b26\u7ed3\u5408\uff0c\u4ee5\u907f\u514d\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u5dee\u5f02\u5bfc\u81f4\u7684\u6b67\u4e49\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 int *arr[3]; \u58f0\u660e\u4e86\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int * \u4e14\u957f\u5ea6\u4e3a 3 \u7684\u6570\u7ec4 arr\uff1b\u8bed\u53e5 int (*ptr)[3]; \u5219\u58f0\u660e\u4e86\u4e00\u4e2a\u6307\u9488 ptr\uff0c\u5b83\u6307\u5411\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int \u4e14\u957f\u5ea6\u4e3a 3 \u7684\u6570\u7ec4\u3002

\u6b64\u5916\uff0c\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u7c7b\u578b\u53ef\u4ee5\u662f\u4e0d\u5b8c\u6574\u7c7b\u578b\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 int (*p)[]; \u8868\u660e\u6307\u9488 p \u6307\u5411\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int\uff0c\u4e14\u957f\u5ea6\u672a\u77e5\u7684\u6570\u7ec4\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u4e0d\u5173\u5fc3\u6570\u7ec4\u957f\u5ea6\uff0c\u6216\u8005\u6570\u7ec4\u957f\u5ea6\u9700\u8981\u5728\u4e4b\u540e\u7684\u7a0b\u5e8f\u4e2d\u901a\u8fc7\u67d0\u4e9b\u65b9\u6cd5\u786e\u5b9a\u3002\u76f8\u5bf9\u5e94\u5730\uff0c\u65e0\u6cd5\u5bf9\u89e3\u5f15\u7528 p \u7684\u7ed3\u679c\u4f7f\u7528 sizeof \u8fd0\u7b97\u7b26\u3002

\u901a\u7528\u6307\u9488\u7c7b\u578b void *

\u7531\u4e8e void \u4e5f\u5c5e\u4e8e\u4e0d\u5b8c\u6574\u7c7b\u578b\uff0cvoid * \u540c\u6837\u662f\u5408\u6cd5\u7684\u6307\u9488\u7c7b\u578b\u3002\u5b83\u7684\u5b9e\u9645\u542b\u4e49\u662f\u6307\u9488\u6307\u5411\u4e00\u4e2a\u7c7b\u578b\u672a\u77e5\u7684\u5bf9\u8c61\uff0c\u4e5f\u5373\u6307\u9488\u53ef\u4ee5\u6307\u5411\u4efb\u4f55\u7c7b\u578b\u7684\u5bf9\u8c61\u3002\u81ea\u7136\u5730\uff0c\u6211\u4eec\u65e0\u6cd5\u89e3\u5f15\u7528\u8be5\u7c7b\u578b\u7684\u6307\u9488\u5bf9\u8c61\u3002\u4e0d\u8fc7\uff0c\u5b83\u53ef\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u4efb\u610f\u5176\u4ed6\u7c7b\u578b\u7684\u6307\u9488\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002

\u867d\u7136 C \u8bed\u8a00\u5728 C11 \u6807\u51c6\u524d\u5e76\u672a\u63d0\u4f9b\u6cdb\u578b\u7279\u6027\uff0c\u4f46\u901a\u8fc7\u5f15\u5165 void * \u7c7b\u578b\u53c2\u6570\uff0c\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u8bbe\u8ba1\u901a\u7528\u63a5\u53e3\uff0c\u4f7f\u7528\u76f8\u540c\u4ee3\u7801\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002\u4e00\u4e2a\u5178\u578b\u7684\u4f8b\u5b50\u662f\uff0cstdlib.h \u4e2d\u5b9a\u4e49\u7684 qsort \u4e0e bsearch \u65b9\u6cd5\u90fd\u901a\u8fc7\u5c06\u6570\u7ec4\u6307\u9488 ptr \u7684\u7c7b\u578b\u89c4\u5b9a\u4e3a void *\uff0c\u5b9e\u73b0\u4e86\u65e0\u89c6\u6570\u7ec4\u5143\u7d20\u7c7b\u578b\u91cd\u7528\u6392\u5e8f\u4ee3\u7801\u7684\u6548\u679c\u3002

\u5f53\u7136\uff0c\u56e0\u4e3a\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u7c7b\u578b\u672a\u77e5\uff0c\u6b64\u65f6 C \u8bed\u8a00\u7f16\u8bd1\u5668\u65e0\u6cd5\u5e2e\u4f60\u68c0\u67e5\u7c7b\u578b\u517c\u5bb9\u95ee\u9898\uff0c\u6240\u4ee5\u4f7f\u7528 void * \u7c7b\u578b\u6307\u9488\u65f6\u9700\u4e07\u5206\u5c0f\u5fc3\u3002

"},{"location":"programming/common/notes/pointers/#_8","title":"\u503c\u4e0e\u8fd0\u7b97","text":"

\u901a\u8fc7\u6307\u9488\u83b7\u5f97\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u8fc7\u7a0b\u79f0\u4e3a\u89e3\u5f15\u7528\uff0c\u7531\u8fd0\u7b97\u7b26 * \u5b8c\u6210\uff1b\u901a\u8fc7\u67d0\u4e2a\u5bf9\u8c61\u83b7\u5f97\u6307\u5411\u8be5\u5bf9\u8c61\u6307\u9488\u7684\u8fc7\u7a0b\u79f0\u4e3a\u53d6\u5740\uff0c\u7531\u8fd0\u7b97\u7b26 & \u5b8c\u6210\u3002

\u7ed3\u5408\u8d4b\u503c\u64cd\u4f5c\uff0c\u53ef\u6839\u636e\u9700\u8981\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u5e76\u4fee\u6539\u6307\u5411\u7684\u5bf9\u8c61\uff0c\u6216\u4ee4\u6307\u9488\u6307\u5411\u4e0d\u540c\u7684\u5bf9\u8c61\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5bf9\u4e8e int \u7c7b\u578b\u53d8\u91cf a\uff0c\u8bed\u53e5 p = &a; \u5c06\u4f7f\u6307\u9488 p \u7684\u503c\u8bbe\u4e3a a \u7684\u5185\u5b58\u5730\u5740\uff0c\u4e5f\u5373\u4ee4 p \u6307\u5411 a\uff1b\u5728\u6b64\u57fa\u7840\u4e0a\uff0c\u8bed\u53e5 *p = 1; \u5c06\u6539\u53d8 p \u6307\u5411\u7684\u5bf9\u8c61\uff0c\u4e5f\u5373\u53d8\u91cf a \u7684\u503c\u3002

\u4e0d\u8fc7\uff0c\u5728\u7f16\u5199\u8868\u8fbe\u5f0f\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u7684\u5f71\u54cd\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8868\u8fbe\u5f0f *p++ \u5c06\u4f7f\u6307\u9488 p \u7684\u503c\u81ea\u589e 1\uff0c\u800c\u8868\u8fbe\u5f0f (*p)++ \u5c06\u4f7f\u6307\u9488 p \u6307\u5411\u5bf9\u8c61\u7684\u503c\u81ea\u589e 1\u3002

\u7406\u89e3\u521d\u59cb\u5316\u8bed\u53e5\u4e2d\u7684 * \u8fd0\u7b97\u7b26

C \u8bed\u8a00\u7684\u8bed\u6cd5\u529b\u56fe\u4f7f\u58f0\u660e\u548c\u4f7f\u7528\u76f8\u4e00\u81f4\u3002

\u5728\u9605\u8bfb\u6307\u9488\u521d\u59cb\u5316\u8bed\u53e5\u65f6\uff0c\u4f60\u53ef\u80fd\u5e38\u5e38\u6df7\u6dc6 * \u7684\u58f0\u660e\u4e0e\u89e3\u5f15\u7528\u8bed\u6cd5\u3002\u6b63\u786e\u5206\u8fa8\u7684\u8981\u70b9\u5728\u4e8e\uff0c\u521d\u59cb\u5316\u8bed\u53e5\u5206\u4e3a\u58f0\u660e\u548c\u521d\u59cb\u5316\u5668\u4e24\u90e8\u5206\uff0c\u5176\u4e2d\u8d4b\u503c\u53f7 = \u524d\u7684\u90e8\u5206\u4e3a\u58f0\u660e\uff0c\u8d4b\u503c\u53f7\u53ca\u5176\u540e\u7684\u90e8\u5206\u4e3a\u521d\u59cb\u5316\u5668\u3002

\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5728\u8bed\u53e5 int *ip = *ipp; \u4e2d\uff0cint *ip \u4e3a\u58f0\u660e\uff0c= *ipp \u4e3a\u521d\u59cb\u5316\u5668\uff0c\u8fd9\u6761\u8bed\u53e5\u7684\u542b\u4e49\u662f\uff1a\u58f0\u660e\u4e00\u4e2a\u6307\u5411 int \u7c7b\u578b\u5bf9\u8c61\u7684\u6307\u9488 ip\uff0c\u5e76\u5c06\u5b83\u7684\u521d\u59cb\u503c\u8bbe\u4e3a ipp \u6307\u5411\u5bf9\u8c61\u7684\u503c\u3002

\u91ce\u6307\u9488

\u58f0\u660e\u81ea\u52a8\u4f5c\u7528\u57df\u7684\u5bf9\u8c61\u540e\uff0cC \u8bed\u8a00\u4ec5\u4fdd\u8bc1\u53ef\u4ee5\u6b63\u5e38\u8bbf\u95ee\u5e76\u4fee\u6539\u8be5\u5bf9\u8c61\uff0c\u800c\u4e0d\u4fdd\u8bc1\u5176\u521d\u59cb\u5185\u5bb9\uff0c\u8fd9\u70b9\u5bf9\u6307\u9488\u540c\u6837\u6210\u7acb\u3002\u5982\u679c\u58f0\u660e\u4e86\u4e00\u4e2a\u6307\u9488\u5374\u6ca1\u6709\u8d4b\u503c\uff0c\u8fd9\u4e2a\u6307\u9488\u7684\u6307\u5411\u4fbf\u65e0\u6cd5\u786e\u5b9a\uff0c\u6211\u4eec\u79f0\u5b83\u4e3a\u91ce\u6307\u9488\u3002

\u56e0\u4e3a\u91ce\u6307\u9488\u53ef\u80fd\u6307\u5411\u4efb\u610f\u5185\u5b58\u6bb5\uff0c\u4e0d\u52a0\u9274\u522b\u7684\u968f\u610f\u4f7f\u7528\u53ef\u80fd\u5bfc\u81f4\u8bbf\u95ee\u975e\u6cd5\u5185\u5b58\u3001\u635f\u574f\u6b63\u5e38\u6570\u636e\uff0c\u751a\u81f3\u9020\u6210\u5176\u4ed6\u672a\u77e5\u540e\u679c\u3002\u5c1d\u8bd5\u89e3\u5f15\u7528\u91ce\u6307\u9488\u662f\u6bb5\u9519\u8bef\uff08Segmentation Fault\uff09\u7684\u4e3b\u8981\u8bf1\u56e0\u4e4b\u4e00\u3002\u56e0\u6b64\uff0c\u58f0\u660e\u6307\u9488\u65f6\u52a1\u5fc5\u5b8c\u6210\u521d\u59cb\u5316\u3002

\u6bcf\u79cd\u7c7b\u578b\u7684\u6307\u9488\u90fd\u542b\u6709\u4e00\u4e2a\u8be5\u7c7b\u578b\u7684\u7279\u6b8a\u503c\uff0c\u79f0\u4e3a\u7a7a\u6307\u9488\u503c\u3002\u503c\u4e3a\u7a7a\u7684\u6307\u9488\u4e0d\u6307\u5411\u4efb\u4f55\u5bf9\u8c61\uff0c\u4e14\u89e3\u5f15\u7528\u7a7a\u6307\u9488\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\u3002\u53ef\u4f7f\u7528\u7a7a\u6307\u9488\u7b26\u53f7\u5e38\u91cf NULL \u4e3a\u6307\u9488\u8d4b\u7a7a\u503c\uff0c\u5b83\u5728 stdio.h\u3001stdlib.h\u3001string.h\u3001stddef.h \u7b49\u5e38\u7528\u5e93\u4e2d\u5747\u6709\u5b9a\u4e49\u3002\u6839\u636e C \u8bed\u8a00\u6807\u51c6\uff0cNULL \u7684\u503c\u4e3a 0\u3002

\u7a7a\u6307\u9488\u5e38\u91cf NULL \u7684\u503c

\u6839\u636e C \u6807\u51c6\u5b9a\u4e49\uff0c\u5b8f NULL \u662f\u5b9e\u73b0\u5b9a\u4e49\u7684\u7a7a\u6307\u9488\u5e38\u91cf\uff0c\u5b83\u53ef\u4ee5\u662f\u503c\u4e3a 0 \u7684\u6574\u6570\u5e38\u91cf\u8868\u8fbe\u5f0f\uff0c\u6216\u8005\u88ab\u8f6c\u6362\u4e3a void * \u7c7b\u578b\u7684\u6b64\u7c7b\u8868\u8fbe\u5f0f\u3002

\u90a3\u4e48\uff0c\u4e3a\u4ec0\u4e48 NULL \u7684\u503c\u88ab\u89c4\u5b9a\u4e3a 0 \u5462\uff1f

\u4f60\u53ef\u80fd\u4f1a\u731c\u60f3\uff0c\u8fd9\u662f\u56e0\u4e3a\u5185\u5b58\u5730\u5740 0x0 \u88ab\u7cfb\u7edf\u9884\u7559\u3002\u5bf9\u65e9\u671f\u64cd\u4f5c\u7cfb\u7edf\u800c\u8a00\uff0c\u8fd9\u79cd\u8bf4\u6cd5\u662f\u6210\u7acb\u7684\uff1b\u4f46\u662f\u73b0\u5728\uff0c\u4e0d\u540c\u5e73\u53f0\u5bf9\u7a7a\u6307\u9488\u7684\u503c\u5df2\u7ecf\u6709\u8bb8\u591a\u4e0d\u540c\u7684\u89c4\u5b9a\u3002\u65e0\u8bba NULL \u7684\u503c\u88ab\u5982\u4f55\u5b9a\u4e49\uff0c\u94fe\u63a5\u5668\u90fd\u5e94\u5c06\u7a7a\u6307\u9488\u7684\u503c\u6539\u4e3a\u76ee\u6807\u5e73\u53f0\u6307\u5b9a\u7684\u7a7a\u6307\u9488\u503c\u3002\u4e3a\u4e86\u5f3a\u8c03\u8fd9\u4e00\u70b9\uff0cC++11 \u5f15\u5165\u4e86 nullptr \u5173\u952e\u5b57\uff0c\u4f46 C \u6807\u51c6\u5e76\u672a\u5bf9\u6b64\u4f5c\u4efb\u4f55\u4fee\u6539\u3002

\u56de\u5230\u95ee\u9898\u672c\u8eab\uff0c\u5c06 0 \u89c6\u4f5c\u7279\u6b8a\u503c\u7684\u4e60\u60ef\u662f\u4e00\u4e2a\u6bd4\u8f83\u6709\u8bf4\u670d\u529b\u7684\u7406\u7531\u3002\u6b64\u5916\uff0c\u5c06 NULL \u5b9a\u4e49\u4e3a 0 \u4e5f\u53ef\u4ee5\u7b80\u5316\u8868\u8fbe\u5f0f\uff0c\u5373\u5229\u7528 C \u8bed\u8a00\u5c06 0 \u89c6\u4e3a false \u7684\u7279\u6027\uff0c\u7b80\u5316\u5bf9\u6307\u9488\u662f\u5426\u4e3a\u7a7a\u7684\u5224\u65ad\u3002

\u4e24\u4e2a\u7c7b\u578b\u517c\u5bb9\u7684\u6307\u9488\u95f4\u7684\u8d4b\u503c\u8fd0\u7b97\u3001\u6bd4\u8f83\u8fd0\u7b97\u4e0e\u51cf\u6cd5\u8fd0\u7b97\u662f\u6709\u6548\u7684\u3002\u82e5\u6307\u9488\u7c7b\u578b\u4e0d\u517c\u5bb9\uff0c\u5219\u9700\u8981\u8fdb\u884c\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u3002\u8fd9\u79cd\u8fd0\u7b97\u4ec5\u5728\u5c11\u6570\u60c5\u5f62\u4e0b\u6709\u610f\u4e49\uff0c\u5982\u4e24\u4e2a\u6307\u9488\u4f4d\u4e8e\u540c\u4e00\u6570\u7ec4\u5185\u65f6\u3002

\u6307\u9488\u4e0e\u6574\u6570\u95f4\u7684\u52a0\u6cd5\u6216\u51cf\u6cd5\u8fd0\u7b97\u4e5f\u662f\u6709\u6548\u7684\uff0c\u5176\u542b\u4e49\u662f\u4ee4\u6307\u9488\u524d\u79fb\u6216\u540e\u79fb\u82e5\u5e72\u4e2a\u6307\u5411\u5bf9\u8c61\u7684\u957f\u5ea6\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8868\u8fbe\u5f0f p + n \u7684\u503c\uff0c\u4ee3\u8868\u6307\u9488 p \u5f53\u524d\u6307\u5411\u7684\u5bf9\u8c61\u4e4b\u540e\u7b2c n \u4e2a\u5bf9\u8c61\u7684\u5730\u5740\u3002\u8fd9\u79cd\u8fd0\u7b97\u5728\u6570\u7ec4\u4e0e\u5b57\u7b26\u4e32\u64cd\u4f5c\u4e2d\u5341\u5206\u5e38\u89c1\u3002

\u867d\u7136\u5185\u5b58\u5730\u5740\u5f80\u5f80\u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u4f46\u662f\u6307\u9488\u4e0e\u6574\u6570\u4e4b\u95f4\u4e0d\u80fd\u76f8\u4e92\u8f6c\u6362\uff0c0 \u662f\u552f\u4e00\u7684\u4f8b\u5916\uff1a\u5e38\u91cf 0 \u53ef\u4ee5\u8d4b\u503c\u7ed9\u6307\u9488\uff0c\u6307\u9488\u4e5f\u53ef\u4e0e\u5e38\u91cf 0 \u8fdb\u884c\u6bd4\u8f83\u3002\u663e\u7136\uff0c\u6b64\u65f6\u5e38\u91cf 0 \u5c06\u88ab\u89c6\u4e3a\u7a7a\u6307\u9488 NULL\u3002

\u9664\u4ee5\u4e0a\u8fd0\u7b97\u5916\uff0c\u5176\u4ed6\u5f62\u5f0f\u7684\u6307\u9488\u8fd0\u7b97\u90fd\u662f\u975e\u6cd5\u7684\u3002

"},{"location":"programming/common/notes/pointers/#_9","title":"\u7528\u6cd5\u6982\u8ff0","text":""},{"location":"programming/common/notes/pointers/#_10","title":"\u53c2\u6570\u4f20\u9012","text":"

\u5728 C \u8bed\u8a00\u4e2d\uff0c\u8c03\u7528\u51fd\u6570\u65f6\u4ee5\u503c\u4f20\u9012\u5f62\u5f0f\u4f20\u9012\u53c2\u6570\uff1b\u5177\u4f53\u800c\u8a00\uff0c\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6\u4f1a\u91cd\u65b0\u521b\u5efa\u5f62\u53c2\uff0c\u5e76\u5c06\u5b9e\u53c2\u7684\u503c\u590d\u5236\u5230\u5bf9\u5e94\u7684\u5f62\u53c2\u3002\u51fd\u6570\u53ef\u4ee5\u4fee\u6539\u81ea\u8eab\u5f62\u53c2\uff0c\u4f46\u662f\u5b9e\u53c2\u7684\u503c\u4e0d\u4f1a\u968f\u4e4b\u6539\u53d8\u3002\u8fd9\u79cd\u8bbe\u8ba1\u5c06\u51fd\u6570\u4e0e\u6570\u636e\u9694\u79bb\uff0c\u907f\u514d\u4ea7\u751f\u610f\u6599\u4e4b\u5916\u7684\u526f\u4f5c\u7528\u3002

C \u8bed\u8a00\u4e2d\u53ea\u6709\u503c\u4f20\u9012

\u5982\u679c\u4f60\u5b66\u4e60\u8fc7 C++\uff0c\u4f60\u53ef\u80fd\u4f1a\u60f3\u5230\u5c06\u5f62\u53c2\u7684\u7c7b\u578b\u58f0\u660e\u4e3a\u5f15\u7528\uff0c\u968f\u540e\u901a\u8fc7\u5f15\u7528\u6539\u53d8\u5b9e\u53c2\u7684\u503c\u3002\u7136\u800c\uff0cC \u8bed\u8a00\u4e2d\u6ca1\u6709\u5f15\u7528\u7c7b\u578b\uff0c\u5728\u5f62\u53c2\u7c7b\u578b\u4e2d\u6dfb\u52a0 & \u662f\u975e\u6cd5\u7684\u3002

\u4e0d\u8fc7\uff0c\u5982\u679c\u6211\u4eec\u671f\u671b\u51fd\u6570\u4ea7\u751f\u526f\u4f5c\u7528\uff0c\u503c\u4f20\u9012\u7684\u65b9\u5f0f\u4fbf\u65e0\u6cd5\u6ee1\u8db3\u9700\u6c42\u3002\u4e3a\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u5f15\u5165\u6307\u9488\u7c7b\u578b\u7684\u53c2\u6570\uff0c\u4ee5\u8fbe\u5230\u4fee\u6539\u5176\u4ed6\u5bf9\u8c61\u7684\u76ee\u7684\u3002

\u6848\u4f8b\uff1a\u4ea4\u6362\u51fd\u6570

\u5047\u8bbe fake_swap \u51fd\u6570\u5b9a\u4e49\u5982\u4e0b\uff1a

void fake_swap(int x, int y) {\n    int tmp = x;\n    x = y;\n    y = tmp;\n}\n

\u8c03\u7528\u90e8\u5206\u5982\u4e0b\uff1a

int a = 1, b = 2;\nfake_swap(a, b);\n

\u5728\u8c03\u7528 fake_swap \u51fd\u6570\u540e\u68c0\u67e5 a\u3001b \u7684\u503c\uff0c\u53ef\u53d1\u73b0\u5b83\u4eec\u7684\u503c\u5e76\u6ca1\u6709\u4ea4\u6362\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u8c03\u7528 fake_swap \u51fd\u6570\u65f6\uff0c\u5b9e\u53c2 a\u3001b \u7684\u503c\u88ab\u590d\u5236\u7ed9\u5f62\u53c2 x\u3001y\uff0c\u51fd\u6570\u4ec5\u4fee\u6539\u4e86\u5f62\u53c2\u7684\u503c\uff0c\u5e76\u672a\u5f71\u54cd\u51fd\u6570\u5916\u90e8\u7684\u5b9e\u53c2\u3002

\u73b0\u5728\uff0c\u6211\u4eec\u5c06 fake_swap \u51fd\u6570\u4fee\u6539\u4e3a\uff1a

void swap(int *x, int *y) {\n    int tmp = *x;\n    *x = *y;\n    *y = tmp;\n}\n

\u8c03\u7528\u90e8\u5206\u5982\u4e0b\uff1a

int a = 1, b = 2;\nswap(&a, &b);\n

\u5728\u8c03\u7528 swap \u51fd\u6570\u540e\u68c0\u67e5 a\u3001b \u7684\u503c\uff0c\u53ef\u53d1\u73b0\u5b83\u4eec\u7684\u503c\u5df2\u7ecf\u4ea4\u6362\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u8c03\u7528 swap \u51fd\u6570\u65f6\uff0c\u5b9e\u53c2 a\u3001b \u7684\u5730\u5740\u88ab\u590d\u5236\u7ed9\u5f62\u53c2 x\u3001y\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0cx\u3001y \u5206\u522b\u6307\u5411 a\u3001b\u3002\u51fd\u6570\u4fee\u6539\u4e86 x\u3001y \u6307\u5411\u5bf9\u8c61\u7684\u503c\uff0c\u4e5f\u5c31\u662f a\u3001b \u7684\u503c\uff0c\u56e0\u6b64\u867d\u7136 a\u3001b \u5728\u51fd\u6570\u5916\u90e8\uff0c\u4f46\u5b83\u4eec\u7684\u503c\u5df2\u88ab\u6210\u529f\u4fee\u6539\u3002

C \u8bed\u8a00\u4e2d\u7684\u51fd\u6570\u53ea\u6709\u4e00\u4e2a\u8fd4\u56de\u503c\u3002\u82e5\u8981\u8fd4\u56de\u591a\u4e2a\u503c\uff0c\u53ef\u5c06\u6240\u6709\u8fd4\u56de\u503c\u653e\u5165\u7ed3\u6784\u4f53\u4e2d\uff1b\u4f46\u662f\uff0c\u8fd9\u9700\u8981\u989d\u5916\u58f0\u660e\u4e00\u4e2a\u4e34\u65f6\u4f7f\u7528\u7684\u7ed3\u6784\u4f53\u7c7b\u578b\uff0c\u62c6\u89e3\u7ed3\u6784\u4f53\u7684\u8fc7\u7a0b\u4e5f\u8017\u65f6\u8017\u529b\u3002\u4e00\u4e2a\u66f4\u597d\u7684\u65b9\u6848\u662f\uff0c\u5411\u51fd\u6570\u4f20\u9012\u6307\u9488\u53c2\u6570\uff0c\u7531\u51fd\u6570\u901a\u8fc7\u6307\u9488\u5c06\u7ed3\u679c\u5199\u5165\u76ee\u6807\u5bf9\u8c61\u3002\u6211\u4eec\u7ecf\u5e38\u4f7f\u7528\u7684 scanf \u51fd\u6570\u4fbf\u662f\u4e00\u4e2a\u5178\u578b\u4f8b\u5b50\u3002

"},{"location":"programming/common/notes/pointers/#_11","title":"\u64cd\u4f5c\u6570\u7ec4","text":"

\u4e00\u822c\u800c\u8a00\uff0c\u63d0\u5230\u201c\u6570\u7ec4\u201d\u65f6\uff0c\u6211\u4eec\u8ba8\u8bba\u7684\u65e2\u53ef\u4ee5\u662f\u6570\u7ec4\u7c7b\u578b\uff0c\u4e5f\u53ef\u4ee5\u662f\u6570\u7ec4\u7c7b\u578b\u7684\u5bf9\u8c61\u3002

\u6307\u9488\u4e0e\u6570\u7ec4\u7684\u5173\u7cfb\u5341\u5206\u5bc6\u5207\uff0c\u5b83\u4eec\u4e4b\u95f4\u7684\u8f6c\u6362\u4e5f\u662f C \u8bed\u8a00\u4e2d\u6700\u5e38\u89c1\u7684\u7c7b\u578b\u8f6c\u6362\u4e4b\u4e00\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u7528\u6307\u9488\u7f16\u5199\u7684\u7a0b\u5e8f\u6bd4\u7528\u6570\u7ec4\u7f16\u5199\u7684\u7a0b\u5e8f\u6267\u884c\u901f\u5ea6\u5feb\uff0c\u4f46\u53ef\u8bfb\u6027\u76f8\u5bf9\u8f83\u5dee\u3002

\u9605\u8bfb\u5efa\u8bae

\u4e0b\u6587\u7684\u8ba8\u8bba\u4e2d\u4f1a\u8bb2\u89e3\u6570\u7ec4\u7684\u90e8\u5206\u7279\u6027\uff0c\u4e0d\u8fc7\u4ecd\u7136\u5efa\u8bae\u5728\u719f\u6089\u6570\u7ec4\u540e\u9605\u8bfb\u3002

"},{"location":"programming/common/notes/pointers/#_12","title":"\u6570\u7ec4\u9000\u5316","text":"

\u6570\u7ec4\u7684\u503c\u5c31\u662f\u8be5\u6570\u7ec4\u7b2c\u4e00\u4e2a\u5143\u7d20\u7684\u5730\u5740\uff1b\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u6570\u7ec4\u4e5f\u7ecf\u5e38\u53ef\u88ab\u770b\u4f5c\u6307\u5411\u5176\u9996\u5143\u7d20\u6307\u9488\u3002\u4e8b\u5b9e\u4e0a\uff0cC \u6807\u51c6\u5bf9\u6b64\u4f5c\u5982\u4e0b\u89c4\u5b9a\uff1a

\u4efb\u4f55\u6570\u7ec4\u7c7b\u578b\u7684\u5de6\u503c\u8868\u8fbe\u5f0f\uff0c\u5f53\u7528\u4e8e\u5f02\u4e8e

\u7684\u8bed\u5883\u65f6\uff0c\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u3002

\u4e60\u60ef\u4e0a\uff0c\u6211\u4eec\u5c06\u6570\u7ec4\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u8fc7\u7a0b\uff0c\u79f0\u4e3a\u6570\u7ec4\u9000\u5316\u4e3a\u6307\u9488\u3002

C \u6807\u51c6\u89c4\u5b9a\uff0c\u8868\u8fbe\u5f0f E1[E2] \u7b49\u4ef7\u4e8e (*((E1) + (E2)))\u3002\u8fd9\u610f\u5473\u7740\uff0c\u6570\u7ec4\u5143\u7d20\u5728\u5185\u5b58\u4e2d\u8fde\u7eed\u3002\u53e6\u5916\uff0c\u5982\u679c\u786e\u4fe1\u76f8\u5e94\u5143\u7d20\u5b58\u5728\uff0c\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u8d85\u51fa\u6570\u7ec4\u8303\u56f4\u7684\u4e0b\u6807\uff0c\u8bbf\u95ee\u6570\u7ec4\u524d\u540e\u7684\u5143\u7d20\u3002

\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c

C \u8bed\u8a00\u4e0d\u4f1a\u68c0\u67e5\u6570\u7ec4\u4e0b\u6807\u662f\u5426\u8d85\u8fc7\u6570\u7ec4\u957f\u5ea6\uff0c\u5bf9\u6307\u9488\u4e5f\u51e0\u4e4e\u6ca1\u6709\u9650\u5236\u63aa\u65bd\u3002\u5c1d\u8bd5\u8bbf\u95ee\u8d85\u51fa\u6570\u7ec4\u8fb9\u754c\u7684\u5185\u5b58\u5730\u5740\uff0c\u53ef\u80fd\u5bfc\u81f4\u4e0e\u5c1d\u8bd5\u89e3\u5f15\u7528\u91ce\u6307\u9488\u7b49\u540c\u7684\u5371\u5bb3\u3002\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c\u662f\u6bb5\u9519\u8bef\u7684\u4e3b\u8981\u8bf1\u56e0\u4e4b\u4e00\u3002\u56e0\u6b64\uff0c\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u524d\uff0c\u52a1\u5fc5\u5145\u5206\u68c0\u67e5\u6307\u5b9a\u7684\u4e0b\u6807\u4e0e\u6307\u9488\u504f\u79fb\u91cf\u662f\u5426\u5728\u6570\u7ec4\u8303\u56f4\u5185\u3002

\u7531\u4e8e\u590d\u5236\u6570\u7ec4\u7684\u5f00\u9500\u7ecf\u5e38\u5927\u5230\u4e0d\u53ef\u63a5\u53d7\uff0cC \u6807\u51c6\u89c4\u5b9a\uff0c\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u65f6\u6570\u7ec4\u4e5f\u5e94\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u5176\u9996\u5143\u7d20\u6307\u9488\u3002\u6240\u4ee5\uff0c\u5728\u8bed\u6cd5\u5c42\u9762\u4e0a\uff0c\u51fd\u6570\u58f0\u660e\u4e0e\u5b9a\u4e49\u4e2d\uff0c\u5f62\u5982 char str[] \u7684\u5f62\u53c2\u58f0\u660e\u4e0e char *str \u662f\u7b49\u4ef7\u7684\uff0c\u4e0d\u8fc7\u524d\u8005\u53ef\u4ee5\u63d0\u9192\u51fd\u6570\u7f16\u5199\u8005\u4e0e\u4f7f\u7528\u8005\u7559\u610f str \u7684\u5b9e\u9645\u542b\u4e49\u3002\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f20\u5165\u6307\u5411\u5176\u4ed6\u5143\u7d20\u7684\u6307\u9488\uff0c\u8fd9\u5728\u4f20\u53c2\u8fc7\u7a0b\u4e2d\u6ca1\u6709\u533a\u522b\u3002

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd4\u56de\u7c7b\u578b\u4e2d\u7684\u6570\u7ec4\u4e0d\u4f1a\u81ea\u52a8\u8f6c\u6362\u6210\u6307\u9488\uff0c\u56e0\u6b64\u5f62\u5982 char func() []; \u7684\u51fd\u6570\u58f0\u660e\u662f\u975e\u6cd5\u7684\u3002

\u6570\u7ec4\u7c7b\u578b\u4e0e\u6307\u9488\u7c7b\u578b\u7684\u533a\u522b

\u5c3d\u7ba1\u5728\u7a0b\u5e8f\u4e2d\u6570\u7ec4\u7ecf\u5e38\u9000\u5316\u4e3a\u6307\u9488\uff0c\u6211\u4eec\u4ecd\u5e94\u8be5\u533a\u5206\u8fd9\u4e24\u4e2a\u7c7b\u578b\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8003\u8651\u5982\u4e0b\u7684\u7a0b\u5e8f\u7247\u6bb5\uff08C \u6807\u51c6\u89c4\u5b9a sizeof \u7684\u8fd4\u56de\u503c\u7c7b\u578b\u4e3a\u65e0\u7b26\u53f7\u6574\u578b size_t\uff0c\u5e94\u4f7f\u7528 %zu \u683c\u5f0f\u6307\u793a\u7b26\u8f93\u51fa\uff09\uff1a

int a[3], *p;\nprintf(\"%zu %zu\", sizeof(a), sizeof(p));\n

\u5b83\u5c06\u4f1a\u8f93\u51fa 12 8\u3002\u8fd9\u662f\u56e0\u4e3a\uff0ca \u662f\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int \u4e14\u957f\u5ea6\u4e3a 3 \u7684\u6570\u7ec4\u5bf9\u8c61\uff0c\u5728\u591a\u6570\u7cfb\u7edf\u4e2d int \u7c7b\u578b\u957f\u5ea6\u4e3a 4 \u5b57\u8282\uff0c\u56e0\u6b64 a \u7684\u957f\u5ea6\u4e3a 12 \u5b57\u8282\uff1b\u800c p \u662f\u4e00\u4e2a\u6307\u9488\uff0c\u5728\u5e38\u7528\u7684 64 \u4f4d\u7cfb\u7edf\u4e2d\u957f\u5ea6\u4e3a 8 \u5b57\u8282\u3002

\u53e6\u5916\uff0c\u6307\u9488\u7684\u503c\u53ef\u5728\u4efb\u610f\u65f6\u523b\u901a\u8fc7\u8d4b\u503c\u4fee\u6539\uff0c\u800c\u6570\u7ec4\u4e0d\u80fd\u88ab\u8d4b\u503c\u3002

"},{"location":"programming/common/notes/pointers/#_13","title":"\u591a\u7ef4\u6570\u7ec4","text":"

\u4e0e\u6307\u9488\u7c7b\u4f3c\uff0c\u6570\u7ec4\u4e5f\u662f\u6d3e\u751f\u7c7b\u578b\u3002\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\uff0c\u4e3a\u4e86\u6b63\u786e\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff0c\u9700\u8981\u77e5\u9053\u6570\u7ec4\u5143\u7d20\u7684\u957f\u5ea6\uff0c\u5373\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u578b\u5fc5\u987b\u662f\u5b8c\u6574\u7684\u3002

\u591a\u7ef4\u6570\u7ec4

\u6211\u4eec\u79f0\u5143\u7d20\u7c7b\u578b\u4e3a\u6570\u7ec4\u7684\u6570\u7ec4\u4e3a\u591a\u7ef4\u6570\u7ec4\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c[] \u8fd0\u7b97\u7b26\u662f\u4ece\u53f3\u5f80\u5de6\u7ed3\u5408\u7684\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 int a[2][3]; \u58f0\u660e\u4e86\u4e00\u4e2a\u957f\u5ea6\u4e3a 2\u7684\u6570\u7ec4 a\uff0c\u5b83\u7684\u5143\u7d20\u7c7b\u578b\u4e3a int [3]\uff1b\u5bf9\u5e94\u5730\uff0c\u901a\u8fc7\u8868\u8fbe\u5f0f a[x][y] \u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u65f6\uff0cx \u4e0e y \u7684\u53d6\u503c\u8303\u56f4\u5206\u522b\u4e3a 0~1 \u4e0e 0~2\u3002

\u5f53\u5e94\u7528\u6570\u7ec4\u5230\u6307\u9488\u8f6c\u6362\u65f6\uff0c\u591a\u7ef4\u6570\u7ec4\u88ab\u8f6c\u6362\u6210\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u6307\u9488\u3002\u6211\u4eec\u79f0\u8fd9\u79cd\u6307\u5411\u6570\u7ec4\u7684\u6307\u9488\u4e3a\u6570\u7ec4\u6307\u9488\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0cint [2][3] \u7c7b\u578b\u7684\u4e8c\u7ef4\u6570\u7ec4\u4f1a\u88ab\u8f6c\u6362\u4e3a int (*)[3] \u7c7b\u578b\u7684\u6570\u7ec4\u6307\u9488\u3002

\u6848\u4f8b\uff1a\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u591a\u7ef4\u6570\u7ec4\u5143\u7d20

\u6839\u636e C \u6807\u51c6\u89c4\u5b9a\uff0c\u4e0d\u96be\u63a8\u65ad\u51fa\u8868\u8fbe\u5f0f a[i][j] \u4e0e\u8868\u8fbe\u5f0f *(*(a + i) + j) \u7b49\u4ef7\u3002\u4e0d\u8fc7\uff0c\u540e\u8005\u7684\u6c42\u503c\u8fc7\u7a0b\u76f8\u6bd4\u524d\u8005\u66f4\u52a0\u62bd\u8c61\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u5c06\u4ee5\u6b64\u4e3a\u4f8b\u9010\u6b65\u5206\u6790\u5176\u6c42\u503c\u8fc7\u7a0b\u3002

  1. \u5047\u8bbe a \u7684\u7c7b\u578b\u4e3a int [2][3]\u3002\u6211\u4eec\u77e5\u9053\uff0c\u6b64\u5904\u6570\u7ec4 a \u4f1a\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a int (*)[3] \u7c7b\u578b\u7684\u6307\u9488\u3002\u56de\u5fc6\u4e00\u4e0b\u6307\u9488\u4e0e\u6574\u6570\u7684\u52a0\u51cf\u6cd5\u8fd0\u7b97\uff0cp + i \u5e76\u975e\u7b80\u5355\u5730\u5c06\u6307\u9488 p \u7684\u503c\u589e\u52a0 i \u5b57\u8282\uff0c\u800c\u662f\u589e\u52a0 i \u4e2a int [3] \u7c7b\u578b\u5bf9\u8c61\u7684\u957f\u5ea6\uff0c\u5373 i * sizeof(int [3]) \u5b57\u8282\u3002

  2. \u4e0d\u59a8\u79f0\u6570\u7ec4 a \u9690\u5f0f\u8f6c\u6362\u7684\u6307\u9488\u4e3a ap\u3002\u90a3\u4e48\uff0c\u5185\u5c42\u8868\u8fbe\u5f0f\u53ef\u6539\u5199\u4e3a *(ap + i)\uff0c\u5176\u542b\u4e49\u662f\u4ece a \u5f00\u59cb\uff0c\u5411\u540e\u79fb\u52a8 i * sizeof(int [3]) \u4e2a\u5b57\u8282\uff0c\u5e76\u83b7\u5f97\u8be5\u5185\u5b58\u5730\u5740\u5b58\u50a8\u7684 int [3] \u7c7b\u578b\u7684\u6570\u7ec4\u3002\u6b64\u65f6\uff0c\u6211\u4eec\u5f97\u5230\u4e86\u6570\u7ec4 a[i]\u3002

  3. \u4e0d\u59a8\u79f0\u4e0a\u4e00\u6b65\u5f97\u5230\u7684\u6570\u7ec4\u4e3a a_i\u3002\u90a3\u4e48\uff0c\u4e0b\u4e00\u5c42\u8868\u8fbe\u5f0f\u53ef\u4ee5\u6539\u5199\u4e3a *(a_i + j)\uff0c\u5176\u542b\u4e49\u662f\u4ece a_i \u5f00\u59cb\uff0c\u5411\u540e\u79fb\u52a8 j * sizeof(int) \u4e2a\u5b57\u8282\uff0c\u5e76\u83b7\u5f97\u8be5\u5185\u5b58\u5730\u5740\u5b58\u50a8\u7684 int \u7c7b\u578b\u5bf9\u8c61\u7684\u503c\u3002\u4e0d\u96be\u770b\u51fa\uff0c\u6211\u4eec\u5f97\u5230\u7684\u7ed3\u679c\u6b63\u662f a[i][j] \u7684\u503c\u3002

\u6709\u5fc5\u8981\u8bf4\u660e\uff0c\u4ee5\u4e0a\u5206\u6790\u8fc7\u7a0b\u5bf9\u6240\u6709\u6574\u6570 i\u3001j \u5747\u6210\u7acb\u3002\u8fd9\u610f\u5473\u7740\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8868\u8fbe\u5f0f a[1][-1] \u8bbf\u95ee a[0] \u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002\u7136\u800c\uff0c\u6b64\u7c7b\u8868\u8fbe\u5f0f\u53ef\u8bfb\u6027\u4e0d\u5f3a\uff0c\u6700\u597d\u5728\u5b9e\u9645\u7a0b\u5e8f\u4e2d\u907f\u514d\u3002

\u6307\u9488\u6570\u7ec4

\u6211\u4eec\u79f0\u5143\u7d20\u7c7b\u578b\u4e3a\u6307\u9488\u7684\u6570\u7ec4\u4e3a\u6307\u9488\u6570\u7ec4\u3002\u5bb9\u6613\u60f3\u5230\uff0c\u6307\u9488\u6570\u7ec4\u5176\u5b9e\u662f\u4e2a\u4e00\u7ef4\u6570\u7ec4\uff1b\u4e0d\u8fc7\u7531\u4e8e\u5176\u5143\u7d20\u7c7b\u578b\u4e3a\u6307\u9488\uff0c\u8bbf\u95ee\u5143\u7d20\u7684\u5f62\u5f0f\u4e0e\u591a\u7ef4\u6570\u7ec4\u6709\u90e8\u5206\u76f8\u4f3c\u4e4b\u5904\u3002\u6307\u9488\u6570\u7ec4\u7684\u4e00\u4e2a\u5178\u578b\u7528\u6cd5\u662f\u5b58\u50a8\u5e76\u4f20\u9012\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u5373\u4e00\u79cd main \u51fd\u6570\u58f0\u660e int main(int argc, char *argv[]) \u4e2d\u7684 argv \u53c2\u6570\u3002

\u7c7b\u4f3c\u5730\uff0c\u6211\u4eec\u79f0\u6307\u5411\u67d0\u4e2a\u6307\u9488\u7684\u6307\u9488\u4e3a\u591a\u7ea7\u6307\u9488\u3002\u4e8c\u7ea7\u6307\u9488\u5e38\u89c1\u4e8e\u94fe\u8868\u64cd\u4f5c\u4e2d\uff0c\u66f4\u9ad8\u7ea7\u7684\u6307\u9488\u5219\u5f88\u5c11\u51fa\u73b0\u3002

\u6570\u7ec4\u9000\u5316\u7684\u9650\u5ea6

\u56de\u5fc6\u4e0a\u6587\u5f15\u7528\u7684 C \u6807\u51c6\u89c4\u5b9a\uff0c\u82e5\u8bed\u5883\u6ee1\u8db3\u6761\u4ef6\uff0c\u6570\u7ec4\u5c06\u4f1a\u9690\u5f0f\u8f6c\u6362\u4e3a\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u6307\u9488\u3002\u8fd9\u610f\u5473\u7740\uff0c\u6570\u7ec4\u9000\u5316\u7684\u9650\u5ea6\u662f\u5c06\u6307\u9488\u7ea7\u6570\u589e\u52a0\u4e00\u7ea7\u3002\u6211\u4eec\u53ef\u4ee5\u60f3\u5230\uff0c\u8fd9\u4e00\u9650\u5ea6\u662f\u4e3a\u4e86\u786e\u4fdd\u8fd0\u7b97\u7b26 [] \u7684\u6b63\u786e\u6027\uff0c\u5373\u4fdd\u8bc1\u6309\u6807\u51c6\u4e0e\u5176\u7b49\u4ef7\u7684\u6307\u9488\u8fd0\u7b97\u53ef\u4ee5\u6b63\u786e\u8ba1\u7b97\u504f\u79fb\u91cf\u3002\u56e0\u6b64\uff0c\u4e8c\u7ef4\u6570\u7ec4\u4e0d\u80fd\u9690\u5f0f\u8f6c\u6362\u4e3a\u4e8c\u7ea7\u6307\u9488\u3002\u7f16\u8bd1\u5668\u5bf9\u6b64\u5c06\u4f1a\u7ed9\u51fa\u8b66\u544a\u3002

"},{"location":"programming/common/notes/pointers/#_14","title":"\u5b57\u7b26\u4e32","text":"

\u6211\u4eec\u77e5\u9053\uff0cC \u8bed\u8a00\u4e2d\u7684\u5b57\u7b26\u4e32\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u7a7a\u5b57\u7b26\uff08\u79f0\u4e3a\u4e2d\u6b62\u5b57\u7b26\uff09\u7ed3\u5c3e\u7684\u5b57\u7b26\u6570\u7ec4\u3002\u56e0\u6b64\uff0c\u4e0a\u4e00\u5c0f\u8282\u7684\u8ba8\u8bba\u540c\u6837\u9002\u7528\u4e8e\u8fd9\u4e00\u5c0f\u8282\u3002

\u7531\u4e8e\u5b57\u7b26\u4e32\u540c\u65f6\u5177\u6709\u6570\u7ec4\u7684\u5c5e\u6027\uff0c\u8ba8\u8bba\u4e0e\u5185\u5b58\u7a7a\u95f4\u6709\u5173\u7684\u6982\u5ff5\u4e0e\u64cd\u4f5c\u65f6\uff0c\u4e3a\u907f\u514d\u6df7\u6dc6\uff0c\u6211\u4eec\u5c06\u6570\u7ec4\u5bf9\u8c61\u5360\u7528\u7684\u5b57\u8282\u6570\u79f0\u4e3a\u5176\u5927\u5c0f\uff0c\u5c06\u5b9e\u9645\u7ec4\u6210\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u6570\u79f0\u4e3a\u5176\u957f\u5ea6\u3002\u4e00\u4e2a\u76f4\u89c2\u7406\u89e3\u662f\uff0c\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u8ba1\u5165\u4e2d\u6b62\u5b57\u7b26\uff0c\u800c\u5176\u957f\u5ea6\u4e0d\u8ba1\u5165\u3002

\u5728 C \u8bed\u8a00\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u662f\u7531\u4e00\u5bf9 \" \u5305\u56f4\u7684\u4efb\u610f\u957f\u5ea6\u7684\u5b57\u7b26\u5e8f\u5217\uff0c\u5176\u4e2d\u7684\u5b57\u7b26\u53ef\u4ee5\u662f\u4e00\u822c\u5b57\u7b26\u6216\u8f6c\u4e49\u5b57\u7b26\uff0c\u5982 \"abc\"\u3001\"x y\\nz\"\u3001\"\"\u3002\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u672b\u5c3e\u9690\u5f0f\u5305\u542b\u4e2d\u6b62\u5b57\u7b26\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\"\" \u4ee3\u8868\u5927\u5c0f\u4e3a 1 \u7684\u5b57\u7b26\u6570\u7ec4\uff0c\u5b83\u7684\u552f\u4e00\u5143\u7d20\u4e3a '\\0'\u3002

\u542b\u7a7a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u5b57\u9762\u91cf

\u82e5\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5b57\u7b26\u5e8f\u5217\u5185\u5305\u542b\u7a7a\u5b57\u7b26\uff0c\u5219\u5b83\u8868\u793a\u542b\u6709\u591a\u4e8e\u4e00\u6761\u5b57\u7b26\u4e32\u7684\u6570\u7ec4\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5bf9\u4e8e\u5b57\u7b26\u4e32\u5b57\u9762\u91cf \"abc\\0\"\uff0c\u5b83\u5305\u542b \"abc\" \u548c \"\" \u4e24\u4e2a\u5b57\u7b26\u4e32\u3002

\u4f60\u53ef\u4ee5\u901a\u8fc7 sizeof \u8fd0\u7b97\u7b26\u548c strlen \u51fd\u6570\u9a8c\u8bc1\u7a0b\u5e8f\u884c\u4e3a\u3002

\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u7c7b\u578b\u4e3a char [N]\uff0c\u5176\u4e2d N \u662f\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\uff0c\u5305\u62ec\u9690\u5f0f\u7684\u4e2d\u6b62\u5b57\u7b26\u3002\u663e\u7136\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u4e5f\u9075\u5b88\u6570\u7ec4\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u89c4\u5219\u3002

\u5c1d\u8bd5\u4fee\u6539\u5b57\u7b26\u4e32\u5b57\u9762\u91cf

\u867d\u7136\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u7c7b\u578b\u6ca1\u6709\u6307\u5b9a\u4e3a const\uff0c\u4f46\u5b83\u5b9e\u9645\u4e0a\u4e5f\u662f\u5e38\u91cf\u3002\u5c1d\u8bd5\u4fee\u6539\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\u3002\u4e00\u822c\u800c\u8a00\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5185\u5bb9\u4f1a\u88ab\u653e\u5165\u53ea\u8bfb\u5185\u5b58\u4e2d\uff0c\u56e0\u6b64\u5c1d\u8bd5\u4fee\u6539\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u9519\u8bef\u3002

\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u672a\u9000\u5316\u60c5\u5f62

\u8003\u8651\u5982\u4e0b\u7a0b\u5e8f\u7247\u6bb5\uff1a

char *str = \"abc\";\nprintf(\"%zu %zu\\n\", sizeof(\"abc\"), sizeof(str));\n

\u5b83\u5c06\u4f1a\u8f93\u51fa 4 8\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u6b64\u65f6\u5b57\u7b26\u4e32\u5b57\u9762\u91cf \"abc\" \u88ab\u4f5c\u4e3a sizeof \u7684\u64cd\u4f5c\u6570\uff0c\u4e0d\u4f1a\u9000\u5316\u4e3a\u6307\u9488\uff0c\u56e0\u6b64\u8868\u8fbe\u5f0f sizeof(\"abc\") \u7684\u7ed3\u679c\u662f\u5b57\u7b26\u4e32\u6570\u7ec4\u7684\u5927\u5c0f\u3002

\u4e0d\u96be\u60f3\u5230\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5176\u6548\u679c\u76f8\u5f53\u4e8e\u4f7f\u7528\u5bf9\u5e94\u7684\u5b57\u7b26\u6570\u7ec4\u5e38\u91cf\u521d\u59cb\u5316\u3002\u4e0e\u4e00\u822c\u7684\u6570\u7ec4\u521d\u59cb\u5316\u7c7b\u4f3c\uff0c\u6570\u7ec4\u957f\u5ea6\u53ef\u7531\u521d\u59cb\u5316\u5668\u9690\u5f0f\u6307\u5b9a\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 char str[] = \"abc\"; \u7b49\u4ef7\u4e8e\u8bed\u53e5 char str[] = {'a', 'b', 'c', '\\0'};\uff0c\u5b83\u58f0\u660e\u5e76\u521d\u59cb\u5316\u4e86\u4e00\u4e2a\u957f\u5ea6\u4e3a 4 \u7684\u5b57\u7b26\u6570\u7ec4 str\u3002

\u6570\u7ec4\u7684\u5927\u5c0f\u53ef\u4ee5\u6bd4\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5927\u5c0f\u5c11 1\uff0c\u6b64\u65f6\u4e2d\u6b62\u5b57\u7b26\u5c06\u88ab\u5ffd\u7565\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 char str[3] = \"abc\"; \u7b49\u4ef7\u4e8e\u8bed\u53e5 char str[3] = {'a', 'b', 'c'};\u3002

\u6848\u4f8b\uff1a\u9519\u8bef\u7684\u5b57\u7b26\u6570\u7ec4\u521d\u59cb\u5316

\u8003\u8651\u5982\u4e0b\u7a0b\u5e8f\u7247\u6bb5\uff1a

char str[3] = \"abc\";\nchar backdoor[] = \"xyz\";\nprintf(\"%s\", str);\n

\u5b83\u5c06\u4f1a\u8f93\u51fa abcxyz\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf \"abc\" \u7684\u5927\u5c0f str \u7684\u5927\u5c0f\u5927 1\uff0c\u521d\u59cb\u5316\u65f6\u4e2d\u6b62\u5b57\u7b26\u88ab\u5ffd\u7565\uff0cstr \u6700\u7ec8\u88ab\u521d\u59cb\u5316\u4e3a {'a', 'b', 'c'}\u3002\u5c06\u5176\u89c6\u4e3a\u5b57\u7b26\u4e32\u5e76\u8f93\u51fa\u65f6\uff0c\u7531\u4e8e str \u5185\u4e0d\u542b\u4e2d\u6b62\u5b57\u7b26\uff0c\u8f93\u51fa\u51fd\u6570\u5c06\u4f1a\u7ee7\u7eed\u8bbf\u95ee str \u540e\u7684\u5185\u5b58\u5730\u5740\uff0c\u5373\u51fa\u73b0\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c\u95ee\u9898\u3002

\u7531\u4e8e C \u6807\u51c6\u5e76\u672a\u5bf9\u5b57\u9762\u91cf\u7684\u5185\u5b58\u6392\u5e03\u4f5c\u4efb\u4f55\u89c4\u5b9a\uff0c\u5728\u4e0d\u540c\u73af\u5883\u4e0b\u5b57\u7b26\u4e32\u5e38\u91cf backdoor \u7684\u5185\u5b58\u5730\u5740\u53ef\u80fd\u4f4d\u4e8e str \u7684\u5185\u5b58\u5730\u5740\u4e4b\u524d\u3002\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u6539\u53d8\u58f0\u660e\u987a\u5e8f\u4ee5\u8fbe\u5230\u7c7b\u4f3c\u7684\u8f93\u51fa\u6548\u679c\u3002

\u6839\u636e\u9690\u5f0f\u8f6c\u6362\u89c4\u5219\uff0c\u5728\u591a\u6570\u8868\u8fbe\u5f0f\u4e2d\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u5c06\u4f1a\u9690\u5f0f\u8f6c\u6362\u4e3a\u6307\u5411\u5b83\u7684\u6307\u9488\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8be5\u6307\u9488\u7684\u503c\u662f\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5185\u5b58\u5730\u5740\u3002\u7c7b\u4f3c\u5730\uff0c\u88ab\u7528\u4e8e\u5bf9\u6307\u9488\u7684\u521d\u59cb\u5316\u65f6\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u4e5f\u4f1a\u9000\u5316\u4e3a\u6307\u9488\u3002

\u5728\u51fd\u6570\u5185\u4fee\u6539\u5b57\u7b26\u4e32\u65f6\uff0c\u4f20\u5165\u7684\u5b57\u7b26\u6570\u7ec4\u5c06\u4f1a\u9000\u5316\u4e3a\u6307\u9488\uff0c\u6570\u7ec4\u7684\u5927\u5c0f\u4fe1\u606f\u56e0\u6b64\u4e22\u5931\u3002\u53ef\u4ee5\u60f3\u5230\uff0c\u5b57\u7b26\u4e32\u672b\u5c3e\u7684\u7a7a\u5b57\u7b26\u6b63\u662f\u4e3a\u8fd9\u79cd\u60c5\u5f62\u8bbe\u8ba1\u7684\u3002

\u7b80\u5316\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570

\u5173\u4e8e\u5229\u7528\u6307\u9488\u7f16\u5199\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\u7684\u6280\u5de7\uff0c\u4f60\u53ef\u4ee5\u53c2\u8003\u300aC \u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u300b\uff08\u4e5f\u5c31\u662f\u7a0b\u8bbe\u8bfe\u7a0b\u4f7f\u7528\u7684\u8bfe\u672c\uff09\u4e2d\u7ed9\u51fa\u7684 strcpy \u4e0e strcmp \u51fd\u6570\u7684\u5b9e\u73b0\u8fed\u4ee3\u3002\u672c\u6587\u5bf9\u6b64\u4e0d\u518d\u8d58\u8ff0\u3002

C \u8bed\u8a00\u6807\u51c6\u5e93\u4e2d\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\uff0c\u5b83\u4eec\u5927\u591a\u88ab\u5b9a\u4e49\u5728 string.h \u5934\u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528\u65f6\u5747\u9700\u4fdd\u8bc1\u63d0\u4f9b\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u7b26\u5408\u7ea6\u5b9a\u3002

\u4e2d\u6b62\u5b57\u7b26\u7f3a\u5931

\u6807\u51c6\u5e93\u4e2d\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\u901a\u8fc7\u68c0\u67e5\u4e2d\u6b62\u5b57\u7b26\u5224\u65ad\u662f\u5426\u5230\u8fbe\u5b57\u7b26\u4e32\u672b\u5c3e\u3002\u56e0\u6b64\uff0c\u5728\u4fee\u6539\u5b57\u7b26\u4e32\u65f6\u52a1\u5fc5\u6ce8\u610f\u4fdd\u7559\u4e2d\u6b62\u5b57\u7b26\u3002\u5982\u679c\u4e2d\u6b62\u5b57\u7b26\u7f3a\u5931\uff0c\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\u5c06\u4f1a\u5bfc\u81f4\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c\u95ee\u9898\u3002

"},{"location":"programming/common/notes/pointers/#_15","title":"\u51fd\u6570\u6307\u9488","text":"

\u6709\u65f6\uff0c\u6211\u4eec\u5e0c\u671b\u51fd\u6570\u53ef\u4ee5\u9075\u5faa\u6307\u5b9a\u7684\u89c4\u5219\uff0c\u6216\u8005\u5b8c\u6210\u6307\u5b9a\u64cd\u4f5c\uff0c\u4f46\u662f\u53c8\u4e0d\u5e0c\u671b\u6216\u65e0\u6cd5\u5b9e\u73b0\u4e00\u7cfb\u5217\u9ad8\u5ea6\u76f8\u4f3c\u7684\u51fd\u6570\uff0c\u56e0\u6b64\u6211\u4eec\u5e0c\u671b\u5728\u53c2\u6570\u4e2d\u5f15\u5165\u53e6\u4e00\u4e2a\u51fd\u6570\u3002C \u8bed\u8a00\u4e3a\u6b64\u63d0\u4f9b\u4e86\u6307\u5411\u51fd\u6570\u7684\u6307\u9488\uff0c\u79f0\u4e3a\u51fd\u6570\u6307\u9488\u3002

\u5728\u7f16\u8bd1\u5f97\u5230\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\uff0c\u7a0b\u5e8f\u4e2d\u7684\u6307\u4ee4\u4e0e\u6570\u636e\u88ab\u5206\u522b\u5b58\u50a8\uff0c\u4ee5\u4f9b CPU \u8bbf\u95ee\u5e76\u4f7f\u7528\u3002\u51fd\u6570\u6307\u9488\u7684\u503c\uff0c\u5b9e\u9645\u4e0a\u662f\u51fd\u6570\u7b2c\u4e00\u6761\u6307\u4ee4\u7684\u5730\u5740\uff0c\u4e5f\u5373\u51fd\u6570\u7684\u5165\u53e3\u5730\u5740\u3002

\u51fd\u6570\u7684\u5185\u5b58\u5e03\u5c40

\u5728\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\uff0c\u6307\u4ee4\u4e0e\u6570\u636e\u88ab\u5206\u522b\u5b58\u50a8\u5728\u4ee3\u7801\u6bb5\u4e0e\u6570\u636e\u6bb5\u4e2d\u3002\u6bcf\u4e2a\u51fd\u6570\u7684\u6307\u4ee4\u5f80\u5f80\u88ab\u5b58\u50a8\u5728\u4ee3\u7801\u6bb5\u4e2d\u7684\u4e00\u6bb5\u8fde\u7eed\u5185\u5b58\u7a7a\u95f4\u4e2d\uff0c\u6839\u636e\u8fd9\u4e00\u7279\u70b9\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u51fd\u6570\u770b\u4f5c\u4e00\u79cd\u7279\u6b8a\u7684\u5bf9\u8c61\u3002

\u4e0e\u6570\u7ec4\u7c7b\u4f3c\uff0c\u51fd\u6570\u4e5f\u4f1a\u9000\u5316\u4e3a\u6307\u9488\u3002C \u6807\u51c6\u5bf9\u6b64\u4f5c\u5982\u4e0b\u89c4\u5b9a\uff1a

\u4efb\u4f55\u51fd\u6570\u6307\u4ee3\u5668\u8868\u8fbe\u5f0f\uff0c\u5728\u7528\u4e8e\u5f02\u4e8e\u4e0b\u5217\u8bed\u5883\u65f6

\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u8868\u8fbe\u5f0f\u6240\u6307\u4ee3\u51fd\u6570\u7684\u6307\u9488\u7684\u8f6c\u6362\u3002

\u5229\u7528\u8fd9\u4e2a\u89c4\u5219\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u540d\u4e3a\u51fd\u6570\u6307\u9488\u8d4b\u503c\uff0c\u4e5f\u53ef\u4ee5\u5199\u51fa\u590d\u6742\u7684\u8868\u8fbe\u5f0f\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c() \u8fd0\u7b97\u7b26\u4e5f\u662f\u4ece\u53f3\u5f80\u5de6\u7ed3\u5408\u7684\uff0c\u4e14\u4f18\u5148\u7ea7\u9ad8\u4e8e * \u8fd0\u7b97\u7b26\u3002\u4e3e\u4f8b\u800c\u8a00\uff0c\u8bed\u53e5 int *f(void); \u58f0\u660e\u4e86\u4e00\u4e2a\u51fd\u6570 f\uff0c\u5b83\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u4e3a int *\uff1b\u800c\u8bed\u53e5 int (*fp)(void); \u58f0\u660e\u4e86\u4e00\u4e2a\u51fd\u6570\u6307\u9488 fp\uff0c\u5b83\u6307\u5411\u4e00\u4e2a\u8fd4\u56de\u503c\u7c7b\u578b\u4e3a int \u7684\u51fd\u6570\u3002

\u51fd\u6570\u6307\u9488\u8bed\u53e5\u9605\u8bfb\u7ec3\u4e60

\u53e6\u4e00\u7bc7\u7b14\u8bb0\u7ec6\u81f4\u8bb2\u89e3\u4e86\u5982\u4f55\u9605\u8bfb\u5e76\u7406\u89e3\u5305\u542b\u51fd\u6570\u6307\u9488\u7684\u8bed\u53e5\uff0c\u672c\u6587\u5bf9\u6b64\u4e0d\u518d\u8d58\u8ff0\u3002

"},{"location":"programming/common/notes/pointers/#_16","title":"\u7ed3\u6784\u4f53\u4e0e\u5185\u5b58\u7ba1\u7406","text":"

\u9605\u8bfb\u5efa\u8bae

\u4e0b\u6587\u7684\u8ba8\u8bba\u4e2d\u4f1a\u8bb2\u89e3\u7ed3\u6784\u4f53\u7684\u90e8\u5206\u7279\u6027\uff0c\u4e0d\u8fc7\u4ecd\u7136\u5efa\u8bae\u5728\u719f\u6089\u7ed3\u6784\u4f53\u540e\u9605\u8bfb\u3002

\u7ed3\u6784\u4f53\u662f\u4e00\u79cd\u805a\u5408\u7c7b\u578b\uff0c\u5b83\u5c06\u591a\u4e2a\u4e0d\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\u7ec4\u5408\u6210\u4e00\u4e2a\u5bf9\u8c61\u3002\u7ed3\u6784\u4f53\u7ecf\u5e38\u88ab\u7528\u4e8e\u7ed9\u4e00\u4e2a\u590d\u6742\u6982\u5ff5\u5efa\u7acb\u6a21\u578b\u3002

\u5728\u590d\u6742\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u7ebf\u6027\u7684\u6570\u7ec4\u5f80\u5f80\u65e0\u6cd5\u5c55\u793a\u6570\u636e\u95f4\u7684\u903b\u8f91\u5173\u7cfb\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u5f80\u5f80\u4f1a\u5927\u91cf\u4f7f\u7528\u7ed3\u6784\u4f53\u4e0e\u7ed3\u6784\u4f53\u6307\u9488\u3002\u7531\u4e8e\u901a\u8fc7\u7ed3\u6784\u4f53\u6307\u9488\u8bbf\u95ee\u5176\u6210\u5458\u7684\u60c5\u5f62\u5341\u5206\u5e38\u89c1\uff0cC \u8bed\u8a00\u63d0\u4f9b\u4e86 -> \u8fd0\u7b97\u7b26\u4ee5\u7b80\u5316\u8868\u8fbe\u5f0f\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8868\u8fbe\u5f0f p->x \u7b49\u4ef7\u4e8e (*p).x\u3002

\u7531\u4e8e\u5efa\u7acb\u8fc7\u7a0b\u6bd4\u8f83\u7e41\u7410\uff0c\u6211\u4eec\u5e0c\u671b\u4e00\u76f4\u5b58\u50a8\u5b8c\u6210\u5efa\u7acb\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4ee5\u4f9b\u7a0b\u5e8f\u4e2d\u7684\u5176\u4ed6\u90e8\u5206\u4f7f\u7528\uff1b\u53e6\u4e00\u65b9\u9762\uff0c\u5b83\u4eec\u5f80\u5f80\u4f1a\u5360\u7528\u6bd4\u8f83\u591a\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u56e0\u6b64\u6211\u4eec\u4e5f\u5e0c\u671b\u5728\u9700\u8981\u65f6\u7acb\u523b\u9500\u6bc1\u3002\u5bf9\u4e8e\u8fd9\u4e9b\u9700\u6c42\uff0c\u65e0\u8bba\u662f\u5168\u5c40\u53d8\u91cf\u8fd8\u662f\u9759\u6001\u5c40\u90e8\u53d8\u91cf\u90fd\u4ecd\u7136\u4e0d\u591f\u7075\u6d3b\u3002\u4e3a\u6b64\uff0cC \u8bed\u8a00\u5728 stdlib.h \u4e2d\u63d0\u4f9b\u4e86\u52a8\u6001\u5185\u5b58\u7ba1\u7406\u51fd\u6570\u3002

\u5e38\u7528\u7684\u52a8\u6001\u5185\u5b58\u7ba1\u7406\u51fd\u6570\u5305\u62ec malloc \u4e0e free\uff0c\u5b83\u4eec\u5206\u522b\u8d1f\u8d23\u7533\u8bf7\u4e0e\u91ca\u653e\u5185\u5b58\u7a7a\u95f4\u3002

\u5185\u5b58\u6cc4\u9732

\u901a\u8fc7\u52a8\u6001\u5185\u5b58\u7ba1\u7406\u63a5\u53e3\u7533\u8bf7\u7684\u5185\u5b58\u7a7a\u95f4\u5c06\u4f1a\u4e00\u76f4\u88ab\u5360\u7528\uff0c\u76f4\u5230\u7a0b\u5e8f\u7ed3\u675f\u6216\u624b\u52a8\u91ca\u653e\u3002\u5982\u679c\u4f60\u6ca1\u6709\u53ca\u65f6\u91ca\u653e\u5b83\u4eec\uff0c\u672a\u91ca\u653e\u5185\u5b58\u5c06\u65e0\u6cd5\u88ab\u518d\u5206\u914d\u3002\u5806\u79ef\u7684\u672a\u91ca\u653e\u5185\u5b58\u6700\u7ec8\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u8d85\u8fc7\u7cfb\u7edf\u9650\u989d\uff0c\u6211\u4eec\u79f0\u4e3a\u5185\u5b58\u6cc4\u9732\uff0c\u6b64\u65f6\u7a0b\u5e8f\u5c06\u4f1a\u88ab\u7cfb\u7edf\u5f3a\u5236\u7ec8\u6b62\u3002\u56e0\u6b64\uff0c\u52a1\u5fc5\u5728\u4e0d\u518d\u4f7f\u7528\u52a8\u6001\u5185\u5b58\u65f6\u53ca\u65f6\u91ca\u653e\u3002

\u60ac\u5782\u6307\u9488

\u91ca\u653e\u7533\u8bf7\u5f97\u5230\u7684\u5185\u5b58\u7a7a\u95f4\u540e\uff0c\u6307\u5411\u8be5\u5185\u5b58\u7a7a\u95f4\u7684\u6307\u9488\u5c06\u4f1a\u53d8\u6210\u60ac\u5782\u6307\u9488\u3002\u5c1d\u8bd5\u7ee7\u7eed\u4f7f\u7528\u60ac\u5782\u6307\u9488\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002

\u53e6\u5916\uff0c\u5c1d\u8bd5\u91ca\u653e\u60ac\u5782\u6307\u9488\uff0c\u5373\u4e8c\u6b21\u91ca\u653e\u540c\u4e00\u5757\u5185\u5b58\u5730\u5740\uff0c\u540c\u6837\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\u3002\u4e8c\u6b21\u91ca\u653e\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002

"},{"location":"programming/common/notes/pointers/#_17","title":"\u8fdb\u9636\u6280\u5de7","text":"

\u9605\u8bfb\u5efa\u8bae

\u672c\u8282\u4e3a\u62d3\u5c55\u5185\u5bb9\uff0c\u4e0d\u5728\u7a0b\u7b97\u8bfe\u7a0b\u8981\u6c42\u8303\u56f4\u5185\u3002\u5982\u679c\u4f60\u80fd\u591f\u719f\u7ec3\u4f7f\u7528\u6307\u9488\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u9605\u8bfb\u5e76\u7406\u89e3\u4ee5\u4e0b\u5185\u5bb9\u3002

\u8f93\u51fa\u4e00\u7cfb\u5217\u7a7a\u683c\u5206\u9694\u7684\u6570\u5b57\uff0c\u672b\u5c3e\u65e0\u591a\u4f59\u7a7a\u683c

\u8fd9\u79cd\u60c5\u5f62\u5e38\u89c1\u4e8e OJ \u7684\u8f93\u51fa\u8981\u6c42\u4e2d\u3002

\u5bf9\u4e8e\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 a\uff0c\u4e00\u4e2a\u5178\u578b\u7684\u5b9e\u73b0\u7a0b\u5e8f\u5982\u4e0b\u3002

printf(\"%d\", a[0]);\nfor (int i = 1; i < n; i++)\n{\n    printf(\" %d\", a[i]);\n}\n

\u4e0d\u96be\u770b\u51fa\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u4e00\u6b21\u5224\u65ad\uff0c\u5c06\u5faa\u73af\u5916\u7684\u8f93\u51fa\u8bed\u53e5\u653e\u5165\u5faa\u73af\u5185\u3002

for (int i = 0; i < n; i++)\n{\n    printf((!i) ? \"%d\" : \" %d\", a[i]);\n}\n

\u8fd9\u4e2a\u7248\u672c\u7684\u7a0b\u5e8f\u770b\u8d77\u6765\u66f4\u52a0\u6574\u6d01\u3002\u540c\u65f6\uff0c\u901a\u8fc7\u5c06\u8868\u8fbe\u5f0f (!i) \u66ff\u6362\u4e3a\u5176\u4ed6\u6807\u5fd7\uff0c\u8be5\u7a0b\u5e8f\u53ef\u5728\u9700\u8981\u65f6\u53e6\u8d77\u4e00\u884c\uff0c\u5e76\u4ee5\u76f8\u540c\u683c\u5f0f\u8f93\u51fa\u5269\u4f59\u7ed3\u679c\u3002\u8fd9\u610f\u5473\u7740\u8f93\u51fa\u7684\u7075\u6d3b\u6027\u5927\u5927\u589e\u5f3a\u3002

\u4e0d\u8fc7\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u7ed9\u51fa\u66f4\u52a0\u70ab\u6280\u7684\u5199\u6cd5\u3002

for (int i = 0; i < n; i++)\n{\n    printf(\" %d\" + !i, a[i]);\n}\n

\u8fd9\u4e2a\u7248\u672c\u7684\u7a0b\u5e8f\u901a\u8fc7\u6307\u9488\u8fd0\u7b97\uff0c\u6539\u53d8\u4e86\u5b57\u7b26\u4e32\u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u4ece\u800c\u6539\u53d8\u4e86\u8f93\u51fa\u683c\u5f0f\u3002\u5177\u4f53\u800c\u8a00\uff0ci \u4e3a 0 \u65f6\uff0cprintf \u5b9e\u9645\u63a5\u6536\u7684\u683c\u5f0f\u5b57\u7b26\u4e32\u4e3a \"%d\"\uff0c\u5373\u4e0d\u5728\u884c\u9996\u8f93\u51fa\u7a7a\u683c\u3002

\u76f8\u6bd4\u524d\u4e00\u7248\u672c\uff0c\u8fd9\u4e00\u7248\u672c\u53ea\u6709\u51cf\u5c11\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u6570\u91cf\u8fd9\u4e00\u610f\u4e49\u4e0d\u5927\u7684\u63d0\u5347\u3002\uff08\u4f46\u7528\u6765\u70ab\u6280\u518d\u597d\u4e0d\u8fc7\u4e86 :P\uff09

\u8f93\u51fa\u6d6e\u70b9\u6570\u7684\u4e8c\u8fdb\u5236\u8868\u793a

\u4e00\u4e2a\u5178\u578b\u7684\u8f93\u51fa\u6574\u6570\u4e8c\u8fdb\u5236\u8868\u793a\u7684\u7a0b\u5e8f\u5982\u4e0b\uff1a

int a = 1;\nfor (int i = 0; i < 32; i++)\n    printf(\"%d\", (a >> (31 - i)) & 1);\n

\u7531\u4e8e\u6d6e\u70b9\u6570\u4e0d\u80fd\u8fdb\u884c\u4f4d\u8fd0\u7b97\uff0c\u6211\u4eec\u65e0\u6cd5\u50cf\u4ee5\u4e0a\u7a0b\u5e8f\u4e00\u6837\u76f4\u63a5\u8f93\u51fa\u6bcf\u4e00\u4f4d\uff08bit\uff09\u3002\u5982\u679c\u5c06\u6d6e\u70b9\u6570\u5f3a\u5236\u8f6c\u6362\u6210\u6574\u6570\uff0c\u5c06\u4f1a\u76f4\u63a5\u5bf9\u6d6e\u70b9\u6570\u53d6\u6574\uff0c\u5bfc\u81f4\u7cbe\u5ea6\u4e22\u5931\u3002

\u4e3a\u4e86\u89c4\u907f\u8fd9\u4e00\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6307\u9488\u7c7b\u578b\u8f6c\u6362\uff0c\u6539\u53d8\u5bf9\u5185\u5b58\u6570\u636e\u7684\u8bfb\u53d6\u65b9\u5f0f\u3002\u5177\u4f53\u800c\u8a00\uff0c\u6211\u4eec\u6307\u5b9a\u4ee5\u6574\u6570\u5f62\u5f0f\u8bfb\u53d6\u6d6e\u70b9\u6570\u5bf9\u8c61\u6240\u5728\u7684\u5185\u5b58\u5730\u5740\uff0c\u4ee5\u907f\u514d\u4fee\u6539\u5bf9\u8c61\u8868\u793a\uff0c\u518d\u8f93\u51fa\u8f6c\u6362\u540e\u6574\u6570\u7684\u4e8c\u8fdb\u5236\u8868\u793a\uff0c\u6765\u5b9e\u73b0\u8f93\u51fa\u6d6e\u70b9\u6570\u4e8c\u8fdb\u5236\u8868\u793a\u7684\u76ee\u7684\u3002

double a = 1.0;\nunsigned long long p = *(unsigned long long *)&a;\nfor (int i = 0; i < 64; i++)\n    printf(\"%llu\", (p >> (63 - i)) & 1);\n

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u79cd\u6307\u9488\u8f6c\u6362\u4e25\u683c\u6765\u8bf4\u5c5e\u4e8e\u672a\u5b9a\u4e49\u884c\u4e3a\u3002But it just works :P

\u4f7f\u7528\u4e8c\u7ea7\u6307\u9488\u5220\u9664\u94fe\u8868\u8282\u70b9

\u6b64\u5904\u4ec5\u8ba8\u8bba\u6ca1\u6709\u5934\u8282\u70b9\u7684\u5355\u5411\u65e0\u73af\u94fe\u8868\u3002

\u94fe\u8868\u8282\u70b9\u5b9a\u4e49\u5982\u4e0b\uff1a

typedef struct node\n{\n    int val;\n    struct node *next;\n} Node;\n

\u4e00\u4e2a\u5178\u578b\u7684\u5220\u9664\u94fe\u8868\u8282\u70b9\u7684\u7a0b\u5e8f\u5982\u4e0b\uff1a

Node *remove(Node *head, int val)\n{\n    for (Node *prev = NULL, *curr = head; curr; )\n    {\n        Node *next = curr->next;\n        if (curr->val == val)\n        {\n            if (prev)\n                prev->next = next;\n            else\n                head = next;\n            free(curr);\n        }\n        else\n            prev = curr;\n        curr = next;\n    }\n    return head;\n}\n

\u4f46\u662f\uff0c\u5728 Linus \u770b\u6765\uff0c\u8fd9\u662f\u4e0d\u61c2\u6307\u9488\u7684\u4eba\u7684\u505a\u6cd5\u3002\u4ed6\u63a8\u5d07\u7684\u505a\u6cd5\u662f\u4f7f\u7528\u4e8c\u7ea7\u6307\u9488\uff0c\u907f\u514d\u5bf9\u79fb\u9664\u7b2c\u4e00\u4e2a\u8282\u70b9\u7684\u7279\u5224\u3002

void remove(Node *head, int val)\n{\n    for (Node **curr = &head; *curr; )\n    {\n        Node *entry = *curr;\n        if (entry->val == val)\n        {\n            *curr = entry->next;\n            free(entry);\n        }\n        else\n            curr = &entry->next;\n    }\n}\n

\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u8fd9\u4e2a\u7248\u672c\u7684 remove \u51fd\u6570\u4e0d\u518d\u9700\u8981\u989d\u5916\u7ef4\u62a4\u4e00\u4e2a prev \u6307\u9488\uff0c\u4e5f\u4e0d\u9700\u8981\u5224\u65ad\u9700\u8981\u79fb\u9664\u7684\u8282\u70b9\u662f\u5426\u4e3a\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002\u53e6\u5916\uff0c\u8fd9\u4e2a\u7248\u672c\u7684 remove \u51fd\u6570\u4e5f\u4e0d\u518d\u9700\u8981\u8fd4\u56de\u503c\u3002

\u8fd9\u662f\u56e0\u4e3a\uff0c\u73b0\u5728\u4e8c\u7ea7\u6307\u9488 curr \u6307\u5411\u4e0a\u4e00\u4e2a\u8282\u70b9\u7684 next \u6210\u5458\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u6307\u5411\u5f53\u524d\u8282\u70b9\u3002\u79fb\u9664\u8282\u70b9\u65f6\uff0c\u901a\u8fc7 curr \u4fee\u6539 next \u6210\u5458\u8d77\u5230\u4e86\u548c\u4fee\u6539 prev->next \u76f8\u540c\u7684\u6548\u679c\u3002\u8fd9\u5bf9\u4e8e\u7b2c\u4e00\u4e2a\u8282\u70b9\u4e5f\u662f\u6210\u7acb\u7684\uff0c\u56e0\u4e3a\u6b64\u65f6\u4e8c\u7ea7\u6307\u9488 curr \u6307\u5411 head\uff0c\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7 curr \u4fee\u6539 head \u6307\u5411\u7684\u8282\u70b9\u3002

"}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"\u9996\u9875","text":"

\ud83d\ude09 \u4f60\u597d\uff0c\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u8ba1\u5212\u7f51\u7ad9~

\u8fd9\u91cc\u662f\u6d59\u6c5f\u5927\u5b66\u7afa\u53ef\u6862\u5b66\u9662\u5b66\u4e1a\u6307\u5bfc\u4e2d\u5fc3\u8f85\u5b66\u8ba1\u5212\u7684\u7ad9\u70b9\u3002\u8f85\u5b66\u8ba1\u5212\u4e3a\u5927\u4e00\u65b0\u751f\u63d0\u4f9b\u6570\u5b66\u5206\u6790\uff08H\uff09\u3001\u7ebf\u6027\u4ee3\u6570\uff08H\uff09\u3001\u5fae\u79ef\u5206\uff08H\uff09\u3001\u666e\u901a\u7269\u7406\u5b66\uff08H\uff09\u3001\u666e\u901a\u5316\u5b66\uff08H\uff09\u3001\u7a0b\u5e8f\u8bbe\u8ba1\uff08H\uff09\u7b49\u7afa\u9662\u8363\u8a89\u8bfe\u7a0b\u7684\u5b66\u4e60\u6307\u5bfc\u4e0e\u5e2e\u52a9\u3002

\u6211\u4eec\u670d\u52a1\u7684\u5bf9\u8c61\u4e3b\u8981\u662f\u7afa\u9662\u5b66\u5b50\uff0c\u4f46\u6211\u4eec\u540c\u6837\u6b22\u8fce\u9662\u5916\u540c\u5b66\u53c2\u4e0e\u6211\u4eec\u7684\u8f85\u5b66\u6d3b\u52a8\uff0c\u4e0d\u8bba\u662f\u542c\u8bb2\u3001\u7b54\u7591\u8fd8\u662f\u6388\u8bfe\u3002\u9662\u5185\u9662\u5916\u8bfe\u7a0b\u5185\u5bb9\u548c\u96be\u5ea6\u65b9\u9762\u53ef\u80fd\u5b58\u5728\u5dee\u5f02\uff0c\u8bf7\u81ea\u884c\u659f\u914c\u3002

\u4f60\u53ef\u4ee5\u901a\u8fc7\u7f51\u7ad9\u4e0a\u65b9\u6216\u5de6\u4fa7\u7684\u5bfc\u822a\u680f\u6d4f\u89c8\u6211\u4eec\u7684\u7f51\u7ad9\u3002\u4e0b\u9762\u662f\u6211\u4eec\u5f00\u8bbe\u7684\u5404\u8f85\u5b66\u8bfe\u7a0b\uff1a

\u5fae\u79ef\u5206 I/II\uff08H\uff09

23-24 \u8f85\u5b66\u7fa4\uff1a869733089

\u6570\u5b66\u5206\u6790 I/II\uff08H\uff09

23-24 \u8f85\u5b66\u7fa4\uff1a879217934

\u7ebf\u6027\u4ee3\u6570 I/II\uff08H\uff09

23-24 \u8f85\u5b66\u7fa4\uff1a148964020

\u7a0b\u5e8f\u8bbe\u8ba1\uff08H\uff09

23-24 \u8f85\u5b66\u7fa4\uff1a878442370

\u666e\u901a\u5316\u5b66\uff08H\uff09

23-24 \u8f85\u5b66\u7fa4\uff1a875585843

\u666e\u901a\u7269\u7406\u5b66 I\uff08H\uff09

23-24 \u8f85\u5b66\u7fa4\uff1a906774937

\u6211\u4eec\u8fd8\u5728\u5176\u4ed6\u8d44\u6e90\u4e2d\u6574\u7406\u4e86\u4e00\u4e9b\u6709\u7528\u7684\u8d44\u6599\uff0c\u4f46\u8fd9\u4e9b\u8d44\u6599\u5e76\u6ca1\u6709\u4e13\u4eba\u8d1f\u8d23\u7ef4\u62a4\u3002\u6211\u4eec\u6b22\u8fce\u5927\u5bb6\u7684\u8d21\u732e\uff5e

"},{"location":"#_2","title":"\u4ec0\u4e48\u662f\u8f85\u5b66\uff1f","text":""},{"location":"#_3","title":"\u5f55\u64ad/\u56de\u653e","text":"

\u81f4\u8c22\uff1a\u7afa\u53ef\u6862\u5b66\u9662\u5168\u5a92\u4f53\u5de5\u4f5c\u5ba4

\u5728\u7afa\u9662\u5168\u5a92\u4f53\u7684\u4eba\u5458\u548c\u8bbe\u5907\u652f\u6301\u4e0b\uff0c\u5927\u90e8\u5206\u8f85\u5b66\u6388\u8bfe\u90fd\u6709\u4e86\u4f18\u8d28\u7684\u5f55\u64ad\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\u5f55\u64ad\u90fd\u5c06\u4e0a\u4f20\u5230\u7afa\u9662\u5b66\u6307\u7684 Bilibili \u8d26\u53f7\u4e2d\uff0c\u70b9\u51fb\u5361\u7247\u5373\u53ef\u8df3\u8f6c\u5230 Bilibili \u9875\u9762\u3002

"},{"location":"#_4","title":"\u8d21\u732e","text":"

\u5982\u679c\u60a8\u613f\u610f\u53c2\u4e0e\u8be5\u7f51\u7ad9\u7684\u5efa\u8bbe\uff0c\u8bf7\u5230 GitHub \u4e2d\u672c\u9879\u76ee\u7684\u4ed3\u5e93\u8fdb\u884c\u8d21\u732e\u3002\u5411\u4ed3\u5e93\u63d0\u4ea4\u524d\uff0c\u8bf7\u67e5\u770b\u8d21\u732e\u9875\u9762\u3002

"},{"location":"#_5","title":"\u5927\u6587\u4ef6\u5b58\u653e\u5904","text":"

\u8d85\u8fc7 20MB \u7684\u5927\u6587\u4ef6\u90fd\u653e\u7f6e\u5728\u5b66\u4e1a\u6307\u5bfc\u4e2d\u5fc3\u516c\u5171\u7f51\u76d8\u7684\u5206\u4eab\u94fe\u63a5\u4e2d\uff0c\u540c\u5b66\u4eec\u53ef\u4ee5\u70b9\u51fb\u4e0b\u9762\u7684\u94fe\u63a5\u67e5\u770b\u3002\u5982\u679c\u6709\u9700\u8981\u653e\u7f6e\u7684\u5927\u6587\u4ef6\uff0c\u8bf7\u8054\u7cfb\u5b66\u4e1a\u6307\u5bfc\u4e2d\u5fc3\u7684\u540c\u5b66\u4e0a\u4f20\u3002

"},{"location":"#_6","title":"\u76f8\u5173\u7f51\u7ad9","text":""},{"location":"contribute/","title":"\u8d21\u732e","text":"

\u5728\u5411 ckc-agc \u4ed3\u5e93\u63d0\u4ea4 PR \u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u4f60\u5df2\u7ecf\u9605\u8bfb\u4e86\u672c\u6587\u6863\u3002

\u6bcf\u4e2a\u8f85\u5b66\u79d1\u76ee\u7684\u6587\u4ef6\u5939\u7ec4\u7ec7\u5982\u4e0b\uff1a

\u5176\u4e2d\u5b66\u671f\u4f7f\u7528\u5e74\u4efd + \u5b63\u8282\u547d\u540d\uff0c\u5982\uff1a23spring\u300124fall\u3002

\u6587\u6863\u7684\u9644\u4ef6\uff08\u5982\u56fe\u7247\u7b49\uff09\uff0c\u5e94\u5f53\u653e\u7f6e\u5728 \u6587\u6863\u540d.assets \u6587\u4ef6\u5939\u4e2d\uff0c\u4ee5\u4fbf\u4e8e\u7ba1\u7406\u3002

Example

\u7a0b\u8bbe\u7684\u6587\u4ef6\u5939\u7ed3\u6784\u5982\u4e0b\uff1a

programming\n\u251c\u2500\u2500 24fall\n\u2502   \u251c\u2500\u2500 index.md\n\u2502   \u251c\u2500\u2500 lec1.md\n\u2502   \u2514\u2500\u2500 ...\n\u251c\u2500\u2500 common\n\u2502   \u251c\u2500\u2500 exam\n\u2502   \u2502   \u251c\u2500\u2500 exam1.pdf\n\u2502   \u2502   \u2514\u2500\u2500 exam1_answer.pdf\n\u2502   \u2514\u2500\u2500 notes\n\u251c\u2500\u2500 archive\n\u2502   \u2514\u2500\u2500 23fall\n\u2502       \u251c\u2500\u2500 index.md\n\u2502       \u2514\u2500\u2500 lec1\n\u2502           \u251c\u2500\u2500 lec1.assets\n\u2502           \u2514\u2500\u2500 lec1.md\n\u2514\u2500\u2500 index.md\n

\u6211\u4eec\u4f7f\u7528 markdownlint\u3001autocorrect \u548c editorconfig \u63d2\u4ef6\u5bf9\u6587\u6863\u8fdb\u884c\u683c\u5f0f\u5316\u3002

"},{"location":"senior/","title":"\u8f85\u5b66\u5b66\u957f\u987b\u77e5","text":""},{"location":"senior/#_2","title":"\u7afa\u53ef\u6862\u5b66\u9662\u8f85\u5b66\u6388\u8bfe\u89c4\u8303\u5316\u610f\u89c1","text":""},{"location":"senior/#_3","title":"\u4e00\u3001\u52a8\u673a\u4e0e\u610f\u4e49","text":"

\u6388\u8bfe\u6d3b\u52a8\u662f\u7afa\u53ef\u6862\u5b66\u9662\u8f85\u5b66\u7684\u91cd\u8981\u73af\u8282\uff0c\u4e00\u65b9\u9762\u7ed9\u540c\u5b66\u4eec\u7684\u5b66\u4e60\u3001\u590d\u4e60\u5e26\u6765\u4fbf\u5229\uff0c\u53e6\u4e00\u65b9\u9762\u5728\u8f85\u5b66\u89c6\u9891\u4e0a\u7f51\u4e4b\u540e\uff0c\u4e5f\u662f\u63d0\u5347\u7afa\u9662\u8f85\u5b66\u54c1\u724c\u5f71\u54cd\u529b\u7684\u91cd\u8981\u9014\u5f84\u3002\u7136\u800c\uff0c\u76ee\u524d\u7684\u8f85\u5b66\u6388\u8bfe\u5b58\u5728\u4ee5\u4e0b\u95ee\u9898\uff1a

  1. \u6388\u8bfe\u5b89\u6392\u5e76\u4e0d\u5b8c\u5907\uff0c\u5b58\u5728\u591a\u6b21\u6388\u8bfe\u5185\u5bb9\u91cd\u53e0\uff0c\u6216\u65e0\u6cd5\u8986\u76d6\u6240\u6709\u91cd\u96be\u70b9\u7684\u60c5\u51b5\uff1b
  2. \u6388\u8bfe\u5b66\u957f\u98ce\u683c\u8fe5\u5f02\u3001\u504f\u597d\u4e0d\u540c\uff0c\u6bcf\u6b21\u6388\u8bfe\u4fa7\u91cd\u65b9\u5411\u3001\u96be\u5ea6\u7b49\u5dee\u5f02\u8f83\u5927\uff0c\u540c\u5b66\u8ddf\u7740\u8f85\u5b66\u6388\u8bfe\u8fdb\u884c\u5b66\u4e60\u5bb9\u6613\u4f53\u9a8c\u4e0d\u4f73\uff0c\u6478\u4e0d\u7740\u5934\u8111\uff1b
  3. \u6bcf\u5e74\u7684\u5907\u8bfe\u8d44\u6599\u5c3d\u7ba1\u4ece\u524d\u5e74\u5f00\u59cb\u6709\u6574\u7406\uff0c\u4f46\u4e0d\u540c\u5b66\u957f\u7684\u98ce\u683c\u5dee\u5f02\uff0c\u4ee5\u53ca\u6bcf\u5e74\u8bfe\u7a0b\u5b89\u6392\u7684\u5dee\u5f02\u7b49\uff0c\u5bfc\u81f4\u540c\u5b66\u4eec\u9762\u5bf9\u8fd9\u4e9b\u8d44\u6599\u4e5f\u53ea\u80fd\u65e0\u5934\u82cd\u8747\u4e00\u6837\u4e1c\u770b\u897f\u770b\uff0c\u6bd4\u8f83\u6df7\u4e71\uff0c\u5f88\u96be\u505a\u5230\u771f\u6b63\u7684\u8d44\u6599\u4f20\u627f\uff1b
  4. \u8f85\u5b66\u5b66\u957f\u867d\u7136\u5927\u90fd\u5177\u6709\u70ed\u60c5\uff0c\u4f46\u5f88\u591a\u65f6\u5019\u53ef\u80fd\u56e0\u4e3a\u81ea\u5df1\u592a\u5fd9\uff0c\u6216\u8005\u957f\u671f\u6ca1\u6709\u5b66\u4e60\u800c\u5fd8\u8bb0\u4e86\u4e00\u4e9b\u5185\u5bb9\u7b49\uff0c\u5bfc\u81f4\u5907\u8bfe\u3001\u6388\u8bfe\u8d28\u91cf\u4e0d\u9ad8\u3002\u5e76\u4e14\u76ee\u524d\u8f85\u5b66\u6574\u4f53\u6388\u8bfe\u7cfb\u7edf\u6027\u8f83\u5dee\uff0c\u5b8c\u5168\u4f9d\u8d56\u4e8e\u8f85\u5b66\u5b66\u957f\u7684\u4e2a\u4eba\u80fd\u529b\u548c\u7406\u89e3\uff0c\u5e76\u4e0d\u80fd\u5f88\u597d\u5730\u9762\u5411\u540c\u5b66\u89e3\u51b3\u540c\u5b66\u7684\u9700\u6c42\uff1b
  5. \u540c\u5b66\u7684\u53cd\u9988\u5728\u521d\u671f\u5f00\u5c55\u89c4\u8303\u5316\u6388\u8bfe\u65f6\u662f\u975e\u5e38\u91cd\u8981\u7684\uff0c\u56e0\u4e3a\u4ec5\u51ed\u501f\u51e0\u4e2a\u6388\u8bfe\u5b66\u957f\u7684\u8ba4\u8bc6\u5f88\u96be\u5168\u9762\u4e86\u89e3\u540c\u5b66\u4eec\u7684\u6838\u5fc3\u9700\u6c42\uff0c\u8bfe\u540e\u7684\u6539\u8fdb\u610f\u89c1\u4e5f\u5bf9\u4e8e\u8fdb\u4e00\u6b65\u63d0\u5347\u8f85\u5b66\u6559\u5b66\u8d28\u91cf\u5f88\u6709\u610f\u4e49\uff0c\u7136\u800c\u73b0\u5728\u7684\u8bfe\u524d\u8bfe\u540e\u53cd\u9988\u5747\u6d6e\u4e8e\u8868\u9762\uff0c\u6d41\u4e8e\u5f62\u5f0f\uff0c\u751a\u81f3\u8bfe\u540e\u53cd\u9988\u5f88\u5c11\u51fa\u73b0\u6709\u7528\u7684\u4fe1\u606f\u3002

\u56e0\u6b64\u6211\u4eec\u5e0c\u671b\u901a\u8fc7\u5c06\u7afa\u9662\u8f85\u5b66\u6388\u8bfe\u89c4\u8303\u5316\uff0c\u4ee5\u89e3\u51b3\u4e0a\u8ff0\u95ee\u9898\u3002\u6211\u4eec\u5c06\u5206\u522b\u4ece\u521d\u671f\u51c6\u5907\u3001\u5907\u8bfe\u6388\u8bfe\u8fc7\u7a0b\u4ee5\u53ca\u540e\u7eed\u5de5\u4f5c\u4e09\u4e2a\u65b9\u9762\u7ed9\u51fa\u6211\u4eec\u5bf9\u89c4\u8303\u5316\u7684\u610f\u89c1\u3002

"},{"location":"senior/#_4","title":"\u4e8c\u3001\u89c4\u8303\u5316\u7684\u51e0\u4e2a\u65b9\u9762","text":""},{"location":"senior/#1","title":"1.\u521d\u671f\u51c6\u5907\u5de5\u4f5c","text":"
  1. \u786e\u5b9a\u6388\u8bfe\u540d\u5355\u65f6\uff0c\u5e94\u5f53\u786e\u8ba4\u62a5\u540d\u5b66\u957f\u7684\u6388\u8bfe\u610f\u613f\uff0c\u7b80\u8981\u8bf4\u660e\u6388\u8bfe\u7684\u8981\u6c42\uff08\u53c2\u4e0e\u89c4\u8303\u5316\u5efa\u8bbe\uff09\uff0c\u8be2\u95ee\u662f\u5426\u613f\u610f\u5c06\u6388\u8bfe\u8d44\u6599\u4f20\u627f\u3001\u5f00\u6e90\uff08\u4e00\u822c\u90fd\u613f\u610f\uff09\uff1b
    1. \u4e0d\u786e\u5b9a\u8bd5\u8bfe\u662f\u5426\u6709\u5fc5\u8981\uff0c\u73b0\u5728\u62a5\u540d\u6388\u8bfe\u7684\u4eba\u6570\u90fd\u5f88\u6709\u9650\uff0c\u53ef\u80fd\u8981\u601d\u8003\u5982\u4f55\u6fc0\u52b1
  2. \u786e\u5b9a\u6388\u8bfe\u540d\u5355\u540e\uff0c\u5e94\u5f53\u7ed3\u5408\u5b66\u6821\u8bfe\u7a0b\u5927\u7eb2\u3001\u6388\u8bfe\u8fdb\u5ea6\u3001\u8003\u8bd5\u4e0e\u5c0f\u6d4b\u5b89\u6392\u7b49\uff0c\u786e\u5b9a\u8f85\u5b66\u7684\u5927\u81f4\u6388\u8bfe\u65f6\u95f4\u548c\u5185\u5bb9\u5b89\u6392\u3002\u7136\u540e\u5404\u8bfe\u7a0b\u7ec4\u5e94\u5f53\u7ec4\u7ec7\u7ebf\u4e0a\u6216\u7ebf\u4e0b\u7684\u4f1a\u8bae\uff0c\u4ecb\u7ecd\u521d\u6b65\u7684\u8ba1\u5212\uff0c\u7136\u540e\u8ba8\u8bba\u8be6\u7ec6\u7684\u6388\u8bfe\u5b89\u6392\u3001\u6388\u8bfe\u5927\u7eb2\uff08\u540e\u9762\u4f1a\u7ed9\u51fa\u793a\u4f8b\uff09\uff0c\u786e\u5b9a\u4e3b\u8981\u7684\u6559\u5b66\u53c2\u8003\u8d44\u6599\uff0c\u521d\u6b65\u786e\u5b9a\u6559\u5b66\u4fa7\u91cd\u70b9\u4ee5\u53ca\u96be\u5ea6\uff0c\u660e\u786e\u5206\u914d\u6388\u8bfe\u4efb\u52a1\uff0c\u9632\u6b62\u91cd\u53e0\u6216\u7f3a\u6f0f\u7b49\uff1b
    1. \u6559\u5b66\u53c2\u8003\u8d44\u6599\u662f\u5fc5\u8981\u7684\uff0c\u7279\u522b\u662f\u5fae\u79ef\u5206\u3001\u6570\u5b66\u5206\u6790\u8fd9\u79cd\u5e02\u9762\u4e0a\u5b58\u5728\u5e7f\u6cdb\u8d44\u6599\u7684\u79d1\u76ee\uff0c\u5e94\u5f53\u4ee5 2 \u672c\u5de6\u53f3\u7684\u7ecf\u5178\u6559\u6750\u6216\u8003\u7814\u6559\u8f85\u4e3a\u6838\u5fc3\u5c55\u5f00\uff0c\u63d0\u5347\u5907\u8bfe\u6548\u7387\u548c\u8d28\u91cf\uff0c\u56e0\u4e3a\u6211\u4eec\u76f8\u4fe1\u90a3\u4e9b\u6559\u6750\u548c\u6559\u8f85\u8d44\u6599\u505a\u4e86\u8fd9\u4e48\u591a\u5e74\u4e00\u5b9a\u662f\u6bd4\u5b66\u957f\u4eec\u81ea\u5df1\u7684\u8ba4\u77e5\u8981\u5b8c\u5907\u5f88\u591a\u7684\uff0c\u5e76\u4e14\u4e5f\u975e\u5e38\u6709\u903b\u8f91\uff0c\u9002\u5408\u8f85\u5b66\u6388\u8bfe\uff0c\u5f53\u7136\u4e5f\u9700\u8981\u7ed3\u5408\u5b66\u957f\u81ea\u5df1\u7684\u7406\u89e3\u4ee5\u53ca\u672c\u6821\u7684\u8003\u8bd5\u60c5\u51b5**\u4ece\u4e2d\u9009\u62e9\u5408\u9002\u7684\u5185\u5bb9\u8bb2\u89e3\uff1b
    2. \u5b89\u6392\u8bfe\u65f6\u53ef\u4ee5\u589e\u52a0\u7ebf\u4e0a\u8bfe\u65f6\uff0c\u56e0\u4e3a\u8f85\u5b66\u7ebf\u4e0b\u8bfe\u7a0b\u4e0d\u53ef\u80fd\u505a\u592a\u591a\u6b21\uff0c\u610f\u4e49\u4e0d\u5927\u5e76\u4e14\u540c\u5b66\u4eec\u65f6\u95f4\u4e5f\u6709\u9650\uff0c\u56e0\u6b64\u90e8\u5206\u4e0d\u90a3\u4e48\u91cd\u8981\u3001\u96be\u5ea6\u8f83\u5927\u6216\u8005\u7ebf\u4e0b\u6388\u8bfe\u96be\u4ee5\u5b89\u6392\u8bb2\u89e3\u7684\u5185\u5bb9\uff08\u4f8b\u5982\u7ebf\u6027\u4ee3\u6570\u4e2d\u7684\u884c\u5217\u5f0f\u8ba1\u7b97\u6280\u5de7\u91cd\u8981\u7a0b\u5ea6\u548c\u96be\u5ea6\u4e0d\u9002\u5408\u7ebf\u4e0b\u8bfe\u7a0b\uff0c\u7279\u5f81\u503c\u4e0e\u4e8c\u6b21\u578b\u90e8\u5206\u65f6\u95f4\u4e0a\u5f88\u96be\u5355\u72ec\u5b89\u6392\u8bfe\u7a0b\uff0c\u4e0e\u671f\u672b\u90bb\u8fd1\uff09\u53ef\u4ee5\u653e\u5728\u7ebf\u4e0a\u5f00\u8bfe\uff0c\u89c6\u9891\u4e0a\u4f20 B \u7ad9\u5373\u53ef\u3002\u7ebf\u4e0a\u5f00\u8bfe\u65f6\u957f\u3001\u5185\u5bb9\u90fd\u76f8\u8f83\u800c\u8a00\u66f4\u52a0\u81ea\u7531\uff1b
    3. \u786e\u5b9a\u6388\u8bfe\u5927\u7eb2\u65f6\uff0c\u5e94\u5f53\u660e\u786e\u5730\u5c06\u6240\u6709\u77e5\u8bc6\u70b9\u5217\u4e3e\uff08\u4f8b\u5982\u6839\u636e\u6559\u6750\uff0c\u7ed3\u5408\u4e00\u4e9b\u6559\u8f85\uff09\uff0c\u7136\u540e\u786e\u5b9a\u6bcf\u6b21\u7684\u6388\u8bfe\u5185\u5bb9\u3001\u6388\u8bfe\u91cd\u70b9\u4ee5\u53ca\u7ebf\u4e0a\u7ebf\u4e0b\u7684\u533a\u5206\uff0c\u9664\u6b64\u4e4b\u5916\uff0c\u6574\u4f53\u6388\u8bfe\u7684\u503e\u5411\u6027\u5e94\u5f53\u7edf\u4e00\uff0c\u4e0d\u5e94\u5f53\u51fa\u73b0\u4e00\u6b21\u6388\u8bfe\u5168\u662f\u4e60\u9898\uff0c\u4e00\u6b21\u6388\u8bfe\u5168\u662f\u57fa\u7840\u77e5\u8bc6\uff0c\u4e00\u6b21\u6388\u8bfe\u51fa\u73b0\u5f88\u591a\u8d85\u7eb2\u77e5\u8bc6\u7684\u60c5\u51b5\uff0c\u5e94\u5f53\u6709\u4e00\u4e2a\u57fa\u672c\u6807\u51c6\uff0c\u5728\u5176\u4e0a\u5404\u4e2a\u5b66\u957f\u53ef\u4ee5\u6309\u7167\u81ea\u5df1\u7684\u559c\u597d\u6dfb\u52a0\u5176\u4ed6\u5185\u5bb9\uff1b
    4. \u671f\u4e2d\u3001\u671f\u672b\u590d\u4e60\u6d89\u53ca\u7684\u77e5\u8bc6\u91cf\u53ef\u80fd\u8f83\u5927\uff0c\u53ef\u4ee5\u62c6\u5206\u6210\u4e24\u6b21\uff0c\u4e5f\u53ef\u4ee5\u7ebf\u4e0a\u7ebf\u4e0b\u7ed3\u5408\uff0c\u5f53\u7136\u5728\u73b0\u5728\u6574\u4f53\u6388\u8bfe\u89c4\u8303\u5316\u4e4b\u540e\uff0c\u590d\u4e60\u8bfe\u5e94\u8be5\u6bd4\u4ee5\u5f80\u66f4\u597d\u4e0a\uff0c\u56e0\u4e3a\u6709\u4e9b\u4e0d\u592a\u91cd\u70b9\u7684\u5185\u5bb9\u53ef\u4ee5\u76f4\u63a5 link \u5230\u4e4b\u524d\u7684\u8bfe\u7a0b\uff0c\u66f4\u52a0\u7a81\u51fa\u590d\u4e60\u91cd\u70b9\u3002
"},{"location":"senior/#2","title":"2.\u5907\u8bfe\u4e0e\u6388\u8bfe\u8fc7\u7a0b","text":"
  1. \u81f3\u5c11\u63d0\u524d\u4e00\u5468\u901a\u77e5\u6388\u8bfe\u5b66\u957f\u8fdb\u884c\u5907\u8bfe\uff0c\u5e76\u4e14\u8bb0\u4f4f\u501f\u6559\u5ba4\uff0c\u53ef\u4ee5\u6839\u636e\u5b66\u957f\u4f7f\u7528 PPT \u6216\u624b\u5199\u677f\u4e66\u7684\u9700\u6c42\u501f\u6559\u5ba4\uff08\u4e5f\u8bb8\u6709\u7684\u5b66\u957f\u4e0d\u559c\u6b22\u7c89\u7b14\uff0c\u6709\u7684\u5b66\u957f\u53d7\u4e0d\u4e86\u767d\u677f\u7b14\uff09\uff1b
  2. \u8bfe\u524d\u62a5\u540d\u901a\u77e5\u4ee5\u53ca\u62a5\u540d\u8868\u4e2d\uff0c\u5e94\u5f53\u6839\u636e\u6700\u540e\u7684\u8bfe\u7a0b\u5927\u7eb2\u793a\u4f8b\u660e\u786e\u5199\u51fa\u672c\u6b21\u6388\u8bfe\u7684\u6240\u6709\u4fe1\u606f\uff0c\u5e76\u4e14\u62a5\u540d\u8868\u4e2d\u5e94\u5f53\u6839\u636e\u6388\u8bfe\u5185\u5bb9\u8981\u6c42\u540c\u5b66\u4eec\u9009\u62e9\u6700\u5e0c\u671b\u542c\u5230\u7684\u5185\u5bb9\uff0c\u5199\u4e0b\u81ea\u5df1\u89c9\u5f97\u5b66\u4e60\u6bd4\u8f83\u56f0\u96be\u7684\u65b9\u9762\u7b49\uff1b
  3. \u5b66\u957f\u5907\u8bfe\u671f\u95f4\uff0c\u5efa\u8bae\u6839\u636e\u8bfe\u7a0b\u5927\u7eb2\u4e2d\u5199\u4e0b\u7684\u53c2\u8003\u8d44\u6599\u4ee5\u53ca\u4e4b\u524d\u8ba8\u8bba\u7684\u6574\u4f53\u5907\u8bfe\u98ce\u683c\u7b49\u7f16\u5199\u8bb2\u4e49\u6216 PPT\uff0c\u5e76\u7ed3\u5408\u540c\u5b66\u4eec\u7684\u542c\u8bfe\u610f\u613f\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u7ed3\u5408\u81ea\u5df1\u7684\u8ba4\u77e5\u548c\u98ce\u683c\u8fdb\u884c\u5907\u8bfe\uff0c\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879\u53ef\u4ee5\u53c2\u8003\u4e0b\u4e00\u8282\uff1b
  4. \u5907\u8bfe\u5b8c\u6210\u540e\uff0c\u5efa\u8bae\u63d0\u524d\u4e00\u5929\u5c06\u8bb2\u4e49\u516c\u5f00\u5728\u6388\u8bfe\u7fa4\uff08\u53ef\u4ee5\u4e0d\u662f\u6700\u7ec8\u7248\uff0c\u5927\u81f4\u5185\u5bb9\u5728\u5c31\u53ef\u4ee5\uff09\uff0c\u7136\u540e\u5ba1\u6838\u8bb2\u4e49\u3001PPT \u662f\u5426\u7b26\u5408\u57fa\u672c\u8981\u6c42\uff0c\u6700\u540e\u5c06\u6700\u7ec8\u7248\u53d1\u5e03\u5728\u8f85\u5b66\u7fa4\u3002
"},{"location":"senior/#3","title":"3.\u540e\u7eed\u5de5\u4f5c","text":"
  1. \u4e0b\u8bfe\u7b7e\u9000\u65f6\uff0c\u53ef\u4ee5\u8003\u8651\u628a\u7b7e\u9000\u7801\u548c\u53cd\u9988\u7801\u653e\u5728\u4e00\u8d77\uff0c\u8981\u6c42\u540c\u5b66\u586b\u5199\u3002\u8bfe\u540e\u53cd\u9988\u95ee\u5377\u5e94\u5f53\u5bf9\u8bfe\u7a0b\u8fdb\u5ea6\u3001\u96be\u5ea6\u3001\u6388\u8bfe\u8d28\u91cf\u3001\u4fa7\u91cd\u70b9\u7f3a\u5931\u7b49\u65b9\u9762\u8fdb\u884c\u5168\u9762\u7684\u8be2\u95ee\uff0c\u591a\u7528\u9009\u62e9\u9898\u53ef\u4ee5\u63d0\u5347\u95ee\u5377\u6548\u7387\uff1b
  2. \u5728\u5b66\u957f\u5141\u8bb8\u7684\u524d\u63d0\u4e0b\uff0c\u6240\u6709 PDF \u8d44\u6599\u5168\u90e8\u516c\u5f00\uff0c\u6e90\u6587\u4ef6\u4f5c\u4e3a\u5185\u90e8\u8d44\u6599\u8fdb\u884c\u5b58\u50a8\u4fdd\u7559\uff0c\u5982\u679c\u662f word\u3001PPT \u7b49\u53ef\u4ee5\u4fdd\u7559\u539f\u6587\u4ef6\uff0clatex\u3001markdown\u3001typst \u7b49\u53ef\u4ee5\u4fdd\u7559\u6e90\u7801\uff1b
  3. \u8865\u5145\u6388\u8bfe\u5927\u7eb2\u4e2d\u7684\u8bfe\u540e\u53cd\u9988\u680f\u76ee\uff0c\u4e3a\u4e0b\u4e00\u6b21\u5b66\u957f\u6388\u8bfe\u63d0\u4f9b\u610f\u89c1\u3002
"},{"location":"senior/#_5","title":"\u4e09\u3001\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879","text":"
  1. \u5404\u4e2a\u5b66\u79d1\u7684\u4e00\u4e9b\u9700\u8981\u6ce8\u610f\u7684\u7279\u70b9\uff08\u5f85\u8865\u5145\uff09\uff1a
    1. \u5fae\u79ef\u5206\uff1a
      1. \u4e2a\u4eba\u8ba4\u4e3a\u5fae\u79ef\u5206\u662f\u6700\u4e0d\u7f3a\u5e02\u9762\u4e0a\u8d44\u6599\u7684\u5b66\u79d1\uff0c\u56e0\u6b64\u5907\u8bfe\u7684\u65f6\u5019\u975e\u5e38\u6709\u5fc5\u8981\u6311\u9009\u597d\u7684\u8d44\u6599\uff0c\u53c2\u7167\u8fd9\u4e9b\u8d44\u6599\u5199\u51fa\u597d\u7684\u8bb2\u4e49\uff1b
      2. \u6743\u8861\u57fa\u7840\u77e5\u8bc6\u3001\u4e60\u9898\u5957\u8def\u3001\u62d3\u5c55\u5185\u5bb9\u3002
  2. \u6570\u5b66\u5206\u6790\uff1a
    1. \u6570\u5b66\u5206\u6790\u4e3b\u8981\u5c31\u662f\u4e24\u4e2a\u65b9\u9762\u7684\u95ee\u9898\uff0c\u4e00\u65b9\u9762\u662f\u6559\u6750\u5e76\u4e0d\u80fd\u628a\u57fa\u672c\u5185\u5bb9\u8bb2\u5f97\u5f88\u6e05\u695a\uff0c\u540c\u5b66\u4eec\u5206\u6790\u57fa\u7840\u8584\u5f31\uff0c\u53e6\u4e00\u65b9\u9762\u4e60\u9898\u4e0d\u591f\uff0c\u5e76\u4e14\u5bf9\u4e00\u4e9b\u57fa\u672c\u5957\u8def\u90fd\u4e0d\u719f\u6089\uff0c\u9762\u5411\u8003\u8bd5\u56f0\u96be\uff1b
    2. \u7b2c\u4e00\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u63a8\u8350\u9605\u8bfb\u5f20\u7b51\u751f\u8001\u5e08\u7684\u300a\u6570\u5b66\u5206\u6790\u65b0\u8bb2\u300b\uff0c\u7b2c\u4e8c\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u63a8\u8350\u4e00\u4e9b\u5e02\u9762\u4e0a\u5e38\u89c1\u7684\u6559\u8f85\uff0c\u4f8b\u5982\u9762\u5411\u8003\u7814\u7684......\uff0c\u751a\u81f3\u53ef\u4ee5\u53c2\u8003\u4e00\u4e9b\u5fae\u79ef\u5206\u7684\u53c2\u8003\u8d44\u6599\uff0c\u603b\u7ed3\u4e00\u4e9b\u5957\u8def\uff0c\u601d\u8def\u66f4\u6e05\u6670\u540c\u5b66\u4eec\u66f4\u5bb9\u6613\u63a5\u53d7\uff1b
    3. \u8f85\u5b66\u7684\u6388\u8bfe\u4e3b\u8981\u9762\u5411\u4e24\u4e2a\u95ee\u9898\uff0c\u5c06\u6211\u4eec\u89c9\u5f97\u6709\u5fc5\u8981\u8bb2\u4e00\u8bb2\u7684\u5185\u5bb9\u4ece\u8fd9\u4e9b\u53c2\u8003\u8d44\u6599\u4e2d\u9009\u51fa\u6765\u4ecb\u7ecd\uff0c\u56e0\u4e3a\u540c\u5b66\u4eec\u53ef\u80fd\u81ea\u5df1\u53bb\u770b\u7684\u52a8\u529b\u4e0d\u8db3\uff0c\u6216\u8005\u5f88\u96be\u770b\u51fa\u4ec0\u4e48\u662f\u5bf9\u76ee\u524d\u5b66\u4e60\u6700\u6709\u6548\u7684\u5185\u5bb9\uff1b
    4. \u6700\u540e\u662f\u4e00\u4e9b\u53ef\u4ee5\u62d4\u9ad8\u7684\u63a8\u8350\uff0c......\u3002
  3. \u7ebf\u6027\u4ee3\u6570\uff1a
    1. \u7ebf\u6027\u4ee3\u6570\u7684\u95ee\u9898\u5728\u4e8e\u5e02\u9762\u4e0a\u53c2\u8003\u8d44\u6599\u592a\u5c11\uff0c\u8fd9\u4e5f\u662f\u7f16\u5199 LALU \u7684\u4e00\u5927\u521d\u8877\uff1b
    2. \u4e00\u4e2a\u6709\u8da3\u7684\u4e8b\u5b9e\u662f\u5f88\u591a\u540c\u5b66\u53ef\u80fd\u5e76\u4e0d\u4f1a\u771f\u7684\u53bb\u770b LALU\uff0c\u6700\u591a\u5f53\u5de5\u5177\u4e66\u505a\u4f5c\u4e1a\u7684\u65f6\u5019\u67e5\u9605\u6216\u8003\u524d\u590d\u4e60\u770b\u4e00\u770b\uff1b
    3. \u56e0\u6b64\u8f85\u5b66\u7684\u76ee\u6807\u57fa\u672c\u4e0a\u662f\u53c2\u7167 LALU \u7684\u6846\u67b6\uff0c\u505a\u4e00\u4e2a\u91cd\u70b9\u7684\u7b5b\u9009\u5728\u4e0a\u8bfe\u7684\u65f6\u5019\u7ed9\u540c\u5b66\u4eec\u8bb2\uff0c\u8ba9\u4ed6\u4eec\u77e5\u9053\u770b\u54ea\u4e9b\u90e8\u5206\uff0c\u505a\u54ea\u4e9b\u9898\u5b66\u4e60\u6548\u7387\u6bd4\u8f83\u9ad8\uff1b
    4. \u9700\u8981\u6ce8\u610f\u7684\u662f\u7ebf\u6027\u4ee3\u6570\u8f85\u5b66\u5e94\u5f53\u6ce8\u91cd\u6982\u5ff5\u7406\u89e3\u548c\u4e60\u9898\u7684\u7ed3\u5408\uff0c\u4e24\u4e2a\u65b9\u9762\u90fd\u4e0d\u53ef\u6216\u7f3a\u3002\u6982\u5ff5\u4e00\u65b9\u9762\uff0c\u53e6\u4e00\u65b9\u9762\u7684\u53ef\u4ee5\u4ece\u66f4\u9ad8\u7684\u89d2\u5ea6\u51fa\u53d1\u7406\u89e3\uff0c\u4e60\u9898\u6ce8\u91cd\u603b\u7ed3\u57fa\u672c\u5957\u8def\uff0c\u7ed3\u5408\u8003\u8bd5\u91cd\u70b9\uff0c\u56e0\u4e3a\u8363\u8a89\u8bfe\u8001\u5e08\u6388\u8bfe\u4e0d\u91cd\u89c6\u8fd9\u4e9b\u3002
  4. \u7a0b\u5e8f\u8bbe\u8ba1\uff1a
    1. \u57fa\u7840\u548c\u63d0\u9ad8\u7684\u6743\u8861\uff08\uff1f\uff09
  5. \u6211\u4eec\u5fc5\u987b\u5f3a\u8c03\u7684\u4e00\u70b9\u662f\uff0c\u5c3d\u7ba1\u4ee5\u4e0a\u6d41\u7a0b\u770b\u8d77\u6765\u6bd4\u8f83\u523b\u677f\uff0c\u4f46\u89c4\u8303\u5316\u5e76\u4e0d\u662f\u8bf4\uff0c\u6211\u4eec\u9650\u5236\u8f85\u5b66\u6388\u8bfe\u53ea\u80fd\u8bb2\u4ec0\u4e48\u5185\u5bb9\u3002\u4e8b\u5b9e\u4e0a\u8fd9\u53ea\u662f\u4e00\u4e2a\u6d41\u7a0b\u4e0a\u7684\u89c4\u8303\uff0c\u6709\u52a9\u4e8e\u63d0\u5347\u8f85\u5b66\u5de5\u4f5c\u6548\u7387\uff0c\u63d0\u5347\u5907\u8bfe\u6388\u8bfe\u8d28\u91cf\u3001\u540c\u5b66\u7684\u542c\u8bfe\u4f53\u9a8c\uff0c\u4ee5\u53ca\u6709\u52a9\u4e8e\u4e0d\u65ad\u8fed\u4ee3\u66f4\u65b0\u8d44\u6599\u7684\u610f\u89c1\u3002\u6211\u4eec\u975e\u5e38\u9f13\u52b1\u6bcf\u4e00\u4f4d\u6388\u8bfe\u5b66\u957f\u878d\u5165\u81ea\u5df1\u7684\u98ce\u683c\uff0c\u63d0\u51fa\u81ea\u5df1\u7684\u770b\u6cd5\uff0c\u65e0\u8bba\u662f\u5bf9\u8bfe\u7a0b\u91cd\u70b9\u3001\u6388\u8bfe\u5185\u5bb9\u8fd8\u662f\u6574\u4f53\u6d41\u7a0b\u7b49\uff0c\u5e76\u5c06\u81ea\u5df1\u7684\u60f3\u6cd5\u878d\u5165\u5230\u6388\u8bfe\u5b9e\u8df5\u3002
"},{"location":"senior/#_6","title":"\u56db\u3001\u8f85\u5b66\u6388\u8bfe\u5927\u7eb2\uff08\u4ee5\u7ebf\u6027\u4ee3\u6570\u4e3a\u4f8b\uff09","text":"

\u6574\u4f53\u4fe1\u606f

\u6388\u8bfe\u6210\u5458\u540d\u5355\uff1a

\u6388\u8bfe\u5f62\u5f0f\uff1a\u7ebf\u4e0a\u7ebf\u4e0b\u7ed3\u5408\uff0c\u7ebf\u4e0a \u8bfe\u65f6\uff0c\u7ebf\u4e0b \u8bfe\u65f6\uff1b

\u53c2\u8003\u8d44\u6599\uff1a

\u6559\u6750\uff1a

  1. \u300a\u5927\u5b66\u6570\u5b66\uff1a\u4ee3\u6570\u4e0e\u51e0\u4f55\u300b\uff08\u7b2c\u4e8c\u7248\uff09\u8427\u6811\u94c1\uff0c\u6e05\u534e\u5927\u5b66\u51fa\u7248\u793e
  2. \u300a\u7ebf\u6027\u4ee3\u6570\u5e94\u8be5\u8fd9\u6837\u5b66\u300b\uff08\u7b2c\u56db\u7248\uff09[\u7f8e] Sheldon Axler\uff0c\u4eba\u6c11\u90ae\u7535\u51fa\u7248\u793e

\u91cd\u70b9\u53c2\u8003\u8d44\u6599\uff1a

  1. \u300a\u7ebf\u6027\u4ee3\u6570\uff1a\u672a\u7adf\u4e4b\u7f8e\u300b\u7afa\u53ef\u6862\u5b66\u9662\u8f85\u5b66\u8bb2\u4e49
  2. \u300a\u9ad8\u7b49\u4ee3\u6570\u5b66\u300b\uff08\u7b2c\u56db\u7248\uff09\u8c22\u542f\u9e3f\uff0c\u59da\u6155\u751f\uff0c\u5434\u6cc9\u6c34\uff0c\u590d\u65e6\u5927\u5b66\u51fa\u7248\u793e
  3. \u300a\u9ad8\u7b49\u4ee3\u6570\u5b66\uff08\u7b2c\u56db\u7248\uff09\u914d\u5957\u5b66\u4e60\u7528\u4e66\u300b\u8c22\u542f\u9e3f\uff0c\u59da\u6155\u751f\uff0c\u590d\u65e6\u5927\u5b66\u51fa\u7248\u793e

\u5176\u5b83\u53c2\u8003\u8d44\u6599\uff1a

  1. \u300a\u8003\u7814\u6570\u5b66\u7ebf\u6027\u4ee3\u6570\u8f85\u5bfc\u8bb2\u4e49\u300b\u6c64\u5bb6\u51e4\uff0c\u4e2d\u56fd\u77f3\u5316\u51fa\u7248\u793e
  2. \u300a\u9ad8\u7b49\u4ee3\u6570\u5f3a\u5316\u8bb2\u4e49\u300b\uff082023 \u8003\u7814\u7248\uff09\u674e\u626c

\u7b2c\u4e00\u6b21\u6388\u8bfe

\u4e3b\u9898\uff1a\u7ebf\u6027\u7a7a\u95f4

\u5f62\u5f0f\uff1a\u7ebf\u4e0b\uff0c\u7ea6 120 \u5206\u949f\uff08\u7ebf\u4e0a / \u7ebf\u4e0b + \u65f6\u957f\uff09

\u6388\u8bfe\u4eba\uff1a\u5434\u4e00\u822a

\u6388\u8bfe\u65f6\u95f4\uff1a2024 \u5e74 10 \u6708 20 \u65e5

\u6388\u8bfe\u5730\u70b9\uff1a\u7d2b\u91d1\u6e2f......\uff08\u7ebf\u4e0a\u65e0\uff09

\u6388\u8bfe\u5185\u5bb9\uff1a

  1. \u8bfe\u7a0b\u7eb5\u89c8\uff0c\u7ebf\u6027\u4ee3\u6570\u7684\u91cd\u8981\u6027\uff08\u8bfe\u524d\u95f2\u8c08\uff09
  2. n\u5143\u5411\u91cf\u4e0e\u77e9\u9635\u7684\u5b9a\u4e49
  3. \u9ad8\u65af\u6d88\u5143\u6cd5\uff1a\u603b\u7ed3\u4e00\u822c\u65b9\u6cd5\uff0c\u7ed9\u542b\u53c2\u6570\u7ebf\u6027\u65b9\u7a0b\u7ec4\u95ee\u9898\u7684\u4f8b\u5b50
  4. \u7ebf\u6027\u7a7a\u95f4\u7684\u5b9a\u4e49\u3001\u6ce8\u610f\u4e8b\u9879\u4e0e\u5178\u578b\u4f8b\u9898\uff0c\u7ebf\u6027\u5b50\u7a7a\u95f4\u7684\u5b9a\u4e49\u4e0e\u5178\u578b\u4f8b\u9898
  5. \u7ebf\u6027\u8868\u793a\u3001\u7ebf\u6027\u6269\u5f20\u3001\u7ebf\u6027\u76f8\u5173\u6027\u3001\u57fa\u4e0e\u7ef4\u6570\u7684\u57fa\u672c\u5b9a\u4e49\u4e0e\u6027\u8d28
  6. \u7ebf\u6027\u76f8\u5173\u6027\u7ecf\u5178\u4f8b\u9898\uff0c\u6781\u5927\u7ebf\u6027\u65e0\u5173\u7ec4\u7684\u6c42\u89e3\uff0c\u57fa\u4e0e\u7ef4\u6570\u5178\u578b\u4f8b\u9898
  7. \u7ebf\u6027\u7a7a\u95f4\u7684\u4ea4\u4e0e\u548c\u7684\u5b9a\u4e49\u4e0e\u6027\u8d28\uff0c\u7ebf\u6027\u7a7a\u95f4\u7ef4\u6570\u516c\u5f0f\u53ca\u5176\u8bc1\u660e\uff0c\u76f4\u548c\u7684\u5b9a\u4e49\u4e0e\u6027\u8d28
  8. \u6c42\u89e3\u7ebf\u6027\u7a7a\u95f4\u4ea4\u4e0e\u548c\u7684\u4f8b\u9898\uff0c\u8986\u76d6\u5b9a\u7406\uff0c\u76f4\u548c\u5224\u5b9a\u7684\u4e24\u79cd\u65b9\u6cd5

\u53c2\u8003\u8d44\u6599\uff1a

  1. \u300a\u7ebf\u6027\u4ee3\u6570\uff1a\u672a\u7adf\u4e4b\u7f8e\u300b\u7afa\u53ef\u6862\u5b66\u9662\u8f85\u5b66\u8bb2\u4e49
  2. \u300a\u9ad8\u7b49\u4ee3\u6570\u5b66\u300b\uff08\u7b2c\u56db\u7248\uff09\u8c22\u542f\u9e3f\uff0c\u59da\u6155\u751f\uff0c\u5434\u6cc9\u6c34\uff0c\u590d\u65e6\u5927\u5b66\u51fa\u7248\u793e
  3. \u300a\u9ad8\u7b49\u4ee3\u6570\u5b66\uff08\u7b2c\u56db\u7248\uff09\u914d\u5957\u5b66\u4e60\u7528\u4e66\u300b\u8c22\u542f\u9e3f\uff0c\u59da\u6155\u751f\uff0c\u590d\u65e6\u5927\u5b66\u51fa\u7248\u793e

\u6388\u8bfe\u53cd\u9988\uff1a

  1. \u8bfe\u524d\u53cd\u9988\uff1a
  2. \u8bfe\u540e\u53cd\u9988\uff1a
"},{"location":"test/","title":"\u6d4b\u8bd5","text":"

\u672c\u9875\u9762\u7528\u4e8e\u6d4b\u8bd5\u5404\u7c7b\u7ec4\u4ef6\u663e\u793a\u6d4b\u8bd5\u3002

"},{"location":"test/#bilibili-stats","title":"Bilibili Stats","text":"

\u8fd9\u91cc\u548c\u8fd9\u91cc\u7684\u4e24\u4e2a\u9879\u76ee\u529f\u80fd\u90fd\u6b8b\u7f3a\u4e86\uff0c\u8003\u8651\u540e\u7eed\u90e8\u7f72\u5230\u670d\u52a1\u5668\u4e0a\u3002

"},{"location":"test/#latex","title":"LaTeX","text":"

simple

\\[ x ={-b \\pm \\sqrt{b^2-4ac}\\over 2a} \\]

matrix

\\[ \\left\\{\\begin{matrix} x=a + r\\text{cos}\\theta \\\\ y=b + r\\text{sin}\\theta \\end{matrix}\\right. \\]

array

\\[ \\begin{array}{l} a\\mathop{{x}}\\nolimits^{{2}}+bx+c=0 \\\\ \\Delta =\\mathop{{b}}\\nolimits^{{2}}-4ac \\\\ \\mathop{{x}}\\nolimits_{{1,2}}=\\frac{{-b \\pm \\sqrt{{\\mathop{{b}}\\nolimits^{{2}}-4ac}}}}{{2a}} \\\\ \\mathop{{x}}\\nolimits_{{1}}+\\mathop{{x}}\\nolimits_{{2}}=-\\frac{{b}}{{a}} \\\\ \\mathop{{x}}\\nolimits_{{1}}\\mathop{{x}}\\nolimits_{{2}}=\\frac{{c}}{{a}} \\end{array} \\]

calculus

\\[ \\int \\frac{1}{\\sqrt{1-x^{2}}}\\mathrm{d}x= \\arcsin x +C \\]

algebra

\\[ \\begin{vmatrix} \\mathbf{i}& \\mathbf{j}& \\mathbf{k} \\\\ \\frac{\\partial X}{\\partial u}& \\frac{\\partial Y}{\\partial u}& 0 \\\\ \\frac{\\partial X}{\\partial v}& \\frac{\\partial Y}{\\partial v}& 0 \\\\ \\end{vmatrix} \\]

physics

\\[ \\mathop \\Phi \\nolimits_e = \\oint { \\mathord{ \\buildrel{ \\lower3pt \\hbox{$ \\scriptscriptstyle \\rightharpoonup$}} \\over E} \\cdot {d \\mathord{ \\buildrel{ \\lower3pt \\hbox{$ \\scriptscriptstyle \\rightharpoonup$}} \\over S}} = {1 \\over {{\\varepsilon _0}}}\\sum {q} } \\]

Unicode

\\[ %\u6b64\u516c\u5f0f\u9700\u8981\u5728\u8bbe\u7f6e\u4e2d\u5f00\u542f unicode \u6269\u5c55\u652f\u6301 \\begin{array}{l} {\\huge \\unicode{8751}}_\\mathbb{S} \\mathbf{E} \\cdot\\mathrm{d}s= \\cfrac{Q}{\\varepsilon_0} \\\\ {\\huge \\unicode{8751}}_\\mathbb{S} \\mathbf{B} \\cdot\\mathrm{d}s= 0 \\\\ {\\huge \\oint}_{\\mathbb{L}}^{} \\mathbf{E} \\cdot \\mathrm{d}l=-\\cfrac{\\mathrm{d}\\Phi _{\\mathbf{B}}}{\\mathrm{d}t } \\\\ {\\huge \\oint}_{\\mathbb{L}}^{} \\mathbf{B} \\cdot \\mathrm{d}l=\\mu_0I+ \\mu_0 \\varepsilon_0\\cfrac{\\mathrm{d}\\Phi _{\\mathbf{E}}}{\\mathrm{d}t } \\end{array} \\]

mhchem

\\[ %\u6b64\u516c\u5f0f\u9700\u8981\u5728\u3010\u8bbe\u7f6e\u3011\u4e2d\u5f00\u542f mhchem \u6269\u5c55\u652f\u6301 \u5177\u4f53\u7528\u6cd5\u8bf7\u53c2\u8003\u3010\u5e2e\u52a9\u30112.11.2 \\ce{SO4^2- + Ba^2+ -> BaSO4 v} \\]"},{"location":"algebra/","title":"\u7ebf\u6027\u4ee3\u6570\u8f85\u5b66","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u7ebf\u6027\u4ee3\u6570\u7248\u5757 \ud83e\udd17\u3002

"},{"location":"algebra/#_2","title":"\u5386\u5e74\u5377","text":""},{"location":"algebra/#ih","title":"\u7ebf\u6027\u4ee3\u6570 I\uff08H\uff09\u671f\u4e2d/\u5c0f\u6d4b\u5386\u5e74\u5377\u8bd5\u9898\u96c6","text":"\u8bd5\u5377 \u7b54\u6848 2022-2023 \u5b66\u5e74 \u5434\u5fd7\u7965 \u671f\u4e2d \u7b54\u6848 2022-2023 \u5b66\u5e74 \u8c08\u4e4b\u5955 \u671f\u4e2d \u6682\u65e0 2022-2023 \u5b66\u5e74 \u5218\u5eb7\u751f \u671f\u4e2d \u6682\u65e0 2021-2022 \u5b66\u5e74 \u5218\u5eb7\u751f \u5c0f\u6d4b \u6682\u65e0 2021-2022 \u5b66\u5e74 \u5434\u5fd7\u7965 \u671f\u4e2d \u7b54\u6848 2020-2021 \u5b66\u5e74 \u8c08\u4e4b\u5955 \u5c0f\u6d4b 1 \u6682\u65e0 2020-2021 \u5b66\u5e74 \u8c08\u4e4b\u5955 \u5c0f\u6d4b 2 \u6682\u65e0 2020-2021 \u5b66\u5e74 \u5434\u5fd7\u7965 \u671f\u4e2d \u6682\u65e0"},{"location":"algebra/#ih_1","title":"\u7ebf\u6027\u4ee3\u6570 I\uff08H\uff09\u671f\u672b\u5386\u5e74\u5377\u8bd5\u9898\u96c6","text":"\u8bd5\u5377 \u7b54\u6848 2009-2010 \u5b66\u5e74 \u6682\u65e0 2010-2011 \u5b66\u5e74 \u6682\u65e0 2011-2012 \u5b66\u5e74 \u6682\u65e0 2012-2013 \u5b66\u5e74 \u6682\u65e0 2013-2014 \u5b66\u5e74 \u6682\u65e0 2014-2015 \u5b66\u5e74 \u6682\u65e0 2018-2019 \u5b66\u5e74 \u6682\u65e0 2019-2020 \u5b66\u5e74 \u6682\u65e0 2021-2022 \u5b66\u5e74 \u6682\u65e0 2022-2023 \u5b66\u5e74 \u6682\u65e0 2023-2024 \u5b66\u5e74 \u6682\u65e0"},{"location":"algebra/#iih","title":"\u7ebf\u6027\u4ee3\u6570 II\uff08H\uff09\u671f\u4e2d/\u5c0f\u6d4b\u5386\u5e74\u5377\u8bd5\u9898\u96c6","text":"\u8bd5\u5377 \u7b54\u6848 2022-2023 \u5b66\u5e74 \u5434\u5fd7\u7965 \u671f\u4e2d \u6682\u65e0 2022-2023 \u5b66\u5e74 \u5218\u5eb7\u751f \u671f\u4e2d \u6682\u65e0 2020-2021 \u5b66\u5e74 \u8c08\u4e4b\u5955 \u671f\u4e2d \u6682\u65e0 2020-2021 \u5b66\u5e74 \u5218\u5eb7\u751f \u671f\u4e2d \u6682\u65e0"},{"location":"algebra/#iih_1","title":"\u7ebf\u6027\u4ee3\u6570 II\uff08H\uff09\u671f\u672b\u5386\u5e74\u5377\u8bd5\u9898\u96c6","text":"\u8bd5\u5377 \u7b54\u6848 2022-2023 \u5b66\u5e74 \u7b54\u6848 2022-2023 \u5b66\u5e74 \u5218\u5eb7\u751f \u8003\u524d\u7ec3\u4e60 \u6682\u65e0 2021-2022 \u5b66\u5e74 \u6682\u65e0"},{"location":"algebra/#_3","title":"\u5386\u5e74\u8d44\u6599\u5f52\u6863","text":""},{"location":"algebra/#2022-2023","title":"2022-2023 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":"\u4e3b\u8bb2\u4eba \u5185\u5bb9 \u8bb2\u4e49 \u56fe\u7075 2002 \u5468\u5065\u5747 \u7ebf\u4ee3 I \u671f\u4e2d\u590d\u4e60 \u8bb2\u4e49\u7b54\u6848 \u56fe\u7075 2001 \u5434\u4e00\u822a \u7ebf\u4ee3 I \u671f\u4e2d\u4e0e\u671f\u672b\u590d\u4e60 \u671f\u4e2d\u590d\u4e60\u671f\u672b\u590d\u4e60\u5df2\u7f16\u7e82\u6210 LALU \u6c42\u6570 2101 \u59dc\u61ff\u84c9 \u7ebf\u6027\u53d8\u6362 \u8bb2\u4e49\u7ffb\u8bd1\u7248 \u56fe\u7075 2101 \u9648\u5c0f\u5ddd \u884c\u5217\u5f0f \u8bb2\u4e49 \u5f3a\u6570 2101 \u51af\u7693\u3001\u5f6d\u6e43 \u7ebf\u6027\u56fe\u5f62\u4e0e\u5185\u79ef\u7a7a\u95f4 \u8bb2\u4e49\u7b54\u6848"},{"location":"algebra/2023/","title":"2023-2024 \u5b66\u5e74\u7ebf\u6027\u4ee3\u6570\u8f85\u5b66","text":""},{"location":"algebra/2023/#ih","title":"\u7ebf\u6027\u4ee3\u6570 I(H)","text":""},{"location":"algebra/2023/#_1","title":"\u8bfe\u9898\u7ec4\u6210\u5458","text":""},{"location":"algebra/2023/#_2","title":"\u8bfe\u7a0b\u5f55\u64ad","text":"

W \u4ee3\u8868\u9002\u914d\u5434\u5fd7\u7965\u73ed\uff0cT \u4ee3\u8868\u9002\u914d\u8c08\u4e4b\u5955\u73ed\uff0cH \u4ee3\u8868\u5408\u73ed\u4e0a\u8bfe\u3002

\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2\u4eba \u5f55\u64ad\u5730\u5740 \u8bb2\u4e49 W1 Oct.29 \u5f15\u5165\uff1a\u7ebf\u6027\u7a7a\u95f4 \u6885\u654f\u70ab Bilibili LALU T1 Oct.29 \u5f15\u5165\uff1a\u7ebf\u6027\u7a7a\u95f4 \u5434\u4e00\u822a Bilibili LALU H2 Nov.18 \u7ebf\u6027\u6620\u5c04\u53ca\u5176\u77e9\u9635\u8868\u793a \u5434\u4e00\u822a Bilibili LALU H3 Dec.3 \u77e9\u9635\u7684\u79e9\u4e0e\u5206\u5757\u77e9\u9635 \u6f58\u90b9\u7eac Bilibili \u8bb2\u4e49 H4 Dec.16 \u884c\u5217\u5f0f\u548c\u7ebf\u6027\u65b9\u7a0b\u7ec4 \u859b\u8fb0\u7acb Bilibili LALU H5 Dec.30 \u671f\u672b\u590d\u4e60 \u5434\u4e00\u822a Bilibili PPT"},{"location":"algebra/2023/#_3","title":"\u8bfe\u7a0b\u5b89\u6392","text":""},{"location":"algebra/2023/#iih","title":"\u7ebf\u6027\u4ee3\u6570 II(H)","text":""},{"location":"algebra/2023/#_4","title":"\u8bfe\u7a0b\u5f55\u64ad","text":"\u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2\u4eba \u5f55\u64ad\u5730\u5740 \u8bb2\u4e49 Jun.8 \u671f\u672b\u590d\u4e60 \u5434\u4e00\u822a Bilibili LALU

\u7b2c\u4e00\u8bb2\u7531\u4e8e\u5f55\u50cf\u7684\u5931\u8bef\u5bfc\u81f4\u6ca1\u6709\u58f0\u97f3\uff0c\u6240\u4ee5\u5e76\u672a\u4e0a\u4f20 B \u7ad9\u3002

"},{"location":"algebra/2023/#_5","title":"\u8bfe\u7a0b\u5b89\u6392","text":""},{"location":"algebra/2024/","title":"2024-2025 \u5b66\u5e74\u7ebf\u6027\u4ee3\u6570\u8f85\u5b66","text":""},{"location":"algebra/2024/#ih","title":"\u7ebf\u6027\u4ee3\u6570 I(H)","text":""},{"location":"algebra/2024/#_1","title":"\u8bfe\u9898\u7ec4\u6210\u5458","text":""},{"location":"algebra/2024/#_2","title":"\u8bfe\u7a0b\u5f55\u64ad","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2\u4eba \u5f55\u64ad\u5730\u5740 \u8bb2\u4e49 1 2024.10.27 \u9ad8\u65af\u6d88\u5143\u6cd5\uff0c\u7ebf\u6027\u7a7a\u95f4 \u6df7\u5408 2303 \u5f90\u827a\u7545 Bilibili \u8bb2\u4e49 2 2024.11.10 \u7ebf\u6027\u6620\u5c04\u53ca\u5176\u77e9\u9635\u8868\u793a \u56fe\u7075 2303 \u674e\u6587\u8000 Bilibili \u8bb2\u4e49 3 2024.11.24 \u77e9\u9635\u8ba1\u7b97 \u76f8\u62b5\u6807\u51c6\u5f62 \u56fe\u7075 2001 \u5434\u4e00\u822a Bilibili \u8bb2\u4e49"},{"location":"algebra/2024/#_3","title":"\u8bfe\u7a0b\u5b89\u6392","text":"

\u6388\u8bfe\u5f62\u5f0f\u4e3a\u7ebf\u4e0a\u7ebf\u4e0b\u7ed3\u5408\uff1a

"},{"location":"algebra/lalu/","title":"\u7ebf\u6027\u4ee3\u6570\uff1a\u672a\u7adf\u4e4b\u7f8e","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u7ebf\u6027\u4ee3\u6570\u8f85\u5b66\u7cbe\u54c1\u8bfe\u7a0b\u7248\u5757 \ud83e\udd17\u3002

"},{"location":"algebra/lalu/#_2","title":"\u8bfe\u7a0b\u7b80\u4ecb","text":"

\u7ebf\u6027\u4ee3\u6570\u4f5c\u4e3a\u5f88\u591a\u540c\u5b66\u5927\u5b66\u63a5\u89e6\u7684\u7b2c\u4e00\u95e8\u6570\u5b66\u8bfe\uff0c\u4e00\u65b9\u9762\u5176\u91cd\u8981\u6027\u4e0d\u8a00\u800c\u55bb\uff0c\u5728\u5f88\u591a\u4e13\u4e1a\u4e2d\u90fd\u662f\u5fc5\u8981\u7684\u9884\u4fee\u77e5\u8bc6\uff0c\u53e6\u4e00\u65b9\u9762\u5f88\u591a\u540c\u5b66\u4e5f\u662f\u7b2c\u4e00\u6b21\u63a5\u89e6\u5982\u6b64\u62bd\u8c61\u7684\u6570\u5b66\u5185\u5bb9\uff0c\u56e0\u6b64\u5728\u5b66\u4e60\u7ebf\u6027\u4ee3\u6570\u65f6\u4f1a\u9047\u5230\u5f88\u591a\u56f0\u96be\u3002\u7279\u522b\u662f\u6d59\u6c5f\u5927\u5b66\u56fe\u7075\u73ed\u540c\u5b66\u4e24\u5b66\u671f\u8981\u9762\u5bf9\u7684\u300a\u5927\u5b66\u6570\u5b66\uff1a\u4ee3\u6570\u4e0e\u51e0\u4f55\u300b\u548c\u300a\u7ebf\u6027\u4ee3\u6570\u5e94\u8be5\u8fd9\u6837\u5b66\u300b\u4e24\u672c\u6559\u6750\uff0c\u7b2c\u4e00\u672c\u76f4\u63a5\u4ece\u62bd\u8c61\u7684\u7ebf\u6027\u7a7a\u95f4\u548c\u7ebf\u6027\u6620\u5c04\u5f15\u5165\uff0c\u629b\u5f03\u4e86\u4f20\u7edf\u5de5\u79d1\u7ebf\u6027\u4ee3\u6570\u4ece\u884c\u5217\u5f0f\u8d77\u6b65\u7684\u6559\u6388\u65b9\u5f0f\uff0c\u66f4\u80fd\u8ba9\u540c\u5b66\u4e86\u89e3\u7ebf\u6027\u4ee3\u6570\u7684\u672c\u8d28\uff0c\u4f46\u5165\u95e8\u5b58\u5728\u4e00\u4e9b\u56f0\u96be\u3002\u800c\u7b2c\u4e8c\u672c\u6559\u6750\u98ce\u683c\u5219\u66f4\u504f\u5411\u4e8e\u6570\u5b66\u4e13\u4e1a\u8bfe\uff0c\u6574\u4f53\u6bd4\u8f83\u62bd\u8c61\uff0c\u4ee5\u201c\u7b97\u5b50\u201d\u4e3a\u6838\u5fc3\uff0c\u907f\u5f00\u884c\u5217\u5f0f\u53d9\u8ff0\u7ebf\u6027\u4ee3\u6570\u4e2d\u7684\u6838\u5fc3\u7406\u8bba\uff0c\u5176\u76ee\u7684\u53ea\u662f\u4e3a\u4e86\u8868\u660e\u4ed6\u6240\u8bb2\u7684\u5185\u5bb9\u548c\u4f20\u7edf\u7ebf\u6027\u4ee3\u6570\u662f\u7edf\u4e00\u7684\u3002

\u6211\u60f3\u5982\u679c\u80fd\u5c06\u8fd9\u4e24\u672c\u6559\u6750\u5b66\u597d\uff0c\u7ebf\u6027\u4ee3\u6570\u7684\u57fa\u7840\u5c06\u4f1a\u662f\u975e\u5e38\u624e\u5b9e\u7684\u3002\u4f46\u7406\u5ff5\u4e0e\u5b9e\u9645\u6267\u884c\u6709\u5f88\u5927\u7684\u504f\u5dee\uff0c\u5e76\u975e\u6240\u6709\u540c\u5b66\u90fd\u80fd\u5728\u521d\u5b66\u65f6\u5b8c\u5168\u63a5\u53d7\u62bd\u8c61\u7684\u6559\u5b66\u65b9\u5f0f\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u7ebf\u6027\u4ee3\u6570\uff08\u6216\u9ad8\u7b49\u4ee3\u6570\uff09\u8fd8\u6709\u5f88\u591a\u7684\u53c2\u8003\u8d44\u6599\uff08\u5982\u4e18\u7ef4\u58f0\u8001\u5e08\uff0c\u8c22\u542f\u9e3f\u8001\u5e08\u7684\u9ad8\u7b49\u4ee3\u6570\uff0c\u6216\u662f Strang \u8001\u5148\u751f\u7684\u7ebf\u6027\u4ee3\u6570\uff0c\u6216\u662f 3blue1brown \u7684\u7ebf\u6027\u4ee3\u6570\u7684\u672c\u8d28\uff09\uff0c\u4f46\u540c\u5b66\u4eec\u5982\u679c\u5b8c\u5168\u6295\u5165\u65f6\u95f4\u5230\u8fd9\u4e9b\u53c2\u8003\u4e66\uff0c\u5f88\u5bb9\u6613\u9677\u5165\u8ff7\u832b\uff0c\u5e76\u4e14\u4e0e\u6700\u7ec8\u7684\u8003\u8bd5\u98ce\u683c\u4e5f\u76f8\u8ddd\u8f83\u8fdc\u3002\u56e0\u6b64\u6211\u4eec\u5e0c\u671b\u6709\u4e00\u672c\u8bb2\u4e49\u80fd\u7efc\u5408\u8fd9\u4e9b\u8d44\u6599\u4e2d\u4e0e\u8fd9\u4e24\u95e8\u8bfe\u7684\u5b66\u4e60\u5173\u8054\u7684\u90e8\u5206\uff0c\u4f18\u5316\u5185\u5bb9\u5b89\u6392\uff0c\u5e76\u5b89\u6392\u8db3\u91cf\u7684\u4e60\u9898\u4f9b\u540c\u5b66\u7ec3\u4e60\uff0c\u4ee5\u4fbf\u540c\u5b66\u4eec\u80fd\u591f\u66f4\u597d\u5730\u5b66\u4e60\u7ebf\u6027\u4ee3\u6570\u3002

\u53e6\u4e00\u65b9\u9762\uff0c\u7ebf\u6027\u4ee3\u6570\u662f\u4e00\u4e2a\u53e4\u8001\u800c\u5e74\u8f7b\u7684\u5b66\u79d1\u3002\u5b83\u53d1\u8f6b\u4e8e\u65e9\u5148\u5bf9\u7ebf\u6027\u65b9\u7a0b\u7ec4\u7684\u7814\u7a76\uff0c\u7ecf\u5386\u4e86\u6f2b\u957f\u7684\u51e0\u4f55\u548c\u4ee3\u6570\u7684\u4ea4\u9519\u4f5c\u7528\uff0c\u6700\u540e\u53c8\u5728\u8fd1\u4e16\u4ee3\u6570\u7684\u53d1\u5c55\u8fc7\u7a0b\u4e2d\u88ab\u4e25\u683c\u5316\u3002\u76f4\u5230\u73b0\u5728\uff0c\u4e00\u4e9b\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u4f8b\u5982\u7ebf\u6027\u4ee3\u6570\u7fa4\u7684\u7814\u7a76\u5c1a\u4e14\u65b9\u5174\u672a\u827e\uff0c\u5728\u73b0\u4ee3\u6570\u5b66\u7684\u79cd\u79cd\u652f\u7ebf\u5f53\u4e2d\u4e5f\u6709\u7740\u91cd\u8981\u7684\u5e94\u7528\u3002\u53e6\u5916\uff0c\u5b83\u7684\u65b9\u6cd5\u8bba\uff0c\u5c24\u5176\u662f\u5176\u5bf9\u4ee3\u6570\u7ed3\u6784\u7684\u7814\u7a76\u5728\u73b0\u4ee3\u6570\u5b66\u4e2d\u4e5f\u5177\u5907\u7740\u4ee3\u8868\u6027\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u5e0c\u671b\u5448\u73b0\u4e00\u4e2a\u66f4\u5e7f\u9614\u7684\u7ebf\u6027\u4ee3\u6570\u89c2\uff0c\u4ece\u7ebf\u6027\u4ee3\u6570\u51fa\u53d1\uff0c\u5bf9\u5b83\u7684\u73b0\u4ee3\u53d1\u5c55\u548c\u5b83\u5728\u73b0\u4ee3\u6570\u5b66\u7684\u5404\u4e2a\u5206\u652f\u7684\u5e94\u7528\u8fdb\u884c\u4e00\u4e9b\u5bfc\u8bba\u6027\u7684\u4ecb\u7ecd\uff0c\u8fd9\u4e00\u65b9\u9762\u662f\u4e3a\u4e86\u4f7f\u5f97\u5e73\u6de1\u7684\u53d9\u8ff0\u66f4\u52a0\u6709\u8da3\uff0c\u53e6\u4e00\u65b9\u9762\u4e5f\u662f\u4e3a\u4e86\u56de\u7b54\u4e00\u4e2a\u7591\u95ee\uff1a\u7ebf\u6027\u4ee3\u6570\u5230\u5e95\u6709\u4ec0\u4e48\u7528\uff1f\u6211\u4eec\u76f8\u4fe1\uff0c\u8fd9\u662f\u8bb8\u591a\u521d\u5b66\u8005\u90fd\u6709\u7684\u4e00\u4e2a\u95ee\u9898\uff0c\u56de\u7b54\u8fd9\u4e2a\u95ee\u9898\u65e2\u9700\u8981\u5bf9\u7ebf\u6027\u4ee3\u6570\u7684\u6df1\u5165\u5b66\u4e60\uff0c\u4e5f\u9700\u8981\u6709\u4e00\u4e2a\u73b0\u4ee3\u6570\u5b66\u7684\u5168\u5c40\u89c2\uff0c\u8fd9\u4e5f\u5c31\u5e26\u6765\u4e86\u672c\u4e66\u7684\u53e6\u4e00\u4e2a\u90e8\u5206\uff0c\u672a\u7adf\u4e13\u9898\uff0c\u4e5f\u662f\u6211\u4eec\u8fd9\u672c\u4e66\u7684\u6807\u9898\u6765\u6e90\u3002

\u5177\u4f53\u800c\u8a00\uff0c\u6211\u4eec\u7684\u8bb2\u4e49\u76ee\u524d\u5206\u522b\u4e24\u4e2a\u90e8\u5206\uff1a

"},{"location":"algebra/lalu/#_3","title":"\u8bfe\u7a0b\u8bb2\u4e49","text":"\u8bb2\u4e49\uff08v0.6\uff09\u7b54\u6848\uff08v0.6\uff09

LALU \u8bfe\u7a0b\u7684\u8bb2\u4e49\u5b58\u653e\u5728\u4e0b\u9762\u7684\u4ed3\u5e93\u4e2d\uff0c\u4f60\u53ef\u4ee5\u70b9\u51fb\u56fe\u7247\u8df3\u8f6c\u5230\u4ed3\u5e93\u9875\u9762\u3002\u6b22\u8fce\u63d0\u51fa issue \u548c pull request\u3002

\u70b9\u51fb\u4e0b\u9762\u7684\u94fe\u63a5\u53ef\u4ee5\u4e0b\u8f7d\u8bb2\u4e49\u7684\u6700\u65b0 Release \u7248\u672c\uff1a

"},{"location":"analysis/","title":"\u6570\u5b66\u5206\u6790\u8f85\u5b66","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u6570\u5b66\u5206\u6790\u7248\u5757 \ud83e\udd17\u3002\u672c\u9875\u9762\u6c47\u603b\u4e86\u6570\u5b66\u5206\u6790\u7684\u8f85\u5b66\u8d44\u6599\uff0c\u5305\u62ec\u5386\u5e74\u8bd5\u5377\u3001\u8bb2\u4e49\u3001\u5f55\u64ad\u7b49\u3002

"},{"location":"analysis/#2024-2025","title":"2024-2025 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":""},{"location":"analysis/#ih","title":"\u79cb\u51ac\u5b66\u671f \u6570\u5b66\u5206\u6790 I\uff08H\uff09","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad\u5730\u5740 1 Oct.19 \u5b9e\u6570\u7cfb\u5b8c\u5907\u6027\u4e0e\u6570\u5217\u6781\u9650 \u5f3a\u7269 2201 \u6f58\u6210\u5586 \u8bb2\u4e49\u601d\u8003\u9898\u53cd\u9988 Bilibili 2 Oct.20 \u4e00\u5143\u51fd\u6570\u6781\u9650\u548c\u8fde\u7eed\u4e0e\u7b2c\u4e00\u6b21\u5c0f\u6d4b\u590d\u4e60 \u6df7\u5408 2206 \u8c22\u96c6 \u8bb2\u4e49\u7b54\u6848 Bilibili 3 Nov.10 \u5bfc\u6570\u3001\u5fae\u5206\u548c\u4e2d\u503c\u5b9a\u7406 \u56fe\u7075 2302 \u6768\u4e66\u534e \u8bb2\u4e49 Bilibili"},{"location":"analysis/#2023-2024","title":"2023-2024 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":""},{"location":"analysis/#ih_1","title":"\u79cb\u51ac\u5b66\u671f \u6570\u5b66\u5206\u6790 I\uff08H\uff09","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad\u5730\u5740 1 Oct.14 \u6570\u5217\u6781\u9650 \u6df7\u5408 2206 \u80e1\u80b2\u73ae \u8bb2\u4e49\u7b54\u6848 Bilibili 2 Oct.28 \u4e00\u5143\u51fd\u6570\u7684\u6781\u9650\u4e0e\u8fde\u7eed\u6027 \u56fe\u7075 2102 \u6f58\u6636\u7693 \u8bb2\u4e49 Bilibili 3 Nov.26 \u5fae\u5206\u4e2d\u503c\u5b9a\u7406\u548cTaylor\u516c\u5f0f\u62d3\u5c55\u5e94\u7528 \u6df7\u5408 2206 \u8c22\u96c6 \u8bb2\u4e49\u7b54\u6848 Bilibili 4 Dec.9/10 \u4e0d\u5b9a\u79ef\u5206 \u6df7\u5408 2203 \u4f55\u5146\u5e73"},{"location":"analysis/#iih","title":"\u6625\u590f\u5b66\u671f \u6570\u5b66\u5206\u6790 II\uff08H\uff09","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad\u5730\u5740 1 Mar.31 \u7ea7\u6570\u4e0e\u7b2c\u4e00\u6b21\u5c0f\u6d4b\u590d\u4e60 \u6df7\u5408 2206 \u8c22\u96c6 \u8bb2\u4e49\u7b54\u6848 Bilibili 2 May.12 \u591a\u5143\u51fd\u6570\u5fae\u5206\u5b66 \u56fe\u7075 2202 \u6885\u654f\u70ab \u8bb2\u4e49 Bilibili 3 Jun.2 \u591a\u5143\u51fd\u6570\u79ef\u5206\u5b66 \u6df7\u5408 2201 \u97e9\u8d8a \u8bb2\u4e49\u7b54\u6848 Bilibili 4 Jun.9 \u671f\u672b\u590d\u4e60 \u5f3a\u7269 2201 \u6f58\u6210\u5586 \u8bb2\u4e49\u8865\u5145 Bilibili 4 Jun.12 \u4e13\u9898\u8bfe \u5f3a\u7269 2201 \u6f58\u6210\u5586 Rn\u7684\u6570\u5b66\u7ed3\u6784\u91cd\u79ef\u5206 Bilibili"},{"location":"analysis/#_2","title":"\u5386\u5e74\u5377","text":""},{"location":"analysis/#ih_2","title":"\u6570\u5b66\u5206\u6790 I\uff08H\uff09","text":"\u5e74\u4efd \u8bd5\u5377 2023-2024 \u5c0f\u6d4b1 \u671f\u672b\u8bd5\u5377/\u7b54\u6848 2022-2023 \u5c0f\u6d4b1/\u7b54\u6848\u5c0f\u6d4b2/\u7b54\u6848\u671f\u672b\u8bd5\u5377/\u7b54\u6848\uff08zhw\uff09/\u7b54\u6848\uff08hz\uff09 2021-2022 \u5c0f\u6d4b/\u7b54\u6848\u671f\u672b\u8bd5\u5377/\u7b54\u6848\uff08lzw\uff09/\u7b54\u6848\uff08hz\uff09 2020-2021 \u671f\u672b\u8bd5\u5377\uff08\u90e8\u5206\uff09"},{"location":"analysis/#iih_1","title":"\u6570\u5b66\u5206\u6790 II\uff08H\uff09","text":"\u5e74\u4efd \u8bd5\u5377 2022-2023 \u5c0f\u6d4b1 2021-2022 \u671f\u672b\u8bd5\u5377 2020-2021 \u671f\u672b\u8bd5\u5377 \u672a\u77e5\u5e74\u4efd \u5c0f\u6d4b\u53ca\u7b54\u6848"},{"location":"analysis/#_3","title":"\u5386\u5e74\u8d44\u6599\u5f52\u6863","text":""},{"location":"analysis/#2022-2023","title":"2022-2023 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":"\u6388\u8bfe\u5185\u5bb9 \u4e3b\u8bb2\u4eba \u4e0d\u5b9a\u79ef\u5206 \u56fe\u7075 2101 \u9646\u6676\u5b87 \u6570\u5b66\u5206\u6790 I \u8003\u524d\u590d\u4e60 1 \u6df7\u5408 2003 \u90b1\u65e5\u5b8f \u6570\u5b66\u5206\u6790 I \u8003\u524d\u590d\u4e60 2 \u8bb2\u4e49\u7b54\u6848 \u56fe\u7075 2102 \u6f58\u6636\u7693 \u7ea7\u6570 \u8bb2\u4e49\u7b54\u6848 \u6df7\u5408 2102 \u5218\u5fd7\u709c \u66f2\u7ebf\u3001\u66f2\u9762\u3001\u542b\u53c2\u53d8\u91cf\u79ef\u5206 \u5f3a\u7269 2101 \u738b\u5bb8\u660a"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/","title":"\u7b2c\u4e00\u8bb2 \u6570\u5217\u6781\u9650","text":""},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_2","title":"\u5b9e\u6570\u5b8c\u5907\u6027\u5b9a\u7406","text":""},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_3","title":"\u8981\u6c42","text":"
  1. \u7ed9\u51fa\u6982\u5ff5\u3001\u5b9a\u7406\u7684\u540d\u5b57\u53ef\u4ee5\u4f7f\u7528\u6570\u5b66\u8bed\u8a00\u51c6\u786e\u53d9\u8ff0\u3002

  2. \u638c\u63e1\u57fa\u672c\u7684\u5b9a\u7406\u8bc1\u660e\u94fe\uff08\u8be6\u7ec6\u53c2\u80031.4.1 1.4.2\uff09\uff1a

    • \u786e\u754c\u539f\u7406\\(\\rightarrow\\)\u5355\u8c03\u6709\u754c\u5b9a\u7406\\(\\rightarrow\\)\u81f4\u5bc6\u6027\u5b9a\u7406\\(\\rightarrow\\)Cauchy\u51c6\u5219

    • \u5355\u8c03\u6709\u754c\u5b9a\u7406\\(\\rightarrow\\)\u95ed\u533a\u95f4\u5957\u5b9a\u7406\\(\\rightarrow\\)\u6709\u9650\u8986\u76d6\u5b9a\u7406\uff08\u805a\u70b9\u539f\u7406\u548cDedekind\u5206\u5272\u5b9a\u7406\u4e0d\u8981\u6c42\uff09

    • \u786e\u754c\u539f\u7406\\(\\rightarrow\\)\u5404\u4e2a\u5b9a\u7406

  3. \u671f\u672b\u8003\u8bd5\u4f1a\u5728\u8fd9\u51e0\u4e2a\u5b9a\u7406\u91cc\u51fa\u53d9\u8ff0\u9898\u548c\u8bc1\u660e\u9898\uff1b\u5c0f\u6d4b\u4f1a\u8003\u5404\u4e2a\u5b9a\u7406\u7684\u6570\u5b66\u53d9\u8ff0\u7ec6\u8282\u3002

"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_4","title":"\u6982\u5ff5\u53d9\u8ff0","text":"
  1. \u6709\u754c\uff0c\u65e0\u754c

    \\[ \\begin{align} \u6570\u5217\u6709\u754c: &\\quad\\forall n>0,\\exists M\\in \\text{R},\u4f7f|x_n|<M\u6052\u6210\u7acb\\\\ \u6570\u5217\u65e0\u754c: &\\quad\\forall M\\in \\text{R},\\exists n>0,\u4f7f|x_n|>M \\\\ \u9519\u8bef(?): &\\quad\\exists n>0,\\forall M\\in \\text{R},\u4f7fx_n>M \\end{align} \\]

    \u6570\u5b66\u8bed\u8a00\u7684\u5426\u5b9a\uff1a\u8f6c\u6362\u5168\u79f0\u91cf\u8bcd\u548c\u5b58\u5728\u91cf\u8bcd\uff0c\u6ce8\u610f\u91cf\u8bcd\u987a\u5e8f\uff0c\u6539\u53d8\u7b26\u53f7

  2. \u6700\u5927\u6570\uff0c\u6700\u5c0f\u6570

    \\[ \\begin{align} \\max\\{S\\}=a &\\iff a\\in S\u4e14\\forall x\\in S,a\\ge x\\\\ \\min\\{S\\}=b &\\iff b\\in S\u4e14\\forall x\\in S,b\\le x \\end{align} \\]
  3. \u4e0a\u786e\u754c\uff0c\u4e0b\u786e\u754c

    \\[ \\begin{align} M=\\sup\\{S\\}\\iff& \\forall x\\in S,x\\le M\u4e14\\forall\\epsilon>0,\\exists x'\\in S\u6709x'>M-\\epsilon\\\\ m=\\inf\\{S\\}\\iff& \\forall x\\in S,x\\ge m\u4e14\\forall\\epsilon>0,\\exists x'\\in S\u6709x'<M+\\epsilon \\end{align} \\]
"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_5","title":"\u5b9a\u7406\u53d9\u8ff0","text":"
  1. \u786e\u754c\u539f\u7406

    \u975e\u7a7a\u6709\u754c\u96c6\u5fc5\u6709\u4e0a\u4e0b\u786e\u754c

  2. \u5355\u8c03\u6709\u754c\u5b9a\u7406

    \u5355\u8c03\u6709\u754c\u6570\u5217\u5fc5\u6536\u655b

  3. \u81f4\u5bc6\u6027\u5b9a\u7406

    \u4efb\u4f55\u6709\u754c\u6570\u5217\u5fc5\u6709\u6536\u655b\u5b50\u5217

  4. Cauchy\u51c6\u5219

    \\[ a_n\u6536\u655b\\iff\\forall \\epsilon>0,\\exists N>0,\\forall m,n>N,\u5747\u6709|a_m-a_n|<\\epsilon \\\\ \\iff \\forall \\epsilon>0,\\exists N>0,\\forall n>N,p>0,\u5747\u6709|a_{n+p}-a_n|<\\epsilon \\]
  5. \u533a\u95f4\u5957\u5b9a\u7406

    \\[ \\begin{align} & \u8bbe\u95ed\u533a\u95f4\u5217\\{[a_n,b_n]\\}\u6ee1\u8db3:\\\\ & 1.[a_{n+1},b_{n+1}]\\subset[a_n,b_n],n=1,2,3..\\\\ & 2.\\lim_{n\\to\\infty}(b_n-a_n)=0 \\\\ & \u5219\u5b58\u5728\u552f\u4e00\u5b9e\u6570\\xi\uff0c\u6ee1\u8db3\\xi\\in[a_n,b_n],n=1,2.. \\end{align} \\]
  6. \u6709\u9650\u8986\u76d6\u5b9a\u7406

    \\[ \\begin{align} & \u8bbe[a,b]\u662f\u4e00\u4e2a\u95ed\u533a\u95f4\uff0c\\{E_\\lambda\\}_{\\lambda\\in\\Lambda}\u662f[a,b]\u7684\u4efb\u610f\u4e00\u4e2a\u5f00\u8986\u76d6\uff0c\\\\ & \u5219\u5fc5\u5b58\u5728\\{E_\\lambda\\}_{\\lambda\\in\\Lambda}\u7684\u4e00\u4e2a\u5b50\u96c6\u6784\u6210[a,b]\u7684\u4e00\u4e2a\u6709\u9650\u8986\u76d6\u3002 \\\\ \\iff & \u5728\\{E_\\lambda\\}_{\\lambda\\in\\Lambda}\u5fc5\u6709\u6709\u9650\u4e2a\u5f00\u533a\u95f4E_1,E_2..E_N\u4f7f[a,b]\\subset\\cup_{j=1}^NE_j \\end{align} \\]
"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_6","title":"\u5e38\u7528\u6280\u5de7","text":"
  1. \u8bc1\u660e\u96c6\u5408\u76f8\u7b49\u7684\u5e38\u7528\u65b9\u6cd5\uff1a\u76f8\u4e92\u5305\u542b

    \u4f8b\u9898\uff1a\u786e\u754c\u7684\u5173\u7cfb\u5f0f

    \u8bbe \\(A,B\\) \u662f\u4e24\u4e2a\u7531\u975e\u8d1f\u6570\u7ec4\u6210\u7684\u4efb\u610f\u6570\u96c6,\u8bd5\u8bc1\u660e \\(\\sup_{x\\in A}\\{x\\}\\cdot \\sup_{y\\in B}\\{y\\}=\\sup_{x\\in A,y\\in B}\\{xy\\}\\)

  2. \u5bf9\u4e8e\u5b9e\u6570\u5b8c\u5907\u6027\u5b9a\u7406\u7684\u8bc1\u660e\u9898\uff0c\u9996\u5148\u5c06\u7ed9\u7684\u6761\u4ef6\u548c\u8bc1\u660e\u5185\u5bb9\u5747\u7ffb\u8bd1\u6210\u6570\u5b66\u8bed\u8a00\uff08\u65b9\u4fbf\u9a97\u5206\uff09\uff0c\u518d\u89c2\u5bdf\u6761\u4ef6\u548c\u8bc1\u660e\u5185\u5bb9\u7684\u8054\u7cfb\u3002

"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_7","title":"\u4f8b\u9898&\u4e60\u9898","text":"
  1. \u7528\u786e\u754c\u539f\u7406\u8bc1\u660e\u5355\u8c03\u6709\u754c\u539f\u7406\u3001\u81f4\u5bc6\u6027\u5b9a\u7406\u3001Cauchy\u51c6\u5219\u3001\u95ed\u533a\u95f4\u5957\u5b9a\u7406\u3001\u6709\u9650\u8986\u76d6\u5b9a\u7406\u3002
  2. \u7528\u5355\u8c03\u6709\u754c\u5b9a\u7406\u8bc1\u660e\u95ed\u533a\u95f4\u5957\u5b9a\u7406\uff0c\u7528\u95ed\u533a\u95f4\u5957\u5b9a\u7406\u8bc1\u660e\u6709\u9650\u8986\u76d6\u5b9a\u7406\uff1b\u7528\u81f4\u5bc6\u6027\u5b9a\u7406\u8bc1\u660eCauchy\u6536\u655b\u51c6\u5219\u3002
  3. \\(f,g\u4e3aD\u4e0a\u6709\u754c\u51fd\u6570,\\text{pf:}\\inf\\{f(x)+g(x)\\}\\le\\inf{f(x)}+\\sup{g(x)}\\)
  4. \u8bbe\\(f(x)\u5728[0,1]\u4e0a\u9012\u589e,f(0)>0,f(1)<1,\u6c42\u8bc1:\\exists x_0\\in(0,1),\u4f7f\u5f97f(x_0)=x_0^2\\) (Hint:\u786e\u754c\u539f\u7406or\u533a\u95f4\u5957\u5b9a\u7406)
  5. \u8bbe\\(f(x)\\)\u5728\\([a,b]\\)\u4e0a\u6709\u5b9a\u4e49\u4e14\u5728\u6bcf\u4e00\u70b9\u5904\u51fd\u6570\u7684\u6781\u9650\u5b58\u5728\uff0c\u6c42\u8bc1\\(f(x)\\)\u5728\\([a,b]\\)\u4e0a\u6709\u754c (Hint:\u6709\u9650\u8986\u76d6)
  6. \\(\u8bbef(x)\u5728(a,b)\u5185\u6709\u5b9a\u4e49\uff0c\\forall\\xi\\in(a,b),\\exists\\delta>0,\u5f53x\\in(\\xi-\\delta,\\xi+\\delta)\\cap(a,b)\u65f6,\\)\u6709\u5f53\\(x<\\xi\\)\u65f6,\\(f(x)<f(\\xi), \u5f53x>\\xi\\)\u65f6,\\(f(x)>f(\\xi)\\).\u8bf7\u8bc1\u660e:\\(f(x)\u5728(a,b)\\)\u5185\u4e25\u683c\u9012\u589e (Hint:\u6709\u9650\u8986\u76d6)
"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_8","title":"\u6570\u5217\u6781\u9650","text":""},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_9","title":"\u8981\u6c42","text":"
  1. \u4ece\u5c0f\u6d4b\u7684\u89d2\u5ea6\u6765\u8bf4\uff0c\u6982\u5ff5\uff0c\u5b9a\u7406\u4ee5\u53ca\u5224\u65ad\u9898\u662f\u6bd4\u8f83\u91cd\u8981\uff08\u641e\u8111\u5b50\uff09\u7684\uff0c\u5f53\u7136\u4e5f\u4f1a\u6709\u8ba1\u7b97\u9898
  2. \u671f\u672b\u8003\u8bd5\u53ef\u80fd\u4f1a\u51fa1-2\u9053\u6c42\u6781\u9650\uff0c1\u9053\u975e\u5e38\u7b80\u5355\u7684\u6781\u9650\u8bc1\u660e\u9898\uff08\u9644\u5728\u5b9a\u7406\u53d9\u8ff0\u4e0a\uff09
  3. \u8ba1\u7b97\u4e5f\u9700\u8981\u638c\u63e1\uff0c\u4f46\u662f\u6280\u5de7\u6027\u5f3a\u7684\u53ef\u4ee5\u4e0d\u638c\u63e1
  4. \u5b66\u597d\u6570\u5217\u6781\u9650\u5bf9\u51fd\u6570\u6781\u9650\u548c\u7ea7\u6570\u90fd\u5f88\u6709\u5e2e\u52a9\uff0c\u800c\u5b66\u597d\u4e86\u51fd\u6570\u6781\u9650\u5c31\u53ef\u4ee5\u5b66\u597d\u5bfc\u6570\u548c\u79ef\u5206\uff0c\u7136\u540e\u4f60\u5c31\u5b66\u4f1a\u4e86\u6570\u52061
"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_10","title":"\u6982\u5ff5\u53d9\u8ff0","text":"
  1. \u6570\u5217\u6781\u9650\uff08\\(\\epsilon-N\\)\u8bed\u8a00\uff09
\\[ \\forall\\epsilon>0,\\exists N>0,\\forall n>N,|x_n-A|<\\epsilon\u79f0\\lim_{x\\rightarrow\\infty}x_n=A\\\\ *:|x_n-A|<f(\\epsilon),f(x)\u6ee1\u8db3\\lim _{x\\rightarrow0}f(x)=0\u5373\u53ef \\]
  1. \u6570\u5217\u53d1\u6563
\\[ \\forall A\\in R,\\exists\\epsilon_0>0,\\forall N>0,\\exists n_N>N,|x_n-A|\\ge\\epsilon_0 \\]
  1. \u5b50\u5217

    \\[ \\{a_n\\}\u6536\u655b\\iff \\{a_n\\}\u7684\u4efb\u610f\u5b50\u5217\u90fd\u6536\u655b\u4e8eA(\u8bf7\u6ce8\u610f\u51cf\u5f31\u547d\u9898) \\]
  2. \u65e0\u7a77\u5c0f\u91cf\u548c\u65e0\u7a77\u5927\u91cf

    \\[ \\begin{align} & \u65e0\u7a77\u5c0f\u91cf : \\lim_{x\\rightarrow\\infty}= 0 \\\\ & \u65e0\u7a77\u5927\u91cf : \\forall M>0,\\exists N,\\forall n>N,|x_n|>M \\end{align} \\]
"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_11","title":"\u5b9a\u7406\u53d9\u8ff0","text":"
  1. Stolz\u5b9a\u7406

    \u5e38\u7528\u4e8e\u8ba1\u7b97\u5f62\u5f0f\u9700\u8981\u6d1b\u5fc5\u8fbe\u7684\u6781\u9650

  2. Cauchy\u6536\u655b\u51c6\u5219\u3001\u7b49\u4ef7\u5f62\u5f0f\u53ca\u5426\u5b9a

\\[ \\begin{align} a_n\u6536\u655b& \\iff\\forall \\epsilon>0,\\exists N>0,\\forall m,n>N,\u5747\u6709|a_m-a_n|<\\epsilon \\\\ & \\iff \\forall \\epsilon>0,\\exists N>0,\\forall n>N,p>0,\u5747\u6709|a_{n+p}-a_n|<\\epsilon \\\\ \u5426\u5b9a\u5f62\u5f0f:a_n\u53d1\u6563& \\iff\\exists\\epsilon_0>0,\\forall N,\\exists n_0>N,p>0,|x_{n_0+p}-x_{n_0}|\\ge\\epsilon_0 \\end{align} \\]"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_12","title":"\u5e38\u7528\u6280\u5de7","text":"
  1. \u4e00\u4e9b\u5173\u7cfb\u94fe\uff1a

    1. \\(n\\rightarrow\\infty\u65f6\\)
    \\[ \\log\\log n\\ll \\log n \\ll n^a\\ll b^n\\ll n!\\ll n^n\\quad(a,b>0) \\]
    1. \\(x\\rightarrow0\u65f6\\)
    \\[ \\begin{align} x \\sim &\\sin x\\sim \\tan x \\sim \\arcsin x\\sim \\arctan x \\\\ \\sim &\\ln{(1+x)} \\sim \\text{e}^x-1 \\sim \\frac{a^x-1}{\\ln a}\\sim \\frac{(1+x)^b-1}b \\quad(a>0,b\\neq0)\\\\ & 1-\\cos x \\sim \\frac12 x^2 \\end{align} \\]
  2. \u8bc1\u660e\u6570\u5217\u6781\u9650\u5b58\u5728\uff1a

    1. \u5b9a\u4e49\uff08\\(\\epsilon-N\\)\u65b9\u6cd5\uff09

    \u6280\u5de7\uff1a\u653e\u5927\u6cd5(\u5e38\u7528)/\u5206\u6b65\u6cd5/\u6784\u9020\u5f62\u5f0f\u7c7b\u4f3c\u7684\u9879/\u62df\u5408\u6cd5(\u6280\u5de7\u6027\u8f83\u5f3a)

    1. Cauchy\u51c6\u5219\uff1a\u4e0d\u9700\u8981\u77e5\u9053\u6781\u9650\u503c

    2. Cauchy\u51c6\u5219\u7684\u63a8\u8bba\uff1a\u5e38\u7528\u4e8e\u5224\u65ad\u6570\u9879\u7ea7\u6570\u662f\u5426\u6536\u655b(\\(a_n=\\sum_{n=1}^{\\infty}f(n)\\))

    3. \u5355\u8c03\u6709\u754c\u539f\u7406\uff1a\u4e0d\u52a8\u70b9\uff0c\u9012\u63a8\u5f0f\u8003\u8651

    4. \u6781\u9650\u7684\u8fd0\u7b97\u6027\u8d28\uff1a\u672c\u8eab\u5b58\u5728\u6781\u9650 \u6709\u9650\u9879\u8fd0\u7b97

  3. \u8bc1\u660e\u6570\u5217\u6781\u9650\u4e0d\u5b58\u5728\uff1a

    1. Cauchy\u547d\u9898\u7684\u5426\u5b9a\u5f62\u5f0f
    2. \u5b50\u5217\u4e0d\u6536\u655b\u6216\u6536\u655b\u4e8e\u4e0d\u540c\u7684\u6570
  4. \u6c42\u6570\u5217(\u51fd\u6570)\u6781\u9650\uff1a

    1. \u6781\u9650\u7684\u8fd0\u7b97\u6027\u8d28

    \u4e00\u4e9b\u91cd\u8981\u6781\u9650\uff1a\\(\\lim\\limits_{n\\rightarrow\\infty}n^\\frac1n=1\\)\uff0c\\(\\lim\\limits_{n\\rightarrow\\infty}(1+\\frac1n)^n=e\\)

    1. Stolz\u5b9a\u7406

    2. \u5939\u903c\u5b9a\u7406

    3. \u7b49\u4ef7\u4ee3\u6362\u4e0e\u521d\u7b49\u53d8\u5f62

    4. \u9012\u63a8\u5f62\u5f0f\u7684\u6781\u9650\uff1a\u5355\u8c03\u6709\u754c\u539f\u7406+\u8bc1\u660e/\u538b\u7f29\u6620\u50cf(\u7565\u96be)/Stolz\u516c\u5f0f\u7684\u5e94\u7528

    5. Taylor/L'Hospital/\u79ef\u5206\u5b9a\u4e49/\u6570\u9879\u7ea7\u6570/\u7ea7\u6570\u7684\u8fde\u7eed\u6027...\uff1a \u5f88\u91cd\u8981\uff0c\u4f46\u8fd9\u662f\u540e\u4e8b\u4e86

"},{"location":"analysis/2023-2024Fall/analysis_lecture1_sequence_limits/#_13","title":"\u4f8b\u9898&\u4e60\u9898","text":"
  1. \u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u5b50\u5217\u7684\u547d\u9898

    1. \u8bbe\\(\\{a_n\\}\\)\u662f\u4e00\u4e2a\u6570\u5217\uff0c\u82e5\u5728\u4efb\u4e00\u5b50\u5217\\(\\{a_{n_k}\\}\\)\u4e2d\u5747\u5b58\u5728\u6536\u655b\u5b50\u5217\\(\\(\\{a_{n_{k_r}}\\}\\)\\),\u5219\\(\\(\\{a_n\\}\\)\\)\u5fc5\u6536\u655b
    2. \\(\\{a_n\\}\u5355\u8c03\u9012\u589e\uff0c\\{a_{n_k}\\}\u4e3a\u5176\u4e2d\u4e00\u4e2a\u5b50\u5217\uff0c\\lim\\limits_{k\\rightarrow\\infty}a_{n_k}=a,\u5219\\lim\\limits_{n\\rightarrow\\infty}{a_n}=a\\)
    3. \\(\\{a_{2k}\\}\\{a_{2p+1}\\}\\{a_{2023t+2024}\\}\u5747\u6536\u655b\uff0c\u5219\\{a_n\\}\u6536\u655b\\)
    4. \\(\\{a_{2k}\\}\\{a_{2t+1}\\}\\{a_{6p+5}\\}\u5747\u6536\u655b\uff0c\u5219\\{a_n\\}\u6536\u655b\\)
  2. \u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u65e0\u7a77\u5c0f\u91cf\u7684\u547d\u9898

    1. \u65e0\u7a77\u591a\u4e2a\u65e0\u7a77\u5c0f\u91cf\u4e4b\u548c\u662f\u65e0\u7a77\u5c0f\u91cf
    2. \u65e0\u7a77\u591a\u4e2a\u65e0\u7a77\u5c0f\u91cf\u4e4b\u79ef\u662f\u65e0\u7a77\u5c0f\u91cf
    3. \u65e0\u7a77\u5c0f\u91cf\u4e0e\u6709\u754c\u91cf\u4e4b\u79ef\u4e3a\u65e0\u7a77\u5c0f\u91cf
  3. \u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u6570\u5217\u6781\u9650\u7684\u547d\u9898

    1. \u6570\u5217\\(a_n\\)\u6536\u655b\\(\\iff \\forall p\\in N,\\lim\\limits_{n\\rightarrow+\\infty}{|a_{n+p}-a_n|=0}\\)
    2. \\(\\lim\\limits_{n\\rightarrow\\infty}x_n=A\\iff\\forall k\\in \\text{N},\\exists N>0,\\forall n>N,|x_n-A|<\\frac1k\\)
    3. \\(a_n\u6536\u655b \\iff \\exists N>0,\\forall \\epsilon>0,\\forall m,n>N,\u5747\u6709|a_m-a_n|<\\epsilon\\)
  4. \u91cd\u8981\u7684\u4e8c\u7ea7\u7ed3\u8bba\uff1a

\\[ Cauchy\u5b9a\u7406:\\lim_{n\\rightarrow\\infty}x_n=A,\u5219\\lim_{n\\rightarrow\\infty}\\frac{x_1+x_2+...+x_n}{n}=A \\]
  1. \\(x_n=\\sum_{i=1}^n\\sin(\\frac{2i-1}{n^2}a),\\text{pf:}\\lim\\limits_{n\\rightarrow\\infty}x_n=a\\) (Hint:\u62df\u5408\u6cd5)

  2. \u6c42\u6781\u9650\\(\\lim\\limits_{n\\rightarrow\\infty}x_n\\)\uff1a

    1. \\(x_n=\\cos\\frac x2\\cos\\frac x{2^2}\\cdots\\cos\\frac x{2^n}\\)
    2. \\(x_n=(\\frac{\\sqrt[n]a+\\sqrt[n]b}{2})^n\\)
    3. \\(x_n=\\frac 1{\\sqrt[n]{n!}}\\)
    4. \\(x_n={(n!)}^{\\frac1{n^2}}\\)
    5. \\(x_n=\\sqrt[6]{x^6+x^5}-\\sqrt[6]{x^6-x^5}\\)
  3. (2019(?)\u5e74\u6570\u52061\u671f\u672b)

\\[ \\begin{align} & \u5bf9\u4e8e\u6570\u5217x_0=a,0<a<\\frac\\pi2,x_n=\\sin x_{n-1}(n=1,2,\\cdots). \\\\ &\\text{pf:}(1)\\lim\\limits_{n\\rightarrow\\infty}x_n=0;(2)\\lim\\limits_{n\\rightarrow\\infty}{\\sqrt\\frac n3}x_n=1 \\end{align} \\]"},{"location":"analysis/analysis1_paper/22test1_answer/","title":"22\u6570\u5206\u5c0f\u6d4b\u7b54\u6848","text":"

\u9898\u76ee\u3001\u9009\u9879\u987a\u5e8f\u53c2\u8003\u5c0f\u6d4b1

  1. D
  2. AC
  3. B
  4. A
  5. BCD
  6. ABD
  7. B
  8. B
  9. A (\u805a\u70b9\u5e94\u8be5\u4e0d\u8981\u6c42\uff0c\u53ef\u4ee5\u5ffd\u7565)
  10. C
"},{"location":"calculus/","title":"\u5fae\u79ef\u5206\u8f85\u5b66","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u5fae\u79ef\u5206\u7248\u5757 \ud83e\udd17\u3002

"},{"location":"calculus/#2023-2024","title":"2023-2024 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad 1 Oct.22 \u6781\u9650\u4e0e\u51fd\u6570\u7684\u8fde\u7eed\u6027 \u6df7\u5408 2106 \u5f20\u5fd7\u5fc3 \u8bb2\u4e49 \u7b54\u6848 Bilibili 2 Nov.5 \u671f\u4e2d\u590d\u4e60 \u6c42\u5316 2201 \u5218\u5b50\u6db5 \u8bb2\u4e49\u7b54\u6848 Bilibili 3 Dec.3 \u5fae\u5206\u4e2d\u503c\u5b9a\u7406\u548c\u4e0d\u5b9a\u79ef\u5206 \u5f3a\u533b 2101 \u5362\u601d\u7426 \u8bb2\u4e49 Bilibili"},{"location":"chemistry/","title":"\u666e\u901a\u5316\u5b66\u8f85\u5b66","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u666e\u901a\u5316\u5b66\u7248\u5757\ud83e\udd17\u3002

"},{"location":"chemistry/#_2","title":"\u8f85\u5b66\u8d44\u6599\u5f52\u6863","text":""},{"location":"chemistry/#2023-2024","title":"2023-2024 \u5b66\u5e74 \u79cb\u51ac\u5b66\u671f","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad 3 Dec.12 \u7535\u5316\u5b66\u4e0e\u7269\u8d28\u7ed3\u6784 \u6df7\u5408 2102 \u674e\u822a\u5947 \u8bb2\u4e49 Bilibili"},{"location":"other/","title":"\u5176\u4ed6\u8d44\u6e90","text":""},{"location":"other/#_2","title":"\u6982\u7387\u8bba\u4e0e\u6570\u7406\u7edf\u8ba1","text":""},{"location":"other/#_3","title":"\u5c0f\u6d4b\u9898\u5e93","text":"\u5b66\u671f \u8bd5\u5377 23\u79cb\u51ac \u5c0f\u6d4b\u4e00(1)\u5c0f\u6d4b\u4e8c(1)/\u5c0f\u6d4b\u4e8c(2)/\u5c0f\u6d4b\u4e8c(3)\u5c0f\u6d4b\u4e09(1)/\u5c0f\u6d4b\u4e09(2) 23\u6625\u590f \u5c0f\u6d4b\u4e00(1)"},{"location":"physics/","title":"\u666e\u7269\u8f85\u5b66","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u666e\u7269\u8f85\u5b66\u7248\u5757\ud83e\udd17\u3002\u4f60\u53ef\u4ee5\u5728\u5de6\u4fa7\u5bfc\u822a\u680f\u4e2d\u8be6\u7ec6\u6d4f\u89c8\u672c\u6a21\u5757\u7684\u5185\u5bb9\u3002

"},{"location":"physics/#2023-2024","title":"2023-2024 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":""},{"location":"physics/#ih","title":"\u6625\u590f\u5b66\u671f \u666e\u901a\u7269\u7406\u5b66 I\uff08H\uff09","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad\u5730\u5740 1 Mar.31 \u9884\u5907\u77e5\u8bc6\u3001\u52a8\u91cf\u3001\u8f6c\u52a8 \u6df7\u5408 2305 \u6768\u5f18\u6bc5 \u8bb2\u4e49\u7b54\u6848 Bilibili"},{"location":"programming/","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u7a0b\u8bbe\u7248\u5757\ud83e\udd17\u3002\u4f60\u53ef\u4ee5\u5728\u5de6\u4fa7\u5bfc\u822a\u680f\u4e2d\u6d4f\u89c8\u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66\u7684\u6240\u6709\u8d44\u6599\u3002

"},{"location":"programming/#_2","title":"\u5176\u4ed6\u8d44\u6e90","text":""},{"location":"programming/#_3","title":"\u5e38\u7528\u7f51\u7ad9","text":""},{"location":"programming/#_4","title":"\u5b66\u957f\u5b66\u59d0\u7684\u7b14\u8bb0\u672c","text":"

\u5f88\u591a\u5b66\u957f\u5b66\u59d0\u90fd\u5728\u81ea\u5df1\u7684\u535a\u5ba2/\u7b14\u8bb0\u672c\u4e2d\u5199\u4e86\u4e00\u4e9b\u5173\u4e8e\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u5185\u5bb9\uff0c\u8fd9\u91cc\u5217\u51fa\u4e00\u4e9b\u94fe\u63a5\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\u3002

"},{"location":"programming/24fall/","title":"24 \u79cb\u51ac \u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66","text":"

\u6b22\u8fce\u6765\u5230 24 \u79cb\u51ac\u7a0b\u8bbe\u8f85\u5b66\u8bfe\u7a0b\u9875\u9762\uff01\u672c\u5b66\u671f\u8ba1\u5212\u5f00\u8bfe 6 \u6b21\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a

\u8282\u6b21 \u65f6\u95f4 \u6388\u8bfe\u5b66\u957f \u8bfe\u7a0b\u6807\u9898 \u56de\u653e\u5730\u5740 \u4e00 \u79cb\u4e03\u5468 \u6df7\u5408 2301 \u502a\u665f\u7fd4 \u7f16\u7a0b\u5165\u95e8 Bilibili \u4e8c \u51ac\u4e8c\u5468 \u6df7\u5408 2205 \u6731\u5b9d\u6797 \u901a\u5f80 Pro \u7684\u7b2c\u4e00\u6b65\u547d\u4ee4\u884c\u4ea4\u4e92\u3001VSCode\u3001AI \u5de5\u5177 Bilibili \u4e09 \u51ac\u56db\u5468 \u56fe\u7075 2302 \u9ec4\u54f2 \u5f00\u6e90\u4e16\u754c\u751f\u5b58\u57fa\u7840SSH \u5bc6\u94a5\u3001ZJUGit\u3001Git\u3001\u8bb8\u53ef\u8bc1 Bilibili \u56db \u51ac\u4e94\u5468 \u56fe\u7075 2201 \u674e\u82f1\u7426 \u5982\u4f55\u5199\u51fa\u7b80\u6d01\u5de5\u6574\u7684\u62a5\u544aMarkdown\u3001LaTeX Bilibili \u4e94 \u51ac\u516d\u5468 \u56fe\u7075 2302 \u6768\u4e66\u534e \u671f\u672b\u590d\u4e60\uff08\u4e0a\uff09 \u516d \u51ac\u4e03\u5468 \u6df7\u5408 2301 \u53f8\u6d69\u8a00 \u671f\u672b\u590d\u4e60\uff08\u4e0b\uff09

\u5173\u4e8e\u8bfe\u7a0b\u96be\u5ea6\uff0c\u6211\u4eec\u4f1a\u4e25\u683c\u63a7\u5236\u5728\u5927\u4e00\u65b0\u751f\u521a\u63a5\u89e6\u8ba1\u7b97\u673a\u65f6\u7684\u6c34\u5e73\u3002\u53bb\u5e74\u6211\u4eec\u8bbe\u5b9a\u7684\u96be\u5ea6\u6709\u70b9\u9ad8\uff0c\u6548\u679c\u4e0d\u662f\u5f88\u597d\uff08\u6709\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u5728\u5de6\u4fa7\u5bfc\u822a\u680f\u6d4f\u89c8\u53bb\u5e74\u7684\u5185\u5bb9\uff09\u3002\u4eca\u5e74\u6211\u4eec\u7684\u76ee\u6807\u662f\u666e\u53ca\uff0c\u8ba9\u5c3d\u53ef\u80fd\u591a\u7684\u540c\u5b66\u53d7\u76ca\u3002

"},{"location":"programming/24fall/#_1","title":"\u8bfe\u7a0b\u52a8\u673a\u4e0e\u76ee\u6807","text":"

Hi\uff0cCSer\uff01\u6b22\u8fce\u4f60\u6765\u5230\u8ba1\u7b97\u673a\u4e13\u4e1a\u7684\u4e16\u754c\u3002\u4f46\u8fd9\u6761\u8def\u521a\u5f00\u59cb\u7684\u4e00\u6bb5\u53ef\u80fd\u5e76\u4e0d\u597d\u8d70\uff1a

\u5927\u4e00\u5165\u5b66\u65f6\u6211\u662f\u4e00\u4e2a\u5bf9\u8ba1\u7b97\u673a\u4e00\u65e0\u6240\u77e5\u7684\u5c0f\u767d\uff0c\u88c5\u4e86\u51e0\u5341\u4e2a G \u7684 Visual Studio \u5929\u5929\u548c OJ \u4f60\u6b7b\u6211\u6d3b\u3002\u51ed\u7740\u9ad8\u4e2d\u7684\u6570\u5b66\u5e95\u5b50\u6211\u6570\u5b66\u8bfe\u5b66\u5f97\u8fd8\u4e0d\u9519\uff0c\u4f46\u5728\u4e13\u4e1a\u8bfe\u4e0a\u5bf9\u7ade\u8d5b\u5927\u4f6c\u53ea\u6709\u4ef0\u671b\u3002\u63d0\u5230\u7f16\u7a0b\u6211\u53ea\u4f1a\u6253\u5f00\u90a3\u7b28\u91cd\u7684 IDE\uff0c\u65b0\u5efa\u4e00\u4e2a\u6211\u4e5f\u4e0d\u77e5\u9053\u5177\u4f53\u662f\u5e72\u5565\u7684\u547d\u4ee4\u884c\u9879\u76ee\uff0c\u7136\u540e\u5c31\u662f cin, cout, for \u5faa\u73af\uff0c\u7136\u540e CE, RE, WA \u5faa\u73af\u3002\u5f53\u65f6\u7684\u6211\u5c31\u5904\u5728\u4e00\u79cd\u62fc\u547d\u60f3\u5b66\u597d\u4f46\u4e0d\u77e5\u9053\u600e\u4e48\u5b66\uff0c\u8bfe\u4e0a\u8ba4\u771f\u542c\u8bb2\u4f46\u9898\u8fd8\u4e0d\u4f1a\u505a\uff0c\u8bfe\u540e\u505a\u4f5c\u4e1a\u5b8c\u5168\u662f\u7528\u65f6\u95f4\u548c\u5b83\u786c\u8017\u7684\u75db\u82e6\u72b6\u6001\u3002\u6211\u81f3\u4eca\u7535\u8111\u91cc\u8fd8\u5b58\u7740\u81ea\u5df1\u5927\u4e00\u4e0a\u5b66\u671f\u8ba1\u7b97\u6982\u8bba\u5927\u4f5c\u4e1a\u7684\u6e90\u4ee3\u7801 \u2014\u2014 \u4e00\u4e2a 1200 \u884c\u7684 C++ \u6587\u4ef6\uff0c\u6ca1\u6709\u5934\u6587\u4ef6\u3001\u6ca1\u6709\u7c7b\u3001\u6ca1\u6709\u5c01\u88c5\u3001\u6ca1\u6709 unit test\u3001\u6ca1\u6709 Makefile\u3001\u6ca1\u6709 Git\uff0c\u552f\u4e00\u7684\u4f18\u70b9\u662f\u5b83\u786e\u5b9e\u80fd\u8dd1\uff0c\u7f3a\u70b9\u662f\u201c\u80fd\u8dd1\u201d\u7684\u8865\u96c6\u3002\u6211\u4e00\u5ea6\u6000\u7591\u6211\u662f\u4e0d\u662f\u4e0d\u9002\u5408\u5b66\u8ba1\u7b97\u673a\uff0c\u56e0\u4e3a\u7ae5\u5e74\u5bf9\u4e8e\u6781\u5ba2\u7684\u6240\u6709\u60f3\u8c61\uff0c\u5df2\u7ecf\u88ab\u6211\u7b2c\u4e00\u4e2a\u5b66\u671f\u7684\u4f53\u9a8c\u5f7b\u5e95\u7c89\u788e\u4e86\u3002

\u4e0a\u9762\u8fd9\u6bb5\u8bdd\u6765\u81ea CS \u81ea\u5b66\u6307\u5357 \u7684\u4f5c\u8005\uff0c\u6211\u60f3\u4e5f\u662f\u5f88\u591a\u540c\u5b66\u7684\u771f\u5b9e\u5199\u7167\u3002\u8fd9\u6bb5\u8bdd\u771f\u5b9e\u5730\u63ed\u793a\u4e86\u56fd\u5185\u8ba1\u7b97\u673a\u672c\u79d1\u6559\u80b2\u7684\u4e00\u4e2a\u666e\u904d\u95ee\u9898\uff1a\u7f3a\u4e4f\u5de5\u5177\u548c\u6280\u80fd\u7684\u57f9\u517b\u3002\u8fd9\u4e00\u60c5\u51b5\u6b63\u5728\u597d\u8f6c\uff0c\u8d8a\u6765\u8d8a\u591a\u56fd\u5185\u5916\u5b66\u6821\u5f00\u59cb\u91cd\u89c6\u8fd9\u65b9\u9762\u7684\u6559\u80b2\uff0c\u5f00\u8bbe\u4e86\u76f8\u5173\u8bfe\u7a0b\uff1a

\u5b66\u6821 \u8bfe\u7a0b MIT\uff08\u9ebb\u7701\u7406\u5de5\u5b66\u9662\uff09 Missing Semester \u6e05\u534e\u5927\u5b66 \u5168\u90e8\u8bfe\u7a0b\u91c7\u7528\u6587\u6863 + \u5f00\u6e90\u4ee3\u7801\u6846\u67b6\u5de5\u5177\u548c\u6280\u80fd\u7684\u57f9\u517b\u5df2\u7ecf\u878d\u5165\u8bfe\u7a0b\u4f53\u7cfb \u4e2d\u56fd\u79d1\u5b66\u6280\u672f\u5927\u5b66 Linux 101 \u5357\u4eac\u5927\u5b66 ICS-PA2024

\u4f46\u5f88\u53ef\u60dc\uff0c\u6d59\u6c5f\u5927\u5b66\u8ba1\u7b97\u673a\u5b66\u9662\u7684\u8bfe\u6539\u8fd8\u6ca1\u6709\u8d70\u5230\u8fd9\u4e00\u6b65\uff0c\u4f60\u53ef\u4ee5\u770b\u5230\u90e8\u5206\u300a\u7a0b\u5e8f\u8bbe\u8ba1\u4e0e\u7b97\u6cd5\u57fa\u7840\u300b\u7684\u8001\u5e08\u8fd8\u5728\u4f7f\u7528 20 \u5e74\u524d\u7684 PPT\u3002\u6240\u4ee5\u6211\u4eec\u5e0c\u671d\u7740\u8fd9\u4e2a\u65b9\u5411\u52aa\u529b\uff0c\u5bf9\u9f50\u5176\u4ed6\u5b66\u6821\u7684\u8bfe\u7a0b\uff0c\u5e2e\u52a9\u540c\u5b66\u4eec\u5c3d\u65e9\u638c\u63e1\u8fd9\u4e9b\u6280\u80fd\uff0c\u8ba9\u4f60\u4eec\u5728\u4e13\u4e1a\u8bfe\u4e0a\u5c11\u8d70\u5f2f\u8def\u3002

\u53bb\u5e74\u6211\u4eec\u5f00\u8bbe\u4e86\u4e24\u5957\u8bfe\u7a0b\uff0c\u4f46\u663e\u7136\u5bf9\u5927\u4e00\u65b0\u751f\u6765\u8bf4\u5185\u5bb9\u8fc7\u591a\u4e14\u96be\u4e86\u3002\u672c\u5b66\u671f\u7684\u76ee\u6807\u662f\u666e\u53ca\uff0c\u8ba9\u5927\u4e00\u65b0\u751f\u6709\u4e00\u4e2a\u9002\u5e94\u7684\u8fc7\u7a0b\uff0c\u6240\u4ee5\u8bfe\u7a0b\u5185\u5bb9\u4f1a\u6781\u4e3a\u7b80\u5355\u3002\u6211\u4eec\u8ba1\u5212\u5728 25spring \u5f00\u8bbe\u6df1\u5165\u7684\u8bfe\u7a0b\uff0c\u5230\u65f6\u5019\u4f1a\u6709\u66f4\u591a\u6df1\u5165\u7684\u5185\u5bb9\u3002

\u611f\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u8fdb\u4e00\u6b65\u9605\u8bfb\uff1a\u8c08\u8c08\u5982\u4f55\u8ba9\u81ea\u5df1\u770b\u4e0a\u53bb\u3001\u95fb\u4e0a\u53bb\u90fd\u50cf\u4e00\u4e2a CS \u4eba - CC98\u3002

"},{"location":"programming/24fall/group-session/","title":"24fall \u7a0b\u8bbe\u8f85\u5b66\u6388\u8bfe\u7ec4\u6559\u7814\u4f1a","text":"

\u65e5\u671f\uff1a2024 \u5e74 10 \u6708 18 \u65e5 \u5730\u70b9\uff1a\u7389\u6e56 7 \u5e62 116 \u4eba\u5458\uff1a\u6731\u5b9d\u6797\u3001\u738b\u666e\u3001\u6768\u4e66\u534e\u3001\u502a\u665f\u7fd4\u3001\u674e\u82f1\u7426\u3001\u6885\u654f\u70ab\u3001\u82cf\u715c\u7a0b\u3001\u9ec4\u54f2\u3001\u53f8\u6d69\u8a00

"},{"location":"programming/24fall/lec1/","title":"\u7b2c\u4e00\u8bb2\uff1a\u7f16\u7a0b\u5165\u95e8","text":"

\u672c\u6b21\u8bfe\u7a0b\u5b9a\u4f4d\u4e3a\u7f16\u7a0b\u5165\u95e8\uff0c\u5e0c\u671b\u4e3b\u8981\u5411\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e9b\u57fa\u672c\u7684\u7f16\u7a0b\u601d\u60f3\uff0c\u5e76\u901a\u8fc7\u4f8b\u9898\u4e0e\u8bb2\u89e3\u7684\u5f62\u5f0f\u52a0\u4ee5\u6e17\u900f\u3002\u4f8b\u9898\u53c2\u8003\u81ea\u53bb\u5e74\u7684 PTA \u4e60\u9898\u3002

"},{"location":"programming/24fall/lec1/#_2","title":"\u8ba1\u7b97\u673a\u57fa\u7840\u77e5\u8bc6","text":"

\u51af\u8bfa\u4f9d\u66fc\u67b6\u6784\uff1a\u8f93\u5165\u3001\u50a8\u5b58\u3001\u8ba1\u7b97\u3001\u8f93\u51fa

\u8ba1\u7b97\u673a\u5982\u4f55\u50a8\u5b58\u6570\u636e\uff1f

\u8ba1\u7b97\u673a\u5982\u4f55\u8fd0\u7b97\u6570\u636e\uff1f

"},{"location":"programming/24fall/lec1/#_3","title":"\u7f16\u7a0b\u601d\u8def","text":"

\u7f16\u7a0b\u7684\u8fc7\u7a0b\u53ef\u4ee5\u662f\u4e00\u79cd\u76f4\u89c2\u601d\u8003\u7684\u62bd\u8c61\u5316\uff0c\u5bf9\u4e8e\u4e00\u822c\u7684\u7f16\u7a0b\u95ee\u9898\uff0c\u6211\u4e00\u822c\u628a\u5b83\u5206\u4e3a\u4e24\u7c7b\uff0c\u5373\uff1a

\u5bf9\u4e8e\u524d\u8005\uff0c\u6211\u4eec\u8fd8\u662f\u53ef\u4ee5\u6709\u4e00\u5b9a\u7684\u601d\u8def\u53bb\u89e3\u51b3\u7684\uff0c\u6bd4\u5982\u4e0b\u9762\u8fd9\u4e2a\u7ecf\u5178\u7684\u4f8b\u5b50\uff1a

\u4f8b\u5b50

\u516c\u9e21 5 \u5143\u4e00\u53ea\u3001\u6bcd\u9e21 3 \u5143\u4e00\u53ea\u3001\u5c0f\u9e21 1 \u5143 3 \u53ea\uff1b100 \u5143\u4e70\u4e86 100 \u53ea\u9e21\uff0c\u95ee\u5404\u591a\u5c11\u53ea\uff1f

\u5bf9\u4e8e\u540e\u8005\uff0c\u6bd4\u5982\uff1a

\u4f8b\u5b50

\u7ed9\u5b9a\u4e24\u4e2a\u5355\u8bcd word1 \u548c word2\uff0c\u8ba1\u7b97\u51fa\u5c06 word1 \u8f6c\u6362\u6210 word2 \u6240\u4f7f\u7528\u7684\u6700\u5c11\u64cd\u4f5c\u6570\u3002

\u7528\u6237\u53ef\u4ee5\u5bf9\u4e00\u4e2a\u5355\u8bcd\u8fdb\u884c\u5982\u4e0b\u4e09\u79cd\u64cd\u4f5c\uff1a\u63d2\u5165\u4e00\u4e2a\u5b57\u7b26\u3001\u5220\u9664\u4e00\u4e2a\u5b57\u7b26\u3001\u66ff\u6362\u4e00\u4e2a\u5b57\u7b26\u3002

\u8df3\u51fa\u505a\u9898\u7684\u6846\u67b6\uff0c\u6211\u4eec\u4e00\u822c\u628a\u7f16\u7a0b\u8303\u5f0f\u5206\u4e3a\u4ee5\u4e0b\u51e0\u79cd\uff1a

"},{"location":"programming/24fall/lec1/#_4","title":"\u57fa\u7840\u77e5\u8bc6\u590d\u4e60","text":""},{"location":"programming/24fall/lec1/#_5","title":"\u57fa\u672c\u8f93\u5165\u8f93\u51fa","text":"

\u53ef\u80fd\u8fd9\u4e00\u8282\u5185\u5bb9\u6709\u4e9b\u57fa\u7840\uff0c\u4f46\u4f5c\u4e3a\u6bcf\u9053\u7f16\u7a0b\u9898\u5fc5\u4e0d\u53ef\u5c11\u7684\u90e8\u5206\uff08\u6709\u65f6\u751a\u81f3\u662f\u901a\u8fc7\u7684\u5173\u952e\u6240\u5728\uff09\uff0c\u6211\u5e0c\u671b\u80fd\u4e3a\u5927\u5bb6\u7a0d\u5fae\u603b\u7ed3\u4e00\u4e0b\u600e\u6837\u8bfb\u6570\u636e\uff0c\u600e\u6837\u8f93\u51fa\u6570\u636e\u3002

\u76ee\u524d\uff0c\u6211\u4eec\u4e00\u822c\u4f7f\u7528 scanf() \u8bfb\u5165\u6570\u636e\uff0cprintf() \u8f93\u51fa\u6570\u636e\u3002\u5176\u4e2d\u7684 'f' \u610f\u4e3a \"format\"\uff0c\u5373\u683c\u5f0f\u5316\u8f93\u5165\u8f93\u51fa\u3002

scanf

scanf() \u7684\u5b9a\u4e49\u5982\u4e0b\uff1a

int scanf(const char *format, ...)\n

\u53c2\u6570\u7531\u4e24\u90e8\u5206\u7ec4\u6210\uff1a\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u3001\u8bfb\u5165\u53c2\u6570\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u524d\u9762\u4e00\u534a\u662f\u544a\u8bc9\u8ba1\u7b97\u673a\u600e\u4e48\u8bfb\uff0c\u540e\u9762\u4e00\u534a\u662f\u544a\u8bc9\u8ba1\u7b97\u673a\u8bfb\u5b8c\u4e86\u5b58\u5728\u54ea\u91cc\u3002

\u7c7b\u578b \u5408\u683c\u7684\u8f93\u5165 \u53c2\u6570\u7684\u7c7b\u578b \u5907\u6ce8 %c \u5355\u4e2a\u5b57\u7b26 char * \u53ef\u4ee5\u4f7f\u5176\u8bfb\u53d6\u591a\u4e2a\u5b57\u7b26 %d \u5341\u8fdb\u5236\u6574\u6570 int * 32 \u4f4d\u6574\u578b %l \u5341\u8fdb\u5236\u6574\u6570 long * 32 \u4f4d\u6574\u578b %ll \u5341\u8fdb\u5236\u6574\u6570 long long * 64 \u4f4d\u6574\u578b %e\u3001%E\u3001%f %F\u3001%g\u3001%G \u5355\u7cbe\u5ea6\u6d6e\u70b9\u6570 float * \u6ce8\u610f\u4e0d\u80fd\u7528\u6765\u8bfb double %lf \u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570 double * 64 \u4f4d\u6d6e\u70b9\u578b %i \u5341\u3001\u516b\u3001\u5341\u516d\u8fdb\u5236\u6574\u6570 int * \u6709\u7684\u65f6\u5019\u53ef\u4ee5\u7528\u6765\u5077\u61d2 %o \u516b\u8fdb\u5236\u6574\u6570 int * \u540c\u4e0a %x\u3001%X \u5341\u516d\u8fdb\u5236\u6574\u6570 int * \u540c\u4e0a\u4e0a %s \u5b57\u7b26\u4e32 char * \u8bfb\u53d6\u76f4\u5230\u9047\u5230\u7b2c\u4e00\u4e2a\u7a7a\u767d\u5b57\u7b26 %p \u6307\u9488 %% \u8bfb\u5165 % \u5b57\u7b26

\u4e00\u4e2a\u5f88\u5bb9\u6613\u72af\u7684\u9519\u8bef\uff1ascanf(%d, &var)\u5199\u6210scanf(%d, var)\u3002\u6b64\u5904\u4f7f\u7528&\u8fd0\u7b97\u7b26\u662f\u56e0\u4e3a\u6211\u4eec\u8981\u544a\u8bc9\u8ba1\u7b97\u673a\u50a8\u5b58\u6570\u636e\u7684\u4f4d\u7f6e &var \u800c\u4e0d\u662f var \u8fd9\u4e2a\u53d8\u91cf\u7684\u503c\u3002

\u800c\u65e5\u5e38\u88ab\u5ffd\u7565\u7684 scanf() \u8fd4\u56de\u503c\u4f1a\u544a\u8bc9\u6211\u4eec\u5b83\u6210\u529f\u8bfb\u5230\u4e86\u51e0\u4e2a\u53c2\u6570\uff08\u53ef\u7528\u4e8e\u5224\u5b9a\u6709\u6ca1\u6709\u8bfb\u5b8c\uff09\u3002

\u8bd5\u8bd5\u770b!\uff08\u53ea\u9700\u8981\u5199\u51fa\u8bfb\u53d6\u8f93\u5165\u7684\u8bed\u53e5\uff09

  1. \u8f93\u5165\u4ec5\u6709\u4e00\u884c\uff0c\u5171 7 \u4e2a\u7528\u7a7a\u683c\u9694\u5f00\u7684\u6574\u6570.
  2. \u7b2c\u4e00\u884c\u4e00\u4e2a\u6574\u6570 \\(N\\)\uff08\\(N\\) \u662f\u5076\u6570\u4e14 \\(1<N<100000\\)\uff09; \u7b2c\u4e8c\u884c \\(N-1\\) \u4e2a\u7528\u7a7a\u683c\u9694\u5f00\u7684\u6b63\u6574\u6570 \\(A_i (0<A_i<100000)\\).
  3. \u8f93\u5165\u7684\u7b2c\u4e00\u884c\u662f\u6574\u6570 \\(L\\)\uff08\\(1< L < 10000\\)\uff09\uff1b \u7b2c\u4e8c\u884c\u662f\u6574\u6570 \\(M\\)\uff08\\(0 < M < 100\\)\uff09\uff1b \u63a5\u4e0b\u6765\u7684 \\(M\\) \u884c\uff0c\u6bcf\u884c\u5305\u542b\u4e24\u4e2a\u4e0d\u540c\u7684\u6574\u6570\uff0c\u7528\u4e00\u4e2a\u7a7a\u683c\u9694\u5f00.
  4. \u8f93\u5165\u7531\u7a7a\u683c\u9694\u5f00\u7684\u6b63\u6570\uff08\u53ef\u4ee5\u662f\u5c0f\u6570\uff09\uff0c\u76f4\u5230\u8f93\u5165 -1.
  5. \u8f93\u5165\u662f 1~5 \u4e2a\u6b63\u6574\u6570.

printf

printf() \u7684\u5b9a\u4e49\u5982\u4e0b\uff1a

int printf(const char *format, ...)\n

\u76f8\u5bf9\u4e8e scanf() \u7684\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0cprintf() \u66f4\u52a0\u590d\u6742\uff1aprintf() \u7684\u683c\u5f0f\u5316\u53c2\u6570\u53ef\u4ee5\u8868\u8fbe\u4e3a\u4ee5\u4e0b\u5f62\u5f0f\uff1a

%[flags][width][.precision][length]specifier\n
\u5176\u4e2d\uff0cspecifier \u5373\u683c\u5f0f\u5b57\u7b26\uff0c\u4e0e scanf() \u4e00\u81f4\uff1b\u5176\u4ed6\u53c2\u6570\u5982\u4e0b\u6240\u793a\uff1a\uff08\u6765\u81ea \u83dc\u9e1f\u6559\u7a0b\uff09

flag \u63cf\u8ff0 - \u5728\u7ed9\u5b9a\u7684\u5b57\u6bb5\u5bbd\u5ea6\u5185\u5de6\u5bf9\u9f50\uff0c\u9ed8\u8ba4\u662f\u53f3\u5bf9\u9f50 + \u5f3a\u5236\u5728\u7ed3\u679c\u4e4b\u524d\u663e\u793a\u52a0\u53f7\u6216\u51cf\u53f7\uff08+ \u6216 -\uff09\uff0c\u5373\u6b63\u6570\u524d\u9762\u4f1a\u663e\u793a + \u53f7\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u53ea\u6709\u8d1f\u6570\u524d\u9762\u4f1a\u663e\u793a\u4e00\u4e2a - \u53f7 \u7a7a\u683c \u5982\u679c\u6ca1\u6709\u5199\u5165\u4efb\u4f55\u7b26\u53f7\uff0c\u5219\u5728\u8be5\u503c\u524d\u9762\u63d2\u5165\u4e00\u4e2a\u7a7a\u683c\u3002 # \u4e0e o\u3001x \u6216 X \u8bf4\u660e\u7b26\u4e00\u8d77\u4f7f\u7528\u65f6\uff0c\u975e\u96f6\u503c\u524d\u9762\u4f1a\u5206\u522b\u663e\u793a 0\u30010x \u6216 0X\u3002\u4e0e e\u3001E \u548c f \u4e00\u8d77\u4f7f\u7528\u65f6\uff0c\u4f1a\u5f3a\u5236\u8f93\u51fa\u5305\u542b\u4e00\u4e2a\u5c0f\u6570\u70b9\uff08\u5373\u4f7f\u540e\u8fb9\u6ca1\u6709\u6570\u5b57\u65f6\u4e5f\u4f1a\u663e\u793a\u5c0f\u6570\u70b9\uff09\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u540e\u8fb9\u6ca1\u6709\u6570\u5b57\u65f6\u5019\uff0c\u4e0d\u4f1a\u663e\u793a\u663e\u793a\u5c0f\u6570\u70b9\u3002\u4e0e g \u6216 G \u4e00\u8d77\u4f7f\u7528\u65f6\uff0c\u7ed3\u679c\u4e0e\u4f7f\u7528 e \u6216 E \u65f6\u76f8\u540c\uff0c\u4f46\u662f\u5c3e\u90e8\u7684\u96f6\u4e0d\u4f1a\u88ab\u79fb\u9664\u3002 0 \u5728\u6307\u5b9a\u586b\u5145 padding \u7684\u6570\u5b57\u5de6\u8fb9\u653e\u7f6e\u96f6\uff080\uff09\uff0c\u800c\u4e0d\u662f\u7a7a\u683c width \u63cf\u8ff0 (number) \u8981\u8f93\u51fa\u7684\u5b57\u7b26\u7684\u6700\u5c0f\u6570\u76ee\u3002\u5982\u679c\u8f93\u51fa\u7684\u503c\u77ed\u4e8e\u8be5\u6570\uff0c\u7ed3\u679c\u4f1a\u7528\u7a7a\u683c\u586b\u5145\u3002\u5982\u679c\u8f93\u51fa\u7684\u503c\u957f\u4e8e\u8be5\u6570\uff0c\u7ed3\u679c\u4e0d\u4f1a\u88ab\u622a\u65ad\u3002 * \u5bbd\u5ea6\u5728 format \u5b57\u7b26\u4e32\u4e2d\u672a\u6307\u5b9a\uff0c\u4f46\u662f\u4f1a\u4f5c\u4e3a\u9644\u52a0\u6574\u6570\u503c\u53c2\u6570\u653e\u7f6e\u4e8e\u8981\u88ab\u683c\u5f0f\u5316\u7684\u53c2\u6570\u4e4b\u524d\u3002 .precision \u63cf\u8ff0 .number \u5bf9\u4e8e\u6574\u6570\u8bf4\u660e\u7b26\uff08d\u3001i\u3001o\u3001u\u3001x\u3001X\uff09\uff1aprecision \u6307\u5b9a\u4e86\u8981\u5199\u5165\u7684\u6570\u5b57\u7684\u6700\u5c0f\u4f4d\u6570\u3002\u5982\u679c\u5199\u5165\u7684\u503c\u77ed\u4e8e\u8be5\u6570\uff0c\u7ed3\u679c\u4f1a\u7528\u524d\u5bfc\u96f6\u6765\u586b\u5145\u3002\u5982\u679c\u5199\u5165\u7684\u503c\u957f\u4e8e\u8be5\u6570\uff0c\u7ed3\u679c\u4e0d\u4f1a\u88ab\u622a\u65ad\u3002\u7cbe\u5ea6\u4e3a 0 \u610f\u5473\u7740\u4e0d\u5199\u5165\u4efb\u4f55\u5b57\u7b26\u3002\u5bf9\u4e8e e\u3001E \u548c f \u8bf4\u660e\u7b26\uff1a\u8981\u5728\u5c0f\u6570\u70b9\u540e\u8f93\u51fa\u7684\u5c0f\u6570\u4f4d\u6570\u3002\u5bf9\u4e8e g \u548c G \u8bf4\u660e\u7b26\uff1a\u8981\u8f93\u51fa\u7684\u6700\u5927\u6709\u6548\u4f4d\u6570\u3002\u5bf9\u4e8e s: \u8981\u8f93\u51fa\u7684\u6700\u5927\u5b57\u7b26\u6570\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u5b57\u7b26\u90fd\u4f1a\u88ab\u8f93\u51fa\uff0c\u76f4\u5230\u9047\u5230\u672b\u5c3e\u7684\u7a7a\u5b57\u7b26\u3002\u5bf9\u4e8e c \u7c7b\u578b\uff1a\u6ca1\u6709\u4efb\u4f55\u5f71\u54cd\u3002\u5f53\u672a\u6307\u5b9a\u4efb\u4f55\u7cbe\u5ea6\u65f6\uff0c\u9ed8\u8ba4\u4e3a 1\u3002\u5982\u679c\u6307\u5b9a\u65f6\u4e0d\u5e26\u6709\u4e00\u4e2a\u663e\u5f0f\u503c\uff0c\u5219\u5047\u5b9a\u4e3a 0\u3002

\u800c\u65e5\u5e38\u88ab\u5ffd\u7565\u7684 printf() \u8fd4\u56de\u503c\u4f1a\u544a\u8bc9\u6211\u4eec\u5199\u5165\u7684\u5b57\u7b26\u603b\u6570\uff08\u5982\u679c\u6709\u8f93\u51fa\uff09\uff0c\u5426\u5219\u4f1a\u662f\u4e00\u4e2a\u8d1f\u6570\uff08\u53ef\u7528\u4e8e\u5224\u5b9a\u6709\u6ca1\u6709\u8f93\u51fa\uff09\u3002

"},{"location":"programming/24fall/lec1/#_6","title":"\u4e00\u4e9b\u9898\u76ee","text":"

\u6c34\u4ed9\u82b1\u6570

\u627e\u51fa 0~999 \u95f4\u6240\u6709\u7684\u6c34\u4ed9\u82b1\u6570\u3002\u6c34\u4ed9\u82b1\u6570\u662f\u6307\u4e00\u4e2a\u4e09\u4f4d\u6570\uff0c\u5b83\u7684\u5404\u4f4d\u6570\u5b57\u7684\u4e09\u6b21\u5e42\u4e4b\u548c\u662f\u5176\u672c\u8eab\u3002

\u5b8c\u7f8e\u6570

\u5b9e\u73b0\u4e00\u4e2a\u8ba1\u7b97\u6574\u6570\u56e0\u5b50\u548c\u7684\u7b80\u5355\u51fd\u6570\uff0c\u5e76\u5229\u7528\u5176\u5b9e\u73b0\u53e6\u4e00\u4e2a\u51fd\u6570\uff0c\u8f93\u51fa\u4e24\u6b63\u6574\u6570 \\(m\\) \u548c \\(n\\)\uff08\\(0<m<n<10000\\)\uff09\u4e4b\u95f4\u7684\u6240\u6709\u5b8c\u6570\u3002\u6240\u8c13\u5b8c\u6570\u5c31\u662f\u8be5\u6570\u6070\u597d\u7b49\u4e8e\u9664\u81ea\u8eab\u5916\u7684\u56e0\u5b50\u4e4b\u548c\u3002\u4f8b\u5982\uff1a\\(6=1+2+3\\)\uff0c\u5176\u4e2d 1\u30012\u30013 \u4e3a 6 \u7684\u56e0\u5b50\u3002

Gram-Schmidt Algorithm

\uff08 \u9898\u76ee\u7701\u7565 \uff09

"},{"location":"programming/24fall/lec2/","title":"\u7b2c\u4e8c\u8bb2\uff1a\u901a\u5f80 Pro \u7684\u7b2c\u4e00\u6b65","text":"

Tip

\u672c\u8282\u8bfe\u5efa\u8bae\u540c\u5b66\u4eec\u643a\u5e26\u7b14\u8bb0\u672c\u7535\u8111\uff0c\u4ee5\u4fbf\u5b9e\u8df5\u3002

"},{"location":"programming/24fall/lec2/#_1","title":"\u4e3a\u4ec0\u4e48\u8981\u5b66\u4e60\u5b9e\u7528\u6280\u80fd\uff1f","text":"

\u4e3a\u4ec0\u4e48\u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66\u4e0d\u4e25\u683c\u6309\u7167\u8bfe\u5185\u5185\u5bb9\uff0c\u800c\u662f\u6269\u5c55\u5b66\u4e60\u8bfe\u5916\u7684\u547d\u4ee4\u884c\u548c AI \u5de5\u5177\uff1f\u4e3a\u4ec0\u4e48\u8981\u5b66\u4e60\u5404\u7c7b\u5b9e\u7528\u6280\u80fd\uff1f\u6211\u60f3\uff0c\u7528\u4e0b\u9762\u8fd9\u53e5\u8bdd\u6765\u56de\u7b54\u8fd9\u4e2a\u95ee\u9898\u6700\u4e3a\u5408\u9002\uff1a

\u5de5\u6b32\u5584\u5176\u4e8b\uff0c\u5fc5\u5148\u5229\u5176\u5668\u3002

\u5bf9\u4e8e\u6570\u5b66\u3001\u7269\u7406\u7b49\u5b66\u79d1\u6765\u8bf4\uff0c\u7eb8\u7b14\u5c31\u662f\u5de5\u5177\uff0c\u540c\u5b66\u4eec\u90fd\u80fd\u7528\u5f97\u5f88\u597d\u3002\u800c\u5bf9\u4e8e\u8ba1\u7b97\u673a\uff0c\u5982\u679c\u53ea\u4f7f\u7528\u7eb8\u7b14\uff0c\u90a3\u5c31\u53ea\u80fd\u505a\u8ba1\u7b97\u673a\u79d1\u5b66\uff0c\u505a\u4e0d\u4e86\u8ba1\u7b97\u673a\u6280\u672f\uff0c\u4f46\u8fd9\u4e24\u8005\u53c8\u7d27\u5bc6\u5173\u8054\u3002\u8ba1\u7b97\u673a\u8f6f\u786c\u4ef6\u5bf9\u5927\u90e8\u5206\u540c\u5b66\u6765\u8bf4\u76f8\u5bf9\u964c\u751f\uff0c\u800c\u4e14\u6ca1\u6709\u4e13\u95e8\u7684\u8bfe\u7a0b\u6765\u6559\u6388\u8fd9\u4e9b\u77e5\u8bc6\u3002\u7f3a\u4e4f\u5b9e\u7528\u6280\u80fd\u5df2\u7ecf\u6210\u4e3a\u592a\u591a\u8ba1\u7b97\u673a\u7cfb\u5b66\u751f\u5728\u5b66\u4e60\u3001\u5de5\u4f5c\u548c\u79d1\u7814\u8def\u4e0a\u7684\u7eca\u811a\u77f3\u3002\u6211\u4eec\u5e0c\u671b\u901a\u8fc7\u300a\u5b9e\u7528\u6280\u80fd\u62fe\u9057\u300b\u8f85\u5b66\u8bfe\u7a0b\uff0c\u8ba9\u66f4\u591a\u540c\u5b66\u5728\u521a\u5f00\u59cb\u63a5\u89e6\u8ba1\u7b97\u673a\u4e13\u4e1a\u65f6\u5c31\u638c\u63e1\u8fd9\u4e9b\u6280\u80fd\uff0c\u8fd9\u5c06\u4e3a\u4f60\u4eec\u4e4b\u540e\u7684\u5b66\u4e60\u548c\u79d1\u7814\u6253\u4e0b\u575a\u5b9e\u7684\u57fa\u7840\u3002

\u5b9e\u7528\u6280\u80fd\u62fe\u9057\u8bfe\u7a0b

\u6700\u65e9\u7531 21 \u7ea7\u56fe\u7075\u738b\u9e64\u7fd4\u5b66\u957f\u5f00\u8bbe\uff0c\u5148\u540e\u5728\u8ba1\u7b97\u673a\u5b66\u9662\u548c\u7afa\u53ef\u6862\u5b66\u9662\u4f5c\u4e3a\u8f85\u5b66\u8bfe\u7a0b\u3002\u8bfe\u7a0b\u5185\u5bb9\u975e\u5e38\u4f18\u8d28\uff0c\u4f60\u53ef\u4ee5\u5728 \u8fd9\u91cc \u627e\u5230\u5f80\u5e74\u7684\u8bfe\u7a0b\u8d44\u6599\u3002

\u4f46\u7531\u4e8e\u96be\u5ea6\u8f83\u9ad8\uff0c\u6211\u4eec\u8ba1\u5212\u5728\u4e0b\u5b66\u671f\u518d\u590d\u523b\u8fd9\u95e8\u8bfe\u7a0b\u3002\u5982\u679c\u4f60\u671f\u5f85\u6df1\u5165\u4e86\u89e3 Docker\u3001Shell\u3001Git \u7b49\u5185\u5bb9\uff0c\u6b22\u8fce\u5173\u6ce8\u540e\u7eed\u7684\u8f85\u5b66\u6d3b\u52a8\u3002

\u5728\u6b64\uff0c\u6211\u4eec\u8981\u5411\u738b\u9e64\u7fd4\u5b66\u957f\u8868\u793a\u6700\u8bda\u631a\u7684\u611f\u8c22\ud83d\ude4f\u3002

Example

\u8bf4\u4e86\u8fd9\u4e48\u591a\u53ef\u80fd\u6ca1\u6709\u4ec0\u4e48\u5b9e\u611f\uff0c\u8ba9\u6211\u4eec\u7b80\u5355\u4e3e\u51e0\u4e2a\u4f8b\u5b50\u3002

"},{"location":"programming/24fall/lec2/#_2","title":"\u521d\u8bc6\u547d\u4ee4\u884c\u754c\u9762","text":"

\u63a5\u4e0b\u6765\u8fdb\u5165\u672c\u8282\u8bfe\u7684\u524d\u534a\u90e8\u5206\uff0c\u521d\u8bc6\u547d\u4ee4\u884c\u754c\u9762\u3002\u6216\u8bb8\u540c\u5b66\u4eec\u73b0\u5728\u63a5\u89e6\u547d\u4ee4\u884c\u8fd8\u6bd4\u8f83\u5c11\uff0c\u4f46\u5982\u679c\u5b66\u4e60\u8ba1\u7b97\u673a\u79d1\u5b66\u4e13\u4e1a\uff0c\u4f60\u7684\u63a5\u4e0b\u6765\u7684\u4e00\u751f\u6216\u8bb8\u90fd\u79bb\u4e0d\u5f00\u547d\u4ee4\u884c\u754c\u9762\u3002

"},{"location":"programming/24fall/lec2/#_3","title":"\u6253\u5f00\u7ec8\u7aef","text":"

\u5f53\u6211\u4eec\u4f7f\u7528\u6587\u672c\u547d\u4ee4\u4e0e\u8ba1\u7b97\u673a\u4ea4\u4e92\u65f6\uff0c\u5c31\u662f\u5728\u4f7f\u7528\u547d\u4ee4\u884c\u4ea4\u4e92\u754c\u9762\uff08Command Line Interface\uff0cCLI\uff09\u3002\u8fd9\u4e0e\u6211\u4eec\u65e5\u5e38\u751f\u6d3b\u4e2d\u4f7f\u7528\u7684\u56fe\u5f62\u4ea4\u4e92\u754c\u9762\uff08Graphical User Interface\uff0cGUI\uff09\u4e0d\u540c\u3002

\u52a8\u624b\u505a\uff1a\u5728\u672c\u5730\u6253\u5f00\u7ec8\u7aef

WindowsmacOSLinux

\u6309\u4e0b Win \u952e\uff0c\u8f93\u5165 cmd \u6216 powershell\uff0c\u56de\u8f66\u3002

\u6309\u4e0b Cmd+Space\uff0c\u8f93\u5165 Terminal\uff0c\u56de\u8f66\u3002

\u4f60\u5e94\u8be5\u77e5\u9053\u600e\u4e48\u505a\ud83d\ude09\u3002

CLI \u7684\u51e0\u4e2a\u7ec4\u6210\u90e8\u5206\u4e4b\u95f4\u7684\u5173\u7cfb\u5982\u4e0b\u56fe\u6240\u793a\uff1a

"},{"location":"programming/24fall/lec2/#_4","title":"\u8fde\u63a5\u5230\u8fdc\u7a0b\u670d\u52a1\u5668","text":"

\u64cd\u4f5c\u7cfb\u7edf\u4e4b\u95f4\u6709\u663e\u8457\u7684\u5dee\u522b\uff0c\u4e0d\u540c Shell \u7684\u547d\u4ee4\u8bed\u6cd5\u4e5f\u4e0d\u540c\u3002\u5927\u5bb6\u4eca\u540e\u63a5\u89e6\u6700\u591a\u7684\u5e94\u8be5\u662f Linux \u7cfb\u7edf\u7684 Bash \u547d\u4ee4\u89e3\u91ca\u5668\uff0c\u6240\u4ee5\u6211\u4eec\u4e3a\u5927\u5bb6\u51c6\u5907\u4e86\u4e00\u4e2a\u8fdc\u7a0b\u670d\u52a1\u5668\uff0c\u63d0\u4f9b\u4e00\u4e2a\u7edf\u4e00\u7684\u73af\u5883\u6765\u5b66\u4e60\u547d\u4ee4\u884c\u3002

\u52a8\u624b\u505a\uff1a\u8fde\u63a5\u5230\u8fdc\u7a0b\u670d\u52a1\u5668

\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5e76\u6309\u63d0\u793a\u8f93\u5165\u5bc6\u7801\uff0c\u8fde\u63a5\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\uff1a

ssh \u4f60\u7684\u5b66\u53f7@clusters.zju.edu.cn -p 16145\n

\u521d\u6b21\u8fde\u63a5\u65f6\u4e00\u822c\u4f1a\u51fa\u73b0

\u7684\u63d0\u793a\uff0c\u8bf7\u8f93\u5165 yes \u5e76\u56de\u8f66\u3002

"},{"location":"programming/24fall/lec2/#bash","title":"Bash \u547d\u4ee4\u8bed\u6cd5","text":"
command [OPTIONS] arguments\n

\u4eca\u540e\u5f53\u4f60\u9605\u8bfb\u5404\u7c7b\u8d44\u6599\u65f6\uff0c\u7ecf\u5e38\u4f1a\u9047\u89c1\u4e0a\u9762\u8fd9\u79cd\u683c\u5f0f\u7684\u8bed\u6cd5\u3002\u5176\u4e2d\u51e0\u79cd\u62ec\u53f7\u7684\u542b\u4e49\u5982\u4e0b\uff1a

\u8ba9\u6211\u4eec\u6765\u770b\u4e00\u770b ls \u548c cat \u547d\u4ee4\ud83d\udc31\u3002

touch [OPTION]... FILE...\n

touch \u547d\u4ee4\u7528\u4e8e\u521b\u5efa\u7a7a\u6587\u4ef6\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e\u89e6\u6478\uff08touch\uff09\u6587\u4ef6\u7684\u65f6\u95f4\u6233\u3002

\u52a8\u624b\u505a 2.3.1

\u5728\u5f53\u524d\u76ee\u5f55 ~/ \u4e0b\u521b\u5efa\u4e00\u4e2a\u7a7a\u6587\u4ef6 2.3.1\u3002

\u63a5\u4e0b\u6765\u7684\u6bcf\u4e2a\u52a8\u624b\u505a\uff0c\u8bf7\u540c\u5b66\u4eec\u5b8c\u6210\u540e touch \u5bf9\u5e94\u7684\u6587\u4ef6\uff0c\u4ee5\u4fbf\u6211\u4eec\u540c\u6b65\u8fdb\u5ea6\ud83d\ude09\u3002

ls [OPTION]... [FILE]...\n

ls \u547d\u4ee4\u7528\u4e8e\u5217\u51fa\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u548c\u5b50\u76ee\u5f55\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e list\uff08\u5217\u51fa\uff09\u3002

\u52a8\u624b\u505a 2.3.2

\u4f7f\u7528 ls \u547d\u4ee4\u770b\u4e00\u770b\u5f53\u524d\u76ee\u5f55\u4e0b\u6709\u54ea\u4e9b\u6587\u4ef6\u548c\u76ee\u5f55\u5427\u3002

cat [OPTION]... [FILE]...\n

cat \u547d\u4ee4\u7528\u4e8e\u67e5\u770b\u6587\u4ef6\u5185\u5bb9\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e concatenate\uff08\u8fde\u63a5\uff09\u3002

\u52a8\u624b\u505a 2.3.3\uff1a\u5c1d\u8bd5 cat \u7684\u51e0\u79cd\u7528\u6cd5

"},{"location":"programming/24fall/lec2/#linux","title":"Linux \u6587\u4ef6\u8def\u5f84","text":"

\u4e0e\u5927\u5bb6\u719f\u6089\u7684 Windows \u4e0d\u540c\uff0cLinux \u6587\u4ef6\u7cfb\u7edf\u6ca1\u6709\u76d8\u7b26\u7684\u6982\u5ff5\u3002\u4f60\u53ef\u4ee5\u60f3\u8c61 Windows \u7684\u6587\u4ef6\u7cfb\u7edf\u662f\u4e00\u7247\u68ee\u6797\uff0c\u800c Linux \u7684\u6587\u4ef6\u7cfb\u7edf\u662f\u4e00\u68f5\u6811\u3002

Windows \u4e0e Linux \u6587\u4ef6\u8def\u5f84\u7684\u5bf9\u6bd4 \u56fe\u7247\u6765\u6e90\uff1aAutomate the Boring Stuff with Python

\u5728 Linux \u7cfb\u7edf\u4e2d\u8def\u5f84\u6709\u4e24\u79cd\u8868\u793a\u65b9\u6cd5\uff1a

\u7edd\u5bf9\u8def\u5f84\u4e0e\u76f8\u5bf9\u8def\u5f84 \u56fe\u7247\u6765\u6e90\uff1aAn Overview of Absolute Path in Linux - The Complete Guide

Question

\u4e0a\u56fe\u4e2d\uff0c\u4f60\u5728 Current \u76ee\u5f55\u3002\u5199\u51fa Dest \u76ee\u5f55\u7684\u76f8\u5bf9\u8def\u5f84\u548c\u7edd\u5bf9\u8def\u5f84\u3002

\u8ba9\u6211\u4eec\u719f\u6089\u51e0\u4e2a\u5728 Linux \u6587\u4ef6\u7cfb\u7edf\u4e2d\u5e38\u7528\u7684\u547d\u4ee4\uff1a

pwd\n

pwd \u547d\u4ee4\u7528\u4e8e\u663e\u793a\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u7684\u8def\u5f84\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e print working directory\uff08\u6253\u5370\u5de5\u4f5c\u76ee\u5f55\uff09\u3002

\u52a8\u624b\u505a 2.4.1

\u770b\u4e00\u770b\u4f60\u73b0\u5728\u5728\u54ea\u4e2a\u76ee\u5f55\u3002

cd [DIRECTORY]\n

cd \u547d\u4ee4\u7528\u4e8e\u5207\u6362\u5de5\u4f5c\u76ee\u5f55\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e change directory\uff08\u6539\u53d8\u76ee\u5f55\uff09\u3002

\u52a8\u624b\u505a 2.4.2

\u5c1d\u8bd5 cd \u7684\u51e0\u79cd\u7528\u6cd5

mkdir [OPTION]... DIRECTORY...\n

mkdir \u547d\u4ee4\u7528\u4e8e\u521b\u5efa\u76ee\u5f55\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e make directory\uff08\u521b\u5efa\u76ee\u5f55\uff09\u3002

\u52a8\u624b\u505a 2.4.3

\u5c1d\u8bd5\u521b\u5efa\u4e00\u4e2a\u76ee\u5f55 hello\u3002

touch [OPTION]... FILE...\n

touch \u547d\u4ee4\u7528\u4e8e\u521b\u5efa\u7a7a\u6587\u4ef6\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e\u89e6\u6478\uff08touch\uff09\u6587\u4ef6\u7684\u65f6\u95f4\u6233\u3002

\u52a8\u624b\u505a 2.4.4

\u5c1d\u8bd5\u5728 hello \u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u7a7a\u6587\u4ef6 world\u3002

rm [OPTION]... FILE...\n

rm \u547d\u4ee4\u7528\u4e8e\u5220\u9664\u6587\u4ef6\u6216\u76ee\u5f55\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e remove\uff08\u5220\u9664\uff09\u3002

\u52a8\u624b\u505a 2.4.5

\u5c1d\u8bd5\u5220\u9664 world \u6587\u4ef6\u3002

rmdir [OPTION]... DIRECTORY...\n

rmdir \u547d\u4ee4\u7528\u4e8e\u5220\u9664\u7a7a\u76ee\u5f55\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e remove directory\uff08\u5220\u9664\u76ee\u5f55\uff09\u3002

\u52a8\u624b\u505a 2.4.6

\u5c1d\u8bd5\u5220\u9664 hello \u76ee\u5f55\u3002

cp [OPTION]... SOURCE DEST\n

cp \u547d\u4ee4\u7528\u4e8e\u590d\u5236\u6587\u4ef6\u6216\u76ee\u5f55\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e copy\uff08\u590d\u5236\uff09\u3002

\u52a8\u624b\u505a 2.4.7

\u5c1d\u8bd5\u590d\u5236 /share/hello.c \u6587\u4ef6\u5230\u5bb6\u76ee\u5f55\u3002

"},{"location":"programming/24fall/lec2/#_5","title":"\u73af\u5883\u53d8\u91cf","text":"

\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u547d\u4ee4\u65f6\uff0cShell \u662f\u5982\u4f55\u627e\u5230\u8fd9\u4e2a\u547d\u4ee4\u7684\u5462\uff1f

  1. \u5185\u5efa\u547d\u4ee4\uff08Built-in Command\uff09\uff1aShell \u5185\u7f6e\u4e86\u4e00\u4e9b\u547d\u4ee4\uff0c\u5982 cd\u3001pwd \u7b49\u3002
  2. \u522b\u540d\uff08Alias\uff09\uff1a\u7528\u6237\u53ef\u4ee5\u4e3a\u547d\u4ee4\u8bbe\u7f6e\u522b\u540d\uff0c\u5982 alias ll='ls -l'\u3002
  3. \u73af\u5883\u53d8\u91cf\uff08Environment Variable\uff09\uff1aShell \u4f1a\u5728\u73af\u5883\u53d8\u91cf PATH \u4e2d\u5217\u51fa\u7684\u76ee\u5f55\u4e2d\u67e5\u627e\u547d\u4ee4\u3002PATH \u662f\u4e00\u4e2a\u5305\u542b\u76ee\u5f55\u8def\u5f84\u7684\u5b57\u7b26\u4e32\uff0c\u7528\u5192\u53f7 : \u5206\u9694\u3002

\u73af\u5883\u53d8\u91cf

\u6211\u4eec\u5df2\u7ecf\u5728 C \u8bed\u8a00\u8bfe\u4e0a\u5b66\u4e60\u8fc7\u53d8\u91cf\u7684\u6982\u5ff5\u3002\u800c\u73af\u5883\u53d8\u91cf\u7531\u64cd\u4f5c\u7cfb\u7edf\u7ef4\u62a4\uff0c\u7528\u4e8e\u5b58\u50a8\u8fdb\u7a0b\u8fd0\u884c\u65f6\u6240\u9700\u7684\u4e00\u4e9b\u4fe1\u606f\u3002\u7a0b\u5e8f\u53ef\u4ee5\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u51fd\u6570\u6765\u8bbf\u95ee\u73af\u5883\u53d8\u91cf\u3002\u6bd4\u5982\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 getenv \u51fd\u6570\u83b7\u53d6\u73af\u5883\u53d8\u91cf\u7684\u503c\u3002

#include <stdlib.h>\n\nchar *getenv(const char *name);\n

\u5728 Bash \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 env \u6216 printenv \u547d\u4ee4\u67e5\u770b\u5f53\u524d\u73af\u5883\u53d8\u91cf\u3002

\u547d\u4ee4\u89e3\u91ca\u5668\u901a\u5e38\u652f\u6301\u73af\u5883\u53d8\u91cf\u7684\u66ff\u6362\u3002\u5728 Bash \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 $ \u7b26\u53f7\u5f15\u7528\u73af\u5883\u53d8\u91cf\u7684\u503c\u3002\u6bd4\u5982 $HOME \u5c06\u88ab\u66ff\u6362\u4e3a\u5bb6\u76ee\u5f55\uff0c$PATH \u5c06\u88ab\u66ff\u6362\u4e3a\u547d\u4ee4\u641c\u7d22\u8def\u5f84\u3002\u8fd9\u4e00\u66ff\u6362\u53d1\u751f\u5728\u547d\u4ee4\u884c\u88ab\u89e3\u91ca\u4e4b\u524d\u3002

echo [OPTIONS] [STRING]\n

echo \u547d\u4ee4\u7528\u4e8e\u6253\u5370\u5b57\u7b26\u4e32\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e\u56de\u58f0\uff08echo\uff09\u3002

\u52a8\u624b\u505a 2.5.1

type [COMMAND]\n

type \u547d\u4ee4\u7528\u4e8e\u663e\u793a\u547d\u4ee4\u7684\u7c7b\u578b\u3002\u5b83\u4f1a\u544a\u8bc9\u4f60\u547d\u4ee4\u662f\u5185\u5efa\u547d\u4ee4\u3001\u522b\u540d\u3001\u8fd8\u662f\u5916\u90e8\u547d\u4ee4\u3002

\u52a8\u624b\u505a 2.5.2

\u5c1d\u8bd5\u67e5\u770b ls \u548c echo \u547d\u4ee4\u7684\u7c7b\u578b\u3002

"},{"location":"programming/24fall/lec2/#_6","title":"\u83b7\u53d6\u5e2e\u52a9","text":"

\u5728\u547d\u4ee4\u884c\u4e2d\u53ef\u4ee5\u65b9\u4fbf\u5730\u83b7\u53d6\u5e2e\u52a9\uff0c\u4e0d\u8981\u518d\u53bb\u7f51\u4e0a\u67e5 CSDN \u7b49\u52a3\u8d28\u8d44\u6599\u4e86\u3002\u6216\u8bb8\u5e2e\u52a9\u4e3b\u8981\u6709 3 \u4e2d\u65b9\u5f0f\uff1a

"},{"location":"programming/24fall/lec2/#gcc-c","title":"\u4f7f\u7528 gcc \u7f16\u8bd1 C \u7a0b\u5e8f","text":"

\u63a5\u4e0b\u6765\u7ec8\u4e8e\u5230\u4e86\u548c\u8bfe\u5185\u77e5\u8bc6\u6709\u4e00\u70b9\u5173\u8054\u7684\u90e8\u5206\u4e86\uff0c\u8ba9\u6211\u4eec\u5b66\u4e60\u5982\u4f55\u4f7f\u7528 gcc \u7f16\u8bd1 C \u7a0b\u5e8f\u3002

gcc [-c|-S|-E] [-std=standard]\n    [-g] [-pg] [-Olevel]\n    [-Wwarn...] [-Wpedantic]\n    [-Idir...] [-Ldir...]\n    [-Dmacro[=defn]...] [-Umacro]\n    [-foption...] [-mmachine-option...]\n    [-o outfile] [@file] infile...\n

gcc \u547d\u4ee4\u7528\u4e8e\u7f16\u8bd1 C \u7a0b\u5e8f\u3002\u5b83\u7684\u540d\u79f0\u6765\u6e90\u4e8e GNU Compiler Collection\uff08GNU \u7f16\u8bd1\u5668\u5957\u4ef6\uff09\u3002

\u52a8\u624b\u505a 2.7.1

-o outfile \u9009\u9879\u7528\u4e8e\u6307\u5b9a\u8f93\u51fa\u6587\u4ef6\u540d\u3002

\u521a\u624d\u6211\u4eec\u5df2\u7ecf\u628a hello.c \u6587\u4ef6\u590d\u5236\u5230\u5bb6\u76ee\u5f55\u4e86\uff0c\u5c1d\u8bd5\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u7f16\u8bd1 ~/hello.c \u7a0b\u5e8f\uff1a

gcc -o hello ~/hello.c\n

\u63a5\u4e0b\u6765\u518d\u590d\u5236 /share/error.c \u6587\u4ef6\u5230\u5bb6\u76ee\u5f55\uff0c\u5c1d\u8bd5\u7f16\u8bd1 ~/error.c \u7a0b\u5e8f\u3002

\u5982\u679c\u6ca1\u51fa\u610f\u5916\uff0cerror.c \u7a0b\u5e8f\u7206\u4e86\u3002\u4f60\u9700\u8981\u9010\u6e10\u5b66\u4f1a\u4ece\u9519\u8bef\u4fe1\u606f\u4e2d\u627e\u5230\u95ee\u9898\u6240\u5728\u3002\u4ee5\u540e\u9047\u5230\u7684\u9519\u8bef\u4fe1\u606f\u53ea\u4f1a\u8d8a\u6765\u8d8a\u590d\u6742\uff0c\u4f46\u4e5f\u4f1a\u4e3a\u4f60\u63d0\u4f9b\u66f4\u591a\u7684\u4fe1\u606f\u3002

\u4e0d\u8981\u61d2\u5f97\u8bfb\u9519\u8bef\u4fe1\u606f\uff01

\u5f88\u591a\u4eba\u559c\u6b22\u4e00\u9047\u5230\u9519\u8bef\u5c31\u628a\u9519\u8bef\u4fe1\u606f\u4e22\u5230\u4e2d\u6587\u641c\u7d22\u5f15\u64ce\u7136\u540e\u5bf9\u7740\u5404\u79cd\u7f51\u4e0a\u7684\u529e\u6cd5\u4e00\u901a\u4e71\u8c03\u3002\u5728\u8fd9\u4e4b\u524d\uff0c\u81f3\u5c11\u5e94\u5f53\u8ba4\u771f\u8bfb\u4e00\u8bfb\u9519\u8bef\u4fe1\u606f\uff0c\u5c1d\u8bd5\u7406\u89e3\u53d1\u751f\u4e86\u4ec0\u4e48\uff0c\u800c\u4e0d\u662f\u76f2\u4ece\u3002\u5e38\u5e38\u9519\u8bef\u4fe1\u606f\u672c\u8eab\u7ed9\u51fa\u7684\u7684\u4fe1\u606f\u5c31\u8db3\u4ee5\u89e3\u51b3\u95ee\u9898\u3002

\u6211\u4eec\u6765\u770b\u770b\u9519\u8bef\u4fe1\u606f\uff1a

error.c: In function \u2018main\u2019:\nerror.c:6:18: error: subscripted value is neither array nor pointer nor vector\n    6 |     printf(num[2][1]);\n      |\n

\u8bfe\u540e\uff1aVim

\u672c\u8282\u8bfe\u6211\u4eec\u4e0d\u6559\u5927\u5bb6\u4f7f\u7528\u547d\u4ee4\u884c\u6587\u672c\u7f16\u8f91\u5668\u3002\u6709\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u5b66\u4e60 Vim\uff0c\u5b83\u7684\u952e\u4f4d\u8bbe\u8ba1\u6210\u4e3a\u5404\u7c7b\u7f16\u8f91\u5668\u7684\u9ec4\u91d1\u51c6\u5219\uff0c\u80fd\u5927\u5e45\u63d0\u9ad8\u4f60\u5728\u5404\u79cd\u5730\u65b9\u7684\u7f16\u8f91\u6548\u7387\u3002

\u4e3e\u4f8b\uff1aVSCode\u3001\u547d\u4ee4\u884c\u3001Overleaf \u7b49\u90fd\u652f\u6301 Vim \u6a21\u5f0f\u3002

"},{"location":"programming/24fall/lec2/#vscode-ai","title":"\u4f7f\u7528 VSCode \u548c AI \u5de5\u5177","text":"

\u6211\u4eec\u7684\u547d\u4ee4\u884c\u4e4b\u65c5\u5230\u6b64\u544a\u4e00\u6bb5\u843d\u3002\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u56de\u5230\u719f\u6089\u7684\u56fe\u5f62\u754c\u9762\uff0c\u5b66\u4e60\u5982\u4f55\u4f7f\u7528 VSCode \u548c AI \u5de5\u5177\u3002

"},{"location":"programming/24fall/lec2/#dev-c-vscode","title":"\u5c3d\u5feb\u653e\u5f03 Dev-C++\uff0c\u62e5\u62b1 VSCode","text":"

2010 \u5e74\u7684\u6587\u7ae0\uff1a\u8acb\u4e0d\u8981\u7528 Dev-C++ | Smaller Things\u3002

\u5982\u679c\u9019\u6a23\u9084\u4e0d\u80fd\u8aaa\u670d\u4f60\uff0c\u55ef\uff0c\u4e8b\u5be6\u4e0a\u9019\u56db\u9ede\u5df2\u7d93\u5b8c\u5168\u5145\u5206\u69cb\u6210\u7406\u7531\uff0c\u5982\u679c\u4f60\u5b8c\u5168\u4e0d\u95dc\u5fc3\uff0c\u90a3\u9ebc\u4f60\u7684\u7a0b\u5f0f\u8a2d\u8a08\u5b78\u7fd2\u5927\u6982\u4e5f\u4e0d\u662f\u5f88\u8a8d\u771f\uff0c\u6240\u4ee5\u6216\u8a31\u7e7c\u7e8c\u7528 Dev-C++ \u4e5f\u6c92\u5dee\u5427\u3002

"},{"location":"programming/24fall/lec2/#vscode","title":"\u4f7f\u7528 VSCode \u8fde\u63a5\u5230\u8fdc\u7a0b\u670d\u52a1\u5668","text":"

\u52a8\u624b\u505a 3.2.1

"},{"location":"programming/24fall/lec2/#_7","title":"\u81ea\u52a8\u8865\u5168\u3001\u4ee3\u7801\u683c\u5f0f\u5316","text":"

VSCode \u672c\u8eab\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u6587\u672c\u7f16\u8f91\u5668\uff0c\u4f46\u662f\u901a\u8fc7\u63d2\u4ef6\u53ef\u4ee5\u5b9e\u73b0\u5f3a\u5927\u7684\u529f\u80fd\uff1a

"},{"location":"programming/24fall/lec2/#ai","title":"\u4f7f\u7528 AI \u5de5\u5177","text":"

\u6b63\u786e\u4f7f\u7528 AI \u5de5\u5177\u7684\u6001\u5ea6

"},{"location":"programming/24fall/lec2/#vscode_1","title":"VSCode \u63d2\u4ef6","text":"

\u5bf9\u4e8e\u5199\u4ee3\u7801\uff0c\u6700\u597d\u7684 AI \u5de5\u5177\u5e94\u8be5\u662f GitHub Copilot\uff0c\u4f46\u662f\u83b7\u53d6\u6761\u4ef6\u5bf9\u4e8e\u65b0\u624b\u53ef\u80fd\u6709\u4e9b\u56f0\u96be\uff1a

\u7136\u540e\u5c31\u53ef\u4ee5\u4f7f\u7528 Copilot \u4e86\u3002

\u8bfe\u540e\uff1a\u5c1d\u8bd5\u83b7\u53d6 Copilot\u3002\u53ef\u4ee5\u8ba9\u8eab\u8fb9\u6ce8\u518c\u6210\u529f\u7684\u540c\u5b66\u5e2e\u5fd9\u3002

\u56fd\u5185\u6709\u5f88\u591a\u7c7b\u4f3c\u7684\u5de5\u5177\uff0c\u6548\u679c\u4e0d\u6bd4 Copilot \u5dee\uff0c\u6bd4\u5982\uff1a

\u8bfe\u540e\uff1a\u81ea\u5df1\u9009\u62e9\u4e00\u4e2a AI \u63d2\u4ef6\u5c1d\u8bd5\u4e00\u4e0b

"},{"location":"programming/24fall/lec2/#_8","title":"\u5176\u4ed6","text":" \u4e00\u4e9b\u53c2\u8003

\u5c31\u5728\u5f00\u8bfe\u7684\u524d\u4e00\u5929\uff0c\u5357\u5927 C \u7a0b\u8bfe\u52a9\u6559\u6070\u597d\u4e5f\u53d1\u51fa\u4e86\u5173\u4e8e AI \u5de5\u5177\u7684\u89c6\u9891\uff1a \u3010\u540c\u5b66\uff0c\u4f60\u7684\u4ee3\u7801\u53c8\u53c8\u53c8\u2026\u2026\u54e6\uff0c\u4f60\u5931\u4e1a\u4e86\u301120241114-Part 3-\u718a\u4e18\u6853-LLM\u548c\u7b97\u6cd5\u7ade\u8d5b\uff0c\u6216\u8bb8\u8bb2\u7684\u66f4\u8be6\u7ec6\u4e00\u4e9b\u3002

"},{"location":"programming/24fall/lec2/#makefile","title":"\u7b80\u5355 Makefile","text":"

make \u662f\u4e00\u4e2a\u7ba1\u7406\u7a0b\u5e8f\u6784\u5efa\u7684\u5de5\u5177\uff0c\u5b83\u901a\u8fc7\u8bfb\u53d6\u4e00\u4e2a\u53eb\u505a Makefile \u7684\u6587\u4ef6\u6765\u6267\u884c\u6784\u5efa\u4efb\u52a1\u3002Makefile \u6587\u4ef6\u4e2d\u5305\u542b\u4e86\u4e00\u7cfb\u5217\u89c4\u5219\uff0c\u6bcf\u4e2a\u89c4\u5219\u63cf\u8ff0\u4e86\u4e00\u4e2a\u6784\u5efa\u4efb\u52a1\u7684\u4f9d\u8d56\u5173\u7cfb\u548c\u6784\u5efa\u6b65\u9aa4\u3002

target: dependencies\n    command\n

\u5bf9\u4e8e\u4e0a\u9762\u7684 hello.c\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 Makefile\uff1a

\u52a8\u624b\u505a 3.5.1

\u521b\u5efa\u4e00\u4e2a Makefile \u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a

hello: hello.c\n    gcc -o hello hello.c\n

\u7136\u540e\u5728\u7ec8\u7aef\u4e2d\u6267\u884c make \u547d\u4ee4\uff1a

make\n

\u4f7f\u7528 Makefile \u7684\u597d\u5904\uff1a

"},{"location":"programming/24fall/lec2/#vscode-gdb","title":"\u4f7f\u7528 VSCode \u53ef\u89c6\u5316 GDB \u8c03\u8bd5","text":"

\u8981\u4f7f\u7528 VSCode \u7ba1\u7406\u7a0b\u5e8f\u6784\u5efa\u548c\u8c03\u8bd5\uff0c\u9700\u8981\u914d\u7f6e\u4efb\u52a1\uff08task\uff09\u548c\u8c03\u8bd5\u4efb\u52a1\uff08launch\uff09\u3002\u6211\u4eec\u8ba9 VSCode \u81ea\u52a8\u4e3a\u6211\u4eec\u751f\u6210\u6a21\u677f\u3002

\u914d\u7f6e Task\uff1a

\u7136\u540e\u5c31\u53ef\u4ee5\u7528 VSCode \u4e00\u952e\u8fd0\u884c\u7a0b\u5e8f\u4e86\u3002\u7b80\u5355\u89e3\u91ca\u4e00\u4e0b\u751f\u6210\u7684 .vscode/tasks.json\uff1a

{\n \"version\": \"2.0.0\",\n \"tasks\": [\n  {\n   \"type\": \"cppbuild\",\n   \"label\": \"C/C++: gcc build active file\",\n   \"command\": \"/usr/bin/gcc\",\n   \"args\": [\n    \"-fdiagnostics-color=always\",\n    \"-g\",\n    \"${file}\",\n    \"-o\",\n    \"${fileDirname}/${fileBasenameNoExtension}\"\n   ],\n   \"options\": {\n    \"cwd\": \"${fileDirname}\"\n   },\n   \"problemMatcher\": [\n    \"$gcc\"\n   ],\n   \"group\": {\n    \"kind\": \"build\",\n    \"isDefault\": true\n   },\n   \"detail\": \"compiler: /usr/bin/gcc\"\n  }\n ]\n}\n

\u914d\u7f6e Launch\uff1a

\u7136\u540e\u5c31\u53ef\u4ee5\u7528 VSCode \u8c03\u8bd5\u7a0b\u5e8f\u4e86\u3002\u7b80\u5355\u89e3\u91ca\u4e00\u4e0b\u751f\u6210\u7684 .vscode/launch.json\uff1a

{\n// Use IntelliSense to learn about possible attributes.\n// Hover to view descriptions of existing attributes.\n// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\n\"version\": \"0.2.0\",\n\"configurations\": [\n    {\n        \"name\": \"(gdb) Launch\",\n        \"type\": \"cppdbg\",\n        \"request\": \"launch\",\n        \"program\": \"${fileDirname}/${fileBasenameNoExtension}\",\n        \"args\": [],\n        \"stopAtEntry\": false,\n        \"cwd\": \"${fileDirname}\",\n        \"environment\": [],\n        \"externalConsole\": false,\n        \"MIMode\": \"gdb\",\n        \"setupCommands\": [\n            {\n                \"description\": \"Enable pretty-printing for gdb\",\n                \"text\": \"-enable-pretty-printing\",\n                \"ignoreFailures\": true\n            },\n            {\n                \"description\": \"Set Disassembly Flavor to Intel\",\n                \"text\": \"-gdb-set disassembly-flavor intel\",\n                \"ignoreFailures\": true\n            }\n        ]\n    }\n]\n}\n

\u8ba9\u6211\u4eec\u5c1d\u8bd5\u8c03\u8bd5\u4e00\u4e0b\u4e0b\u9762\u7684\u547d\u4ee4\uff1a

Note

/dev/zero \u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u6587\u4ef6\uff0c\u5b83\u4f1a\u8fd4\u56de\u65e0\u9650\u591a\u4e2a 0 \u5b57\u8282\u3002

./gets < /dev/zero\n

\u52a8\u624b\u505a 3.6.1

\u5c1d\u8bd5\u8c03\u8bd5 gets \u7a0b\u5e8f\u3002

"},{"location":"programming/24fall/lec2/#_9","title":"\u7ed3\u8bed","text":"

\u901a\u8fc7\u4eca\u5929\u7684\u8bfe\u7a0b\uff0c\u4f60\u5e94\u8be5\u5177\u5907\u4e86\u4e0d\u8f93\u4e8e\u5927\u4f6c\u4eec\u7684\u81ea\u5b66\u8d44\u6e90\uff1a

\u5982\u679c\u672c\u8bfe\u7684\u5185\u5bb9\u4e0d\u80fd\u6ee1\u8db3\u4f60\uff0c\u63a8\u8350\u6d4f\u89c8\u53bb\u5e74\u7684\u8bfe\u7a0b\u3002

\u4e0b\u4e00\u8282\u8bfe\uff0c\u9ec4\u54f2\u5b66\u957f\u5c06\u5411\u5927\u5bb6\u4ecb\u7ecd\u66f4\u591a\u5b9e\u7528\u6280\u80fd\uff0c\u656c\u8bf7\u671f\u5f85\uff01

"},{"location":"programming/24fall/lec3/","title":"\u7b2c\u4e09\u8bb2\uff1a\u5f00\u6e90\u4e16\u754c\u751f\u5b58\u57fa\u7840","text":"

Tip

\u5efa\u8bae\u540c\u5b66\u4eec\u643a\u5e26\u7b14\u8bb0\u672c\u7535\u8111\uff0c\u5e76\u5728\u8bfe\u524d\u6309\u7167\u7b2c 2.2 \u8282\u5728\u81ea\u5df1\u7684\u7535\u8111\u4e0a\u5b89\u88c5\u597d Git\uff0c\u4ee5\u4fbf\u8bfe\u4e0a\u5b9e\u8df5\u3002

"},{"location":"programming/24fall/lec3/#what-why","title":"What & Why","text":"

\u5f00\u6e90\uff08Open Source\uff09\u662f\u6307\u5c06\u6e90\u4ee3\u7801\u516c\u5f00\u5230\u4e92\u8054\u7f51\u4e0a\uff0c\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u5728\u5f00\u6e90\u8bb8\u53ef\u8bc1\uff08License\uff09\u7684\u7ea6\u675f\u4e0b\u67e5\u770b\u3001\u4fee\u6539\u751a\u81f3\u91cd\u65b0\u53d1\u5e03\u4ee3\u7801\u3002

\u4e3a\u4e86\u4fbf\u4e8e\u7ba1\u7406\u548c\u534f\u4f5c\uff0c\u901a\u5e38\u4f1a\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff08Version Control Systems\uff0cVCS\uff09\u6765\u7ba1\u7406\u4ee3\u7801\uff0c\u5176\u4e2d\u6700\u6d41\u884c\u7684\u5de5\u5177\u662f Git\u3002\u4e0e\u6b64\u540c\u65f6\uff0c\u65e2\u7136\u4ee3\u7801\u662f\u516c\u5f00\u7684\uff0c\u5c31\u9700\u8981\u4e00\u4e2a\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\u6765\u5b58\u50a8\u548c\u7ba1\u7406\u4ee3\u7801\uff0c\u6700\u4e3a\u77e5\u540d\u7684\u5e73\u53f0\u662f GitHub\u3002\u8003\u8651\u5230\u56fd\u5185\u7684\u7f51\u7edc\u73af\u5883\uff0c\u672c\u8282\u8bfe\u5c06\u4ee5\u6d59\u6c5f\u5927\u5b66\u8d85\u7b97\u961f\u63d0\u4f9b\u7684 ZJU Git \u4e3a\u793a\u8303\u5e73\u53f0\u3002

Example

\u5f88\u597d\uff0c\u5f00\u6e90\u770b\u4e0a\u53bb\u5f88\u9177\uff0c\u4f46\u6211\u4e3a\u4ec0\u4e48\u8981\u5b66\u5b83\u5462\uff1f

\u5f88\u68d2\uff01\u90a3\u6211\u4eec\u5f00\u59cb\u5427\uff01

"},{"location":"programming/24fall/lec3/#git","title":"Git\uff1a\u6700\u4f18\u79c0\u7684\u7248\u672c\u63a7\u5236\u5de5\u5177","text":"

\u4f60\u662f\u5426\u9047\u5230\u8fc7\u8fd9\u6837\u7684\u60c5\u666f\uff1f

\u66f4\u8fdb\u4e00\u6b65\uff0c\u5f53\u4f60\u9ad8\u9ad8\u5174\u5174\u5730\u5199\u5b8c\u4e86\u62a5\u544a\uff0c\u521a\u628a\u5404\u79cd\u5907\u4efd\u6587\u4ef6\u5220\u9664\uff0c\u56de\u6536\u7ad9\u6e05\u7a7a\uff0c\u7136\u540e\u5bfc\u5e08\u7a81\u53d1\u5947\u60f3\uff0c\u544a\u8bc9\u4f60\u4ed6\u89c9\u5f97\u4ee5\u524d\u7684\u7248\u672c\u66f4\u597d\uff0c\u53eb\u4f60\u56de\u9000\u4ee5\u524d\u7684\u7248\u672c\uff0c\u8fd9\u65f6\u4f60\u7684\u5fc3\u60c5\u662f\u4ec0\u4e48\u6837\u7684\uff1f

Git \u5c31\u662f\u4e3a\u4e86\u89e3\u51b3\u8fd9\u79cd\u95ee\u9898\u800c\u751f\u7684\u3002\u901a\u8fc7\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u53ef\u4ee5\u5e2e\u4f60\u8bb0\u5f55\u6587\u4ef6\u7684\u81ea\u521b\u5efa\u4ee5\u6765\u7684\u6bcf\u4e00\u4e2a\u7248\u672c\uff0c\u751a\u81f3\u5141\u8bb8\u4f60\u5728\u4e0d\u540c\u7248\u672c\u4e4b\u95f4\u81ea\u7531\u5207\u6362\u3002

\u8fdc\u53e4\u65f6\u671f\u7684 Linux \u4ee3\u7801

\u4f60\u751a\u81f3\u53ef\u4ee5\u627e\u5230 Linux \u5185\u6838\u5728 GitHub \u4e0a\u7684\u7b2c\u4e00\u6b21\u63d0\u4ea4\uff01\uff08\u5b9e\u9645\u4e0a\uff0c\u56e0\u4e3a\u5e74\u4ee3\u8fc7\u4e8e\u4e45\u8fdc\uff0c\u8fd9\u4e2a\u63d0\u4ea4\u5728 GitHub \u63d0\u4ea4\u5217\u8868\u4e0a\u662f\u9690\u85cf\u7684\uff0c\u611f\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u81ea\u5df1\u8bd5\u8bd5\u770b\u770b\u80fd\u4e0d\u80fd\u628a\u5b83\u627e\u51fa\u6765\ud83d\ude09\uff09

\u68a6\u5f00\u59cb\u7684\u5730\u65b9

"},{"location":"programming/24fall/lec3/#_2","title":"\u5386\u53f2","text":"

Linus Torvalds \u5728\u5f00\u53d1 Linux \u5185\u6838\u65f6\uff0c\u539f\u672c\u4f7f\u7528\u7684\u7248\u672c\u7ba1\u7406\u7cfb\u7edf\u53eb BitKeeper\u3002\u4f46\u662f\u7531\u4e8e\u5f53\u65f6 BitKeeper \u7684\u514d\u8d39\u7248\u672c\u52a0\u5165\u4e86\u9650\u5236\uff0c\u4ed6\u51b3\u5b9a\u5f00\u53d1\u4e00\u6b3e\u81ea\u7531\u3001\u514d\u8d39\u7684\u7248\u672c\u7ba1\u7406\u7cfb\u7edf\uff0c\u987a\u5e26\u89e3\u51b3\u4e00\u4e0b\u5386\u4ee3 VCS \u7684\u7f3a\u9677\uff0c\u4e8e\u662f Git \u8bde\u751f\u4e86\u3002

"},{"location":"programming/24fall/lec3/#git_1","title":"Git \u5b89\u88c5\u53ca\u914d\u7f6e","text":"

\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165 git --version\uff0c\u5982\u679c\u6b63\u5e38\u8f93\u51fa\u7248\u672c\u53f7\uff0c\u5219\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u914d\u7f6e Git \u7684\u4e00\u4e9b\u57fa\u672c\u4fe1\u606f\uff0c\u4f8b\u5982\u7528\u6237\u540d\u548c\u90ae\u7bb1\u3002

git config --global user.name \"<\u4f60\u7684\u7528\u6237\u540d>\"\ngit config --global user.email \"<\u4f60\u7684\u90ae\u7bb1>\"\n
"},{"location":"programming/24fall/lec3/#git_2","title":"Git \u7684\u6570\u636e\u6a21\u578b","text":"

\u4ece Git \u7684\u4ea4\u4e92\u6307\u4ee4\u51fa\u53d1\u5f88\u5bb9\u6613\u8ba9\u4eba\u542c\u5f97\u4e00\u5934\u96fe\u6c34\uff0c\u6240\u4ee5\u6211\u4eec\u4ece\u5e95\u5c42\u51fa\u53d1\uff0c\u81ea\u4e0b\u800c\u4e0a\u5730\u5b66\u4e60 Git\u3002

\u56fe\u7247\u6765\u6e90\uff1aTonyCrane \u7684\u8bb2\u4e49

Git \u542f\u52a8\u65f6\uff0c\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a .git \u7684\u9690\u85cf\u6587\u4ef6\u5939\uff0c\u8fd9\u4e2a\u6587\u4ef6\u5939\u5c31\u662f Git \u7684\u7248\u672c\u5e93\uff08Repository\uff09\u3002

\u7248\u672c\u5e93\u4e2d\uff0c\u4fdd\u5b58\u7740\u6240\u6709\u6587\u4ef6\u7684\u5386\u53f2\uff08History\uff09\uff0c\u4ee5\u53ca\u4e00\u4e2a\u53eb\u6682\u5b58\u533a\uff08Stage\uff09\u7684\u4e1c\u897f\u3002

"},{"location":"programming/24fall/lec3/#_3","title":"\u5feb\u7167","text":"

\u4e3a\u4e86\u8bb0\u5f55\u6587\u4ef6\u7684\u5386\u53f2\uff0cGit \u4f1a\u7ed9\u6bcf\u4e00\u4e2a\u7248\u672c\u521b\u5efa\u4e00\u4e2a\u5feb\u7167\uff08Snapshot\uff0c\u53c8\u79f0 Commit\u3001\u63d0\u4ea4\uff09\uff0c\u4e0d\u540c\u7684\u5feb\u7167\u4e4b\u95f4\u901a\u8fc7\u4e00\u79cd\u53eb\u505a\u6709\u5411\u65e0\u73af\u56fe\uff08Directed Acyclic Graph\uff0cDAG\uff09\u7684\u6570\u636e\u7ed3\u6784\uff08\u5927\u5bb6\u4f1a\u5728\u5927\u4e00\u4e0b\u300a\u6570\u636e\u7ed3\u6784\u57fa\u7840\u300b\u7684\u8bfe\u7a0b\u4e2d\u5b66\u5230\uff09\u8054\u7cfb\u8d77\u6765\u3002

\u4e00\u79cd\u53ef\u80fd\u7684\u5386\u53f2 \u82e5\u672a\u7279\u6b8a\u8bf4\u660e\uff0c\u672c\u8bb2\u4e49\u4e2d\u624b\u7ed8\u98ce\u683c\u793a\u610f\u56fe\u5747\u4e3a\u539f\u521b\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904

\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u5386\u53f2\u5728 C \u5feb\u7167\u5904\u4ea7\u751f\u4e86\u4e24\u4e2a\u5206\u652f\uff08Branch\uff09\uff0c\u5e76\u5728 I \u5feb\u7167\u5904\u5408\u5e76\uff08Merge\uff09\u3002\u8fd9\u79cd\u5206\u652f\u548c\u5408\u5e76\u7684\u64cd\u4f5c\u662f Git \u7684\u5f3a\u5927\u4e4b\u5904\uff0c\u6211\u4eec\u4f1a\u5728\u540e\u9762\u8be6\u7ec6\u8bb2\u89e3\u3002

\u5728 Git \u4e2d\uff0c\u6bcf\u4e00\u4e2a\u5feb\u7167\u90fd\u7531\u4e00\u4e2a\u5341\u516d\u8fdb\u5236\u6570\u552f\u4e00\u6807\u8bc6\uff0c\u5b83\u76f8\u5f53\u4e8e\u5feb\u7167\u7684 ID\u3002\u901a\u5e38\u53ea\u9700\u8981\u524d\u51e0\u4f4d\u5c31\u53ef\u4ee5\u552f\u4e00\u786e\u5b9a\u4e00\u4e2a\u5feb\u7167\uff0c\u4f8b\u5982\u4e4b\u524d\u56fe\u7247\u4e2d\u7684 1da177e\u3002\u4f46\u5f88\u663e\u7136\uff0c\u8fd9\u79cd\u5341\u516d\u8fdb\u5236\u6570\u4e0d\u9002\u5408\u4eba\u7c7b\u8bb0\u5fc6\u3002\u56e0\u6b64 Git \u5141\u8bb8\u7ed9\u5feb\u7167\u521b\u5efa\u5f15\u7528\uff08Reference\uff09\uff0c\u5b83\u662f\u4e00\u4e2a\u6307\u5411\u5feb\u7167\u7684\u6307\u9488\uff0c\u4f8b\u5982\u4eba\u4eec\u901a\u5e38\u4f7f\u7528 master\u3001main \u7b49\u540d\u5b57\u6765\u8868\u793a\u6700\u65b0\u7684\u5feb\u7167\u3002

Git \u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u6307\u9488\u53eb\u505a HEAD\uff0c\u5b83\u6307\u5411\u5f53\u524d\u6240\u5728\u7684\u5206\u652f\u6216\u8005\u5feb\u7167\uff0c\u4e5f\u5c31\u662f\u5f53\u524d\u6b63\u5728\u5de5\u4f5c\u7684\u7248\u672c\u3002

\u6307\u5411\u5206\u652f\u7684\u6307\u9488

\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u5728\u4e0d\u540c\u5feb\u7167\u4e4b\u95f4\u5207\u6362\u3002

"},{"location":"programming/24fall/lec3/#_4","title":"\u6682\u5b58\u533a","text":"

\u4f60\u53ef\u80fd\u4f1a\u60f3\u8c61\uff0c\u6bcf\u6b21\u63d0\u4ea4\u90fd\u4f1a\u5bf9\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\uff08Working Directory\uff09\u6253\u4e00\u4e2a\u5feb\u7167\uff0c\u7136\u540e\u4fdd\u5b58\u5230\u7248\u672c\u5e93\u4e2d\uff0c\u4f46\u5b9e\u9645\u4e0a\u5e76\u975e\u5982\u6b64\u3002

\u8bbe\u60f3\u8fd9\u6837\u4e00\u4e2a\u573a\u666f\uff1a\u4f60\u540c\u65f6\u4fee\u6539\u4e86\u4e24\u4e2a\u6587\u4ef6\uff0c\u4f46\u53ea\u60f3\u63d0\u4ea4\u5176\u4e2d\u4e00\u4e2a\uff0c\u8fd9\u65f6\u5019\u5c31\u9700\u8981\u4e00\u4e2a\u4e2d\u95f4\u72b6\u6001\u6765\u4fdd\u5b58\u4f60\u7684\u4fee\u6539\u3002\u8fd9\u4e2a\u4e2d\u95f4\u72b6\u6001\u5c31\u662f\u6240\u8c13\u7684\u6682\u5b58\u533a\u3002

\u56fe\u7247\u6765\u6e90\uff1aTonyCrane \u7684\u8bb2\u4e49"},{"location":"programming/24fall/lec3/#_5","title":"\u57fa\u7840\u7528\u6cd5","text":"

Let's get our hands dirty!

\u56fe\u7247\u6765\u6e90\uff1aXKCD GIT"},{"location":"programming/24fall/lec3/#_6","title":"\u521d\u59cb\u5316\u7248\u672c\u5e93","text":"

\u5feb\u901f\u56de\u987e

\u5728 Linux / macOS \u7cfb\u7edf\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 ls \u547d\u4ee4\u67e5\u770b\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u548c\u6587\u4ef6\u5939\uff0c\u4f7f\u7528 cd \u547d\u4ee4\u5207\u6362\u76ee\u5f55\u3002

\u5bf9\u4e8e Windows \u7cfb\u7edf\uff0c\u8fd9\u91cc\u63a8\u8350\u5927\u5bb6\u4f7f\u7528\u7cfb\u7edf\u81ea\u5e26\u7684 Windows Terminal \u8fdb\u884c\u5b9e\u9a8c\uff0c\u5176\u8fd0\u884c\u7684\u9ed8\u8ba4\u7ec8\u7aef\u662f Powershell\uff0c\u4f7f\u7528\u4e60\u60ef\u66f4\u63a5\u8fd1 Linux\uff08\u76f8\u8f83\u4e8e cmd \u800c\u8a00\uff09\u3002

\u8981\u4f7f\u7528 Git\uff0c\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2a Git \u7248\u672c\u5e93\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u662f\u901a\u8fc7 git init \u547d\u4ee4\u5b8c\u6210\u7684\u3002

\u52a8\u624b\u505a\uff1a\u521d\u59cb\u5316\u7248\u672c\u5e93

\u5728\u81ea\u5df1\u7684\u7535\u8111\u4e0a\u6253\u5f00\u7ec8\u7aef\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5939\uff08mkdir \u547d\u4ee4\uff09\uff0c\u7136\u540e\u8fdb\u5165\u8fd9\u4e2a\u6587\u4ef6\u5939\uff08cd \u547d\u4ee4\uff09\uff0c\u5e76\u4f7f\u7528 git init \u521d\u59cb\u5316\u4e00\u4e2a Git \u7248\u672c\u5e93\u3002

mkdir my-repo\ncd my-repo\ngit init\n

\u5c1d\u8bd5\u4f7f\u7528 ls \u547d\u4ee4\u67e5\u770b\u5f53\u524d\u76ee\u5f55\u7684\u5185\u5bb9\uff0c\u80fd\u627e\u5230 .git \u6587\u4ef6\u5939\u5417\uff1f\u4e3a\u4ec0\u4e48\uff1f

"},{"location":"programming/24fall/lec3/#commit","title":"\u5e74\u8f7b\u4eba\u7684\u7b2c\u4e00\u4e2a Commit\uff01","text":"

\u73b0\u5728\u6211\u4eec\u5df2\u7ecf\u6709\u4e86\u4e00\u4e2a\u7a7a\u7684 Git \u7248\u672c\u5e93\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u5c1d\u8bd5\u5f80\u91cc\u9762\u6dfb\u52a0\u4e00\u4e9b\u6587\u4ef6\u3002

\u52a8\u624b\u505a\uff1a\u4e00\u4e9b\u51c6\u5907\u5de5\u4f5c

\u7528 VSCode \u6253\u5f00\u8fd9\u4e2a\u6587\u4ef6\u5939\uff0c\u521b\u5efa\u4e00\u4e2a hello.c \u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a

#include <stdio.h>\n\nint main() {\n    printf(\"Hello World\");\n    return 0;\n}\n

\u8fd9\u662f\u4e00\u4e2a\u7b80\u5355\u7684 Hello World \u7a0b\u5e8f\uff0c\u5b9e\u9645\u4f7f\u7528\u4e2d\u7684\u573a\u666f\u53ef\u80fd\u662f\u4f60\u7684\u5b9e\u9a8c\u62a5\u544a\u3001\u9879\u76ee\u4ee3\u7801\u7b49\uff0c\u8fd9\u91cc\u53ea\u662f\u4e3a\u4e86\u6f14\u793a\u3002

\u73b0\u5728\u7684\u5de5\u4f5c\u76ee\u5f55\u4e2d\u6709\u4e86\u4e00\u4e2a hello.c \u6587\u4ef6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 git status \u547d\u4ee4\u67e5\u770b\u5f53\u524d\u7248\u672c\u5e93\u7684\u72b6\u6001\u3002

git status\n

\u67e5\u770b\u5f53\u524d\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u5e93\u7684\u72b6\u6001\u3002

\u6587\u4ef6\u6709\u4e09\u4e2a\u7c7b\u522b\uff1a\u672a\u8ddf\u8e2a\uff08Untracked\uff09\u3001\u5df2\u8ffd\u8e2a\uff08Tracked\uff09\u3001\u88ab\u5ffd\u7565\uff08Ignored\uff09\u3002

\u52a8\u624b\u505a 2.4.1

\u8fd0\u884c git status \u547d\u4ee4\uff0c\u4f60\u770b\u5230\u4e86\u4ec0\u4e48\uff1f\u4f60\u80fd\u591f\u89e3\u91ca\u8fd9\u4e9b\u4fe1\u606f\u5417\uff1f

git add <FILE>\n

\u5c06\u6240\u9009\u7684\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u6dfb\u52a0\u5230\u6682\u5b58\u533a\u3002

\u52a8\u624b\u505a 2.4.2

\u628a hello.c \u6dfb\u52a0\u5230\u6682\u5b58\u533a\u3002\u8fd9\u4e2a\u65f6\u5019\u518d\u6b21\u8fd0\u884c git status\uff0c\u770b\u770b\u6709\u4ec0\u4e48\u53d8\u5316\u3002

\u601d\u8003\uff1a\u5982\u679c\u6211\u60f3\u4e00\u6b21\u6027\u6dfb\u52a0\u591a\u4e2a\u6587\u4ef6\uff0c\u6216\u8005\u8bf4\u6dfb\u52a0\u6240\u6709\u6587\u4ef6\uff0c\u5e94\u8be5\u600e\u4e48\u505a\u5462\uff1f

git commit -m \"<MESSAGE>\"\n

\u5c06\u6682\u5b58\u533a\u7684\u6587\u4ef6\u63d0\u4ea4\u5230\u7248\u672c\u5e93\uff0c-m \u53c2\u6570\u540e\u9762\u662f\u63d0\u4ea4\u7684\u4fe1\u606f\uff0c\u7528\u4e8e\u63cf\u8ff0\u8fd9\u6b21\u63d0\u4ea4\u7684\u5185\u5bb9\u3002

git log\n

\u67e5\u770b\u7248\u672c\u5e93\u7684\u5386\u53f2\u3002

\u52a8\u624b\u505a 2.4.3

\u63d0\u4ea4 hello.c \u6587\u4ef6\u5230\u7248\u672c\u5e93\uff0c\u63d0\u4ea4\u4fe1\u606f\u53ef\u4ee5\u662f\u4efb\u610f\u7684\uff0c\u4f8b\u5982 Add hello.c\u3002

git commit -m \"Add hello.c\"\n

\u8bd5\u4e00\u8bd5 git log \u547d\u4ee4\uff0c\u4f60\u80fd\u89e3\u91ca\u8fd9\u4e9b\u4fe1\u606f\u5417\uff1f

\ud83c\udf89 \u606d\u559c\u4f60\u5b8c\u6210\u4e86\u81ea\u5df1\u7684\u7b2c\u4e00\u4e2a Commit\uff01\u4e0b\u9762\u8ba9\u6211\u4eec\u591a\u6dfb\u52a0\u4e00\u4e9b\u6587\u4ef6\u3002

\u52a8\u624b\u505a\uff1a\u5e74\u8f7b\u4eba\u7684\u7b2c i \u4e2a Commit\uff08i = 2, 3, ...\uff09

\u4e00\u4e2a\u4f18\u79c0\u7684\u9879\u76ee\u53ea\u6709\u4ee3\u7801\u600e\u4e48\u884c\uff1f\u8ba9\u6211\u4eec\u6dfb\u52a0\u4e00\u4e2a\u4ecb\u7ecd\u6587\u6863\u5427\uff01\u521b\u5efa README.txt\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a

hello.c\uff1a\u4e00\u4e2a\u7b80\u5355\u7684 Hello World \u7a0b\u5e8f\uff08\u771f\u7684\u5f88\u7b80\u5355\uff01\uff09\u3002\n

\u7136\u540e\u63d0\u4ea4\u8fd9\u4e2a\u6587\u4ef6\u3002\u518d\u6b21\u8fd0\u884c git log\uff0c\u4f60\u770b\u5230\u4e86\u4ec0\u4e48\uff1f

\u8bd5\u7740\u4fee\u6539\u3001\u521b\u5efa\u3001\u5220\u9664\uff0c\u770b\u770b git status\uff0c\u7528 git diff \u67e5\u770b\u5f53\u524d\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u533a\u7684\u5dee\u5f02\uff0c\u7136\u540e\u63d0\u4ea4\u8fd9\u4e9b\u4fee\u6539\u3002

\u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u5e38\u7528\u7684\u547d\u4ee4\uff1a

\u52a8\u624b\u505a\uff1a\u73a9\u4e00\u73a9

\u8bd5\u7740\u4f7f\u7528\u4e0a\u9762\u63d0\u5230\u7684\u547d\u4ee4\uff0c\u73a9\u4e00\u73a9 Git \u5427\uff01\u5982\u679c\u6709\u4ec0\u4e48\u95ee\u9898\uff0c\u6b22\u8fce\u968f\u65f6\u63d0\u95ee\u3002

"},{"location":"programming/24fall/lec3/#_7","title":"\u5206\u652f","text":"

\u5206\u652f\uff08Branch\uff09\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u6982\u5ff5\u3002\u5b83\u5141\u8bb8\u4f60\u5728\u4e0d\u5f71\u54cd\u4e3b\u7ebf\u7684\u60c5\u51b5\u4e0b\u8fdb\u884c\u5f00\u53d1\uff0c\u7136\u540e\u518d\u5c06\u4f60\u7684\u5de5\u4f5c\u5408\u5e76\u5230\u4e3b\u7ebf\u4e0a\u3002

\u52a8\u624b\u505a\uff1a\u5206\u652f

\u5047\u5982\u8bf4\u6211\u60f3\u7ed9\u6211\u4eec\u7684 hello.c \u6dfb\u52a0\u4e00\u4e2a\u51fd\u6570\uff0c\u4f46\u662f\u7531\u4e8e\u8fd9\u4e2a\u51fd\u6570\u5f88\u590d\u6742\uff0c\u53ef\u80fd\u4f1a\u65ad\u65ad\u7eed\u7eed\u4fee\u6539\u5f88\u957f\u65f6\u95f4\uff0c\u6240\u4ee5\u6211\u4e0d\u60f3\u5f71\u54cd\u5230\u4e3b\u7ebf\u7684\u5f00\u53d1\u3002\u8fd9\u65f6\u5019\u5c31\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5206\u652f\uff0c\u7136\u540e\u5728\u8fd9\u4e2a\u5206\u652f\u4e0a\u4e0e\u4e3b\u7ebf\u5e73\u884c\u5f00\u53d1\u3002

\u8bd5\u7740\u521b\u5efa\u4e00\u4e2a dev \u5206\u652f\uff0c\u5207\u6362\u8fdb\u53bb\uff0c\u7136\u540e\u5728 hello.c \u4e2d\u6dfb\u52a0\u4e00\u4e2a print_hello() \u51fd\u6570\uff1a

void print_hello() {\n    printf(\"Hello from dev branch!\");\n}\n

\u7136\u540e\u63d0\u4ea4\u8fd9\u4e2a\u4fee\u6539\u3002\u518d\u8fd0\u884c git log\uff08\u4f60\u53ef\u4ee5\u540c\u65f6\u8bd5\u4e00\u8bd5\u5b83\u7684\u5404\u79cd\u53c2\u6570\uff09\uff0c\u4f60\u770b\u5230\u4e86\u4ec0\u4e48\uff1f\u5728\u8111\u6d77\u91cc\u60f3\u4e00\u60f3\u5f53\u524d\u7684\u5206\u652f\u7ed3\u6784\u3002

\u5207\u6362\u56de\u4e3b\u5206\u652f\uff08master \u6216\u8005 main\uff09\uff0chello.c \u91cc\u9762\u6709\u8fd9\u4e2a\u51fd\u6570\u5417\uff1f\u4e3a\u4ec0\u4e48\uff1f

Answer

"},{"location":"programming/24fall/lec3/#detached-head","title":"Detached HEAD \u95ee\u9898","text":"

\u6240\u8c13 Detached HEAD\uff0c\u6307\u7684\u662f HEAD \u6307\u5411\u7684\u4e0d\u662f\u4e00\u4e2a\u5206\u652f\uff0c\u800c\u662f\u4e00\u4e2a\u5177\u4f53\u7684\u5feb\u7167\u3002

\u5982\u679c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u8fdb\u884c\u4fee\u6539\u5e76\u63d0\u4ea4\uff0c\u65b0\u7684\u63d0\u4ea4\u4e0d\u5c5e\u4e8e\u4efb\u4f55\u5206\u652f\uff0c\u5b83\u53ea\u80fd\u901a\u8fc7 Commit ID \u6765\u8bbf\u95ee\uff0c\u76f8\u5f53\u4e8e\u4e22\u5931\u4e86\u3002

\u56fe\u7247\u6765\u6e90\uff1aTonyCrane \u7684\u8bb2\u4e49

\u6f14\u793a\uff1aDetached HEAD

\u4f7f\u7528 git log \u67e5\u770b\u5386\u53f2\uff0c\u627e\u5230\u4e00\u4e2a Commit ID\uff0c\u7136\u540e\u4f7f\u7528 git checkout <ID> \u5207\u6362\u5230\u8fd9\u4e2a\u5feb\u7167\uff0c\u4f60\u770b\u5230\u4e86\u4ec0\u4e48\uff1f

\u8bd5\u7740\u4fee\u6539\u8fd9\u4e2a\u5feb\u7167\uff0c\u63d0\u4ea4\uff0c\u7136\u540e\u4f7f\u7528 checkout \u56de\u5230\u4e3b\u5206\u652f\uff0c\u4f60\u8fd8\u80fd\u627e\u5230\u8fd9\u4e2a\u4fee\u6539\u5417\uff1f

\u5982\u679c\u6211\u60f3\u4fdd\u7559\u8fd9\u4e2a\u4fee\u6539\uff0c\u5e94\u8be5\u600e\u4e48\u505a\uff1f

"},{"location":"programming/24fall/lec3/#_8","title":"\u5408\u5e76","text":"
git merge <BRANCH1> [<BRANCH2> ...] -m \"<MESSAGE>\"\n

\u5c06\u4e00\u4e2a\u6216\u591a\u4e2a\u5206\u652f\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f\u3002\u5408\u5e76\u672c\u8eab\u4e5f\u662f\u4e00\u6b21\u63d0\u4ea4\uff0c-m \u53c2\u6570\u540e\u9762\u662f\u63d0\u4ea4\u4fe1\u606f\u3002

\u56fe\u7247\u6765\u6e90\uff1aTonyCrane \u7684\u8bb2\u4e49

\u52a8\u624b\u505a\uff1a\u5408\u5e76\u51b2\u7a81

\u5728\u4e3b\u5206\u652f\u7684 hello.c \u4e2d\u4e5f\u6dfb\u52a0\u4e00\u4e2a print_hello() \u51fd\u6570\uff08\u771f\u5b9e\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u662f\u4f60\u5728 dev \u548c main \u4e2d\u540c\u65f6\u4fee\u6539\u4e86\u67d0\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u6216\u8005\u4e24\u4e2a\u4eba\u4e0d\u7ecf\u610f\u95f4\u540c\u65f6\u4fee\u6539\u4e86\u540c\u4e00\u4e2a\u6587\u4ef6\uff09\uff1a

void print_hello() {\n    printf(\"Hello from main branch!\");\n}\n

\u63d0\u4ea4\u8fd9\u4e2a\u4fee\u6539\uff0c\u7136\u540e\u5c1d\u8bd5\u5408\u5e76 dev \u5206\u652f\u3002\u4f60\u6210\u529f\u4e86\u5417\uff1f\u5982\u679c\u6ca1\u6709\uff0c\u4f60\u5e94\u8be5\u600e\u4e48\u505a\uff1f

\u8bd5\u7740\u89e3\u51b3\u8fd9\u4e2a\u51b2\u7a81\uff0c\u7136\u540e\u63d0\u4ea4 merge\u3002

\u5b9e\u9645\u4e0a\uff0cMerge \u8fd8\u6709\u5f88\u591a\u5176\u4ed6\u7684\u7b56\u7565\u3002

\u56fe\u7247\u6765\u6e90\uff1aTonyCrane \u7684\u8bb2\u4e49"},{"location":"programming/24fall/lec3/#_9","title":"\u7be1\u6539\u5386\u53f2","text":"

\u6210\u4e3a\u5386\u53f2\u7684\u7f6a\u4eba

Git \u7684\u5386\u53f2\u4e00\u822c\u60c5\u51b5\u4e0b\u662f\u4e0d\u53ef\u7be1\u6539\u7684\uff0c\u4f46\u5b9e\u9645\u4e0a\u8fd8\u662f\u6709\u4e00\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5bf9\u5386\u53f2\u8fdb\u884c\u4fee\u6539\uff1a

"},{"location":"programming/24fall/lec3/#vscode-git","title":"\u5728 VSCode \u4e2d\u4f7f\u7528 Git","text":"

Visual Studio Code \u9ed8\u8ba4\u96c6\u6210\u4e86 Git\uff0c\u70b9\u51fb\u5de6\u4fa7\u6e90\u4ee3\u7801\u7ba1\u7406\uff08Source Control\uff09\u6309\u94ae\u5373\u53ef\u6253\u5f00\u56fe\u5f62\u5316\u7684 Git \u754c\u9762\u3002

\u52a8\u624b\u505a\uff1a\u73a9\u4e00\u73a9

\u7528 VSCode \u6253\u5f00\u770b\u770b\u4f60\u521a\u521a\u521b\u5efa\u7684 Git \u9879\u76ee\u5427\uff5e

"},{"location":"programming/24fall/lec3/#gitignore","title":".gitignore \u6587\u4ef6","text":"

\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u6709\u4e00\u4e9b\u6587\u4ef6\u662f\u4e0d\u9700\u8981\u7eb3\u5165\u7248\u672c\u5e93\u7684\uff0c\u4f8b\u5982\u7f16\u8bd1\u751f\u6210\u7684\u6587\u4ef6\u3001\u65e5\u5fd7\u6587\u4ef6\u3001\u7f13\u5b58\u6587\u4ef6\u7b49\u3002\u8fd9\u65f6\u5019\u5c31\u9700\u8981\u5728\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a .gitignore \u6587\u4ef6\u3002

.gitignore \u6587\u4ef6\u662f\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u6bcf\u4e00\u884c\u662f\u4e00\u4e2a\u5339\u914d\u89c4\u5219\uff0c\u4f8b\u5982\uff1a

# Logs\nlogs\n*.log\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\npnpm-debug.log*\nlerna-debug.log*\n\nnode_modules\n.DS_Store\ndist\ndist-ssr\ncoverage\n*.local\ncache\n\n/cypress/videos/\n/cypress/screenshots/\n\n# Editor directories and files\n.vscode/*\n!.vscode/extensions.json\n.idea\n*.suo\n*.ntvs*\n*.njsproj\n*.sln\n*.sw?\n\n*.tsbuildinfo\n.vercel\n

\u8bed\u6cd5\uff1a

\u5b98\u65b9\u6587\u6863\uff1agit-scm.com/docs/gitignore\uff0cGitHub \u4e5f\u63d0\u4f9b\u4e86\u4e00\u4e2a\u6a21\u677f\u3002

"},{"location":"programming/24fall/lec3/#github-zju-git","title":"GitHub / ZJU Git \u57fa\u7840","text":"

\u8bbe\u60f3\u591a\u4eba\u534f\u4f5c\u7684\u573a\u666f\uff0c\u6bcf\u4e2a\u4eba\u90fd\u5728\u672c\u5730\u6709\u81ea\u5df1\u7684\u7248\u672c\u5e93\uff0c\u90a3\u5982\u4f55\u5b9e\u73b0\u540c\u6b65\u5462\uff1f

\u7b54\u6848\u662f\u6bcf\u4e2a\u4eba\u90fd\u4f7f\u7528\u4e00\u4e2a\u201c\u6743\u5a01\u201d\u7684\u8fdc\u7a0b\u7248\u672c\u5e93\uff08Remote Repository\uff09\u3002

"},{"location":"programming/24fall/lec3/#_10","title":"\u8fdc\u7a0b\u7248\u672c\u5e93","text":"\u56fe\u7247\u6765\u6e90\uff1aTonyCrane \u7684\u8bb2\u4e49

\u8fdc\u7a0b\u7248\u672c\u5e93\u4e5f\u662f\u4e00\u4e2a\u666e\u901a\u7684 Git \u7248\u672c\u5e93\uff0c\u53ea\u4e0d\u8fc7\u7531\u4e8e\u4e0d\u9700\u8981\u5de5\u4f5c\u76ee\u5f55\u548c\u6682\u5b58\u533a\uff0c\u6240\u4ee5\u4e00\u822c\u4f7f\u7528\u88f8\u7248\u672c\u5e93\u3002

\u8fdc\u7a0b\u7248\u672c\u5e93\u53ef\u4ee5\u7b80\u5355\u5730\u7406\u89e3\u6210\u662f\u672c\u5730\u7684\u4e00\u4e2a origin/main \u5206\u652f\u3002

"},{"location":"programming/24fall/lec3/#zju-git","title":"ZJU Git","text":"

\u4f5c\u4e3a\u4e00\u4e2a\u5168\u7403\u9876\u5c16\u7684\u4e09\u672c\uff0c\u600e\u4e48\u80fd\u6ca1\u6709\u4e00\u4e2a\u81ea\u5df1\u7684 Git \u670d\u52a1\u5668\u5462\uff1f

\u7f51\u5740\uff1agit.zju.edu.cn\uff0c\u53ea\u80fd\u901a\u8fc7\u6821\u7f51\u6216 WebVPN \u8bbf\u95ee\u3002

\u6ce8\u610f\u533a\u5206

ZJU Git \u548c GitHub \u662f\u5e73\u884c\u7684\u5173\u7cfb\uff0c\u5b83\u4eec\u63d0\u4f9b\u7c7b\u4f3c\u7684\u529f\u80fd\uff08\u975e\u5e38\u7c7b\u4f3c\uff09\uff0c\u90fd\u53ef\u4ee5\u4f5c\u4e3a Git \u7684\u8fdc\u7a0b\u7248\u672c\u5e93\u3002

\u4e0d\u8981\u628a ZJU Git / GitHub \u548c Git \u6df7\u6dc6\uff01

"},{"location":"programming/24fall/lec3/#_11","title":"\u6ce8\u518c\u8d26\u53f7","text":"

\u4f7f\u7528\u7edf\u4e00\u8eab\u4efd\u8ba4\u8bc1\u767b\u5f55\u3002

\u8bbe\u60f3\u4e00\u4e0b\uff0cZJU Git \u5982\u4f55\u786e\u5b9a\u4f60\u7684\u8eab\u4efd\u5462\uff1f

SSH \u5bc6\u94a5

SSH \u5bc6\u94a5\u91c7\u7528\u975e\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5\uff0c\u5b83\u5305\u62ec\u516c\u94a5\u548c\u79c1\u94a5\u4e24\u90e8\u5206\u3002

\u901a\u8fc7 SSH \u5bc6\u94a5\uff0c\u53ef\u4ee5\u4e0e\u8fdc\u7a0b\u670d\u52a1\u5668\u5efa\u7acb\u5b89\u5168\u7684\u8fde\u63a5\u3002

\u52a8\u624b\u505a\uff1a\u8bbe\u7f6e SSH \u5bc6\u94a5

\u6253\u5f00 Git Bash\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a

ssh-keygen -t ed25519 -C \"<\u4f60\u7684\u90ae\u7bb1>\"\n

\u5b83\u4f1a\u5411\u4f60\u8be2\u95ee\u5bc6\u94a5\u7684\u4fdd\u5b58\u4f4d\u7f6e\u548c\u5bc6\u7801\uff0c\u76f4\u63a5\u56de\u8f66\u4f7f\u7528\u9ed8\u8ba4\u503c\u5373\u53ef\u3002

\u8fd9\u6761\u6307\u4ee4\u4f1a\u5728 ~/.ssh \u76ee\u5f55\uff08\u5bf9\u4e8e Windows\uff0c\u662f C:/Users/<\u7528\u6237\u540d>/.ssh\uff09\u4e0b\u751f\u6210\u4e24\u4e2a\u6587\u4ef6\uff1aid_ed25519 \u548c id_ed25519.pub\uff0c\u524d\u8005\u662f\u79c1\u94a5\uff0c\u540e\u8005\u662f\u516c\u94a5\u3002

\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00 id_ed25519.pub\uff0c\u590d\u5236\u91cc\u9762\u7684\u5185\u5bb9\uff0c\u7136\u540e\u5728 ZJU Git \u7684\u8bbe\u7f6e\u4e2d\u6dfb\u52a0 SSH \u5bc6\u94a5\u5373\u53ef\u3002

"},{"location":"programming/24fall/lec3/#_12","title":"\u521b\u5efa\u4ed3\u5e93","text":"

\u52a8\u624b\u505a\uff1a\u521b\u5efa\u4ed3\u5e93

\u5728 ZJU Git \u4e0a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u4ed3\u5e93\uff0c\u7136\u540e\u5c06\u672c\u5730\u7684 Git \u9879\u76ee\u63a8\u9001\u5230\u8fd9\u4e2a\u4ed3\u5e93\u3002

git remote add origin <\u4f60\u7684\u4ed3\u5e93\u5730\u5740>\ngit branch -M main\ngit push -uf origin main\n

\u56de\u5230 ZJU Git \u7f51\u7ad9\uff0c\u770b\u770b\u4f60\u7684\u4ed3\u5e93\u5427\uff01

\u52a8\u624b\u505a\uff1a\u63d0\u4ea4\u66f4\u65b0

\u5728\u672c\u5730\u4fee\u6539 hello.c\uff0c\u7136\u540e\u628a\u5b83\u63d0\u4ea4\u5230 ZJU Git \u4e0a\u3002

\u8fd8\u8bb0\u5f97\u8981\u7528\u54ea\u4e9b\u6307\u4ee4\u5417\uff1f\uff08add\u3001commit\u3001push\uff09

"},{"location":"programming/24fall/lec3/#_13","title":"\u591a\u4eba\u534f\u4f5c","text":"

\u52a8\u624b\u505a\uff1a\u5e74\u8f7b\u4eba\u7684\u7b2c\u4e00\u4e2a PR\uff01

Fork \u8fd9\u4e2a\u4ed3\u5e93\uff1alec3-git\u3002

\u7136\u540e cd \u5230\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5939\uff0c\u4f7f\u7528 git clone \u514b\u9686\u4f60 Fork \u7684\u4ed3\u5e93\u3002

\u968f\u4fbf\u6539\u4e00\u4e9b\u4e1c\u897f\u5427\uff5e\u7136\u540e\u628a\u8fd9\u4e9b\u4fee\u6539\u63d0\u4ea4\u5230\u4f60 Fork \u7684\u4ed3\u5e93\u3002

\u6700\u540e\uff0c\u5411\u539f\u4ed3\u5e93\u63d0\u4ea4\u4e00\u4e2a PR\uff0c\u8bf7\u6c42\u5408\u5e76\u4f60\u7684\u4fee\u6539\u3002

"},{"location":"programming/24fall/lec3/#github","title":"GitHub \u7b80\u4ecb","text":"

\u6240\u8c13 GitHub\uff0c\u5c31\u662f Git \u7684 Hub\uff08\u6211\u5728\u8bf4\u4ec0\u4e48\uff09\u3002

GitHub \u662f\u5168\u7403\u6700\u5927\u7684\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\uff0c\u62e5\u6709\u6570\u4ebf\u7684\u5f00\u53d1\u8005\uff08\u622a\u81f3 2023 \u5e74 1 \u6708\uff09\u548c\u6570\u4ee5\u4ebf\u8ba1\u7684\u4ee3\u7801\u4ed3\u5e93\u3002

\u8bfe\u540e\uff1a\u6ce8\u518c\u4e00\u4e2a GitHub \u8d26\u53f7

\u6ce8\u518c\u4e00\u4e2a\u81ea\u5df1\u7684 GitHub \u8d26\u53f7\u5427\uff5e\uff08\u4f60\u53ef\u80fd\u9700\u8981\u9b54\u6cd5\uff09

\u6253\u5f00\u6211\u4eec\u73b0\u5728\u8fd9\u4e2a\u7f51\u7ad9\u7684 GitHub \u4ed3\u5e93\uff0c\u770b\u4e00\u770b Commit \u8bb0\u5f55\uff0c\u4f53\u4f1a\u4e00\u4e0b\u771f\u5b9e\u9879\u76ee\u4e2d\u7684\u56e2\u961f\u534f\u4f5c\u5427\uff01\u5982\u679c\u4f60\u89c9\u5f97\u4e0d\u9519\uff0c\u4e0d\u59a8\u7ed9\u6211\u4eec\u4e00\u4e2a Star \u2b50\u3002

\u540c\u65f6\u63a8\u8350 TonyCrane \u5b66\u957f\u7684 Slides\uff0c\u6709\u66f4\u591a\u5173\u4e8e GitHub \u7684\u8be6\u7ec6\u7684\u4ecb\u7ecd\u3002

"},{"location":"programming/24fall/lec3/#_14","title":"\u5f00\u6e90\u9879\u76ee\u57fa\u7840","text":""},{"location":"programming/24fall/lec3/#_15","title":"\u8bb8\u53ef\u8bc1","text":"

\u516c\u5f00\u6e90\u4ee3\u7801\u4e0d\u4ee3\u8868\u4f60\u53ef\u4ee5\u62ff\u5b83\u505a\u4efb\u4f55\u60f3\u505a\u7684\u4e8b\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u9700\u8981\u8bb8\u53ef\u8bc1\uff08License\uff09\u3002

\u5e38\u7528\u8f6f\u4ef6\u5f00\u6e90\u8bb8\u53ef\u8bc1\uff1a

\u53c2\u8003 choosealicense.com\u3002

\u56fe\u7247\u6765\u6e90\uff1a\u962e\u4e00\u5cf0\u300a\u5982\u4f55\u9009\u62e9\u5f00\u6e90\u8bb8\u53ef\u8bc1\uff1f\u300b

\u5982\u679c\u6ca1\u6709\u8bb8\u53ef\u8bc1\u5462\uff1f

\u539f\u4f5c\u8005\u4fdd\u7559\u6240\u6709\u6743\u5229\uff0c\u4e0d\u5141\u8bb8\u590d\u5236\u3001\u5206\u53d1\u3001\u4fee\u6539\uff0c\u4f7f\u7528\u7684\u8bdd\u9700\u8981\u8054\u7cfb\u539f\u4f5c\u8005\uff01\uff08\u6ce8\u610f\u548c Unlicense \u533a\u5206\uff09

\u4fb5\u6743\u662f\u975e\u5e38\u4e25\u8083\u7684\u4e8b\u60c5\uff01

\u539f\u4f5c\u8005\u6709\u6743\u5bf9\u4f60\u7684\u9879\u76ee\u8fdb\u884c DMCA Takedown\uff08DMCA\uff1a\u300a\u5343\u79a7\u5e74\u6570\u5b57\u8457\u4f5c\u6743\u6cd5\u6848\u300b\uff09\uff0c\u751a\u81f3\u901a\u8fc7\u6cd5\u5f8b\u9014\u5f84\u8ffd\u7a76\u8d23\u4efb\uff01

\u6848\u4f8b\uff1a

\u5728\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u540d\u4e3a LICENSE \u7684\u6587\u4ef6\uff0c\u7136\u540e\u5728\u5176\u4e2d\u9644\u4e0a\u8bb8\u53ef\u8bc1\u7684\u5185\u5bb9\u3002\u5982\u679c\u4e0d\u540c\u90e8\u5206\u91c7\u7528\u4e86\u4e0d\u540c\u7684\u8bb8\u53ef\u8bc1\uff0c\u90a3\u4e48\u9700\u8981\u5728\u6bcf\u4e2a\u6587\u4ef6\u7684\u5f00\u5934\u6ce8\u660e\u3002

GitHub \u80fd\u591f\u81ea\u52a8\u8bc6\u522b\u5e38\u89c1\u7684\u8bb8\u53ef\u8bc1\u7c7b\u578b\uff0c\u5e76\u5728\u4ed3\u5e93\u7684\u4e3b\u9875\u4e0a\u663e\u793a\u3002

\u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u6709\u975e\u8f6f\u4ef6\u7c7b\u8bb8\u53ef\u8bc1\uff0c\u6700\u5e38\u4f7f\u7528\u7684\u662f CC\uff08Creative Commons\uff0c\u77e5\u8bc6\u5171\u4eab\uff09\u7cfb\u5217\u8bb8\u53ef\u8bc1\uff0c\u76ee\u524d\u6700\u5e7f\u6cdb\u4f7f\u7528\u7684\u7248\u672c\u662f 4.0\uff0c\u5b83\u5305\u542b\u5982\u4e0b\u51e0\u79cd\uff1a

\u5f80\u5f80\u901a\u8fc7\u4e00\u6bb5\u6587\u5b57\u5373\u53ef\u8868\u793a\u8bb8\u53ef\uff1a

\u672c\u4f5c\u54c1\u91c7\u7528\u77e5\u8bc6\u5171\u4eab\u7f72\u540d-\u975e\u5546\u4e1a\u6027\u4f7f\u7528-\u7981\u6b62\u6f14\u7ece 4.0 \u56fd\u9645\u8bb8\u53ef\u534f\u8bae\u8fdb\u884c\u8bb8\u53ef\u3002\n

\u601d\u8003

\u8fd9\u7bc7\u6587\u7ae0\u4e5f\u662f\u901a\u8fc7 CC \u8bb8\u53ef\u8bc1\u53d1\u5e03\u7684\uff0c\u4f60\u80fd\u627e\u5230\u5b83\u7684\u8bb8\u53ef\u8bc1\u5417\uff1f

"},{"location":"programming/24fall/lec3/#_16","title":"\u7ed3\u8bed","text":"

\u901a\u8fc7\u4eca\u5929\u7684\u5b66\u4e60\uff0c\u60f3\u5fc5\u4f60\u5df2\u7ecf\u5bf9\u5f00\u6e90\u6709\u4e86\u66f4\u6df1\u7684\u4e86\u89e3\uff0c\u6b22\u8fce\u4f60\u52a0\u5165\u5f00\u6e90\u7684\u5927\u5bb6\u5ead\uff01

\u4e00\u4e9b\u5b66\u4e60\u8d44\u6e90\uff1a

\u4e0b\u4e00\u6b21\u8bfe\uff0c\u674e\u82f1\u7426\u5b66\u957f\u5c06\u4e3a\u5927\u5bb6\u5e26\u6765 Markdown \u548c LaTeX \u7b49\u6392\u7248\u76f8\u5173\u7684\u5185\u5bb9\uff08\u5b9e\u9645\u4e0a\u8fd9\u4e2a\u8bb2\u4e49\u5c31\u662f\u7528 Markdown \u5199\u7684\uff09\uff0c\u656c\u8bf7\u671f\u5f85\uff5e

"},{"location":"programming/24fall/lec4/","title":"\u7b2c\u56db\u8bb2\uff1a\u5982\u4f55\u5199\u51fa\u7b80\u6d01\u5de5\u6574\u7684\u62a5\u544a","text":"

Danger

\u672c\u6587\u6863\u5c1a\u672a\u5b8c\u6210\u3002

"},{"location":"programming/24fall/lec5/","title":"\u7b2c\u4e94\u8bb2\uff1a\u671f\u672b\u590d\u4e60\uff08\u4e0a\uff09","text":""},{"location":"programming/24fall/lec5/#_2","title":"\u53d8\u91cf\u4e0e\u8ba1\u7b97","text":""},{"location":"programming/24fall/lec5/#_3","title":"\u53d8\u91cf","text":"
\u7c7b\u578b\u540d \u53d8\u91cf\u540d;\nint x;\n

\u5173\u952e\u5b57\u5982\u4e0b\uff1a

\u4f8b1.1-1

Which one below is NOT a valid identifier in the C programming language?

A. printf B. _m$ C. 114514 D. define

\u672a\u521d\u59cb\u5316\u7684\u53d8\u91cf\u7684\u503c\u662f\u4e0d\u786e\u5b9a\u7684

"},{"location":"programming/24fall/lec5/#_4","title":"\u6570\u636e\u7c7b\u578b\u548c\u5b57\u9762\u91cf","text":""},{"location":"programming/24fall/lec5/#_5","title":"\u6570\u636e\u7c7b\u578b","text":"

\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u5360\u636e\u4e0d\u540c\u7684\u5927\u5c0f\uff0c\u6709\u4e0d\u540c\u7684\u53d6\u503c\u8303\u56f4

unsigned short sht = 0;\nsht--;\n

\u4f8b1.2-1

0.1 + 0.2 == 0.3 ?

int n=1;\nchar ch='\\012'; \nprintf(\"%d\", ch*n++);\n// printf(\"%d\", ch*++n);\n

sizeof \u53ef\u4ee5\u83b7\u5f97\u67d0\u4e2a\u7c7b\u578b\u6216\u53d8\u91cf\u5728\u5185\u5b58\u4e2d\u6240\u5360\u636e\u7684\u5b57\u8282\u6570\uff0c\u5b83\u7684\u7ed3\u679c\u5728\u7f16\u8bd1\u65f6\u523b\u5c31\u51b3\u5b9a\u4e86\uff0c\u662f\u4e00\u4e2a\u8fd0\u7b97\u7b26\u800c\u4e0d\u662f\u51fd\u6570

int a = 1;\nprintf(\"%d\\n\", sizeof(a++));\nprintf(\"%d\\n\", a);\n
"},{"location":"programming/24fall/lec5/#_6","title":"\u5b57\u9762\u91cf","text":"

\u5b57\u9762\u91cf\u5373\u4e00\u4e2a\u503c\u7684\u8868\u793a\u65b9\u6cd5\uff0c\u540c\u4e00\u4e2a\u503c\u53ef\u80fd\u6709\u5f88\u591a\u79cd\u8868\u793a\u65b9\u6cd5

char a = 65;            // \u5341\u8fdb\u5236\nchar b = 0101;          // 0\u5f00\u5934\u8868\u793a\u516b\u8fdb\u5236\nchar c = 0x41;          // 0x\u5f00\u5934\u8868\u793a\u5341\u516d\u8fdb\u5236\n\nchar d = 'A';           // \u5355\u5f15\u53f7\uff0c\u5b57\u7b26\u5e38\u91cf\n\nchar e = '\\101';        // \u5355\u5f15\u53f7\u91cc\u9762\u53cd\u659c\u6760\u8f6c\u4e49\u6700\u591a\u4e09\u4e2a\u6570\u5b57\uff0c\u8868\u793a\u516b\u8fdb\u5236\uff0c\u9047\u52300-7\u4e4b\u5916\u7684\u5c31\u4f1a\u7ed3\u675f\nchar e0 = '\\08';        // \u9519\u8bef\uff0c\u8fd9\u662f\u4e24\u4e2a\u5b57\u7b26\u653e\u5230\u4e86\u4e00\u4e2a\u5355\u5f15\u53f7\u91cc\n\nchar f = '\\x41';        // \u5341\u516d\u8fdb\u5236\uff0c\u6ca1\u6709\u957f\u5ea6\u9650\u5236\uff0c\u9047\u5230\u975e\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u5c31\u4f1a\u7ed3\u675f\nchar f0 = '\\x00041';    // \u548c\u4e0a\u9762\u7684\u662f\u4e00\u6837\u7684\n
"},{"location":"programming/24fall/lec5/#_7","title":"\u8ba1\u7b97","text":"

\u5e26\u8fd0\u7b97\u7b26\u7684\u5f0f\u5b50\u662f\u8868\u8fbe\u5f0f\uff0c\u8868\u8fbe\u5f0f\u6709\u503c\u548c\u526f\u4f5c\u7528

"},{"location":"programming/24fall/lec5/#_8","title":"\u8fd0\u7b97\u7b26","text":"

% & << \u8fd0\u7b97\u7b26\u4e0d\u80fd\u7528\u5728 double \u4e0a

\u8fd0\u7b97\u987a\u5e8f\u95ee\u9898\uff0c\u7b80\u5355\u6765\u8bf4\uff1a\u8d4b\u503c\u8fd0\u7b97\u7b26\u548c\u4f4d\u8fd0\u7b97\u7b26\u8f83\u4f4e\uff0c\u7565\u9ad8\u7684\u662f\u7b97\u672f\u8fd0\u7b97\uff0c\u518d\u9ad8\u7684\u662f\u81ea\u589e/\u51cf

\u4f8b1.3-1

\u82e5\u5b9a\u4e49 int a=1,b=2,c=3,d=4 \u90a3\u4e48\u8868\u8fbe\u5f0f (a>b?c>a?c-3:c-1:b==c?d-a:d-c) \u7684\u503c\u4e3a

"},{"location":"programming/24fall/lec5/#_9","title":"\u8868\u8fbe\u5f0f\u7684\u7ed3\u679c","text":"

\u4f8b1.3-2

"},{"location":"programming/24fall/lec5/#_10","title":"\u5206\u652f\u548c\u5faa\u73af","text":""},{"location":"programming/24fall/lec5/#_11","title":"\u5206\u652f","text":"

else \u603b\u662f\u4e0e\u6700\u8fd1\u7684\u4e00\u4e2a\u6ca1\u6709\u88ab\u5339\u914d\u7684 if \u914d\u5bf9

if (x > -2){\n    if (x > 0) {\n        // do something\n        if (x > 2){\n            // do something\n        }\n    } else{\n        // do something\n        else {\n            // do something\n        }\n    }\n}\n

\u5206\u652f\u8bed\u53e5\u5982\u5305\u62ec\u6709\u4e00\u4e2a\u4ee5\u4e0a\u7684\u8bed\u53e5\uff0c\u5219\u5fc5\u987b\u7528\u4e00\u5bf9\u5927\u62ec\u53f7 {} \u62ec\u8d77\u6765\uff0c\u7ec4\u6210\u590d\u5408\u8bed\u53e5\uff0c\u590d\u5408\u8bed\u53e5\u5728\u8bed\u6cd5\u4e0a\u88ab\u8ba4\u4e3a\u662f\u4e00\u6761\u8bed\u53e5

if \u8bed\u53e5\u6267\u884c\u7684\u65f6\u5019\u4f1a\u5148\u6267\u884c () \u91cc\u7684\u8868\u8fbe\u5f0f\uff0c\u5982\u679c\u8be5\u8868\u8fbe\u5f0f\u7684\u503c\u975e\u96f6\uff0c\u5219\u6267\u884c {} \u91cc\u7684\u8bed\u53e5

int x = 10;\nif (x--) {\n    printf(\"x is %d\\n\", x);\n}\n

\u8bbe\u8ba1\u6d4b\u8bd5\u7528\u4f8b\u6765\u9a8c\u8bc1\u5206\u652f\u8bed\u53e5\u7684\u6b63\u786e\u6027

if (x < 0) {\n    y = 0;\n} else if (x <= 15) {\n    y = 4 * x / 3;\n} else { \n    y = 2.5 * x - 10.5;\n}   \n

\u5bf9\u4e8e switch \u8bed\u53e5\uff0ccase \u53ea\u89c4\u5b9a\u4e86\u8d77\u70b9\uff0c\u800c\u4f55\u65f6\u9000\u51fa switch \u5757\u5219\u7531 break \u51b3\u5b9a\uff0c\u53ea\u8981\u6ca1\u6709\u9047\u5230 break\uff0c\u5219\u4e00\u76f4\u5411\u4e0b\u6267\u884c\uff08\u5373\u4f7f\u78b0\u5230\u4e86\u4e0b\u4e00\u4e2a case \u4e14\u4e0d\u6ee1\u8db3\uff09

int i, b; i = b = 1;\nswitch (i) {\n    case 0: b += 1;\n    case 1: b += 2;\n    case '1': b += 3;\n    case 2 : switch (b) {\n        case 1: b += 4;\n        case 3: i++;\n        default: break;\n    }\n    i += 1;\n}\nprintf(\"%d#%d#\", i, b);\n
"},{"location":"programming/24fall/lec5/#_12","title":"\u5faa\u73af","text":"

\u5faa\u73af\u4f53\u5982\u5305\u62ec\u6709\u4e00\u4e2a\u4ee5\u4e0a\u7684\u8bed\u53e5\uff0c\u5219\u5fc5\u987b\u7528\u4e00\u5bf9\u5927\u62ec\u53f7 {} \u62ec\u8d77\u6765\uff0c\u7ec4\u6210\u590d\u5408\u8bed\u53e5\uff0c\u590d\u5408\u8bed\u53e5\u5728\u8bed\u6cd5\u4e0a\u88ab\u8ba4\u4e3a\u662f\u4e00\u6761\u8bed\u53e5\u3002

int a, i;\nfor (a=1, i=-1; -1 <= i < 1; i++) {\n    a++;\n    printf(\"%2d\", a);\n}\nprintf(\"%2d\", i);\n
"},{"location":"programming/24fall/lec5/#_13","title":"\u6570\u7ec4","text":"

\u6570\u7ec4\u7684\u5b9a\u4e49

\u7c7b\u578b\u540d \u6570\u7ec4\u540d[\u6570\u7ec4\u957f\u5ea6];\nint a[10];\n

\u6570\u7ec4\u7684\u521d\u59cb\u5316

\u7c7b\u578b\u540d \u6570\u7ec4\u540d[\u6570\u7ec4\u957f\u5ea6(\u53ef\u7701\u7565)] = {\u5143\u7d201, \u5143\u7d202, ...};\nint a[5] = {1, 2, 3, 4, 5};\nint b[ ] = {1, 2, 3, 4, 5};\nint c[5] = {1, 2, 3};        // \u5176\u4f59\u5143\u7d20\u4e3a0\n

\u5143\u7d20\u7c7b\u578b\u4e3a\u6570\u7ec4\u7684\u6570\u7ec4\u88ab\u79f0\u4e3a\u9ad8\u7ef4\u6570\u7ec4

int a[][];\n\nint b[3][];\n\nint c[][4];\n\nint d[3][4];\n\nint e[][] = {\n    {1, 2, 3, 4},\n    {5, 6, 7, 8},\n    {9, 10, 11, 12}\n};\n\nint f[][4] = {\n    {1, 2, 3, 4},\n    {5, 6, 7, 8},\n    {9, 10, 11, 12}\n};\n
"},{"location":"programming/24fall/lec5/#_14","title":"\u51fd\u6570","text":"

\u4f8b4-1

C\u8bed\u8a00\u4e2d\uff0c\u901a\u8fc7\u51fd\u6570\u8c03\u7528\u53ea\u80fd\u83b7\u5f97\u4e00\u4e2a\u8fd4\u56de\u503c\uff1f

\u4f8b4-2

\u51fd\u6570\u53ef\u4ee5\u5d4c\u5957\u8c03\u7528\u4f46\u4e0d\u80fd\u5d4c\u5957\u5b9a\u4e49\uff1f

\u4f8b4-3

\u82e5\u51fd\u6570\u8c03\u7528\u65f6\u7684\u5b9e\u53c2\u4e3a\u53d8\u91cf\uff0c\u4e0b\u5217\u5173\u4e8e\u51fd\u6570\u5f62\u53c2\u548c\u5b9e\u53c2\u7684\u53d9\u8ff0\u4e2d\u6b63\u786e\u7684\u662f( )\u3002

A. \u51fd\u6570\u7684\u5b9e\u53c2\u548c\u5176\u5bf9\u5e94\u7684\u5f62\u53c2\u5171\u5360\u540c\u4e00\u5b58\u50a8\u5355\u5143 B. \u5f62\u53c2\u53ea\u662f\u5f62\u5f0f\u4e0a\u7684\u5b58\u5728, \u4e0d\u5360\u7528\u5177\u4f53\u5b58\u50a8\u5355\u5143 C. \u540c\u540d\u7684\u5b9e\u53c2\u548c\u5f62\u53c2\u5360\u540c\u4e00\u5b58\u50a8\u5355\u5143 D. \u51fd\u6570\u7684\u5f62\u53c2\u548c\u5b9e\u53c2\u5206\u522b\u5360\u7528\u4e0d\u540c\u7684\u5b58\u50a8\u5355\u5143

#include <stdio.h>\n\nint x = 5, y = 7;\nvoid swap(int,int); // \u51fd\u6570\u58f0\u660e\nint main() {\n    int x = 3, y = 8;\n    swap(x,y);\n    printf(\"%d,%d\\n\", x, y);\n\n    return 0 ;\n}\n\nvoid swap(int x,int y) { // \u51fd\u6570\u5b9a\u4e49\n    int temp = x;\n    x = y;\n    y = temp;\n}\n

\u4f8b4-4

\u51fd\u6570\u8c03\u7528\u8bed\u53e5 function((a,b),c) \u4e2d\u542b\u6709\u7684\u5b9e\u53c2\u4e2a\u6570\u4e3a\uff1f

"},{"location":"programming/24fall/lec5/#_15","title":"\u6392\u5e8f","text":"\u7b97\u6cd5 \u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6 \u6700\u597d\u60c5\u51b5 \u6700\u574f\u60c5\u51b5 \u7a33\u5b9a\u6027 \u5192\u6ce1\u6392\u5e8f \\(O(n^2)\\) \\(O(n)\\) \\(O(n^2)\\) \u7a33\u5b9a \u9009\u62e9\u6392\u5e8f \\(O(n^2)\\) \\(O(n^2)\\) \\(O(n^2)\\) \u4e0d\u7a33\u5b9a \u63d2\u5165\u6392\u5e8f \\(O(n^2)\\) \\(O(n)\\) \\(O(n^2)\\) \u7a33\u5b9a"},{"location":"programming/24fall/lec5/#_16","title":"\u6307\u9488","text":""},{"location":"programming/24fall/lec5/#_17","title":"\u5b9a\u4e49","text":"

\u6307\u9488\u53d8\u91cf\u7684\u503c\u662f\u53d8\u91cf\u7684\u5730\u5740\uff0c\u6307\u9488\u53d8\u91cf\u672c\u8eab\u4e5f\u6709\u81ea\u5df1\u7684\u5185\u5b58\u5730\u5740

int a = 1;\nint *p = &a; // &\u662f\u53d6\u5730\u5740\u8fd0\u7b97\u7b26\n

\u6307\u9488\u53d8\u91cf p \u7684\u503c\u662f a \u7684\u5730\u5740\uff0c*p \u8868\u793a p \u6307\u5411\u7684\u53d8\u91cf\uff0c\u5373 a\uff0c*p \u7684\u503c\u662f a \u7684\u503c\uff0c\u5373 1

\u58f0\u660e\u4e2d * \u53ea\u5bf9\u76f4\u63a5\u7ed3\u5408\u7684\u6807\u8bc6\u7b26\u751f\u6548

\u4f8b6.1-1

\u53d8\u91cf\u5b9a\u4e49\uff1aint *p, q; \u4e2d\uff0cp \u548c q \u90fd\u662f\u6307\u9488\uff1f

\u6307\u9488\u5141\u8bb8\u6307\u5411\u4e00\u4e2a\u4e0d\u5b8c\u6574\u7c7b\u578b:

int *a[3];   // a\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u5143\u7d20\u662f\u6307\u9488\nint (*b)[3]; // b\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u5143\u7d20\u662fint,\u6570\u7ec4\u957f\u5ea6\u4e3a3\nint *c[];    // ?\nint (*d)[];  // d\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411\u4e00\u4e2a\u957f\u5ea6\u672a\u77e5\u7684\u6570\u7ec4\uff0c\u6570\u7ec4\u5143\u7d20\u662fint\n

\u4f8b6.1-2

Among the following statements, __ is equivalent to the declaration: int *p[4];

A.int p[4]; B.int **p; C.int *(p[4]); D.int (*p)[4];

void * \u662f\u5408\u6cd5\u7684\u6307\u9488\u7c7b\u578b\uff0c\u6307\u5411\u4e00\u4e2a\u7c7b\u578b\u672a\u77e5\u7684\u5bf9\u8c61\uff0c\u53ef\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u4efb\u610f\u5176\u4ed6\u7c7b\u578b\u7684\u6307\u9488

"},{"location":"programming/24fall/lec5/#_18","title":"\u7528\u6cd5","text":""},{"location":"programming/24fall/lec5/#_19","title":"\u6307\u9488\u7684\u8fd0\u7b97","text":""},{"location":"programming/24fall/lec5/#_20","title":"\u6307\u9488\u4e0e\u6570\u7ec4","text":"

\u6307\u9488\u548c\u6570\u7ec4\u5173\u7cfb\u7d27\u5bc6\uff1a

\u4f8b6.2-1

Given the declaration: int a[3][3]={1,2,3,4,5,6,7,8,9};, the value of a[-1][5] is ?

\u4f8b6.2-2

Given the declaration: int a[3][2]={1,2,3,4,5,6}; what is the value of expression (a[1]+1)[0]?

\u9690\u5f0f\u8f6c\u6362\uff1aC \u8bed\u8a00\u89c4\u5b9a\u4efb\u4f55\u6570\u7ec4\u7c7b\u578b\u7684\u5de6\u503c\u8868\u8fbe\u5f0f\uff0c\u5f53\u7528\u4e8e\u5f02\u4e8e

\u7684\u8bed\u5883\u65f6\uff0c\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\uff0c\u5178\u578b\u573a\u666f\uff1a

  1. \u4f5c\u4e3a\u51fd\u6570\u7684\u53c2\u6570\u65f6\uff0c\u6570\u7ec4\u540d\u88ab\u8f6c\u6362\u6210\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u6307\u9488
  2. \u66f4\u6539\u6570\u7ec4\u5143\u7d20\u65f6

\u4f8b6.2-3

According to the declaration: int p[5], *a[5]; the expression ______ is correct.

A. p=a B. p[0]=a C. *(a+1)=p D. a[0]=2

\u4e8c\u7ef4\u6570\u7ec4\u4e0d\u80fd\u9690\u5f0f\u8f6c\u6362\u4e3a\u4e8c\u7ea7\u6307\u9488

\u4f8b6.2-4

For the function declaration void f(char** p),the definition __ of var makes the function call f(var) incorrect.

A. char var[10][10]; B. char *var[10]; C. void *var = NULL; D. char *v=NULL, **var=&v; E. char var[10][10], **p=var;

"},{"location":"programming/24fall/lec5/#_21","title":"\u6307\u9488\u4e0e\u5b57\u7b26\u4e32","text":"

\u5b57\u7b26\u4e32\u5e38\u91cf\u5728\u5185\u5b58\u4e2d\u662f\u8fde\u7eed\u5b58\u50a8\u7684\uff0c\u5b57\u7b26\u4e32\u5e38\u91cf\u5728\u5185\u5b58\u4e2d\u7684\u5b58\u50a8\u5f62\u5f0f\u662f\u5b57\u7b26\u6570\u7ec4\u7684\u5f62\u5f0f\uff0c\u5b57\u7b26\u4e32\u5e38\u91cf\u5728\u5185\u5b58\u4e2d\u662f\u8fde\u7eed\u5b58\u50a8\u7684\uff0c\u5b57\u7b26\u4e32\u5e38\u91cf\u5728\u5185\u5b58\u4e2d\u7684\u5b58\u50a8\u5f62\u5f0f\u662f\u5b57\u7b26\u6570\u7ec4\u7684\u5f62\u5f0f

char *p = \"hello\";\nchar a[] = \"hello\";\nchar b[] = {'h', 'e', 'l', 'l', 'o', '\\0'};\n
"},{"location":"programming/24fall/lec6/","title":"\u7b2c\u516d\u8bb2\uff1a\u671f\u672b\u590d\u4e60\uff08\u4e0b\uff09","text":""},{"location":"programming/24fall/lec6/#_2","title":"\u6307\u9488","text":""},{"location":"programming/24fall/lec6/#_3","title":"\u5f62\u8c61\u7406\u89e3","text":""},{"location":"programming/24fall/lec6/#_4","title":"\u6307\u9488\u7684\u58f0\u660e","text":"
int *p, q;\n

\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c \u7528\u4e8e\u4fee\u9970 p \u53d8\u91cf\uff0c\u4f7f\u5176\u6210\u4e3a int \u6307\u9488\u7c7b\u578b \u7684\u53d8\u91cf\uff1b\u4f46\u662f\u53d8\u91cf q \u5e76\u6ca1\u6709\u88ab * \u4fee\u9970\uff0c\u6240\u4ee5\u5176\u8fd8\u662f int \u7c7b\u578b* \u7684\u53d8\u91cf\u3002

"},{"location":"programming/24fall/lec6/#_5","title":"\u6307\u9488\u7684\u8d4b\u503c","text":"
int a = 10;\nint *p, *q = &a;\np = &a;\n*p = 20;\n
"},{"location":"programming/24fall/lec6/#_6","title":"\u6307\u9488\u7684\u8fd0\u7b97","text":"

\u6307\u9488\u53ef\u4ee5\u8fdb\u884c\u52a0\u51cf\u8fd0\u7b97\uff0c\u5f97\u5230\u7684\u7ed3\u679c\u53ef\u4ee5\u8868\u793a\u5730\u5740\u7684\u5dee\u3002 \u4f46\u6ce8\u610f \uff0c\u6307\u9488\u51cf\u6cd5\u4e2d\u6d89\u53ca\u5230\u7684\u5e38\u6570\u4e0d\u662f\u771f\u6b63\u7684\u5730\u5740\u4e4b\u5dee\uff0c\u800c\u662f \u5730\u5740\u5dee/\u8be5\u7c7b\u578b\u5b57\u8282\u6570 \uff0c\u5982\uff1a

Example1

int a[10];\nint *p = a, *q = &a[1];\nprintf(\"%d\", q - p);\n
\u6700\u540e\u7684\u7ed3\u679c\u4e3a 1\u3002\u867d\u7136 a[1] \u548c a[0] \u4e4b\u95f4\u5730\u5740\u76f8\u5dee\u56db\u4e2a\u5b57\u8282\uff0c\u4f46\u662f\u7a0b\u5e8f\u6700\u540e\u4ecd\u4f1a\u8fd4\u56de 1\u3002

Example2

int a[10] = {1, 2, 3, 4};\nint *p = a;\nprintf(\"%d %d\", *p, *(p + 1));\n
\u6700\u540e\u7684\u8f93\u51fa\u7ed3\u679c\u4e3a 1 2\uff0c\u6240\u4ee5\u53ef\u89c1\uff0cp + 1 \u6307\u5411\u7684\u662f a \u6570\u7ec4\u4e2d\u7684 a[1] \u4f4d\u7f6e\uff0c\u800c\u4e0d\u662f a[0] \u7684\u4e0b\u4e00\u4e2a\u5b57\u8282\u5904\u3002

\u4f8b1.4.1

int a[] = {1, 2, 3, 4, 5};\nint *p = a, *q = &a[2];\nprintf(\"%lu\\n\", q - p);\n
\u4e0a\u8ff0\u4ee3\u7801\u7684\u8fd0\u7b97\u7ed3\u679c\u4e3a\uff1a

Answer: 2

"},{"location":"programming/24fall/lec6/#_7","title":"\u591a\u7ea7\u6307\u9488","text":"

int a = 10;\nint *p = &a;\nint **var = &p;\nprintf(\"%d = %d = %d\", a, *p, **var);\n
\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a \u4e8c\u7ea7\u6307\u9488 var\u3002\u4e8c\u7ea7\u6307\u9488\u53ef\u4ee5\u7406\u89e3\u4e3a \u201c\u6307\u9488\u7684\u6307\u9488\u201c\u3002\u4e00\u7ea7\u6307\u9488\u53ef\u4ee5\u7528\u6765\u5b58\u50a8\u4e00\u822c\u53d8\u91cf\u6216\u5176\u4ed6\u5e38\u91cf\u7684\u5730\u5740\uff0c\u800c\u4e00\u7ea7\u6307\u9488\u540c\u6837\u662f\u53d8\u91cf\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e8c\u7ea7\u6307\u9488\u6765\u5b58\u50a8\u4e00\u7ea7\u6307\u9488\u7684\u5730\u5740\u3002

\u6ce8\u610f

\u5728\u7a0b\u5e8f\u4e2d\uff0c\u6700\u597d\u4e0d\u8981\u6df7\u7528\u4e0d\u540c\u7ea7\u7684\u6307\u9488\u3002

"},{"location":"programming/24fall/lec6/#_8","title":"\u6570\u7ec4\u548c\u6307\u9488","text":"

\u6570\u7ec4\u540d\u5b9e\u9645\u4e0a\u5c31\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6570\u7ec4\u8868\u793a a[1] \u548c\u6307\u9488\u8868\u793a &(a + 1) \u5b9e\u9645\u4e0a\u6307\u7684\u662f\u540c\u4e00\u4e2a\u4e1c\u897f\uff0c\u4e24\u8005\u4e5f\u53ef\u4ee5\u76f8\u4e92\u8f6c\u5316\u3002 \u6b64\u5916\uff0c\u4e8c\u7ef4\u6570\u7ec4\u7684\u5730\u5740\u5206\u5e03\u548c\u6211\u4eec\u7684\u76f4\u89c2\u611f\u53d7\u5e76\u4e0d\u76f8\u540c\uff0c\u5176\u6709\u4e0b\u9762\u7684\u89c4\u5f8b\uff1a

\u4e8c\u7ef4\u6570\u7ec4

int a[3][2]; 1. \u9996\u5148\u9700\u8981\u77e5\u9053\uff0c\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u7684\u5730\u5740\u662f\u7ebf\u6027\u5206\u5e03\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\uff0ca[0][1] \u7684\u4e0b\u4e00\u4e2a\u5c31\u662f a[1][0] 2. \u5176\u6b21\uff0c\u4e8c\u7ef4\u6570\u7ec4\u662f\u5982\u4f55\u5b9e\u73b0\u4e8c\u7ef4\u5b58\u50a8\u6570\u636e\u7684\u5462\uff1f\u539f\u56e0\u5728\u4e8e\uff1aa \u662f\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\u7684\u6307\u9488\u3002\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0ca \u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a 2 \u7684 int \u6570\u7ec4\u7684\u6307\u9488\uff0c\u6240\u4ee5 a[0] \u6307\u5411\u7b2c\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\uff0ca[1] \u6307\u5411\u7b2c\u4e8c\u4e2a\u4e00\u7ef4\u6570\u7ec4\u3002 3. \u5b9e\u9645\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 *(*(a + i) + j) \u6765\u8868\u793a a[i][j]\u3002\u56e0\u4e3a *(a + i) \u6307\u5411\u7b2c i \u4e2a\u6570\u7ec4\uff08\u5047\u8bbe\u53eb b\uff09\uff0c\u800c\u6211\u4eec\u53ef\u4ee5\u7528 *(b + j) \u6765\u8868\u793a b[j]\u3002 4. \u53e6\u5916\uff0c\u4e8c\u7ef4\u6570\u7ec4\u4e0d\u80fd\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u4e8c\u7ea7\u6307\u9488 \u3002\u6211\u4eec\u4e0d\u80fd\u80a4\u6d45\u7684\u5c06\u4e8c\u7ef4\u6570\u7ec4\u7406\u89e3\u4e3a\u4e8c\u7ea7\u6307\u9488\u3002\u5b9e\u9645\u4e0a\uff0c\u65e0\u8bba\u6211\u4eec\u5b9a\u4e49\u591a\u5c11\u7ef4\u6570\u7ec4\uff0c\u5176\u90fd\u662f\u4e00\u7ea7\u6307\u9488\uff0c\u53ea\u662f\u6307\u5411\u7684\u5143\u7d20\u4e0d\u540c\u800c\u5df2\u3002

\u53e6\u5916\u6ce8\u610f\uff0cint *p[3] \u76f8\u5f53\u4e8e\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6307\u9488\u6570\u7ec4\uff0c\u5176\u5b58\u50a8\u7684\u6570\u636e\u90fd\u662f int \u7c7b\u578b\u6307\u9488\u3002 \u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0c\u5b57\u7b26\u4e32\u76f8\u5f53\u4e8e\u4e00\u4e2a\u4ee5 '\\0' \u7ed3\u5c3e\u7684 char \u7c7b\u578b\u6570\u7ec4\u3002

\u5b57\u7b26\u4e32\u76f8\u5173\u51fd\u6570

\u5934\u6587\u4ef6\uff1a<string.h> strlen: \u8fd4\u56de\u5b57\u7b26\u4e32\u957f\u5ea6\uff08\u4e0d\u5305\u62ec\u672b\u5c3e\u7684 '\\0'\uff09 strcpy: \u5c06 str2 \u76f4\u63a5\u62f7\u8d1d\u5230 str1 \u4e2d\uff08\u62f7\u8d1d\u5185\u5bb9\u4f1a\u5305\u62ec str2 \u672b\u5c3e\u7684 '\\0'\uff09 strcat: \u5c06 str2 \u8ffd\u52a0\u5230 str1 \u7684\u672b\u5c3e\uff08\u4ece str1 \u7684 '\\0' \u5904\u5f00\u59cb\u8ffd\u52a0\uff09 strcmp: \u5bf9\u4e24\u4e2a\u5b57\u7b26\u4e32\u505a\u5dee\uff0c\u8fd4\u56de\u5dee\u503c\uff08\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\uff09 strncpy strncat strncmp

\u4f8b1.6.1

Answer: A

\u4f8b1.6.2

char str1[20] = \"1234567890123\";\nchar str2[20] = \"hello\";\nstrcpy(str1, str2);\nint l = strlen(str1);\nprintf(\"%d %s\\n\", l, str1);\nfor(int i = 0; i < 10; ++ i)\n{\n    printf(\"%c\", str1[i]);\n}\n
\u6700\u540e\u7684\u8f93\u51fa\u7ed3\u679c\u4e3a\u4ec0\u4e48\uff1f

Answer: 5 hello hello7890

\u4f8b1.6.3

int a[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9);\nprintf(\"%d\\n\", a[-1][5]);\n
\u8fd0\u884c\u7ed3\u679c\u4e3a\uff1f

Answer: 3

\u4f8b1.6.4

\u7ed9\u51fa\uff1a char s[2][3] = {\"ab\", \"cd\"}, *p = (char *)s; \u4e0b\u9762\u54ea\u4e00\u9879\u662f\u6b63\u786e\u4e14\u548c s[1][1] \u7684\u503c\u76f8\u7b49\uff1f A. *(s + 3) B. *s + 2 C. p[1][1] D. *++p + 2

Answer: D

\u4f8b1.6.5

char *week[]={\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"}, **pw=week;\nchar c1, c2;\nc1 = (*++pw)[1];\nc2 = *++pw[1];\nprintf(\"%c %c\\n\", c1, c2);\n
\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a

Answer: u e

"},{"location":"programming/24fall/lec6/#_9","title":"\u7a7a\u6307\u9488\u548c\u91ce\u6307\u9488","text":"

\u5728\u7a0b\u5e8f\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 0 \u6216 NULL \u6765\u8868\u793a\u4e00\u4e2a\u7a7a\u6307\u9488\uff0c\u5f53\u4e00\u4e2a\u6307\u9488\u662f\u7a7a\u6307\u9488\u65f6\uff0c\u6211\u4eec\u65e0\u6cd5\u4f7f\u7528 * \u6765\u5bf9\u8be5\u6307\u9488\u8fdb\u884c\u8bfb\u53d6\uff0c\u4f1a\u51fa\u73b0\u6bb5\u9519\u8bef\u3002 \u56e0\u6b64\uff0c\u7a7a\u6307\u9488\u5728\u521d\u59cb\u5316\u548c\u5f02\u5e38\u60c5\u51b5\u5904\u7406\u65f6\u975e\u5e38\u91cd\u8981\u3002 \u7528\u6765\u5904\u7406\u4ec0\u4e48\u5f02\u5e38\u60c5\u51b5\u5462\uff1f

\u91ce\u6307\u9488

\u5f53\u6211\u4eec\u5199

int *p\n*p = 10;\n
\u7f16\u8bd1\u5668\u5c31\u4f1a\u62a5\u9519\u3002\u8fd9\u662f\u56e0\u4e3a\u6211\u4eec\u8fd9\u91cc\u7684 p \u662f\u4e00\u4e2a \u91ce\u6307\u9488\u3002

\u7c7b\u4f3c\u4e0a\u9762\u7684\u4f8b\u5b50\uff0c\u5f53\u6211\u4eec\u5199 int *p \u65f6\uff0c\u6211\u4eec\u5e76\u6ca1\u6709\u7ed9\u8fd9\u4e2a\u6307\u9488 p \u8fdb\u884c\u5730\u5740\u7684\u8d4b\u503c\u3002\u8fd9\u4e5f\u5c31\u8bf4\u660e\uff0c\u6211\u4eec\u5e76\u6ca1\u6709\u7ed9 p \u4e00\u4e2a\u771f\u6b63\u7684\u7a7a\u95f4\uff0c\u800c\u662f\u8ba9\u8fd9\u4e2a\u6307\u9488\u4e71\u6307\uff08\u663e\u7136\uff0c\u8fd9\u662f 100% \u4e0d\u5b89\u5168\u7684\uff09\uff0c\u8fd9\u5c31\u662f\u91ce\u6307\u9488\u3002\u6b64\u65f6\u82e5\u6211\u4eec\u5bf9 p \u8fdb\u884c\u53d6\u6570\u636e\u64cd\u4f5c\uff0c\u81ea\u7136\u4f1a\u5f97\u5230\u7f16\u8bd1\u5668\u7684\u62a5\u9519\u3002 \u91ce\u6307\u9488\u4e5f\u662f\u521d\u5b66\u8005\u5199\u76f8\u5173\u7a0b\u5e8f\u6700\u5bb9\u6613\u72af\u7684\u9519\u8bef\uff08\u5305\u62ec\u6211\uff09\u3002\u56e0\u6b64\uff0c\u5bf9\u6307\u9488\u8fdb\u884c\u521d\u59cb\u5316\uff0c\u9632\u6b62\u6307\u9488\u4e71\u6307\u5c31\u53d8\u5f97\u975e\u5e38\u6709\u5fc5\u8981\u4e86\u3002

\u4f8b1.7.1

\u7ed9\u51fa char *s, str[10]\uff0c\u4e0b\u5217\u9009\u9879\u4e2d\u8868\u8fbe\u5b8c\u5168\u6b63\u786e\u7684\u662f\uff1a A. strcpy(s, \"hello\"); B. str = \"hello\" + 1; C. s = *&(str + 1); D. s = str + 1

Answer: D

"},{"location":"programming/24fall/lec6/#_10","title":"\u51fd\u6570\u6307\u9488*","text":"

\u5f88\u5c11\u6d89\u53ca\uff0c\u5177\u4f53\u5185\u5bb9\u53ef\u4ee5\u67e5\u770b\u8f85\u5b66\u7f51\u7ad9\u3002

"},{"location":"programming/24fall/lec6/#_11","title":"\u5f62\u53c2\u548c\u5b9e\u53c2","text":"

\u5b9e\u53c2

\u5b9e\u9645\u53c2\u6570\u3002\u5176\u53ef\u4ee5\u662f\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u8868\u8fbe\u5f0f\u7b49\u7b49\uff0c\u5728\u51fd\u6570\u8c03\u7528\u65f6\uff0c\u5b9e\u53c2\u5c06\u5177\u4f53\u7684\u503c\u4f20\u9012\u7ed9\u51fd\u6570\u3002

int a = 10;//\u8fd9\u662f\u5b9e\u53c2\nint b = 20;//\u8fd9\u4e5f\u662f\u5b9e\u53c2\n

\u5f62\u53c2

\u5f62\u5f0f\u53c2\u6570\u3002\u5176\u4e0d\u662f\u771f\u5b9e\u5b58\u5728\u7684\u53d8\u91cf\uff0c\u800c\u662f\u7528\u6765\u63a5\u6536\u8c03\u7528\u51fd\u6570\u65f6\u4f20\u5165\u7684\u53c2\u6570\u800c\u8bbe\u7f6e\u7684\u53d8\u91cf\u3002 ``` int max(int a, int b)//\u8fd9\u91cc\u7684 a, b \u90fd\u662f\u5f62\u53c2 { return (a > b ? a : b); }

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5f53\u6211\u4eec\u4f7f\u7528\u5b9e\u53c2\u5c06\u6570\u636e\u4f20\u5230\u51fd\u6570\u5185\u90e8\u4e4b\u540e\uff0c\u6211\u4eec\u5728\u51fd\u6570\u5185\u4f7f\u7528\u7684\u53d8\u91cf\u5c31\u4e0d\u662f\u539f\u6765\u7684\u53d8\u91cf\u4e86\uff0c\u800c\u662f\u4e3a\u4e86\u5728\u51fd\u6570\u5185\u4fdd\u5b58\u8fd9\u4e9b\u6570\u636e\u800c\u81ea\u52a8\u8bbe\u7f6e\u7684\u5f62\u53c2\u3002\u6240\u4ee5\uff0c\u5f53\u6211\u4eec\u5728\u51fd\u6570\u5185\u5bf9\u5f62\u53c2\u8fdb\u884c\u8fd0\u7b97\u65f6\uff0c\u5e76\u4e0d\u4f1a\u5bf9\u539f\u6765\u7684\u5b9e\u53c2\u4ea7\u751f\u4efb\u4f55\u5f71\u54cd \u3002 \u8ba9\u6211\u4eec\u6765\u770b\u4e0b\u9762\u7684\u4f8b\u5b50\uff1a

void swap(int a, int b)\n{\n    int t = a;\n    a = b;\n    b = t;\n    return ;\n}\nint main()\n{\n    int a = 10, b = 20;\n    printf(\"%d %d\\n\", a, b);\n    swap(a, b);\n    printf(\"%d %d\", a, b);\n}\n

\u5f53\u6211\u4eec\u8fd0\u884c\u4e4b\u540e\uff0c\u4f1a\u53d1\u73b0\uff1a\u4e0a\u4e0b\u4e24\u884c\u7684\u8f93\u51fa\u7ed3\u679c\u6ca1\u6709\u4efb\u4f55\u6539\u53d8\u3002\u800c\u539f\u56e0\u5c31\u662f\u4e0a\u9762\u63d0\u5230\u7684\u5f62\u53c2\u548c\u5b9e\u53c2\u3002 \u90a3\u4e48\u6211\u4eec\u5e94\u8be5\u5982\u4f55\u81ea\u5df1\u5b9e\u73b0 swap \u529f\u80fd\u5462\uff1f\u53ef\u4ee5\u4f7f\u7528\u6307\u9488\u6765\u89e3\u51b3\u3002

Solution

void swap(int *a, int *b)\n{\n    int t = *a;\n    *a = *b;\n    *b = t;\n    return ;\n}\nint main()\n{\n    int a = 10, b = 20;\n    printf(\"%d %d\\n\", a, b);\n    swap(&a, &b);\n    printf(\"%d %d\", a, b);\n}\n

\u5982\u4e0a\uff0c\u6211\u4eec\u5728 swap \u51fd\u6570\u4e2d\u4f7f\u7528\u6307\u9488\u6765\u8fdb\u884c\u4ea4\u6362\u3002\u6b64\u65f6\uff0c\u7531\u4e8e\u6211\u4eec\u4ea4\u6362\u65f6\u4f7f\u7528\u7684\u662f\u6307\u9488\u5b58\u50a8\u5730\u5740\u6240\u4ee3\u8868\u7684\u6570\u636e\uff0c\u800c\u51fd\u6570\u4f20\u9012\u6307\u9488\u53c2\u6570\u65f6\uff0c\u8fd9\u4e2a\u5730\u5740\u4f5c\u4e3a\u88ab\u4f20\u9012\u7684\u6570\u636e\u662f\u4e0d\u4f1a\u6539\u53d8\u7684\uff08\u8fd9\u91cc\u7684\u5f62\u53c2\u662f swap \u5185\u7684\u6307\u9488\u53d8\u91cf a\u3001b\uff09\u6240\u4ee5\u6211\u4eec\u5728\u4ea4\u6362\u65f6\u53ef\u4ee5\u76f4\u63a5\u5f71\u54cd\u5230\u4e3b\u51fd\u6570\u4e2d\u7684\u53d8\u91cf a\u3001b\uff0c\u4ece\u800c\u5b9e\u73b0\u6211\u4eec\u7684\u76ee\u7684\u3002 \u6240\u4ee5\uff0c\u5f53\u6211\u4eec\u9700\u8981\u5728\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u5f71\u54cd\u5230\u539f\u51fd\u6570\u7684\u53d8\u91cf\u65f6\uff0c\u53ef\u4ee5\u5c06\u4f20\u9012\u7684\u53c2\u6570\u6539\u4e3a\u53d8\u91cf\u7684\u6307\u9488\u800c\u4e0d\u662f\u539f\u6765\u7684\u53d8\u91cf \u3002

"},{"location":"programming/24fall/lec6/#linked-list","title":"\u94fe\u8868 Linked-List","text":""},{"location":"programming/24fall/lec6/#_12","title":"\u7ed3\u6784","text":"

\u5927\u6982\u7684\u7ed3\u6784\u5982\u4e0b\uff1a

\u5176\u4e2d\uff0c\u5176\u4e2d\u6bcf\u4e00\u4e2a\u70b9\u90fd\u662f\u4e00\u4e2a\u7ed3\u6784\u4f53\uff0c\u524d\u540e\u4e24\u4e2a\u8282\u70b9\u4f7f\u7528\u6307\u9488\u76f8\u8fde\u63a5\u3002 \u6700\u57fa\u672c\u7684\u94fe\u8868\u5927\u6982\u662f\u4e0b\u9762\u8fd9\u4e2a\u6837\u5b50\uff1a

typedef struct List_Node* Node\nstruct List_Node{\n    Element_type data;\n    Node next;\n};\n

"},{"location":"programming/24fall/lec6/#_13","title":"\u8bb2\u70b9\u57fa\u7840\u77e5\u8bc6","text":""},{"location":"programming/24fall/lec6/#_14","title":"\u7ed3\u6784\u4f53\u6307\u9488","text":"

\u6bd4\u5982\u6211\u4eec\u73b0\u5728\u5b9a\u4e49\u4e86\u4ee5\u4e0b\u7ed3\u6784\u4f53\u548c\u5176\u6307\u9488\uff1a

struct course{\n    char name[100];\n    float credit;\n    int score;\n    float point;\n}A;\nint main()\n{\n    struct course* p = &A;\n    return 0;\n}\n
\u90a3\u4e48\u5f53\u6211\u4eec\u9700\u8981\u5bf9 A \u8fdb\u884c\u8d4b\u503c\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a
A.name = \"FDS\";\nA.credit = 2.5;\n
\u800c\u82e5\u89c4\u5b9a\u6211\u4eec\u4e0d\u4f7f\u7528 A \u8fdb\u884c\u8d4b\u503c\uff0c\u4f7f\u7528\u6307\u9488 p \u4ee3\u66ff A \u8fdb\u884c\u8d4b\u503c\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u9700\u8981\u8fd9\u6837\u5199\uff1a
p -> name = \"FDS\";//\u5f53\u7136\uff0c\u4e5f\u53ef\u4ee5\u5199 (*p).name = \"FDS\"\np -> credit = 2.5;\n

Tip

\u5f53\u6211\u4eec\u4f7f\u7528\u6307\u9488\u6765\u63cf\u8ff0\u7ed3\u6784\u4f53\u65f6\uff0c\u9700\u8981\u4f7f\u7528 '->' \u7b26\u53f7\u800c\u4e0d\u662f '.' \u7b26\u53f7\u3002

"},{"location":"programming/24fall/lec6/#_15","title":"\u5185\u5b58\u5206\u914d\u4e0e\u91ca\u653e","text":"

\u5728\u5b9e\u9645\u4f7f\u7528\u65f6\uff0c\u6211\u4eec\u901a\u5e38\u90fd\u9700\u8981\u8ba9\u4e00\u4e2a\u7ed3\u6784\u4f53\u6307\u9488\u6307\u5411\u4e00\u4e2a\u5b9e\u9645\u6709\u5185\u5b58\u7684\u7ed3\u6784\u4f53\uff08\u4e5f\u5c31\u662f\u8ba9 p \u6307\u5411 A\uff09\u3002\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u662f\u5148\u5b9a\u4e49\u4e86\u7ed3\u6784\u4f53 A\uff0c\u7136\u540e\u518d\u8bbe\u4e86\u4e00\u4e2a\u7ed3\u6784\u4f53\u6307\u9488\u6307\u5411 A\u3002\u90a3\u4e48\u80fd\u5426\u6709\u4e00\u4e2a\u66f4\u7b80\u4fbf\u7684\u505a\u6cd5\u5462\uff1f

\u5c0f\u5fc3\u91ce\u6307\u9488

\u6ce8\u610f\uff0c\u5343\u4e07\u4e0d\u8981\u5b9a\u4e49\u4e00\u4e2a\u7ed3\u6784\u4f53\u6307\u9488 p \u540e\u5c31\u76f4\u63a5\u8fdb\u884c\u76f8\u5173\u8d4b\u503c\u3002\u56e0\u4e3a\u6b64\u65f6\u6211\u4eec\u8fd8\u6ca1\u6709\u7ed9\u6307\u9488 p \u5206\u914d\u4e00\u4e2a\u786e\u5b9a\u7684\u7a7a\u95f4\uff0c\u53ef\u4ee5\u7406\u89e3\u6210 p \u6307\u5411\u4e86\u4e00\u4e2a\u865a\u65e0\u7f25\u7f08\u7684\u5730\u65b9\uff0c\u662f\u4e00\u4e2a \u91ce\u6307\u9488 \u3002

\u6b64\u65f6\uff0c\u5c31\u9700\u8981 malloc \u51fd\u6570 \u4e86\u3002\u5176\u7528\u6cd5\u5982\u4e0b\uff1a

malloc

#include <stdlib.h>\nvoid* malloc (size_t size);\n

malloc \u51fd\u6570\u7684\u53c2\u6570\u4e3a size\uff0c\u5176\u662f\u4e00\u4e2a\u65e0\u7b26\u53f7\u6574\u578b\uff0c\u8868\u793a\u9700\u8981\u7533\u8bf7\u7684\u7a7a\u95f4\u5927\u5c0f\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u501f\u52a9 sizeof \u6765\u7b80\u5355\u6613\u61c2\u7684\u8868\u793a\u8fd9\u4e2a\u53c2\u6570\u3002 malloc \u51fd\u6570\u7684\u8fd4\u56de\u503c\u662f void \u4e5f\u5c31\u662f\u65e0\u7c7b\u578b\u6307\u9488\uff0c\u5f53\u6211\u4eec\u7ed9\u4e00\u4e2a\u6307\u9488\u7528 malloc \u7533\u8bf7\u7a7a\u95f4\u65f6\uff0c\u9700\u8981\u5728 malloc \u524d\u9762\u4f7f\u7528\u5176\u4ed6\u6307\u9488\u7c7b\u578b\u5f3a\u5236\u8f6c\u6362\u3002\u82e5 malloc \u51fd\u6570\u7533\u8bf7\u7a7a\u95f4\u5931\u8d25\uff0c\u5176\u4f1a\u8fd4\u56de NULL \u7a7a\u6307\u9488\uff0c\u6b64\u65f6\u4e00\u5b9a\u8981\u6ce8\u610f\u68c0\u67e5\u3002 \u6ce8\u610f\uff1a* \u4f7f\u7528 malloc \u51fd\u6570\u7533\u8bf7\u7a7a\u95f4\u4e4b\u540e\uff0c\u8fd9\u5757\u7a7a\u95f4\u91cc\u9762\u6709\u4ec0\u4e48\u5185\u5bb9\u662f\u4e0d\u786e\u5b9a\u7684\uff0c\u6240\u4ee5\u5728\u4f7f\u7528\u4e4b\u524d\u4e00\u5b9a\u8981\u5bf9\u8fd9\u4e9b\u5185\u5b58\u8fdb\u884c\u521d\u59cb\u5316\u3002 \u4e3e\u4e2a\u6817\u5b50\uff1a

Example

\u5bf9\u4e0a\u9762\u7684\u4f8b\u5b50\u6765\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u5199\u4ee5\u4e0b\u4ee3\u7801\uff1a

struct course{\n    char name[100];\n    float credit;\n    int score;\n    float point;\n};\nint main()\n{\n    struct course* p = (struct course*)malloc(sizeof(struct course));\n    memset(p -> name, 0, sizeof(p -> name));\n    p -> credit = 0;\n    p -> score = 0;\n    p -> point = 0;\n    return 0;\n}\n

\u6b64\u5916\uff0c\u7531\u4e8e\u6307\u9488 p \u6307\u5411\u7684\u7a7a\u95f4\u662f\u6211\u4eec\u4f7f\u7528 malloc \u51fd\u6570\u5411\u7535\u8111\u7533\u8bf7\u7684\uff0c\u5f53\u6211\u4eec\u4e0d\u518d\u9700\u8981\u4f7f\u7528\u8fd9\u5757\u5185\u5b58\u540e\uff0c\u9700\u8981\u5c06\u8fd9\u5757\u5185\u5b58 \u201c\u8fd8\u7ed9\u201d \u7535\u8111\uff0c\u6b64\u65f6\u9700\u8981\u4f7f\u7528 free \u51fd\u6570 \u3002

free

\u4f7f\u7528 free(\u6307\u9488) \u5373\u53ef\u3002

"},{"location":"programming/24fall/lec6/#_16","title":"\u521d\u59cb\u5316","text":"

\u5f53\u6211\u4eec\u9700\u8981\u65b0\u5efa\u4e00\u4e2a\u94fe\u8868\u65f6\uff0c\u4e00\u822c\u90fd\u662f\u5148\u5b9a\u4e49\u4e00\u4e2a\u5934\u8282\u70b9\uff0c\u5c06\u5176\u521d\u59cb\u5316\u4e3a\u7a7a\u6307\u9488 NULL\u3002\u53ea\u6709\u5f53\u6211\u4eec\u9700\u8981\u5f80\u91cc\u9762\u585e\u5185\u5bb9\u65f6\uff0c\u6211\u4eec\u624d\u5411\u7535\u8111\u7533\u8bf7\u7a7a\u95f4\u5e76\u521d\u59cb\u5316\u3001\u8d4b\u503c\u7b49\u3002

"},{"location":"programming/24fall/lec6/#_17","title":"\u94fe\u8868\u7684\u904d\u5386","text":"

\u5bf9\u4e8e\u4e00\u4e2a\u6570\u7ec4\u800c\u8a00\uff0c\u6211\u4eec\u60f3\u8bbf\u95ee\u8fd9\u4e2a\u6570\u7ec4\u4ec0\u4e48\u5730\u65b9\u5c31\u53ef\u4ee5\u8bbf\u95ee\u4ec0\u4e48\u5730\u65b9\uff0c\u53ea\u9700\u8981\u9009\u5bf9\u4e0b\u6807\u5c31\u53ef\u4ee5\u3002\u6bd4\u5982\u8bbf\u95ee\u6570\u7ec4\u7684\u5f00\u5934\uff1aa[0]\uff1b\u8bbf\u95ee\u6570\u7ec4\u7684\u7b2c\u4e94\u4e2a\u4f4d\u7f6e\uff1aa[4]\uff1b\u8bbf\u95ee\u6570\u7ec4\u672b\u5c3e\uff08\u5047\u8bbe\u6570\u7ec4\u6709 10 \u4e2a\u4f4d\u7f6e\uff09\uff1aa[9]\u3002 \u4f46\u662f\u5bf9\u94fe\u8868\u800c\u8a00\uff0c\u8fd9\u6837\u7684\u64cd\u4f5c\u662f\u65e0\u6cd5\u5b9e\u73b0\u7684\u3002\u5f53\u6211\u4eec\u9700\u8981\u8bbf\u95ee\u94fe\u8868\u672b\u5c3e\u7684\u6570\u636e\u65f6\uff0c\u53ea\u80fd\u4ece\u94fe\u8868\u7684\u5934\u8282\u70b9\u5f00\u59cb\uff0c\u4e00\u76f4\u6cbf\u7740\u6307\u9488\u5f80\u4e0b\u627e\uff0c\u76f4\u5230\u627e\u5230\u6700\u540e\u7684\u4f4d\u7f6e\u4e3a\u6b62\u3002\u56e0\u6b64\uff0c\u5728\u94fe\u8868\u4e2d\u8bbf\u95ee\u6570\u636e\u975e\u5e38\u6d88\u8017\u65f6\u95f4\u3002

"},{"location":"programming/24fall/lec6/#_18","title":"\u54e8\u5175\u8282\u70b9","text":"

\u6216\u8005\u53ef\u4ee5\u53eb\u505a \u201d\u50f5\u5c38\u8282\u70b9\u201c\u3002 \u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u4e00\u4e2a\u94fe\u8868\u4e0d\u4f1a\u4ece\u5934\u8282\u70b9\u5f00\u59cb\u5c31\u5b58\u50a8\u6570\u636e\uff0c\u800c\u662f\u4f7f\u7528\u4e00\u4e2a\u4e0d\u5b58\u50a8\u6570\u636e\u7684\u7a7a\u767d\u8282\u70b9\u5f53\u4f5c\u5934\u8282\u70b9\uff0c\u5176\u540e\u9762\u4f7f\u7528\u6307\u9488\u8fde\u63a5\u5176\u4ed6\u5b58\u6709\u6570\u636e\u7684\u8282\u70b9\u3002\u8fd9\u6837\u7684\u7a7a\u767d\u8282\u70b9\u53eb \u54e8\u5175\u8282\u70b9 \u3002

"},{"location":"programming/24fall/lec6/#_19","title":"\u94fe\u8868\u7684\u5176\u4ed6\u5f62\u5f0f","text":"

\u9664\u4e86\u6211\u4eec\u4e00\u5f00\u59cb\u63d0\u5230\u7684 \u201c\u5355\u5411\u94fe\u8868\u201d\uff0c\u94fe\u8868\u8fd8\u6709\u5176\u4ed6\u51e0\u79cd\u5f62\u5f0f\uff0c\u5982 \u201d\u53cc\u5411\u94fe\u8868\u201c\u3001\u201d\u5faa\u73af\u5355\u5411\u94fe\u8868\u201c\u3001\u201d\u5faa\u73af\u53cc\u5411\u94fe\u8868\u201c \u7b49\u3002

\u4f8b2.3.1

\u4f7f\u7528\u73af\u5f62\u94fe\u8868\u6a21\u4eff\u7ea6\u745f\u592b\u95ee\u9898\u3002

"},{"location":"programming/24fall/lec6/#_20","title":"\u94fe\u8868\u7684\u57fa\u672c\u64cd\u4f5c","text":"

\u4ee5\u4e0b\u90fd\u662f\u4ee5\u5355\u5411\u94fe\u8868\u4e3a\u4f8b\u3002

"},{"location":"programming/24fall/lec6/#_21","title":"\u589e","text":"

\u5f53\u6211\u4eec\u9700\u8981\u5f80\u91cc\u9762\u589e\u52a0\u4e00\u4e2a\u8282\u70b9\u65f6\uff0c\u9996\u5148\u6211\u4eec\u9700\u8981\u60f3\u529e\u6cd5\u76f4\u5230\u63d2\u5165\u8282\u70b9\u7684\u4f4d\u7f6e\uff0c\u4e5f\u5c31\u662f\u9700\u8981\u76f4\u5230\u5f85\u63d2\u5165\u8282\u70b9\u7684\u524d\u9a71\u8282\u70b9\u662f\u4ec0\u4e48\u3002 \u5f53\u6211\u4eec\u5f97\u5230\u524d\u9a71\u8282\u70b9\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u8fdb\u884c\u63d2\u5165\u4e86\u3002\u6bd4\u5982\u6211\u4eec\u7684\u524d\u9a71\u8282\u70b9\u4e3a front\uff0c\u5f85\u63d2\u5165\u8282\u70b9\u4e3a p\uff0cf \u539f\u6765\u7684\u540e\u9a71\u8282\u70b9\u4e3a back\uff1a

\u8282\u70b9 p \u8d4b\u503c\nNode back = front -> next;//\u5c06 front \u7684\u540e\u9a71\u8282\u70b9 back \u8bb0\u5f55\u4e0b\u6765\uff0c\u65b9\u4fbf\u540e\u7eed\u64cd\u4f5c\nfront -> next = p;//\u5c06 front \u7684\u540e\u9a71\u8282\u70b9\u6539\u4e3a p\np -> next = back;//\u5c06 p \u7684\u540e\u9a71\u8282\u70b9\u8d4b\u503c\u4e3a back\n

"},{"location":"programming/24fall/lec6/#_22","title":"\u5220","text":"

\u5f53\u6211\u4eec\u9700\u8981\u5220\u9664\u4e00\u4e2a\u8282\u70b9\u65f6\uff0c\u9996\u5148\u4e5f\u662f\u9700\u8981\u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\u7684\u4f4d\u7f6e\u3002\u5728\u627e\u7684\u540c\u65f6\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u4e00\u8d77\u8bb0\u5f55\u5f53\u524d\u70b9\u7684\u524d\u9a71\u8282\u70b9\u662f\u4ec0\u4e48\u3002 \u5f53\u5f85\u5220\u9664\u70b9\u627e\u5230\u4e4b\u540e\uff0c\u5047\u8bbe\u4e3a p\uff0c\u5176\u524d\u9a71\u8282\u70b9\u4e3a front\uff0cp \u7684\u540e\u9a71\u8282\u70b9\u4e3a back\uff1a

front -> next = p -> next;//\u5c06 front \u7684\u540e\u9a71\u8282\u70b9\u6539\u4e3a back\uff0c\u8fd9\u91cc\u7701\u7565\u4e86\u8bb0\u5f55 back \u7684\u8fc7\u7a0b\nfree(p);//\u8bb0\u5f97\u5c06 p \u7684\u7a7a\u95f4\u91ca\u653e\u6389\n

"},{"location":"programming/24fall/lec6/#_23","title":"\u6539","text":"

\u5f53\u6211\u4eec\u9700\u8981\u6539\u53d8\u4e00\u4e2a\u8282\u70b9\u4e2d\u7684\u6570\u636e\u65f6\uff0c\u53ea\u9700\u8981\u5148\u627e\u5230\u8fd9\u4e2a\u8282\u70b9\u7684\u4f4d\u7f6e\uff0c\u7136\u540e\u5bf9\u5176\u6570\u636e\u8fdb\u884c\u4fee\u6539\u5373\u53ef\u3002

"},{"location":"programming/24fall/lec6/#_24","title":"\u67e5","text":"

\u524d\u9762\u4e09\u4e2a\u64cd\u4f5c\u90fd\u662f\u5efa\u7acb\u5728\u67e5\u7684\u57fa\u7840\u4e0a\u3002\u5f53\u6211\u4eec\u9700\u8981\u5728\u94fe\u8868\u4e2d\u67e5\u4e00\u4e2a\u70b9\u65f6\uff0c\u6211\u4eec\u9700\u8981\u4ece\u5934\u8282\u70b9\u5f00\u59cb\u4e00\u76f4\u5f80\u4e0b\u627e\uff0c\u76f4\u5230\u627e\u5230\u7b26\u5408\u8981\u6c42\u7684\u70b9\u4e3a\u6b62\u3002 \u5047\u8bbe\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u51fd\u6570 int check(Node p) \u7528\u6765\u68c0\u9a8c\u8be5\u8282\u70b9\u662f\u5426\u662f\u6211\u4eec\u9700\u8981\u627e\u7684\u8282\u70b9\uff08\u7b26\u5408\u8981\u6c42\u5219\u8fd4\u56de 1\uff09\uff0c\u5e76\u5047\u8bbe\u5934\u8282\u70b9\u4e3a\u54e8\u5175\u8282\u70b9\uff1a

Node find(Node head)\n{\n    int p = head -> next;//\u4ece\u7b2c\u4e00\u4e2a\u5b58\u6709\u6570\u636e\u7684\u8282\u70b9\u5f00\u59cb\u627e\n    while(p != NULL)//\u4e00\u76f4\u627e\u5230\u6574\u4e2a\u94fe\u8868\u5168\u90e8\u904d\u5386\u5b8c\u4e3a\u6b62\n    {\n        if(check(p))\n        {\n            return p;//\u82e5\u627e\u5230\u7b26\u5408\u8981\u6c42\u7684\u8282\u70b9\uff0c\u5c31\u8fd4\u56de\u8fd9\u4e2a\u70b9\uff0c\u540c\u65f6\u7ed3\u675f\u7a0b\u5e8f\n        }\n        p = p -> next;//\u5982\u679c\u7a0b\u5e8f\u6267\u884c\u5230\u8fd9\u91cc\uff0c\u8bf4\u660e\u524d\u9762\u6ca1\u627e\u5230\u3002\u6b64\u65f6\u66f4\u65b0 p\uff0c\u8ba9\u5176\u53d8\u6210\u4e0b\u4e00\u4e2a\u70b9\uff0c\u7ee7\u7eed\u5bfb\u627e\n    }\n    return NULL;//\u82e5\u6267\u884c\u5230\u8fd9\u91cc\uff0c\u8bf4\u660e\u904d\u5386\u6574\u4e2a\u94fe\u8868\u90fd\u6ca1\u627e\u5230\u5bf9\u5e94\u7684\u8282\u70b9\u3002\u6b64\u65f6\u76f4\u63a5\u8fd4\u56de NULL\n}\n

"},{"location":"programming/24fall/lec6/#_25","title":"\u8f93\u51fa\u94fe\u8868","text":"

\u82e5\u6211\u4eec\u9700\u8981\u5c06\u6574\u4e2a\u94fe\u8868\u8f93\u51fa\uff0c\u53ea\u9700\u8981\u904d\u5386\u6574\u4e2a\u94fe\u8868\uff0c\u8fb9\u904d\u5386\u8fb9\u6253\u5370\u5373\u53ef\u3002 \u5047\u8bbe\u8be5\u94fe\u8868\u6709\u54e8\u5175\u8282\u70b9\uff0c\u540c\u65f6\u6211\u4eec\u5b9a\u4e49 void print(Node p) \u7528\u6765\u8f93\u51fa\u76f8\u5173\u6570\u636e\u3002

int p = head -> next;//\u4ece\u7b2c\u4e00\u4e2a\u5b58\u6709\u6570\u636e\u7684\u8282\u70b9\u5f00\u59cb\u6253\u5370\nwhile(p != NULL)//\u4e00\u76f4\u6253\u5370\u76f4\u5230\u904d\u5386\u5b8c\u6574\u4e2a\u94fe\u8868\u4e3a\u6b62\n{\n    print(p);//\u6253\u5370\u76f8\u5173\u5185\u5bb9\n    p = p -> next;//\u66f4\u65b0 p\uff0c\u8ba9 p \u53d8\u4e3a\u4e0b\u4e00\u4e2a\u8282\u70b9\u7ee7\u7eed\u6253\u5370\n}\nreturn ;\n

"},{"location":"programming/24fall/lec6/#_26","title":"\u5220\u9664\u94fe\u8868","text":"

\u5f53\u6211\u4eec\u9700\u8981\u5220\u9664\u4e00\u4e2a\u94fe\u8868\u65f6\uff0c\u6211\u4eec\u540c\u6837\u4e5f\u9700\u8981\u904d\u5386\u6574\u4e2a\u94fe\u8868\uff0c\u4e00\u8fb9\u904d\u5386\u4e00\u8fb9\u91ca\u653e\u7a7a\u95f4\u3002 \u5047\u8bbe\u8be5\u94fe\u8868\u6709\u54e8\u5175\u8282\u70b9\uff1a

int p = head;//\u54e8\u5175\u8282\u70b9\u540c\u6837\u9700\u8981\u5220\u9664\nwhile(p != NULL)//\u76f4\u5230\u904d\u5386\u5b8c\u6574\u4e2a\u94fe\u8868\u4e3a\u6b62\n{\n    free(p);//\u91ca\u653e\u7a7a\u95f4\n    p = p -> next;//\u66f4\u65b0 p\n}\nreturn ;\n

"},{"location":"programming/24fall/lec6/#_27","title":"\u7b80\u5355\u4ecb\u7ecd\u4e24\u79cd\u6570\u636e\u7ed3\u6784","text":""},{"location":"programming/24fall/lec6/#stack","title":"\u6808 stack","text":"

\u6808\u6bd4\u8f83\u7c7b\u4f3c\u4e00\u645e\u7897\uff0c\u5f53\u6211\u4eec\u9700\u8981\u62ff\u7897\u6216\u8005\u653e\u7897\u7684\u65f6\u5019\uff0c\u53ea\u80fd\u4ece\u6700\u9876\u4e0a\u5f00\u59cb\u62ff\u6216\u8005\u653e\u3002

\u4f7f\u7528\u6570\u7ec4\u6216\u8005\u94fe\u8868\u90fd\u53ef\u4ee5\u5b9e\u73b0\u6808\u3002

"},{"location":"programming/24fall/lec6/#queue","title":"\u961f\u5217 queue","text":"

\u60f3\u8c61\u8bb8\u591a\u4eba\u6392\u961f\u7ad9\u5728\u72ed\u7a84\u901a\u9053\u5185\u90e8\uff0c\u6b64\u65f6\u4eba\u9700\u8981\u51fa\u53bb\u5c31\u53ea\u80fd\u4ece\u6700\u524d\u9762\u8d70\uff0c\u4eba\u9700\u8981\u8fdb\u6765\u5c31\u53ea\u80fd\u4ece\u6700\u540e\u9762\u8fdb\u3002

\u540c\u6837\u7684\uff0c\u4f7f\u7528\u6570\u7ec4\u6216\u8005\u94fe\u8868\u90fd\u53ef\u4ee5\u5b9e\u73b0\u961f\u5217\u3002

\u4f8b2.5.2.1

Answer: A

"},{"location":"programming/24fall/lec6/#_28","title":"\u591a\u6587\u4ef6\u7f16\u7a0b","text":""},{"location":"programming/24fall/lec6/#_29","title":"\u5b8f","text":"

\u4e0b\u9762\uff0c\u6211\u4eec\u6765\u56de\u987e\u4e00\u4e0b\u5b8f\u5b9a\u4e49\u76f8\u5173\u7684\u77e5\u8bc6\u3002

"},{"location":"programming/24fall/lec6/#_30","title":"\u6700\u57fa\u672c\u7684\u7528\u6cd5\uff1a\u5b9a\u4e49\u4e00\u4e2a\u5e38\u6570","text":"

#define \u7684\u7528\u6cd5\u4e3a\uff1adefine <\u540d\u5b57> <\u503c> \uff0c\u5176\u6700\u540e\u4e0d\u4f7f\u7528\u5206\u53f7\uff0c \u5728\u7a0b\u5e8f\u5f00\u59cb\u7f16\u8bd1\u4e4b\u524d\uff0c\u7f16\u8bd1\u5668\u4f1a\u5c06\u7a0b\u5e8f\u4e2d\u6240\u6709\u8bbe\u8ba1\u5b8f\u5b9a\u4e49\u7684\u91cf\u8fdb\u884c\u66ff\u6362\u3002

"},{"location":"programming/24fall/lec6/#_31","title":"\u4f7f\u7528\u5b8f\u5b9a\u4e49\u7b80\u5355\u51fd\u6570","text":"

\u5b8f\u5b9a\u4e49\u53ef\u4ee5\u4f7f\u7528\u53c2\u6570\uff0c\u5982\uff1a

#define cube(x) ((x) * (x) * (x))\n
\u6b64\u65f6\uff0c\u5c31\u76f8\u5f53\u4e8e\u6211\u4eec\u4f7f\u7528\u5b8f\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u7b97\u7acb\u65b9\u7684\u51fd\u6570\u3002 \u5728\u7f16\u8bd1\u65f6\uff0c\u7f16\u8bd1\u5668\u4f1a\u5c06\u6240\u6709 cube(x) \u66ff\u6362\u4e3a ((x) * (x) * (x)) \uff08\u5176\u4e2d x \u4e3a\u4e00\u4e2a\u53c2\u6570\uff0c\u53ef\u4ee5\u662f 2\u30013.5\u3001a \u7b49\u6570\u5b57\u6216\u53d8\u91cf\uff09\uff0c\u7136\u540e\u8ba1\u7b97\u5f97\u5230\u7ed3\u679c\u3002

\u5f53\u4f7f\u7528\u5b8f\u5b9a\u4e49\u4e00\u4e2a\u6709\u53c2\u6570\u7684\u5f0f\u5b50\u65f6\uff0c\u4e00\u5b9a\u8981\u6ce8\u610f\u52a0\u4e0a\u62ec\u53f7\u3002\u4e0d\u4ec5\u662f\u7ed9\u53c2\u6570\u52a0\u4e0a\u62ec\u53f7\uff0c\u8fd8\u8981\u7ed9\u6574\u4f53\u52a0\u4e0a\u62ec\u53f7\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u9519\u8bef\u3002

#define RADTODEG(x) (x * 57.29) \u5f53\u6211\u4eec\u5199 RADTODEG(4 - 3) \u65f6\uff0c\u7f16\u8bd1\u5668\u4f1a\u66ff\u6362\u4e3a\uff1a4 - 3 * 57.29 \uff0c\u548c\u6211\u4eec\u7684\u76ee\u7684\u76f8\u6096\u3002 #define RADTODEG(x) (x) * 57.29 \u5f53\u6211\u4eec\u5199 4 / RADTODEG(3) \u65f6\uff0c\u7f16\u8bd1\u5668\u4f1a\u66ff\u6362\u4e3a\uff1a4 / 3 * 57.29 \uff0c\u548c\u6211\u4eec\u7684\u76ee\u7684\u4e5f\u76f8\u6096\u3002

\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u53c2\u6570\uff0c\u6784\u9020\u66f4\u591a\u7684\u51fd\u6570\uff1a

#define MAX(a,b) ((a) > (b) ? (a) : (b))\n

"},{"location":"programming/24fall/lec6/#define","title":"\u65e0\u5b9a\u4e49\u503c\u7684 define","text":"

\u6211\u4eec\u53ef\u4ee5\u5728\u6587\u4ef6\u5f00\u59cb\u5199 #define SEARCH \u7c7b\u4f3c\u7684\u5b8f\u5b9a\u4e49\u3002\u8fd9\u7c7b\u5b8f\u5b9a\u4e49\u7684\u4e3b\u8981\u662f\u8d77\u6807\u8bc6\u4f5c\u7528\uff0c\u4e00\u822c\u9700\u8981\u548c #ifdef\u3001#else\u3001#endif \u7b49\u914d\u5408\u4f7f\u7528\u3002 \u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6587\u4ef6\u4e00\u5f00\u59cb\u4f7f\u7528 #define \u5b9a\u4e49\u6807\u8bc6\u7b26\uff0c\u7136\u540e\u4f7f\u7528 #ifdef \u6807\u8bc6\u7b26 \u68c0\u67e5\u524d\u9762\u662f\u5426\u6709\u5b9a\u4e49\u8be5\u6807\u8bc6\u7b26\uff0c\u82e5\u6709\uff0c\u5219\u6267\u884c #ifdef \u540e\u9762\u7684\u7a0b\u5e8f\uff1b\u82e5\u6ca1\u6709\uff0c\u5219\u6267\u884c #else \u540e\u9762\u7684\u7a0b\u5e8f\u3002\u6700\u540e\uff0c\u8bb0\u5f97\u4f7f\u7528 #endif \u505a\u7ed3\u5c3e\u3002

"},{"location":"programming/24fall/lec6/#_32","title":"\u591a\u6587\u4ef6\u7f16\u7a0b","text":"

\u5f53\u6211\u4eec\u6709\u5f88\u591a\u5f88\u591a\u4ee3\u7801\u53ca\u5f88\u591a\u5f88\u591a\u51fd\u6570\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u51fd\u6570\u653e\u5230\u4e0d\u540c\u7684\u6587\u4ef6\u4e2d\u5206\u522b\u7f16\u8bd1\uff0c\u6700\u540e\u518d\u8fde\u63a5\u5230\u4e00\u8d77\u6784\u6210\u4e00\u4e2a\u5927\u7a0b\u5e8f\u3002 \u800c\u8fde\u63a5\u5c31\u9700\u8981\u901a\u8fc7 #include \u5b9a\u4e49\u3002

"},{"location":"programming/24fall/lec6/#_33","title":"\u5feb\u901f\u4e0a\u624b","text":"
  1. \u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5e93\u51fd\u6570\u6587\u4ef6\uff0c\u540e\u7f00\u662f '.h'\u3002
  2. \u5728\u8be5\u6587\u4ef6\u4e2d\uff08\u6211\u4eec\u5047\u8bbe\u53eb 'a.h'\uff09\uff0c\u6211\u4eec\u9700\u8981\u5199\uff1a
    #ifndef \u67d0\u6807\u8bc6\u7b26\n#define \u67d0\u6807\u8bc6\u7b26//\u8fd9\u91cc\u662f\u4e3a\u4e86\u9632\u6b62\u4e4b\u524d\u5df2\u7ecf\u5b9a\u4e49\u8fc7\u8be5\u6807\u8bc6\u7b26\uff0c\u4ece\u800c\u51fa\u73b0\u91cd\u590d\u58f0\u660e\u7684\u9519\u8bef\n\u4f60\u7684\u51fd\u6570\u58f0\u660e\n#endif\n
  3. \u7136\u540e\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a '.c' \u6587\u4ef6\uff0c\u5e76\u5728\u6587\u4ef6\u5f00\u5934\u5199\u4e0a\uff1a
    #include \"a.h\"//\u5f53\u5f15\u5165\u540c\u4e00\u76ee\u5f55\u4e0b\u7684\u5e93\u65f6\uff0c\u6211\u4eec\u4f7f\u7528\u53cc\u5f15\u53f7\uff1b\u82e5\u6211\u4eec\u4f7f\u7528 '<>'\uff0c\u5219\u7f16\u8bd1\u5668\u4f1a\u76f4\u63a5\u53bb\u6307\u5b9a\u76ee\u5f55\u4e0b\u9762\u5bfb\u627e\u5bf9\u5e94\u7684\u5e93\n
  4. \u5e76\u4e14\uff0c\u6211\u4eec\u9700\u8981\u5728\u8be5 'a.c' \u6587\u4ef6\u5185\u5199\u4e0a 'a.h' \u4e2d\u5df2\u58f0\u660e\u51fd\u6570\u7684\u8be6\u7ec6\u4ee3\u7801\u3002
  5. \u6700\u540e\u7684\u6700\u540e\uff0c\u6211\u4eec\u9700\u8981\u5728\u5305\u542b\u4e3b\u51fd\u6570\u7684 '.c' \u6587\u4ef6\u4e2d\u4e5f\u5199\u4e0a #include \"a.h\" \u3002\u8fd9\u6837\uff0c\u5c31\u7b97\u5927\u529f\u544a\u6210\u4e86\u3002
  6. \u6700\u540e\uff0c\u6211\u4eec\u53ea\u9700\u8981\u4f9d\u9760\u4e00\u70b9\u624b\u6bb5\u5c06\u6240\u6709\u6587\u4ef6\u90fd\u7f16\u8bd1\u8fde\u63a5\u5373\u53ef\u3002
"},{"location":"programming/24fall/lec6/#_34","title":"\u539f\u7406\uff1f","text":"

\u6211\u4eec\u53ef\u4ee5\u5c06 #include \u7406\u89e3\u4e3a\u4e00\u4e2a\u63a5\u53e3\uff0c\u5f53\u6211\u4eec\u5728\u4ee3\u7801\u6700\u5f00\u59cb\u5199 #include \u5e76\u7f16\u8bd1\u3001\u8fde\u63a5\u7a0b\u5e8f\u65f6\uff0c\u4f1a\u6839\u636e #include \u540e\u7684\u6587\u4ef6\u5c06\u5bf9\u5e94\u7684\u51fd\u6570\u548c\u6211\u4eec\u81ea\u5df1\u5199\u7684\u51fd\u6570\u653e\u5230\u4e00\u8d77\u3002\u6240\u4ee5\u6211\u4eec\u624d\u53ef\u4ee5\u4f7f\u7528\u672c\u6587\u4ef6\u5b9a\u4e49\u51fd\u6570\u4e4b\u5916\u7684\u5176\u4ed6\u51fd\u6570\u3002 \u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5199\u4e86 #include \"a.h\" \uff0c\u5728\u7f16\u8bd1\u8fde\u63a5\u65f6\uff0c\u7535\u8111\u4f1a\u5c06\u540c\u6837\u63a5\u4e86 #include \"a.h\" \u63a5\u53e3\u7684 'a.c' \u6587\u4ef6\u4e00\u8d77\u653e\u8fdb\u6765\uff0c\u6240\u4ee5\u6211\u4eec\u624d\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u6587\u4ef6\u5b9a\u4e49\u7684\u51fd\u6570\u3002

"},{"location":"programming/24fall/lec6/#static","title":"static \u53d8\u91cf","text":"

\u89c2\u5bdf\u4e0b\u9762\u7684\u4ee3\u7801\uff1a

void function();\nint main()\n{\n    for(int i = 0; i < 5; ++ i)\n    {\n        function();\n    }\n    return 0;\n}\nvoid function()\n{\n    int j = 1;\n    j ++;\n    printf(\"j = %d\\n\", j);\n    return ;\n}\n
\u7a0b\u5e8f\u6267\u884c\u4e4b\u540e\uff0c\u4e0d\u96be\u770b\u51fa\uff0c\u6700\u540e\u7684\u7ed3\u679c\u5c06\u4f1a\u662f 5 \u884c \"j = 2\"\u3002 \u4f46\u662f\u82e5\u6211\u4eec\u5c06 function \u4e2d\u7684 int j = 1 \u6539\u4e3a static int j = 1 \uff0c\u90a3\u4e48\u7ed3\u679c\u5c31\u4f1a\u5927\u5927\u4e0d\u540c\uff1a
void function();\nint main()\n{\n    for(int i = 0; i < 5; ++ i)\n    {\n        function();\n    }\n    return 0;\n}\nvoid function()\n{\n    static int j = 1;\n    j ++;\n    printf(\"j = %d\\n\", j);\n    return ;\n}\n
\u5f97\u5230\u7684\u7ed3\u679c\u5c06\u662f 2\u30013\u30014\u30015\u30016\u3002 \u8fd9\u662f\u56e0\u4e3a\uff0cstatic \u4fee\u9970\u7684 j \u53d8\u91cf\u6539\u53d8\u4e86\u751f\u547d\u5468\u671f\u3002\u539f\u672c j \u5728 function \u51fd\u6570\u7ed3\u675f\u4e4b\u540e\u5c31\u4f1a\u88ab\u6e05\u9664\uff0c\u4e0b\u4e00\u6b21\u6267\u884c function \u65f6\uff0cj \u53d8\u91cf\u4f1a\u88ab\u91cd\u65b0\u5b9a\u4e49\u3002\u4f46\u662f\u82e5\u4f7f\u7528 static \u4fee\u9970 j \u53d8\u91cf\uff0c\u90a3\u4e48\u5728 function \u51fd\u6570\u7ed3\u675f\u4e4b\u540e\uff0cj \u4e0d\u4f1a\u88ab\u6e05\u9664\uff0c\u5176\u503c\u4e5f\u4e0d\u4f1a\u88ab\u6e05\u9664\u3002\u867d\u7136\u5728\u5176\u4ed6\u51fd\u6570\u4e2d\u65e0\u6cd5\u4f7f\u7528\u8fd9\u4e2a j \u53d8\u91cf\uff0c\u4f46\u662f\u5f53\u56de\u5230 function \u51fd\u6570\u4e2d\uff0cj \u4f1a\u5e26\u7740\u4e0a\u4e00\u6b21\u8fd0\u884c\u51fd\u6570\u7559\u4e0b\u7684\u7ed3\u679c\u91cd\u65b0\u53c2\u4e0e\u8fd0\u7b97\u3002

"},{"location":"programming/24fall/lec5.assets/","title":"Index","text":"

lec5 images

"},{"location":"programming/archive/23fall/","title":"\uff0823fall\uff09\u7a0b\u8bbe\u8f85\u5b66\u8bfe\u7a0b \u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057","text":"

\u6b22\u8fce\u6765\u5230\u7afa\u9662\u7a0b\u8bbe\u8f85\u5b66\u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057\u7248\u5757 \ud83e\udd17\u3002\u4f60\u53ef\u4ee5\u5728\u5de6\u4fa7\u5bfc\u822a\u680f\u4e2d\u8be6\u7ec6\u6d4f\u89c8\u672c\u6a21\u5757\u7684\u5185\u5bb9\u3002

"},{"location":"programming/archive/23fall/#_1","title":"\u8bfe\u7a0b\u7b80\u4ecb","text":"

\u7a0b\u5e8f\u8bbe\u8ba1\u4e0e\u7b97\u6cd5\u57fa\u7840\u8bfe\u7a0b\u8bb2\u8ff0\u7684\u5185\u5bb9\u5c40\u9650\u4e8e\u8bed\u8a00\u672c\u8eab\uff0c\u8f83\u4e3a\u8868\u8c61\u3002\u7136\u800c\uff0cC \u8bed\u8a00\u5b9e\u8d28\u4e0a\u662f\u4e00\u95e8\u5f88\u96be\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u4e0d\u61c2\u7f16\u8bd1\u539f\u7406\u3001\u64cd\u4f5c\u7cfb\u7edf\u548c\u8ba1\u7b97\u673a\u4f53\u7cfb\u7ed3\u6784\u65e0\u6cd5\u83b7\u5f97\u6df1\u5165\u7684\u7406\u89e3\uff0c\u800c\u8fd9\u4e9b\u4e5f\u662f\u5b66\u4e60\u8ba1\u7b97\u673a\u4e13\u4e1a\u7684\u540c\u5b66\u5e94\u5f53\u5c3d\u65e9\u4e86\u89e3\u7684\u77e5\u8bc6\u3002

\u672c\u8f85\u5b66\u8bfe\u7a0b\u5c06\u7ed3\u5408\u8ba1\u7b97\u673a\u7cfb\u7edf\u65b9\u9762\u7684\u77e5\u8bc6\uff0c\u4e3a\u540c\u5b66\u4eec\u63d0\u4f9b\u6df1\u5165\u7406\u89e3 C \u8bed\u8a00\u7684\u89c6\u89d2\u3002\u6211\u4eec\u7684\u76ee\u7684\u662f\u89e3\u7b54\u7a0b\u5e8f\u8bbe\u8ba1\u4e2d\u8f83\u4e3a\u5e95\u5c42\u7684\u95ee\u9898\uff1a

\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u80fd\u591f\u4e3a\u4f60\u5f00\u542f\u4ece C \u8bed\u8a00\u5230\u8ba1\u7b97\u673a\u79d1\u5b66\u4e0e\u6280\u672f\u7684\u771f\u6b63\u7684\u5927\u95e8\u3002\u5982\u679c\u5bf9\u8bfe\u7a0b\u5185\u5bb9\u6709\u4efb\u4f55\u7591\u95ee\u548c\u5efa\u8bae\uff0c\u6b22\u8fce\u4f60\u8054\u7cfb\u6211\u4eec\u3002\u4f60\u53ef\u4ee5\u5728\u4ed3\u5e93\u4e2d\u53d1\u8d77 issue \u6216\u53d1\u9001\u90ae\u4ef6\u5230 zhubaolin228@gmail.com\u3002

"},{"location":"programming/archive/23fall/#_2","title":"\u8bfe\u7a0b\u5b89\u6392","text":"

2023-2024 \u5b66\u5e74\uff0c\u7a0b\u8bbe\u8f85\u5b66\u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057\u8bfe\u9898\u7ec4\u540c\u5b66\u6709\uff1a

\u8bfe\u7a0b\u5b89\u6392\u5982\u4e0b\uff1a

\u8282\u6b21 \u5185\u5bb9 \u4e3b\u8bb2 \u65f6\u95f4 \u5730\u70b9 PPT \u4e0e\u8bb2\u4e49 \u76f4\u64ad\u56de\u653e 1 \u7a0b\u5e8f\u7f16\u8bd1\u8fc7\u7a0b\u4e0e\u8c03\u8bd5\u6280\u672f \u6731\u5b9d\u6797 10.14 \u4e0b\u5348 2:30-4:30 \u4e1c 1A-132 \u8bfe\u524d\u51c6\u5907\u8bb2\u4e49 Bilibili 2 \u7c7b\u578b\u7cfb\u7edf\u4e0e\u5185\u5b58\u6a21\u578b \u674e\u82f1\u7426 10.29 \u65e9 9:30-11:30 \u5317 1-311 \u8bfe\u524d\u51c6\u5907\u8bb2\u4e49 Bilibili 3 I/O \u4e0e\u6587\u4ef6 \u80e1\u80b2\u73ae 11.18 \u4e0b\u5348 14:30-16:30 \u5317 1-312 \u8bfe\u524d\u51c6\u5907\u8bb2\u4e49 Bilibili 4 C \u6807\u51c6\u5e93 \u6731\u5b9d\u6797 12.2 \u65e9 9:00-11:00 \u5317 2-225 \u8bb2\u4e49\u8bfe\u540e\u6269\u5c55 Bilibili 5 \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5 \u8c22\u96c6\u82cf\u715c\u7a0b \u3010\u6682\u5b9a\u301112.15"},{"location":"programming/archive/23fall/lec1/lec1/","title":"\u8bb2\u4e49\uff1a\u7a0b\u5e8f\u7f16\u8bd1\u8fc7\u7a0b\u4e0e\u8c03\u8bd5\u6280\u672f","text":"\u76f4\u64ad\u56de\u653e

Bilibili

\u5185\u5bb9\u63d0\u8981 \u5982\u4f55\u98df\u7528\u672c\u8bb2\u4e49

\u4f5c\u4e3a\u5728\u7ebf\u8bb2\u4e49\uff0c\u6211\u4f1a\u5c3d\u91cf\u5199\u5f97\u8be6\u7ec6\u4e00\u4e9b\uff0c\u4e3a\u540c\u5b66\u4eec\u63d0\u4f9b\u590d\u4e60\u548c\u8fdb\u4e00\u6b65\u6269\u5c55\u7684\u6307\u5f15\u3002\u56e0\u4e3a\u65f6\u95f4\u6709\u9650\uff0c\u5728\u8bfe\u4e0a\u6211\u65e0\u6cd5\u8986\u76d6\u8bb2\u4e49\u4e2d\u6240\u6709\u7684\u5185\u5bb9\u3002\u540c\u5b66\u4eec\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u4e60\u60ef\u9009\u62e9\u5728\u8bfe\u524d\u8bfe\u540e\u6d4f\u89c8\u672c\u8bb2\u4e49\uff5e

\u672c\u6b21\u8bfe\u7684\u6838\u5fc3\u5185\u5bb9\u4ece\u300c\u7a0b\u5e8f\u7684\u7f16\u8bd1\u8fc7\u7a0b\u300d\u5f00\u59cb\u3002\u524d\u9762\u7684\u5185\u5bb9\u4f5c\u4e3a\u9884\u5907\u77e5\u8bc6\uff0c\u5728\u8bfe\u4e0a\u5c06\u4f1a\u5feb\u901f\u5e26\u8fc7\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_2","title":"\u8bfe\u7a0b\u5bfc\u8a00","text":"

Hi\uff0c\u6b22\u8fce\u5404\u4f4d\u540c\u5b66\u6765\u5230\u7afa\u9662\u7a0b\u8bbe\u8f85\u5b66\u300c\u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057\u300d\u7684\u7b2c\u4e00\u8282\u8bfe\u3002

\u5728\u524d\u51e0\u5468\u7684\u7a0b\u5e8f\u8bbe\u8ba1\u8bfe\u7a0b\u4e2d\uff0c\u8001\u5e08\u4eec\u5e94\u8be5\u5df2\u7ecf\u4e3a\u540c\u5b66\u4eec\u8bb2\u89e3\u4e86 C \u8bed\u8a00\u7684\u57fa\u7840\u8bed\u6cd5\u7b49\u77e5\u8bc6\u3002\u4f46\u662f\u540c\u5b66\u4eec\u6216\u8bb8\u4f1a\u6709\u4e0b\u9762\u8fd9\u4e9b\u7591\u95ee\uff1a

\u8f85\u5b66\u8bfe\u7a0b\u7684\u76ee\u7684\u5c31\u662f\u5e2e\u52a9\u540c\u5b66\u4eec\u89e3\u51b3\u8fd9\u4e9b\u8fdb\u4e00\u6b65\u7684\u95ee\u9898\u3002\u5b9e\u8d28\u4e0a C \u8bed\u8a00\u662f\u4e00\u95e8\u5f88\u96be\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u4e0d\u61c2\u7f16\u8bd1\u539f\u7406\u3001\u64cd\u4f5c\u7cfb\u7edf\u548c\u8ba1\u7b97\u673a\u4f53\u7cfb\u7ed3\u6784\u65e0\u6cd5\u83b7\u5f97\u6df1\u5165\u7684\u7406\u89e3\u3002\u6211\u4eec\u5e0c\u671b\u901a\u8fc7\u7ebf\u4e0b\u6388\u8bfe\uff0c\u4e3a\u540c\u5b66\u4eec\u63d0\u4f9b\u8bed\u8a00\u4e4b\u5916\u7684\u8fdb\u4e00\u6b65\u7684\u77e5\u8bc6\u6269\u5c55\u548c\u6280\u80fd\u8bad\u7ec3\u3002\u8ba9\u540c\u5b66\u4eec\u5728\u8ba1\u7b97\u673a\uff08\u800c\u975e\u7b97\u6cd5\u9898\uff09\u7684\u8bed\u5883\u4e0b\u7406\u89e3 C \u8bed\u8a00\uff0c\u7406\u89e3\u7a0b\u5e8f\u8bbe\u8ba1\u3002

\u90a3\u4e48\u5728\u672c\u8282\u8bfe\uff0c\u6211\u4eec\u5c06\u4e3a\u5927\u5bb6\u7cfb\u7edf\u8bb2\u89e3\u7a0b\u5e8f\u7f16\u8bd1\u8fc7\u7a0b\u4e0e\u8c03\u8bd5\u6280\u672f\uff0c\u4e3a\u540e\u7eed\u7684\u8bfe\u7a0b\u505a\u94fa\u57ab\u3002\u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec\u4e00\u8d77\u8fdb\u5165\u8ba1\u7b97\u673a\u7684\u4e16\u754c\u5427\uff01

"},{"location":"programming/archive/23fall/lec1/lec1/#_3","title":"\u57fa\u7840\u77e5\u8bc6","text":"

\u9996\u5148\uff0c\u6211\u4eec\u6765\u4e86\u89e3\u4e00\u4e0b\u6211\u4eec\u5b66\u4e60\u7684\u5bf9\u8c61\u2014\u2014\u8ba1\u7b97\u673a\u7684\u57fa\u672c\u77e5\u8bc6\u3002\u5b83\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff1f\u6211\u4eec\u5982\u4f55\u4e0e\u5b83\u4ea4\u6d41\uff1f

"},{"location":"programming/archive/23fall/lec1/lec1/#_4","title":"\u8ba1\u7b97\u673a\u80fd\u505a\u4ec0\u4e48\uff1f","text":"

\u73b0\u4ee3\u8ba1\u7b97\u673a\u7531\u591a\u79cd\u90e8\u4ef6\u6784\u6210\uff0c\u6bd4\u5982\u4e2d\u592e\u5904\u7406\u5355\u5143\uff08Central Processing Unit\uff0cCPU\uff09\u3001\u968f\u673a\u5b58\u53d6\u5185\u5b58\uff08Random Access Memory\uff0cRAM\uff09\u3001\u786c\u76d8\uff08Hard Disk\uff09\u7b49\u3002\u5176\u4e2d CPU \u8d1f\u8d23\u5904\u7406\u7a0b\u5e8f\u3002

RISC CPU

\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684 CPU \u7684\u7535\u8def\uff0c\u5b83\u80fd\u591f\u6267\u884c\u4f60\u7528 0 \u548c 1 \u7f16\u5199\u7684\u673a\u5668\u6307\u4ee4\u3002

CPU \u57fa\u672c\u7ed3\u6784

CPU \u4e3b\u8981\u7531\u63a7\u5236\u5355\u5143\u3001\u7b97\u672f\u903b\u8f91\u5355\u5143\u548c\u5bc4\u5b58\u5668\u7ec4\u6210\u3002\u63a7\u5236\u5355\u5143\u4e2d\u6709\u7a0b\u5e8f\u8ba1\u6570\u5668\u548c\u6307\u4ee4\u5bc4\u5b58\u5668\u3002

CPU \u65e0\u6cd5\u76f4\u63a5\u8bfb\u61c2\u4f60\u5199\u7684 C \u8bed\u8a00\u4ee3\u7801\uff0c\u5b83\u662f\u7531\u6570\u5b57\u7535\u8def\u6784\u6210\u7684\u3002\u6570\u5b57\u7535\u8def\u53ea\u80fd\u5904\u7406 0 \u548c 1\uff0c\u56e0\u6b64\u8ba1\u7b97\u673a\u4e2d\u7684\u4efb\u4f55\u6570\u636e\u90fd\u5fc5\u987b\u4f7f\u7528\u4e8c\u8fdb\u5236\u8868\u793a\uff0c\u7a0b\u5e8f\u4e5f\u662f\u5982\u6b64\u3002

\u5728\u8ba1\u7b97\u673a\u521a\u521a\u8bde\u751f\u7684\u9636\u6bb5\uff0c\u5de5\u7a0b\u5e08\u4eec\u4e0d\u5f97\u4e0d\u4f7f\u7528 0 \u548c 1 \u6784\u6210\u7684\u6307\u4ee4\u5e8f\u5217\u548c\u8ba1\u7b97\u673a\u6253\u4ea4\u9053\uff0c\u8fd9\u5c31\u662f\u673a\u5668\u8bed\u8a00\u3002\u56e0\u4e3a\u5177\u4f53\u7535\u8def\u8bbe\u8ba1\u4e0d\u540c\uff0c\u6bcf\u79cd CPU \u6240\u80fd\u7406\u89e3\u7684\u6307\u4ee4\u6709\u9650\uff0c\u8fd9\u4e9b\u6307\u4ee4\u7684\u96c6\u5408\u53eb\u505a\u6307\u4ee4\u96c6\u3002

CPU \u7684\u5de5\u4f5c\u975e\u5e38\u7b80\u5355\uff1a\u4ece\u5185\u5b58\u4e2d\u8bfb\u53d6\u5e76\u6267\u884c\u4e00\u6761\u6307\u4ee4\uff0c\u518d\u4ece\u5185\u5b58\u4e2d\u8bfb\u53d6\u5e76\u6267\u884c\u4e0b\u4e00\u6761\u6307\u4ee4\u2026\u20261 GHz \u7684 CPU \u6bcf\u79d2\u80fd\u91cd\u590d\u8fd9\u4e00\u64cd\u4f5c\u7ea6\u5341\u4ebf\u6b21\u3002

\u8fd9\u4e9b\u6307\u4ee4\u90fd\u76f8\u5f53\u5177\u4f53\uff0c\u6bd4\u5982\u628a\u4e00\u4e2a\u6570\u5b57\u4ece\u4e00\u4e2a\u4f4d\u7f6e\u79fb\u52a8\u5230\u53e6\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u628a\u4e24\u4e2a\u6570\u5b57\u76f8\u52a0\u5e76\u628a\u7ed3\u679c\u5b58\u50a8\u518d\u67d0\u4e2a\u5730\u65b9\u3002\u662f\u7684\uff0c\u4f60\u7684 CPU \u4e5f\u5728\u75af\u72c2\u505a\u7740\u8fd9\u4e9b\u4e8b\u60c5\u3002\u4f46\u662f\u901a\u8fc7\u7cbe\u5de7\u7684\u8bbe\u8ba1\uff0c\u8fd9\u4e9b\u7b80\u5355\u7684\u6307\u4ee4\u5c31\u80fd\u6784\u5efa\u8d77\u7a0b\u5e8f\u7684\u63a7\u5236\u903b\u8f91\uff0c\u5b9e\u73b0\u590d\u6742\u7684\u529f\u80fd\u3002

CPU \u8fd8\u6709\u81ea\u5df1\u7684\u5c0f\u5de5\u4f5c\u533a\u2014\u2014\u7531\u82e5\u5e72\u5bc4\u5b58\u5668\uff08Register\uff09\u7ec4\u6210\u7684\u5bc4\u5b58\u5668\u7ec4\u3002\u6bcf\u4e2a\u5bc4\u5b58\u5668\u80fd\u5b58\u50a8\u4e00\u4e2a\u6570\u5b57\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_5","title":"\u4ece\u673a\u5668\u8bed\u8a00\u3001\u6c47\u7f16\u8bed\u8a00\u5230\u9ad8\u7ea7\u8bed\u8a00","text":"

\u73b0\u4ee3\u8ba1\u7b97\u673a\u7684\u7ed3\u6784\u4e0e 70 \u5e74\u524d\u5e76\u6ca1\u6709\u672c\u8d28\u4e0a\u7684\u4e0d\u540c\uff0c\u4f46\u662f\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u53d6\u5f97\u4e86\u5f88\u5927\u7684\u53d1\u5c55\uff0c\u4ea7\u751f\u4e86\u6c47\u7f16\u8bed\u8a00\u548c\u9ad8\u7ea7\u8bed\u8a00\u3002\u6211\u4eec\u4ecd\u7136\u4e0d\u80fd\u76f4\u63a5\u5bf9 CPU \u8bf4\uff1a\u4e3a\u6211\u8ba1\u7b97 \\(1 + 1\\)\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u7528\u9ad8\u7ea7\u8bed\u8a00\u7b80\u6d01\u7684\u8868\u8fbe\u5b83\uff0c\u8ba9\u7f16\u8bd1\u5668\uff08compiler\uff09\u548c\u6c47\u7f16\u5668\uff08assembler\uff09\u5c06\u5176\u7ffb\u8bd1\u6210 0101 \u7684\u673a\u5668\u8bed\u8a00\u3002\u4e0b\u56fe\u5c55\u793a\u4e86\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u7684\u53d1\u5c55\u5386\u53f2\uff0c\u7f16\u8bd1\u8fc7\u7a0b\u5176\u5b9e\u5c31\u662f\u8fd9\u4e00\u5386\u53f2\u7684\u53cd\u5411\u3002

\u673a\u5668\u8bed\u8a00 Machine Code

\u8fd9\u662f\u7b2c\u4e00\u4ee3\u7f16\u7a0b\u8bed\u8a00\uff0c\u4e5f\u662f\u8ba1\u7b97\u673a\u552f\u4e00\u80fd\u8bc6\u522b\u7684\u8bed\u8a00\u3002\u4e0a\u56fe\u5c55\u793a\u4e86\u4e16\u754c\u4e0a\u7b2c\u4e00\u4e2a\u8ba1\u7b97\u673a\u7a0b\u5e8f\uff0c\u5b83\u7528\u6765\u627e\u51fa\u4e00\u4e2a\u6570\u6700\u5927\u7684\u56e0\u6570\u3002

\u6c47\u7f16\u8bed\u8a00 Assembly Language

\u8fd9\u662f\u7b2c\u4e8c\u4ee3\u7f16\u7a0b\u8bed\u8a00\uff0c\u5176\u5b9e\u5c31\u662f\u673a\u5668\u8bed\u8a00\u7684\u52a9\u8bb0\u7b26\u3002\u5b83\u4f7f\u5f97\u7a0b\u5e8f\u5458\u4e0d\u7528\u518d\u76f4\u63a5\u4e0e 0 \u548c 1 \u6253\u4ea4\u9053\uff0c\u7a0b\u5e8f\u7684\u53ef\u8bfb\u6027\u4e5f\u66f4\u5f3a\u4e86\u3002\u4e0a\u56fe\u663e\u793a\u4e86\u5c06\u4e24\u4e2a\u6574\u6570\u76f8\u52a0\u7684\u6c47\u7f16\u4ee3\u7801\u3002

\u9ad8\u7ea7\u8bed\u8a00 High-level Language

\u8fd9\u662f\u7b2c\u4e09\u4ee3\u7f16\u7a0b\u8bed\u8a00\uff0c\u5b83\u8ba9\u7a0b\u5e8f\u5458\u4eec\u4e0d\u7528\u518d\u5173\u6ce8\u8ba1\u7b97\u673a\u7ed3\u6784\u4e0a\u7684\u7ec6\u8282\uff0c\u800c\u662f\u5c06\u6ce8\u610f\u529b\u8f6c\u79fb\u5230\u8981\u89e3\u51b3\u7684\u95ee\u9898\u4e0a\u6765\u3002

\u4e0b\u9762\u4e09\u884c\u4ee3\u7801\u5206\u522b\u662f\u7528 C \u8bed\u8a00\u3001\u6c47\u7f16\u8bed\u8a00\u548c\u673a\u5668\u8bed\u8a00\uff08\u5341\u516d\u8fdb\u5236\uff09\u63cf\u8ff0\u7684\u540c\u4e00\u4ef6\u4e8b\uff1a

\u7b80\u5355\u7684\u4f8b\u5b50\u590d\u6742\u7684\u4f8b\u5b50
c = a + b;\n
add $t0, $t1, $t2\n
01 2a 40 20\n
void multstore(long x, long y, long *dest) {\n    long t = mult2(x, y);\n    *dest = t;\n}\n
multstore:\n    pushq   %rbx\n    movq    %rdx, %rbx\n    call    mult2\n    movq    %rax, (%rbx)\n    popq    %rbx\n    ret\n
53 48 89 d3 48 83 ec 08 e8 00 00 00 00 48 89 03 5b c3\n
\u4e3a\u4ec0\u4e48\u9700\u8981\u9ad8\u7ea7\u8bed\u8a00\uff1f
  1. \u673a\u5668\u8bed\u8a00\u548c\u6c47\u7f16\u8bed\u8a00\u90fd\u662f\u975e\u5e38\u5e95\u5c42\u7684\u8bed\u8a00\uff0c\u7a0b\u5e8f\u5458\u9700\u8981\u5173\u6ce8\u8ba1\u7b97\u673a\u7684\u7ec6\u8282\uff0c\u8fd9\u4f7f\u5f97\u7a0b\u5e8f\u7684\u53ef\u8bfb\u6027\u5f88\u5dee\u3002\u4f7f\u7528\u9ad8\u7ea7\u8bed\u8a00\uff0c\u7a0b\u5e8f\u5458\u80fd\u5c06\u6ce8\u610f\u529b\u8f6c\u79fb\u5230\u8981\u89e3\u51b3\u7684\u95ee\u9898\u4e0a\u6765\u3002
  2. \u673a\u5668\u8bed\u8a00\u548c\u6c47\u7f16\u8bed\u8a00\u90fd\u662f\u4e0e\u5177\u4f53 CPU \u76f8\u5173\u7684\uff0c\u7a0b\u5e8f\u5458\u9700\u8981\u4e3a\u4e0d\u540c\u7684 CPU \u7f16\u5199\u4e0d\u540c\u7684\u7a0b\u5e8f\uff0c\u53ef\u79fb\u690d\u6027\u5dee\u3002\u4f7f\u7528\u9ad8\u7ea7\u8bed\u8a00\uff0c\u7a0b\u5e8f\u5458\u53ea\u9700\u8981\u5199\u4e00\u6b21\u7a0b\u5e8f\uff0c\u518d\u4f7f\u7528\u7f16\u8bd1\u5668\u5c31\u80fd\u5c06\u5176\u7ffb\u8bd1\u6210\u80fd\u5728\u7279\u5b9a CPU \u7684\u673a\u5668\u8bed\u8a00\u3002
\u524d\u77bb\uff1a\u7b2c\u56db\u4ee3\u548c\u7b2c\u4e94\u4ee3\u7f16\u7a0b\u8bed\u8a00

\u7f16\u7a0b\u8bed\u8a00\u4ecd\u5728\u53d1\u5c55\u6f14\u5316\u3002\u76ee\u524d\u5df2\u7ecf\u6709\u4e86\u7b2c\u56db\u4ee3\u548c\u7b2c\u4e94\u4ee3\u7f16\u7a0b\u8bed\u8a00\u7684\u6982\u5ff5\u3002\u7b2c\u4e09\u4ee3\u7684\u7f16\u7a0b\u8bed\u8a00\u867d\u7136\u662f\u7528\u8bed\u53e5\u7f16\u7a0b\u800c\u4e0d\u76f4\u63a5\u7528\u6307\u4ee4\u7f16\u7a0b\uff0c\u4f46\u8bed\u53e5\u4e5f\u5206\u4e3a\u8f93\u5165\u3001\u8f93\u51fa\u3001\u57fa\u672c\u8fd0\u7b97\u3001\u6d4b\u8bd5\u5206\u652f\u548c\u5faa\u73af\u7b49\u51e0\u79cd\uff0c\u548c\u6307\u4ee4\u6709\u76f4\u63a5\u7684\u5bf9\u5e94\u5173\u7cfb\u3002\u800c\u7b2c\u56db\u4ee3\u4ee5\u540e\u7684\u7f16\u7a0b\u8bed\u8a00\u66f4\u591a\u662f\u63cf\u8ff0\u8981\u505a\u4ec0\u4e48\uff08Declarative\uff09\u800c\u4e0d\u63cf\u8ff0\u5177\u4f53\u4e00\u6b65\u4e00\u6b65\u600e\u4e48\u505a\uff08Imperative\uff09\uff0c\u5177\u4f53\u4e00\u6b65\u4e00\u6b65\u600e\u4e48\u505a\u5b8c\u5168\u7531\u7f16\u8bd1\u5668\u6216\u89e3\u91ca\u5668\u51b3\u5b9a\uff0c\u4f8b\u5982SQL\u8bed\u8a00\uff08SQL\uff0cStructured Query Language\uff0c\u7ed3\u6784\u5316\u67e5\u8be2\u8bed\u8a00\uff09\u5c31\u662f\u8fd9\u6837\u7684\u4f8b\u5b50\u3002

\u5bf9\u673a\u5668\u8bed\u8a00\u6709\u5174\u8da3\uff1f

\u8fd9\u91cc\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5c06\u6c47\u7f16\u8bed\u8a00\u8f6c\u6362\u4e3a MIPS \u6307\u4ee4\u96c6\u673a\u5668\u8bed\u8a00\u7684\u57fa\u7840\u4f8b\u5b50\uff0c\u6709\u5174\u8da3\u53ef\u4ee5\u4e86\u89e3\u4e00\u4e0b\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_6","title":"\u7a0b\u5e8f\u7684\u57fa\u672c\u8bed\u6cd5\u7ed3\u6784","text":"

\u7ecf\u8fc7\u4e86 2-3 \u5468\u8bfe\u7a0b\u7684\u5b66\u4e60\uff0c\u76f8\u4fe1\u540c\u5b66\u4eec\u591a\u5c11\u90fd\u5199\u8fc7\u4e86\u4e00\u4e9b\u4ee3\u7801\uff0c\u5bf9\u8bed\u8a00\u6709\u4e86\u4e00\u4e9b\u57fa\u672c\u8ba4\u8bc6\u3002\u672c\u8282\u5c06\u7cfb\u7edf\u5730\u68b3\u7406\u7a0b\u5e8f\u7684\u8bed\u6cd5\u548c\u7ed3\u6784\u77e5\u8bc6\uff0c\u5e2e\u52a9\u5927\u5bb6\u7406\u6e05\u601d\u8def\uff0c\u4e3a\u540e\u7eed\u7406\u89e3\u7a0b\u5e8f\u7f16\u8bd1\u8fc7\u7a0b\u548c\u8c03\u8bd5\u6280\u672f\u4f5c\u94fa\u57ab\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_7","title":"\u5199\u7a0b\u5e8f\u7684\u76ee\u6807\u662f\u4ec0\u4e48\uff1f","text":"

\u4ece\u6839\u672c\u4e0a\u8bf4\uff0c\u8ba1\u7b97\u673a\u662f\u7531\u6570\u5b57\u7535\u8def\u7ec4\u6210\u7684\u8fd0\u7b97\u673a\u5668\uff0c\u53ea\u80fd\u5bf9\u6570\u5b57\u505a\u8fd0\u7b97\uff0c\u7a0b\u5e8f\u4e4b\u6240\u4ee5\u80fd\u505a\u7b26\u53f7\u8fd0\u7b97\uff0c\u662f\u56e0\u4e3a\u7b26\u53f7\u5728\u8ba1\u7b97\u673a\u5185\u90e8\u4e5f\u662f\u7528\u6570\u5b57\u8868\u793a\u7684\u3002\u6b64\u5916\uff0c\u7a0b\u5e8f\u8fd8\u53ef\u4ee5\u5904\u7406\u58f0\u97f3\u548c\u56fe\u50cf\uff0c\u58f0\u97f3\u548c\u56fe\u50cf\u5728\u8ba1\u7b97\u673a\u5185\u90e8\u5fc5\u7136\u4e5f\u662f\u7528\u6570\u5b57\u8868\u793a\u7684\uff0c\u8fd9\u4e9b\u6570\u5b57\u7ecf\u8fc7\u4e13\u95e8\u7684\u786c\u4ef6\u8bbe\u5907\u8f6c\u6362\u6210\u4eba\u53ef\u4ee5\u542c\u5230\u3001\u770b\u5230\u7684\u58f0\u97f3\u548c\u56fe\u50cf\u3002

\u7a0b\u5e8f\u7531\u4e00\u7cfb\u5217\u6307\u4ee4\uff08Instruction\uff09\u7ec4\u6210\uff0c\u6307\u4ee4\u662f\u6307\u793a\u8ba1\u7b97\u673a\u505a\u67d0\u79cd\u8fd0\u7b97\u7684\u547d\u4ee4\uff0c\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u51e0\u7c7b\uff1a

\u5bf9\u4e8e\u7a0b\u5e8f\u6765\u8bf4\uff0c\u6709\u4e0a\u9762\u8fd9\u51e0\u7c7b\u6307\u4ee4\u5c31\u8db3\u591f\u4e86\u3002\u4f60\u66fe\u7528\u8fc7\u7684\u4efb\u4f55\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u4e0d\u7ba1\u5b83\u6709\u591a\u4e48\u590d\u6742\uff0c\u90fd\u662f\u7531\u8fd9\u51e0\u7c7b\u6307\u4ee4\u7ec4\u6210\u7684\u3002\u7a0b\u5e8f\u662f\u90a3\u4e48\u7684\u590d\u6742\uff0c\u800c\u7f16\u5199\u7a0b\u5e8f\u53ef\u4ee5\u7528\u7684\u6307\u4ee4\u5374\u53ea\u6709\u8fd9\u4e48\u7b80\u5355\u7684\u51e0\u79cd\uff0c\u8fd9\u4e2d\u95f4\u5de8\u5927\u7684\u843d\u5dee\u5c31\u8981\u7531\u7a0b\u5e8f\u5458\u53bb\u586b\u4e86\uff0c\u6240\u4ee5\u7f16\u5199\u7a0b\u5e8f\u7406\u5e94\u662f\u4e00\u4ef6\u76f8\u5f53\u590d\u6742\u7684\u5de5\u4f5c\u3002\u7f16\u5199\u7a0b\u5e8f\u53ef\u4ee5\u8bf4\u5c31\u662f\u8fd9\u6837\u4e00\u4e2a\u8fc7\u7a0b\uff1a\u628a\u590d\u6742\u7684\u4efb\u52a1\u5206\u89e3\u6210\u5b50\u4efb\u52a1\uff0c\u628a\u5b50\u4efb\u52a1\u518d\u5206\u89e3\u6210\u66f4\u7b80\u5355\u7684\u4efb\u52a1\uff0c\u5c42\u5c42\u5206\u89e3\uff0c\u76f4\u5230\u6700\u540e\u7b80\u5355\u5f97\u53ef\u4ee5\u7528\u4ee5\u4e0a\u6307\u4ee4\u6765\u5b8c\u6210\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_8","title":"\u8bcd\u6cd5\u548c\u8bed\u6cd5\u89c4\u5219","text":"

\u8bcd\u6cd5\uff08Lexical\uff09\u548c\u8bed\u6cd5\uff08Syntax\uff09\u662f\u7f16\u7a0b\u8bed\u8a00\u7684\u4e24\u4e2a\u57fa\u672c\u6982\u5ff5\u3002\u8bcd\u6cd5\u89c4\u5219\u5b9a\u4e49\u4e86\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u57fa\u672c\u7b26\u53f7\uff0c\u8bed\u6cd5\u89c4\u5219\u5b9a\u4e49\u4e86\u8fd9\u4e9b\u7b26\u53f7\u5982\u4f55\u7ec4\u6210\u5408\u6cd5\u7684\u8868\u8fbe\u5f0f\u3001\u8bed\u53e5\u548c\u7a0b\u5e8f\u3002

C \u7684\u8bcd\u6cd5\u89c4\u5219\uff1a\u8d2a\u5fc3\u6cd5

\u672f\u8bed token \uff08\u7b26\u53f7\uff09\u662f\u8bed\u8a00\u7684\u57fa\u672c\u8868\u610f\u5355\u5143\u3002\u5b57\u7b26\u7ec4\u6210\u7b26\u53f7\u3002\u4f8b\u5b50: ->\u3001file \u90fd\u662f\u7b26\u53f7\u3002\u540c\u4e00\u7ec4\u5b57\u7b26\u5e8f\u5217\u5728\u4e0d\u540c\u4e0a\u4e0b\u6587\u4e2d\u53ef\u80fd\u5c5e\u4e8e\u4e0d\u540c\u7b26\u53f7\u3002

\u5982\u679c\u8be5\u5b57\u7b26\u53ef\u80fd\u7ec4\u6210\u7b26\u53f7\uff0c\u90a3\u4e48\u518d\u8bfb\u5165\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff0c\u76f4\u5230\u8bfb\u5165\u7684\u5b57\u7b26\u4e32\u5df2\u7ecf\u4e0d\u53ef\u80fd\u518d\u7ec4\u6210\u4e00\u4e2a\u6709\u610f\u4e49\u7684\u7b26\u53f7\u3002

\u8bcd\u6cd5\u7ec3\u4e60\uff1a\u8bf7\u601d\u8003\u4e0b\u9762\u8fd9\u4e9b\u8868\u8fbe\u5f0f\u7684\u884c\u4e3a

\u70b9\u51fb\u300c+\u300d\u53f7\u5c55\u5f00\u7b54\u6848\u3002

a---b /*(1)!*/\na -- - b /*(2)!*/\na - -- b /*(3)!*/\n\n//\u4e0b\u9762\u7684 p \u6307\u5411\u9664\u6570\u3002\ny = x/*p     \n/*(4)!*/\ny = x / *p /*(5)!*/\n\nn-->0 /*(6)!*/\nn-- >0 /*(7)!*/\nn- -> 0 /*(8)!*/\n\na+++++b /*(9)!*/\n
  1. \u7b49\u4ef7\u4e8e (a--) - b\u3002\u6309\u7167\u8d2a\u5fc3\u6cd5\uff0c\u7f16\u8bd1\u5668\u8bfb\u5165\u4e24\u4e2a\u8fde\u7eed\u7684 - \u53f7\u540e\uff0c\u5df2\u7ecf\u4e0d\u53ef\u80fd\u518d\u7ec4\u6210\u4e00\u4e2a\u6709\u610f\u4e49\u7684\u7b26\u53f7\uff0c\u56e0\u6b64\u8fd9\u4e2a\u7b26\u53f7\u88ab\u786e\u5b9a\u4e3a\u540e\u7f00\u9012\u51cf\u8fd0\u7b97\u7b26\u3002\u63a5\u7740\u8bfb\u53d6\u4e0b\u4e00\u4e2a\u7b26\u53f7\u3002
  2. \u7b49\u4ef7\u4e8e (a--) - b
  3. \u7b49\u4ef7\u4e8e a - (--b)
  4. \u7b49\u4ef7\u4e8e y = x\u3002/* \u88ab\u8d2a\u5fc3\u6cd5\u89e3\u91ca\u4e3a\u6ce8\u91ca\u7684\u5f00\u5934\u3002
  5. \u7b49\u4ef7\u4e8e y = x / (*p)
  6. \u7b49\u4ef7\u4e8e (n--) > 0
  7. \u7b49\u4ef7\u4e8e (n--) > 0
  8. \u7b49\u4ef7\u4e8e (n-) -> 0\u3002\u8fd9\u662f\u4e00\u4e2a\u65e0\u6548\u7684\u8bed\u53e5\uff0cn- \u672c\u8eab\u4e0d\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u8868\u8fbe\u5f0f\uff0c\u4e5f\u65e0\u6cd5\u7528\u4f5c -> \u7684\u64cd\u4f5c\u6570\u3002
  9. \u7b49\u4ef7\u4e8e ((a++)++) + b\u3002\u8bf7\u601d\u8003\u4e00\u4e0b\uff0c\u8fd9\u4e2a\u8bed\u53e5\u6709\u6548\u5417\uff1f
\u8bed\u6cd5\uff1a\u6807\u8bc6\u7b26\u3001\u8868\u8fbe\u5f0f\u548c\u8bed\u53e5

\u4e3a\u4e86\u4fbf\u4e8e\u521d\u5b66\u8005\u7406\u89e3\uff0c\u6211\u4eec\u91c7\u7528\u4e00\u5957\u7b80\u5316\u7684\u8bed\u6cd5\u89c4\u5219\uff1a

\u5bf9\u8c61\u7684\u4e0d\u540c\u542b\u4e49

\u5728\u8fd9\u91cc\uff0c\u5bf9\u8c61\uff08Object\uff09\u7684\u542b\u4e49\u4e0e C++ \u4e2d\u4e0d\u540c\u3002\u8fd9\u91cc\u7684\u5bf9\u8c61\u6307\u6570\u636e\u5b58\u50a8\u7684\u4e00\u4e2a\u533a\u57df\uff0c\u5176\u5185\u5bb9\u53ef\u4ee5\u8868\u793a\u503c\u3002\u6bd4\u5982\u4e0b\u9762\u7684\u8bed\u53e5\u521b\u5efa\u4e86\u4e00\u4e2a\u5bf9\u8c61\uff1a

int a;\n

\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u7684\u610f\u601d\u5c31\u662f\u5206\u914d\u4e86\u4e00\u5757\u5b58\u50a8\u7a7a\u95f4\u3002\u6807\u8bc6\u7b26 a \u7528\u4e8e\u6307\u4ee3\u8fd9\u4e2a\u5bf9\u8c61\u3002\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u6709\u5927\u5c0f\u3001\u751f\u5b58\u671f\u3001\u5b58\u50a8\u5668\u3001\u503c\u7b49\u5c5e\u6027\uff0c\u6211\u4eec\u5c06\u5728\u4e0b\u8282\u8bfe\u8be6\u7ec6\u5c55\u5f00\u3002

\u5b8c\u6574\u7684 C \u8bed\u6cd5\u89c4\u5219\u8bf7\u53c2\u8003\uff1a

\u8bed\u6cd5\u5c06\u5728\u540e\u7eed\u8bfe\u7a0b\u4e2d\u4f5c\u6df1\u5165\u8bb2\u89e3\uff08\u7b2c 2 \u8bb2\u6d89\u53ca\u7c7b\u578b\u76f8\u5173\u7684\u8bed\u6cd5\uff0c\u7b2c 4 \u8bb2\u6d89\u53ca\u51fd\u6570\u6307\u9488\uff09\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#c","title":"\u51fd\u6570\uff1aC \u7a0b\u5e8f\u7684\u57fa\u672c\u6a21\u5757","text":"

\u300c\u6307\u4ee4\u300d\u662f\u7b2c\u4e00\u3001\u4e8c\u4ee3\u7f16\u7a0b\u8bed\u8a00\u7684\u57fa\u672c\u7ed3\u6784\u3002C \u8bed\u8a00\u662f\u9762\u5411\u8fc7\u7a0b\u7684\u9ad8\u7ea7\u8bed\u8a00\uff0c\u5b83\u7684\u57fa\u672c\u6a21\u5757\u662f\u51fd\u6570\uff08Function\uff09\u3002

\u5173\u952e\u6982\u5ff5\uff1a\u51fd\u6570

\u4ece\u5916\u9762\u770b\uff0c\u51fd\u6570\u5c31\u50cf\u4e00\u4e2a\u9ed1\u76d2\u5b50\uff0c\u53ea\u80fd\u770b\u5230\u51fd\u6570\u7684\u4e09\u5927\u8981\u7d20\uff1a

\u4e0b\u9762\u8fd9\u884c\u8bed\u53e5\u88ab\u79f0\u4e3a\u51fd\u6570\u7b7e\u540d\uff08Function Signature\uff09\u6216\u51fd\u6570\u539f\u578b\uff08Function Prototype\uff09\u3002\u5b83\u7ed9\u51fa\u4e86\u51fd\u6570\u5bf9\u5916\u7684\u4e00\u5207\u4fe1\u606f\uff1a

int MyFunc(int a, int b);\n

\u4ece\u91cc\u9762\u770b\uff0c\u51fd\u6570\u662f\u4e00\u7ec4\u6307\u4ee4\u7684\u96c6\u5408\uff0c\u5b83\u4eec\u6309\u7167\u4e00\u5b9a\u7684\u987a\u5e8f\u6267\u884c\uff0c\u5b8c\u6210\u67d0\u4e2a\u7279\u5b9a\u7684\u529f\u80fd\u3002

\u5f53\u6211\u4eec\u8c03\u7528\u4e00\u4e2a\u51fd\u6570\u65f6\uff0c\u6211\u4eec\u5e94\u5f53\u6309\u7167\u51fd\u6570\u7b7e\u540d\u4e2d\u7684\u8981\u6c42\u4f20\u5165\u53c2\u6570\uff0c\u5e76\u53ef\u4ee5\u83b7\u5f97\u5b83\u7684\u8fd4\u56de\u503c\u3002\u5728\u51fd\u6570\u7b7e\u540d\u7684\u8bed\u5883\u4e0b\uff0cvoid \u8868\u793a\u7a7a\uff0c\u5373\u4e0d\u5b58\u5728\u3002\u4e0b\u9762\u7684\u8fd9\u4e2a\u51fd\u6570\u6ca1\u6709\u53c2\u6570\uff0c\u4e5f\u6ca1\u6709\u8fd4\u56de\u503c\u3002

void MyFunc(void);\n

\u56e0\u4e3a\u6211\u4eec\u6bd4\u8f83\u5173\u5fc3\u51fd\u6570\u8fd4\u56de\u503c\u7684\u7c7b\u578b\uff0c\u6709\u65f6\u4f1a\u628a\u51fd\u6570\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u79f0\u4e3a\u8fd9\u4e2a\u51fd\u6570\u7684\u201c\u7c7b\u578b\u201d\uff0c\u6bd4\u5982\u4f1a\u8bf4 MyFunc \u8fd9\u4e2a\u51fd\u6570\u662f\u4e00\u4e2a void \u51fd\u6570\u3002

\u5173\u4e8e void

Q\uff1avoid \u5230\u5e95\u6709\u54ea\u4e9b\u542b\u4e49\uff1f

A: \u4e0b\u9762\u662f void \u7684\u4e00\u822c\u7528\u6cd5

\u4ece\u8fd9\u4e9b\u7528\u6cd5\u6765\u770b\uff0c\u4f3c\u4e4e void \u662f\u4e00\u79cd\u7c7b\u578b\uff0c\u4f46\u8fd9\u4f1a\u5f15\u8d77\u4e0b\u9762\u95ee\u9898\u4e2d\u7684\u77db\u76fe\u3002\u53e6\u4e00\u79cd\u770b\u5f85\u65b9\u5f0f\u662f\uff1a\u4e0a\u9762\u7684\u7528\u6cd5\u90fd\u662f\u7279\u6b8a\u7684\u8bed\u6cd5\uff0c\u4e0d\u8fc7\u662f\u6070\u597d\u7528\u4e86\u540c\u4e00\u4e2a\u5173\u952e\u5b57 void \u7f62\u4e86\u3002

Q\uff1a\u6240\u4ee5 void \u662f\u4e00\u79cd\u7c7b\u578b\u5417\uff1f

A\uff1aC \u6807\u51c6\u4ece\u6982\u5ff5\u4e0a\u5c06 void \u4f5c\u4e3a\u4e00\u79cd\u7c7b\u578b\u3002\u4f46\u662f void \u7c7b\u578b\u7684\u53d8\u91cf\u662f\u4e0d\u5b58\u5728\u7684\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u5927\u5c0f\uff0c\u7f16\u8bd1\u5668\u4e5f\u4e0d\u5141\u8bb8\u4f60\u5199\u4e0b void a;\u3002\u8fd9\u4f1a\u5f15\u8d77\u4e00\u4e9b\u56f0\u60d1\u3002

\u51fd\u6570\u6709\u4e24\u4e2a\u529f\u80fd\uff1a

\u4e00\u4e9b\u4f8b\u5b50\uff1a

\u51fd\u6570\u7b7e\u540d \u8fd4\u56de\u503c\u7684\u542b\u4e49 \u526f\u4f5c\u7528 int printf(const char *format, ...); \u6253\u5370\u7684\u5b57\u7b26\u6570 \u6253\u5370\u5b57\u7b26\u4e32\u5230\u6807\u51c6\u8f93\u51fa int scanf(const char *format, ...); \u8bfb\u53d6\u7684\u5b57\u7b26\u6570 \u4ece\u6807\u51c6\u8f93\u5165\u8bfb\u53d6\u5b57\u7b26\u4e32 int rand(void); \u751f\u6210\u7684\u968f\u673a\u6570 \u65e0 void exit(int status); \u65e0 \u9000\u51fa\u7a0b\u5e8f

\u6bcf\u4e2a C \u8bed\u8a00\u7a0b\u5e8f\u90fd\u5fc5\u987b\u5305\u542b\u4e00\u4e2a main \u51fd\u6570\uff0c\u5b83\u662f\u7a0b\u5e8f\u7684\u5165\u53e3\u3002main \u7684\u51fd\u6570\u7b7e\u540d\u4e00\u822c\u662f\u8fd9\u6837\u7684\uff1a

int main(void);\nint main(int argc, char *argv[]); //\u4ee5\u540e\u5b66\u547d\u4ee4\u884c\u53c2\u6570\u5c31\u4f1a\u7528\u5230\u8fd9\u79cd\u5f62\u5f0f\n

main \u7684\u8c03\u7528\u8005\u662f\u64cd\u4f5c\u7cfb\u7edf\u3002\u64cd\u4f5c\u7cfb\u7edf\u770b\u5230 main \u7684\u7b7e\u540d\u4e2d\u8bf4\u8fd4\u56de\u503c\u4e3a int\uff0c\u56e0\u6b64\u7cfb\u7edf\u4f1a\u7b49\u5f85 main \u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u3002\u8fd9\u4e2a\u6574\u6570\u4e00\u822c\u88ab\u7528\u4e8e\u544a\u77e5\u64cd\u4f5c\u7cfb\u7edf\u7a0b\u5e8f\u7684\u6267\u884c\u72b6\u6001\uff0c0 \u8868\u793a\u6b63\u5e38\u7ed3\u675f\uff0c\u5176\u4ed6\u503c\u53ef\u4ee5\u4f20\u9012\u5176\u4ed6\u4fe1\u606f\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48 main \u7684\u672b\u5c3e\u5e94\u5f53\u5199 return 0\u3002\u5982\u679c main \u51fd\u6570\u4e2d\u6ca1\u6709 return \u8bed\u53e5\uff0c\u6709\u4e9b\u7f16\u8bd1\u5668\u4f1a\u4e3a\u4f60\u8865\u5168\uff08\u5176\u4ed6\u51fd\u6570\u4e0d\u4f1a\uff09\u3002\u4f46\u8bf7\u8bb0\u5f97\u5199\u4e0a\uff0c\u8fd9\u662f\u4f60\u7684\u8d23\u4efb\u3002

\u6ca1\u6709\u8fd4\u56de\u503c\u7684\u51fd\u6570\u4e5f\u53ef\u4ee5\u4f7f\u7528 return \u8bed\u53e5\uff0c\u6b64\u65f6\u5b83\u6ca1\u6709\u8fd4\u56de\u503c\u7684\u4f5c\u7528\uff0c\u800c\u662f\u7ed3\u675f\u5f53\u524d\u51fd\u6570\u7684\u6267\u884c\u5e76\u8fd4\u56de\u3002\u4f8b\u5b50\uff1a

void print_logarithm(double x)\n{\n if (x <= 0.0) {\n  printf(\"Positive numbers only, please.\\n\");\n  return;\n }\n printf(\"The log of x is %f\", log(x));\n}\n
\u5176\u4ed6\u5efa\u8bae

\u6bcf\u4e2a\u51fd\u6570\u90fd\u5e94\u8be5\u8bbe\u8ba1\u5f97\u5c3d\u53ef\u80fd\u7b80\u5355\uff0c\u7b80\u5355\u7684\u51fd\u6570\u624d\u5bb9\u6613\u7ef4\u62a4\u3002\u5e94\u9075\u5faa\u4ee5\u4e0b\u539f\u5219\uff1a

  1. \u5b9e\u73b0\u4e00\u4e2a\u51fd\u6570\u53ea\u662f\u4e3a\u4e86\u505a\u597d\u4e00\u4ef6\u4e8b\u60c5\uff0c\u4e0d\u8981\u628a\u51fd\u6570\u8bbe\u8ba1\u6210\u7528\u9014\u5e7f\u6cdb\u3001\u9762\u9762\u4ff1\u5230\u7684\uff0c\u8fd9\u6837\u7684\u51fd\u6570\u80af\u5b9a\u4f1a\u8d85\u957f\uff0c\u800c\u4e14\u5f80\u5f80\u4e0d\u53ef\u91cd\u7528\uff0c\u7ef4\u62a4\u56f0\u96be\u3002

  2. \u51fd\u6570\u5185\u90e8\u7684\u7f29\u8fdb\u5c42\u6b21\u4e0d\u5b9c\u8fc7\u591a\uff0c\u4e00\u822c\u4ee5\u5c11\u4e8e 4 \u5c42\u4e3a\u5b9c\u3002\u5982\u679c\u7f29\u8fdb\u5c42\u6b21\u592a\u591a\u5c31\u8bf4\u660e\u8bbe\u8ba1\u5f97\u592a\u590d\u6742\u4e86\uff0c\u5e94\u8003\u8651\u5206\u5272\u6210\u66f4\u5c0f\u7684\u51fd\u6570\uff08Helper Function\uff09\u6765\u8c03\u7528\u3002

  3. \u51fd\u6570\u4e0d\u8981\u5199\u5f97\u592a\u957f\uff0c\u5efa\u8bae\u5728 24 \u884c\u7684\u6807\u51c6\u7ec8\u7aef\u4e0a\u4e0d\u8d85\u8fc7\u4e24\u5c4f\uff0c\u592a\u957f\u4f1a\u9020\u6210\u9605\u8bfb\u56f0\u96be\uff0c\u5982\u679c\u4e00\u4e2a\u51fd\u6570\u8d85\u8fc7\u4e24\u5c4f\u5c31\u5e94\u8be5\u8003\u8651\u5206\u5272\u51fd\u6570\u4e86\u3002[CodingStyle]\u4e2d\u7279\u522b\u8bf4\u660e\uff0c\u5982\u679c\u4e00\u4e2a\u51fd\u6570\u5728\u6982\u5ff5\u4e0a\u662f\u7b80\u5355\u7684\uff0c\u53ea\u662f\u957f\u5ea6\u5f88\u957f\uff0c\u8fd9\u5012\u6ca1\u5173\u7cfb\u3002\u4f8b\u5982\u51fd\u6570\u7531\u4e00\u4e2a\u5927\u7684 switch \u7ec4\u6210\uff0c\u5176\u4e2d\u6709\u975e\u5e38\u591a\u7684 case\uff0c\u8fd9\u662f\u53ef\u4ee5\u7684\uff0c\u56e0\u4e3a\u5404 case \u5206\u652f\u4e92\u4e0d\u5f71\u54cd\uff0c\u6574\u4e2a\u51fd\u6570\u7684\u590d\u6742\u5ea6\u53ea\u7b49\u4e8e\u5176\u4e2d\u4e00\u4e2a case \u7684\u590d\u6742\u5ea6\uff0c\u8fd9\u79cd\u60c5\u51b5\u5f88\u5e38\u89c1\uff0c\u4f8b\u5982 TCP \u534f\u8bae\u7684\u72b6\u6001\u673a\u5b9e\u73b0\u3002

  4. \u6267\u884c\u51fd\u6570\u5c31\u662f\u6267\u884c\u4e00\u4e2a\u52a8\u4f5c\uff0c\u51fd\u6570\u540d\u901a\u5e38\u5e94\u5305\u542b\u52a8\u8bcd\uff0c\u4f8b\u5982 get_current\u3001radix_tree_insert\u3002

  5. \u6bd4\u8f83\u91cd\u8981\u7684\u51fd\u6570\u5b9a\u4e49\u4e0a\u4fa7\u5fc5\u987b\u52a0\u6ce8\u91ca\uff0c\u8bf4\u660e\u6b64\u51fd\u6570\u7684\u529f\u80fd\u3001\u53c2\u6570\u3001\u8fd4\u56de\u503c\u3001\u9519\u8bef\u7801\u7b49\u3002

  6. \u53e6\u4e00\u79cd\u5ea6\u91cf\u51fd\u6570\u590d\u6742\u5ea6\u7684\u529e\u6cd5\u662f\u770b\u6709\u591a\u5c11\u4e2a\u5c40\u90e8\u53d8\u91cf\uff0c5 \u5230 10 \u4e2a\u5c40\u90e8\u53d8\u91cf\u5df2\u7ecf\u5f88\u591a\u4e86\uff0c\u518d\u591a\u5c31\u5f88\u96be\u7ef4\u62a4\u4e86\uff0c\u5e94\u8be5\u8003\u8651\u5206\u5272\u6210\u591a\u4e2a\u51fd\u6570\u3002

\u6269\u5c55\uff1a\u7f16\u8bd1\u548c\u89e3\u91ca

\u7b80\u5355\u4e86\u89e3\u4e00\u4e0b\u5c31\u597d\u3002

\u5c06\u9ad8\u7ea7\u8bed\u8a00\u7f16\u5199\u7684\u6e90\u4ee3\u7801\u8f6c\u5316\u6210\u673a\u5668\u8bed\u8a00\u7684\u76ee\u6807\u7a0b\u5e8f\u7684\u8fc7\u7a0b\u7edf\u79f0\u4e3a\u7ffb\u8bd1\uff08Translation\uff09\u3002\u7ffb\u8bd1\u7684\u65b9\u5f0f\u6709\u4e24\u79cd\uff1a\u7f16\u8bd1\uff08Compile\uff09\u548c\u89e3\u91ca\uff08Interpret\uff09\u3002\u7f16\u8bd1\u5c06\u6574\u4e2a\u7a0b\u5e8f\u7ffb\u8bd1\u6210\u673a\u5668\u8bed\u8a00\uff0c\u89e3\u91ca\u5219\u662f\u8fb9\u7ffb\u8bd1\u8fb9\u6267\u884c\u3002

C \u8bed\u8a00\u662f\u5178\u578b\u7684\u7f16\u8bd1\u578b\u8bed\u8a00\uff0c\u6e90\u4ee3\u7801\u9700\u8981\u7ecf\u8fc7\u7f16\u8bd1\u540e\u624d\u80fd\u8fd0\u884c\uff0c\u800c\u7f16\u8bd1\u9636\u6bb5\u5e76\u4e0d\u4f1a\u6267\u884c\u7a0b\u5e8f\u3002Python \u5219\u662f\u5178\u578b\u7684\u89e3\u91ca\u578b\u8bed\u8a00\uff0c\u9010\u53e5\u6267\u884c\u6e90\u4ee3\u7801\uff0c\u4e0d\u9700\u8981\u4ea7\u751f\u53ef\u6267\u884c\u6587\u4ef6\u3002

\u8fd9\u4e9b\u63cf\u8ff0\u7684\u90fd\u662f\u4e00\u79cd\u8bed\u8a00\u7684\u5178\u578b\u7528\u6cd5\u3002\u4e8b\u5b9e\u4e0a C \u8bed\u8a00\u4e5f\u5f00\u53d1\u51fa\u4e86\u76f8\u5e94\u7684\u89e3\u91ca\u5668\uff0cPython \u4e5f\u5f00\u53d1\u51fa\u4e86\u76f8\u5e94\u7684\u7f16\u8bd1\u5668\u3002\u4e24\u79cd\u7ffb\u8bd1\u65b9\u5f0f\u5404\u6709\u4f18\u52a3\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_9","title":"\u73b0\u5728\u4f60\u662f\u7f16\u8bd1\u5668","text":"

\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u5316\u8eab C \u8bed\u8a00\u7f16\u8bd1\u5668\uff0c\u89e3\u8bfb\u4e00\u4e9b\u4ee3\u7801\u3002\u76f8\u4fe1\u7ecf\u8fc7\u4e0b\u9762\u7684\u8bad\u7ec3\uff0c\u4f60\u5bf9\u4ee3\u7801\u548c\u7a0b\u5e8f\u6267\u884c\u7684\u7406\u89e3\u4f1a\u66f4\u52a0\u6df1\u5165\u3002

\u4f8b\u5b50\uff1a\u8bed\u6cd5\u6811
printf(\"%d:%d is %d minutes after 00:00\\n\", hour, minute, hour * 60 + minute);\n

\u7f16\u8bd1\u5668\u5728\u7ffb\u8bd1\u8fd9\u6761\u8bed\u53e5\u65f6\uff0c\u9996\u5148\u6839\u636e\u4e0a\u8ff0\u8bed\u6cd5\u89c4\u5219\u628a\u8fd9\u4e2a\u8bed\u53e5\u89e3\u6790\u6210\u4e0b\u56fe\u6240\u793a\u7684\u8bed\u6cd5\u6811\uff0c\u7136\u540e\u518d\u6839\u636e\u8bed\u6cd5\u6811\u751f\u6210\u76f8\u5e94\u7684\u6307\u4ee4\u3002\u8bed\u6cd5\u6811\u7684\u672b\u7aef\u7684\u662f\u4e00\u4e2a\u4e2aToken\uff0c\u6bcf\u4e00\u6b65\u5c55\u5f00\u5229\u7528\u4e00\u6761\u8bed\u6cd5\u89c4\u5219\u3002

\u7406\u89e3\u7ec4\u5408\uff08Composition\uff09\u89c4\u5219\u662f\u7406\u89e3\u8bed\u6cd5\u89c4\u5219\u7684\u5173\u952e\u6240\u5728\uff0c\u6b63\u56e0\u4e3a\u53ef\u4ee5\u6839\u636e\u8bed\u6cd5\u89c4\u5219\u4efb\u610f\u7ec4\u5408\uff0c\u6211\u4eec\u624d\u53ef\u4ee5\u7528\u7b80\u5355\u7684\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u8868\u8fbe\u5f0f\u3001\u8bed\u53e5\u642d\u5efa\u51fa\u4efb\u610f\u590d\u6742\u7684\u7a0b\u5e8f\uff0c\u4ee5\u540e\u6211\u4eec\u5b66\u4e60\u65b0\u7684\u8bed\u6cd5\u89c4\u5219\u65f6\u4f1a\u8fdb\u4e00\u6b65\u4f53\u4f1a\u5230\u8fd9\u4e00\u70b9\u3002\u4ece\u4e0a\u9762\u7684\u4f8b\u5b50\u53ef\u4ee5\u770b\u51fa\uff0c\u8868\u8fbe\u5f0f\u4e0d\u5b9c\u8fc7\u5ea6\u7ec4\u5408\uff0c\u5426\u5219\u4f1a\u7ed9\u9605\u8bfb\u548c\u8c03\u8bd5\u5e26\u6765\u56f0\u96be\u3002

\u8868\u8fbe\u5f0f\u4e0d\u5b9c\u8fc7\u5ea6\u7ec4\u5408

\u8fd9\u6d89\u53ca\u4ee3\u7801\u53ef\u8bfb\u6027\u95ee\u9898\u3002\u770b\u770b\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\uff1a

double distance(double x1, double y1, double x2, double y2)\n{\n  return sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));\n}\n

\u8fd9\u6837\u5199\u5f88\u7b80\u6d01\uff0c\u4f46\u5982\u679c\u5199\u9519\u4e86\u5462\uff1f\u53ea\u77e5\u9053\u662f\u8fd9\u4e00\u957f\u4e32\u8868\u8fbe\u5f0f\u6709\u9519\uff0c\u6839\u672c\u4e0d\u77e5\u9053\u9519\u5728\u54ea\uff0c\u800c\u4e14\u6574\u4e2a\u51fd\u6570\u5c31\u4e00\u4e2a\u8bed\u53e5\uff0c\u63d2printf\u90fd\u6ca1\u5730\u65b9\u63d2\u3002\u6240\u4ee5\u7528\u4e34\u65f6\u53d8\u91cf\u6709\u5b83\u7684\u597d\u5904\uff0c\u4f7f\u7a0b\u5e8f\u66f4\u6e05\u6670\uff0c\u8c03\u8bd5\u66f4\u65b9\u4fbf\uff0c\u800c\u4e14\u6709\u65f6\u5019\u53ef\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\uff0c\u4f8b\u5982\u4e0a\u9762\u8fd9\u4e00\u884c\u8868\u8fbe\u5f0f\u8981\u628a(x2-x1)\u8ba1\u7b97\u4e24\u904d\uff0c\u5982\u679c\u7b97\u5b8c(x2-x1)\u628a\u7ed3\u679c\u5b58\u5728\u4e00\u4e2a\u4e34\u65f6\u53d8\u91cfdx\u91cc\uff0c\u5c31\u4e0d\u9700\u8981\u518d\u7b97\u7b2c\u4e8c\u904d\u4e86\uff08\u867d\u7136\u8fd9\u4e9b\u4f18\u5316\u73b0\u4ee3\u7f16\u8bd1\u5668\u90fd\u4f1a\u66ff\u4f60\u81ea\u52a8\u5b8c\u6210\uff09\u3002\u4e0b\u9762\u8fd9\u4e2a\u7248\u672c\u662f\u53ef\u8bfb\u6027\u9ad8\u7684\u4ee3\u7801\uff1a

double distance(double x1, double y1, double x2, double y2)\n{\n double dx = x2 - x1;\n double dy = y2 - y1;\n double dsquared = dx * dx + dy * dy;\n double result = sqrt(dsquared);\n\n return result;\n}\n

\u7801\u98ce\u4e0d\u662f\u6b7b\u7684\uff0c\u8bf7\u540c\u5b66\u4eec\u89c6\u60c5\u51b5\u5207\u6362\u7801\u98ce\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#lap","title":"Lap\uff1a\u5173\u4e8e\u505a\u9898\u76ee","text":"

\u5982\u679c\u60f3\u505a\u9898\u7684\u8bdd\uff0c\u6709\u57fa\u7840\u7684\u540c\u5b66\u53ef\u4ee5\u65e9\u70b9\u5f00\u59cb\u505a\u5386\u5e74\u5377\uff0c\u4e86\u89e3\u4e00\u4e0b\u7a0b\u8bbe\u8003\u8bd5\u90fd\u8003\u4e9b\u5565\u3002

\u7b80\u5355\u63d0\u4e00\u4e9b Tips\uff1a

\u5e72\u788e\u4e00\u7247\u4eba\u7684\u9009\u62e9\u9898

Suppose T is a type name and t is a variable of type T. Which of the following is NOT a valid expression?

A. sizeof(T) B. sizeof(t) C. sizeof T D. sizeof t

\u7b54\u6848

\u7b54\u6848\u662f C\uff0c\u4e0d\u77e5\u9053\u4f60\u731c\u5bf9\u4e86\u5417\uff1f

\u5927\u5bb6\u4e00\u822c\u5199\u4ee3\u7801 sizeof \u540e\u9762\u90fd\u4f1a\u52a0\u62ec\u53f7\u7684\u5bf9\u5427\uff0c\u4f46\u4f60\u77e5\u9053\u4e3a\u4ec0\u4e48\u5417\uff1f\u60f3\u8981\u77e5\u9053\u4e3a\u4ec0\u4e48\uff0c\u9700\u8981\u56de\u987e\u524d\u9762\u5b66\u4e60\u7684\u8bed\u6cd5\u77e5\u8bc6\u3002

sizeof \u662f\u4e00\u4e2a\u8fd0\u7b97\u7b26\uff0c\u5b83\u6709\u4e24\u79cd\u4f7f\u7528\u65b9\u5f0f\uff1a

sizeof(\u7c7b\u578b)\nsizeof \u8868\u8fbe\u5f0f\n

\u6211\u4eec\u77e5\u9053\uff0ct \u662f\u8868\u8fbe\u5f0f\uff0c(t) \u4e5f\u662f\u8868\u8fbe\u5f0f\u3002sizeof(T) \u7684\u4f7f\u7528\u7b26\u5408\u89c4\u8303\u3002\u56e0\u6b64 A\u3001B\u3001D \u90fd\u662f\u6b63\u786e\u7684\u3002\u4e3a\u4ec0\u4e48\u4e0d\u89c4\u5b9a sizeof \u7c7b\u578b \u7684\u7528\u6cd5\u5462\uff1f\u56e0\u4e3a\u8fd9\u53ef\u80fd\u5f15\u8d77\u6b67\u4e49\uff0c\u6709\u4e9b\u7c7b\u578b\u540d\u5c31\u643a\u5e26\u7a7a\u683c\uff0c\u6bd4\u5982\uff1ashort int\u3001struct node \u7b49\u7b49\u3002\u4e86\u89e3\u4e86\u8fd9\u4e9b\u77e5\u8bc6\uff0c\u4f60\u80fd\u8bf4\u8bf4\u4e0b\u9762\u7684\u8bed\u53e5\u662f\u5426\u5408\u6cd5\u5417\uff1f\u5982\u679c\u5408\u6cd5\uff0c\u4f60\u80fd\u89e3\u91ca\u5b83\u7684\u542b\u4e49\u5417\uff1f\u5982\u679c\u4e0d\u89c4\u5b9a\u7c7b\u578b\u5fc5\u987b\u5e26\u62ec\u53f7\uff0c\u53ef\u80fd\u4f1a\u4ea7\u751f\u54ea\u4e9b\u4e8c\u4e49\u6027\uff1f

sizeof int***p\nsizeof(int)*p\nsizeof int * + 1\n

\u5982\u679c\u4f60\u60f3\u7684\u8bdd\uff0c\u53ef\u4ee5\u518d\u6765\u4e24\u9053\uff1a

C \u5927 16 \u5e74\u9009\u62e9\u9898

In the following notations, _____ can express a character constant( \u5b57\u7b26\u5e38\u91cf ) correctly.

A. '\\x100' B. 125 C. '\\08' D. '\\'

\u7b54\u6848

B

"},{"location":"programming/archive/23fall/lec1/lec1/#_10","title":"\u7a0b\u5e8f\u7684\u7f16\u8bd1\u8fc7\u7a0b","text":"

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u4e86\u89e3\u7f16\u8bd1\u5668\u548c\u6c47\u7f16\u5668\u662f\u5982\u4f55\u4e00\u6b65\u6b65\u628a\u4f60\u7684\u7a0b\u5e8f\u7f16\u8bd1\u6210\u673a\u5668\u7801\u7684\u3002\u6211\u4eec\u4ee5\u6700\u7ecf\u5178\u7684 C \u8bed\u8a00\u7f16\u8bd1\u7cfb\u7edf GCC \u4e3a\u4f8b\u3002

\u4ec0\u4e48\u662f GCC\uff1f

\u7b80\u5355\u5730\u8bf4\uff0cGNU \u9879\u76ee\u65e8\u5728\u5f00\u53d1\u4e00\u4e2a\u5b8c\u5168\u81ea\u7531\u7684\u64cd\u4f5c\u7cfb\u7edf\u4ee5\u53ca\u914d\u5957\u7684\u8f6f\u4ef6\u3002GCC \u6700\u65e9\u662f GNU C Compiler \u7684\u7b80\u79f0\uff0c\u73b0\u5728\u4ee3\u8868 GNU Compiler Collection\u3002\u8fd9\u8868\u660e\u5b83\u4e0d\u662f\u5355\u4e2a\u7a0b\u5e8f\uff0c\u800c\u662f\u4e00\u7cfb\u5217\u7f16\u8bd1\u5de5\u5177\u7684\u96c6\u5408\uff0c\u5305\u62ec\u4e86 C\u3001C++\u3001Objective-C\u3001Fortran\u3001Ada\u3001Go\u3001D \u7b49\u8bed\u8a00\u7684\u524d\u7aef\uff0c\u4ee5\u53ca\u6c47\u7f16\u5668\u3001\u94fe\u63a5\u5668\u7b49\u540e\u7aef\uff0c\u548c\u8fd9\u4e9b\u8bed\u8a00\u7684\u5e93\u6587\u4ef6\u3002

\u5f53\u6211\u4eec\u4f7f\u7528\u547d\u4ee4 gcc -o test test.c \u7f16\u8bd1\u4e00\u4e2a C \u8bed\u8a00\u7a0b\u5e8f\u65f6\uff0cGCC \u4f1a\u8c03\u7528\u4e00\u7cfb\u5217\u7684\u7a0b\u5e8f\u5c06\u6e90\u4ee3\u7801\u7ffb\u8bd1\u6210\u6c47\u7f16\u8bed\u8a00\u3001\u518d\u7ffb\u8bd1\u6210\u673a\u5668\u8bed\u8a00\uff0c\u6700\u540e\u7ecf\u8fc7\u94fe\u63a5\u4ea7\u751f\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4e0b\u56fe\u5c55\u793a\u4e86\u8fd9\u4e2a\u8fc7\u7a0b\u3002

  1. \u9884\u5904\u7406\uff1a\u7531 C \u9884\u5904\u7406\u5668\uff08C Preprocessor\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u6e90\u4ee3\u7801\u4e2d\u7684\u5b8f\u5b9a\u4e49\u5c55\u5f00\uff0c\u5c06\u5934\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u63d2\u5165\u5230\u6e90\u4ee3\u7801\u4e2d\uff0c\u5220\u9664\u6ce8\u91ca\u7b49\u3002\u9884\u5904\u7406\u540e\u7684\u4ee3\u7801\u6587\u4ef6\u4ee5 .i \u4e3a\u540e\u7f00\u3002
  2. \u7f16\u8bd1\uff1a\u7531 C \u7f16\u8bd1\u5668\uff08C Compiler\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u9884\u5904\u7406\u540e\u7684\u6587\u4ef6\u7ffb\u8bd1\u6210\u6c47\u7f16\u8bed\u8a00\u3002\u7f16\u8bd1\u540e\u5f97\u5230\u7684\u6c47\u7f16\u4ee3\u7801\u6587\u4ef6\u4ee5 .s \u4e3a\u540e\u7f00\u3002
  3. \u6c47\u7f16\uff1a\u7531\u6c47\u7f16\u5668\uff08Assembler\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u6c47\u7f16\u4ee3\u7801\u7ffb\u8bd1\u6210\u673a\u5668\u8bed\u8a00\u3002\u6c47\u7f16\u540e\u5f97\u5230\u7684\u673a\u5668\u4ee3\u7801\u6587\u4ef6\u4ee5 .o \u4e3a\u540e\u7f00\u3002
  4. \u94fe\u63a5\uff1a\u7531\u94fe\u63a5\u5668\uff08Linker\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u591a\u4e2a\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u94fe\u63a5\u540e\u5f97\u5230\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4ee5 .exe \u4e3a\u540e\u7f00\u3002
"},{"location":"programming/archive/23fall/lec1/lec1/#gcc","title":"\u89e3\u8bfb gcc \u663e\u793a\u7684\u8be6\u7ec6\u4fe1\u606f","text":"

\u4e0b\u9762\u8fd9\u4e9b\u6587\u672c\u662f gcc -v -o prog main.c sum.c \u547d\u4ee4\u7684\u8f93\u51fa\u7ed3\u679c\u3002

gcc \u7684\u8f93\u51fa\u4fe1\u606f

\u70b9\u51fb\u6587\u672c\u4e2d\u5e26\u5706\u5708\u7684 + \u53f7\u53ef\u4ee5\u5c55\u5f00\u8be6\u7ec6\u4fe1\u606f\uff0c\u9ad8\u4eae\u7684\u884c\u662f\u8fd0\u884c\u67d0\u4e2a\u7f16\u8bd1\u5de5\u5177\u7684\u5177\u4f53\u547d\u4ee4\u3002

<!--(1)!-->Using built-in specs.\nCOLLECT_GCC=gcc\nCOLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper\nOFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa\nOFFLOAD_TARGET_DEFAULT=1\nTarget: x86_64-linux-gnu\nConfigured with: ../src/configure -v --with-pkgversion='Ubuntu 12.3.0-1ubuntu1~23.04' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-12-DAPbBt/gcc-12-12.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-DAPbBt/gcc-12-12.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu\nThread model: posix\nSupported LTO compression algorithms: zlib zstd\ngcc version 12.3.0 (Ubuntu 12.3.0-1ubuntu1~23.04) \nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n<!--(2)!--> /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -quiet -v -imultiarch x86_64-linux-gnu main.c -quiet -dumpdir prog- -dumpbase main.c -dumpbase-ext .c -mtune=generic -march=x86-64 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/ccClT5M4.s\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nignoring nonexistent directory \"/usr/local/include/x86_64-linux-gnu\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/include-fixed\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include\"\n<!--(3)!-->#include \"...\" search starts here:\n#include <...> search starts here:\n /usr/lib/gcc/x86_64-linux-gnu/12/include\n /usr/local/include\n /usr/include/x86_64-linux-gnu\n /usr/include\nEnd of search list.\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nCompiler executable checksum: d9353c3f0a32d3e91a16ba312e2a9024\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n<!--(4)!--> as -v --64 -o /tmp/ccEgqpgY.o /tmp/ccClT5M4.s\nGNU assembler version 2.40 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.40\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n<!--(5)!--> /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -quiet -v -imultiarch x86_64-linux-gnu sum.c -quiet -dumpdir prog- -dumpbase sum.c -dumpbase-ext .c -mtune=generic -march=x86-64 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/ccClT5M4.s\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nignoring nonexistent directory \"/usr/local/include/x86_64-linux-gnu\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/include-fixed\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include\"\n#include \"...\" search starts here:\n#include <...> search starts here:\n /usr/lib/gcc/x86_64-linux-gnu/12/include\n /usr/local/include\n /usr/include/x86_64-linux-gnu\n /usr/include\nEnd of search list.\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nCompiler executable checksum: d9353c3f0a32d3e91a16ba312e2a9024\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n as -v --64 -o /tmp/ccxMA26W.o /tmp/ccClT5M4.s\nGNU assembler version 2.40 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.40\nCOMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/\nLIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../:/lib/:/usr/lib/\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog.'\n<!--(6)!--> /usr/lib/gcc/x86_64-linux-gnu/12/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/12/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper -plugin-opt=-fresolution=/tmp/ccyzC2ZB.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o prog /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/12/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/12 -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/12/../../.. /tmp/ccEgqpgY.o /tmp/ccxMA26W.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/12/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crtn.o\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog.'\n
  1. \u6700\u5f00\u5934\u662f gcc \u7684\u76f8\u5173\u4fe1\u606f\uff0c\u5305\u62ec\u5b83\u8fd0\u884c\u7684\u5e73\u53f0\u3001\u914d\u7f6e\u7684\u9009\u9879\u7b49\u3002
  2. \u8fd9\u91cc\u8c03\u7528\u4e86 cc1 \u5b8c\u6210\u9884\u5904\u7406\u548c\u7f16\u8bd1\u9636\u6bb5\uff0c\u5c06\u6e90\u4ee3\u7801\u6587\u4ef6 main.c \u7f16\u8bd1\u6210\u4e86 ASCII \u7f16\u7801\u7684\u6c47\u7f16\u6587\u4ef6 /tmp/ccCWi0p2.s\u3002
  3. \u8fd9\u91cc\u663e\u793a\u4e86\u5934\u6587\u4ef6\u641c\u7d22\u8def\u5f84\uff0c\u5982\u679c\u4f60\u7f16\u8bd1\u65f6\u62a5\u9519\u7f3a\u5c11\u5934\u6587\u4ef6\uff0c\u53ef\u4ee5\u68c0\u67e5\u4e00\u4e0b\u8fd9\u91cc\u6709\u6ca1\u6709\u5305\u542b\u5bf9\u5e94\u7684\u8def\u5f84\u3002
  4. \u8fd9\u91cc\u8c03\u7528\u4e86 as \u5b8c\u6210\u6c47\u7f16\u9636\u6bb5\uff0c\u5c06\u6c47\u7f16\u6587\u4ef6 /tmp/ccCWi0p2.s \u7ffb\u8bd1\u6210\u4e86\u673a\u5668\u8bed\u8a00\u6587\u4ef6 /tmp/ccAnKDEo.o\u3002
  5. \u63a5\u4e0b\u6765\u53c8\u5bf9 sum.c \u91cd\u590d\u9884\u5904\u7406\u3001\u7f16\u8bd1\u548c\u6c47\u7f16\u7684\u8fc7\u7a0b\uff0c\u5f97\u5230\u4e86 /tmp/ccgMFTqK.o\u3002
  6. \u6700\u540e\u8c03\u7528 collect2 \uff08\u8fd9\u662f ld \u7684\u5305\u88c5\u7a0b\u5e8f\uff09\u5b8c\u6210\u94fe\u63a5\u9636\u6bb5\uff0c\u5c06\u4e24\u4e2a\u6e90\u4ee3\u7801\u751f\u6210\u7684\u76ee\u6807\u6587\u4ef6 /tmp/ccAnKDEo.o \u548c /tmp/ccgMFTqK.o \u4e0e\u5176\u4ed6\u5f88\u591a\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u6210\u4e86\u53ef\u6267\u884c\u6587\u4ef6 prog\u3002\u8fd9\u5c31\u662f\u4f60\u80fd\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u7684\u7a0b\u5e8f\u3002
\u4e3a\u4ec0\u4e48\u6ca1\u6709\u770b\u89c1\u9884\u5904\u7406\u5668 cpp \u7684\u6267\u884c\u5462\uff1f

\u67d0\u4e9b\u7248\u672c\u7684 gcc \u4f1a\u5c06\u9884\u5904\u7406\u5668 cpp \u548c\u7f16\u8bd1\u5668 gcc \u5408\u5e76\u6210\u4e00\u4e2a\u6307\u4ee4\uff0c\u6bd4\u5982\u4e0a\u9762\u7684 cc1\uff0c\u8fd9\u6837\u5c31\u4e0d\u7528\u5355\u72ec\u8c03\u7528 cpp \u4e86\u3002

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u8be6\u89e3\u5176\u4e2d\u7684\u6bcf\u4e00\u4e2a\u9636\u6bb5\u4ee5\u53ca\u53ef\u80fd\u4f1a\u53d1\u751f\u7684\u95ee\u9898\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_11","title":"\u9884\u5904\u7406","text":"

\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u67e5\u770b\u9884\u5904\u7406\u540e\u7684\u6587\u4ef6 hello.i\uff1a

cpp hello.c > hello.i\n

\u4f60\u4f1a\u53d1\u73b0\uff0c\u539f\u6765 hello.c \u4e2d #include \u9884\u5904\u7406\u6307\u4ee4\u7684\u5730\u65b9\u88ab\u66ff\u6362\u4e3a\u5b8c\u6574\u7684 stdio.h \u6587\u4ef6\u5185\u5bb9\uff0c\u8fd9\u4e9b\u5185\u5bb9\u5305\u62ec printf \u7b49\u51fd\u6570\u7684\u539f\u578b\u3002\u5176\u4ed6\u9884\u5904\u7406\u6307\u4ee4\uff08\u5728\u540e\u7eed\u8bfe\u7a0b\u4f1a\u5b66\u4e60\u5230\uff09\u6bd4\u5982 #define \u4e5f\u4f1a\u5728\u8fd9\u4e00\u9636\u6bb5\u751f\u6548\u3002\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u53ea\u63d2\u5165\u4e86\u51fd\u6570\u539f\u578b\u800c\u6ca1\u6709\u5b9a\u4e49\uff0c\u63a5\u4e0b\u6765\u7684\u94fe\u63a5\u9636\u6bb5\u4f1a\u89e3\u7b54\u3002

\u9884\u5904\u7406\u9636\u6bb5\u6700\u7ecf\u5e38\u4ea7\u751f\u7684\u95ee\u9898\u662f\u627e\u4e0d\u5230\u5934\u6587\u4ef6\u3002C \u8bed\u8a00\u5934\u6587\u4ef6\u641c\u7d22\u89c4\u5219\u5982\u4e0b\uff1a

\u5982\u679c\u4f60\u7684\u5934\u6587\u4ef6\u4e0d\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\uff0c\u90a3\u4e48\u4f60\u9700\u8981\u4f7f\u7528 -I \u9009\u9879\u544a\u8bc9\u7f16\u8bd1\u5668\u5934\u6587\u4ef6\u7684\u4f4d\u7f6e\u3002\u6bd4\u5982\u4f60\u7684\u5934\u6587\u4ef6\u5728 include \u76ee\u5f55\u4e0b\uff1a

.\n\u251c\u2500\u2500 hello.c\n\u2514\u2500\u2500 include\n \u00a0\u00a0 \u2514\u2500\u2500 header.h\n

\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8bd1\uff1a

gcc -Iinclude -o hello hello.c\n

\u8def\u5f84\u53ef\u4ee5\u662f\u76f8\u5bf9\u8def\u5f84\u6216\u7edd\u5bf9\u8def\u5f84\uff0c\u6bd4\u5982\uff1a

gcc -I../include -o hello hello.c\ngcc -I/home/user/include -o hello hello.c\n

\u53e6\u4e00\u79cd\u65b9\u5f0f\u662f\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf CPATH \u6307\u5b9a\u641c\u7d22\u8def\u5f84\u3002

export CPATH=\"$HOME/.local:$CPATH\"\n

\u8bbe\u7f6e\u540e\uff0c\u4f60\u5e94\u5f53\u80fd\u5728\u7f16\u8bd1\u5668\u7684\u8f93\u51fa\u4fe1\u606f\u4e2d\u770b\u5230\u65b0\u589e\u7684\u8def\u5f84\u3002

#include <...> search starts here:\n /home/bowling/.local\n
"},{"location":"programming/archive/23fall/lec1/lec1/#_12","title":"\u7f16\u8bd1","text":"

\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u67e5\u770b\u7f16\u8bd1\u540e\u7684\u6587\u4ef6 hello.s\uff1a

gcc -S hello.i\n

\u6240\u6709\u9ad8\u7ea7\u8bed\u8a00\u5c42\u9762\u7684\u7c7b\u578b\u3001\u63a7\u5236\u7ed3\u6784\u7b49\uff0c\u90fd\u88ab\u4e0e\u7279\u5b9a CPU \u6307\u4ee4\u96c6\u76f8\u5173\u7684\u6c47\u7f16\u6307\u4ee4\u4ee3\u66ff\u3002\u5728\u6c47\u7f16\u8bed\u8a00\u4e2d\uff0c\u6240\u6709\u6570\u636e\u90fd\u662f\u5b57\u8282\u5757\uff0c\u6ca1\u6709\u7c7b\u578b\u7684\u6982\u5ff5\u3002

\u5728\u8fd9\u4e2a\u9636\u6bb5\uff0c\u7f16\u8bd1\u5668\u4f1a\u68c0\u67e5\u4e00\u4e9b\u95ee\u9898\uff0c\u5e76\u629b\u51fa\u4e0d\u540c\u7b49\u7ea7\u7684\u4fe1\u606f\uff1a

error.c: In function \u2018main\u2019:\nerror.c:9:5: error: too many arguments to function \u2018my_print\u2019\n    9 |     my_print(1);\n      |     ^~~~~~~~\nerror.c:4:6: note: declared here\n    4 | void my_print(void)\n      |      ^~~~~~~~\n
warning.c: In function \u2018main\u2019:\nwarning.c:8:18: warning: format \u2018%d\u2019 expects argument of type \u2018int\u2019, but argument 2 has type \u2018double\u2019 [-Wformat=]\n    8 |     printf(\"a = %d\\n\", a);\n      |                 ~^     ~\n      |                  |     |\n      |                  int   double\n      |                 %f\n

\u5927\u90e8\u5206\u8b66\u544a\u4fe1\u606f\u9ed8\u8ba4\u4e0d\u4f1a\u8f93\u51fa\uff0c\u4f7f\u7528 -Wall \u548c -Wextra \u9009\u9879\u53ef\u4ee5\u6253\u5f00\u66f4\u591a\u7684\u8b66\u544a\u4fe1\u606f\u3002\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 -Werror \u9009\u9879\u5c06\u8b66\u544a\u4fe1\u606f\u89c6\u4e3a\u9519\u8bef\uff0c\u8fd9\u6837\u7f16\u8bd1\u5668\u5c31\u4f1a\u505c\u6b62\u7f16\u8bd1\u3002\u5728\u7f16\u8bd1\u65f6\u5e26\u4e0a\u8fd9\u4e9b\u53c2\u6570\u662f\u4e00\u4e2a\u597d\u4e60\u60ef\u3002

gcc -Wall -Wextra -Werror -o hello hello.c\n
"},{"location":"programming/archive/23fall/lec1/lec1/#_13","title":"\u6c47\u7f16","text":"

\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u6c47\u7f16\u5668\u5c06\u6c47\u7f16\u6307\u4ee4\u7ffb\u8bd1\u4e3a\u673a\u5668\u7801\uff0c\u4ea7\u751f\u53ef\u91cd\u5b9a\u4f4d\u76ee\u6807\u6587\u4ef6 hello.o\uff1a

as -o hello.o hello.s\n
\u76ee\u6807\u6587\u4ef6

\u76ee\u6807\u6587\u4ef6\u4e2d\u5305\u542b\u8ba1\u7b97\u673a\u80fd\u8bfb\u61c2\u7684\u673a\u5668\u4ee3\u7801\u548c\u6570\u636e\uff0c\u6709\u4e09\u79cd\u5f62\u5f0f\uff1a

\u5f62\u5f0f \u7531\u8c01\u4ea7\u751f \u6709\u4ec0\u4e48\u7528 \u53ef\u91cd\u5b9a\u4f4d\u76ee\u6807\u6587\u4ef6 \u7f16\u8bd1\u5668\u6216\u6c47\u7f16\u5668 \u53ea\u5305\u542b\u7f16\u8bd1\u5668\u4e3a\u4f60\u7f16\u5199\u7684\u4ee3\u7801\u7ffb\u8bd1\u7684\u673a\u5668\u8bed\u8a00\u4ee3\u7801\uff0c\u9700\u8981\u4e0e\u5176\u4ed6\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u5408\u5e76\u4e3a\u53ef\u6267\u884c\u76ee\u6807\u6587\u4ef6 \u53ef\u6267\u884c\u76ee\u6807\u6587\u4ef6 \u94fe\u63a5\u5668 \u5305\u542b\u4f60\u7f16\u5199\u7684\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u7684\u5e93\u51fd\u6570\u548c\u542f\u52a8\u4ee3\u7801\u7684\u673a\u5668\u4ee3\u7801\uff0c\u80fd\u591f\u88ab\u64cd\u4f5c\u7cfb\u7edf\u6b63\u786e\u8fd0\u884c \u5171\u4eab\u76ee\u6807\u6587\u4ef6 \u7f16\u8bd1\u5668\u6216\u6c47\u7f16\u5668 \u7ed9\u5176\u4ed6\u7a0b\u5e8f\u7528\u7684\u4ee3\u7801\uff0c\u53ef\u4ee5\u5728\u7a0b\u5e8f\u52a0\u8f7d\u6216\u8fd0\u884c\u65f6\u94fe\u63a5

hello.o \u4e2d\u5305\u542b\u4e86 hello.c \u4e2d\u7684 C \u8bed\u8a00\u4ee3\u7801\u7ffb\u8bd1\u6210\u7684\u4e8c\u8fdb\u5236\u4ee3\u7801\u4ee5\u53ca\u4e00\u4e9b\u6570\u636e\uff0c\u6bd4\u5982\u5b57\u7b26\u4e32 Hello, world.\\n\u3002\u5982\u679c\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00 hello.o\uff0c\u4f60\u4f1a\u770b\u89c1\u4e00\u5806\u4e71\u7801\uff0c\u5176\u4e2d\u5939\u6742\u7740\u4e00\u4e9b\u5b57\u7b26\u3002\u56e0\u4e3a\u5b57\u7b26\u5728\u6e90\u6587\u4ef6\u548c\u5185\u5b58\u4e2d\u90fd\u662f\u7528 ASCII \u7f16\u7801\u7684\uff0c\u6240\u4ee5 ASCII \u5b57\u7b26\u4ecd\u80fd\u88ab\u6587\u672c\u7f16\u8f91\u5668\u8bc6\u522b\uff0c\u4f46\u5176\u4ed6\u7684\u673a\u5668\u6307\u4ee4\u548c\u6570\u636e\u53ea\u4f1a\u88ab\u89e3\u8bfb\u4e3a\u4e71\u7801\u3002

\u5982\u679c\u8fd0\u884c ./hello.o\uff0c\u7ec8\u7aef\u4f1a\u544a\u8bc9\u4f60\u8fd9\u4e2a\u6587\u4ef6\u4e0d\u80fd\u88ab\u64cd\u4f5c\u7cfb\u7edf\u6267\u884c\u3002

exec: Failed to execute process: './hello.o' the file could not be run by the operating system.\n

\u5b83\u8fd8\u7f3a\u5c11\u4e00\u4e9b\u4e1c\u897f\uff0c\u5982\uff1a

\u4e00\u4e2a\u4e0d\u5e26\u542f\u52a8\u4ee3\u7801\u7684\u4f8b\u5b50

Linux \u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u4e00\u822c\u662f _start\uff0c\u5b83\u5b8c\u6210\u4e00\u4e9b\u5185\u5b58\u521d\u59cb\u5316\u7684\u5de5\u4f5c\uff0c\u7136\u540e\u8df3\u8f6c\u5230 main \u51fd\u6570\u3002\u6211\u4eec\u5728\u94fe\u63a5\u9636\u6bb5\u4e0d\u5e26\u4e0a\u542b\u6709\u542f\u52a8\u4ee3\u7801\u7684\u76ee\u6807\u6587\u4ef6\uff0c\u770b\u770b\u5728\u7f3a\u5c11 _start \u7684\u60c5\u51b5\u4e0b\u4f1a\u53d1\u751f\u4ec0\u4e48\u3002

$ ld hello.o -o hello -lc --dynamic-linker /lib64/ld-linux-x86-64.so.2\nld: warning: cannot find entry symbol _start; defaulting to 0000000000401030\n$ ./hello\nHello World.\nfish: Job 1, './hello' terminated by signal SIGSEGV (Address boundary error)\n

\u8fd9\u4e2a\u7a0b\u5e8f\u6e90\u4ee3\u7801\u6b63\u5e38\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u6bb5\u9519\u8bef\u5462\uff1f

\u5728\u94fe\u63a5\u9636\u6bb5\uff0cld \u7684\u8f93\u51fa\u8868\u660e\u627e\u4e0d\u5230\u5165\u53e3\u70b9 _start\uff0c\u56e0\u6b64\u628a\u5165\u53e3\u70b9\u9ed8\u8ba4\u653e\u5728\u4e86 0000000000401030 \u5904\u7684\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u662f main \u51fd\u6570\u3002\u56e0\u6b64\uff0c\u5f53\u7a0b\u5e8f\u6267\u884c\u5230 main \u51fd\u6570\u7684\u6700\u540e\u4e00\u6761\u6307\u4ee4\u65f6\uff0c\u4f1a\u7ee7\u7eed\u5f80\u4e0b\u6267\u884c\uff0c\u4f46\u6b64\u65f6\u6808\u5df2\u7ecf\u88ab\u6e05\u7a7a\uff0c\u56e0\u6b64\u4f1a\u53d1\u751f\u6bb5\u9519\u8bef\u3002

\u4f7f\u7528 gdb \u67e5\u770b\u9519\u8bef\u4f4d\u7f6e\uff1a

Program received signal SIGSEGV, Segmentation fault.\n0x0000000000000001 in ?? ()\n

\u8bc1\u5b9e\u4e86\u4e0a\u9762\u7684\u5206\u6790\u3002

crt \u662f C Runtime \u7684\u7f29\u5199\u3002C \u8bed\u8a00\u76f8\u5173\u542f\u52a8\u4ee3\u7801\u5728\u8fd9\u4e9b\u76ee\u6807\u6587\u4ef6\u4e2d\uff1a

Linux \u5e73\u53f0\u4e0b\uff0c\u5b83\u4eec\u7684\u94fe\u63a5\u987a\u5e8f\u4e3a\uff1a

ld crt1.o crti.o [user_objects] [system_libraries] crtn.o\n

\u5728\u63a5\u4e0b\u6765\u7684\u94fe\u63a5\u6b65\u9aa4\uff0c\u6211\u4eec\u5c06\u8fd9\u4e9b\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u5230\u6211\u4eec\u7684\u7a0b\u5e8f\u4e2d\uff0c\u751f\u6210\u53ef\u4ee5\u6267\u884c\u7684\u7a0b\u5e8f\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_14","title":"\u94fe\u63a5","text":"

\u94fe\u63a5\u6709\u4e24\u79cd\u7c7b\u578b\uff1a\u9759\u6001\u94fe\u63a5\u548c\u52a8\u6001\u94fe\u63a5\u3002

\u9759\u6001\u94fe\u63a5

\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u4e0e\u9759\u6001\u5e93\u94fe\u63a5\uff0c\u90a3\u4e48\u94fe\u63a5\u5668\u4f1a\u5c06\u9759\u6001\u5e93\u4e2d\u7684\u4ee3\u7801\u590d\u5236\u5230\u4f60\u7684\u7a0b\u5e8f\u4e2d\u3002\u8fd9\u6837\uff0c\u4f60\u7684\u7a0b\u5e8f\u5c31\u4e0d\u518d\u4f9d\u8d56\u9759\u6001\u5e93\u4e86\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u8fd0\u884c\u3002\u4f46\u662f\uff0c\u5982\u679c\u9759\u6001\u5e93\u4e2d\u7684\u4ee3\u7801\u53d1\u751f\u4e86\u53d8\u5316\uff0c\u4f60\u7684\u7a0b\u5e8f\u5e76\u4e0d\u4f1a\u81ea\u52a8\u66f4\u65b0\uff0c\u4f60\u9700\u8981\u91cd\u65b0\u7f16\u8bd1\u4f60\u7684\u7a0b\u5e8f\u3002

\u5728 Linux \u7cfb\u7edf\u4e0a\uff0c\u9759\u6001\u5e93\u7684\u6587\u4ef6\u540d\u4ee5 .a \u7ed3\u5c3e\uff0c\u6bd4\u5982 libm.a\u3002\u5728 Window \u4e0a\uff0c\u9759\u6001\u5e93\u7684\u6587\u4ef6\u540d\u4ee5 .lib \u7ed3\u5c3e\uff0c\u6bd4\u5982 libm.lib\u3002\u9759\u6001\u5e93\u53ef\u4ee5\u4f7f\u7528 ar \uff08archive program\uff09\u5de5\u5177\u521b\u5efa\u3002

\u52a8\u6001\u94fe\u63a5

\u5f53\u4f60\u7684\u7a0b\u5e8f\u4e0e\u52a8\u6001\u5e93\u94fe\u63a5\u65f6\uff0c\u7a0b\u5e8f\u4e2d\u521b\u5efa\u4e86\u4e00\u4e2a\u8868\u3002\u5728\u7a0b\u5e8f\u8fd0\u884c\u524d\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5c06\u9700\u8981\u7684\u5916\u90e8\u51fd\u6570\u7684\u673a\u5668\u7801\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u8fd9\u5c31\u662f\u52a8\u6001\u94fe\u63a5\u8fc7\u7a0b\u3002

\u4e0e\u9759\u6001\u94fe\u63a5\u76f8\u6bd4\uff0c\u52a8\u6001\u94fe\u63a5\u4f7f\u7a0b\u5e8f\u6587\u4ef6\u66f4\u5c0f\uff0c\u56e0\u4e3a\u4e00\u4e2a\u52a8\u6001\u5e93\u53ef\u4ee5\u88ab\u591a\u4e2a\u7a0b\u5e8f\u5171\u4eab\uff0c\u8282\u7701\u78c1\u76d8\u7a7a\u95f4\u3002\u90e8\u5206\u64cd\u4f5c\u7cfb\u7edf\u8fd8\u5141\u8bb8\u52a8\u6001\u5e93\u4ee3\u7801\u5728\u5185\u5b58\u4e2d\u7684\u5171\u4eab\uff0c\u8fd8\u80fd\u591f\u8282\u7701\u5185\u5b58\u3002\u52a8\u6001\u5e93\u5347\u7ea7\u65f6\uff0c\u4e5f\u4e0d\u9700\u8981\u91cd\u5199\u7f16\u8bd1\u4f60\u7684\u7a0b\u5e8f\u3002

\u5728 Linux \u7cfb\u7edf\u4e0a\uff0c\u52a8\u6001\u5e93\u7684\u6587\u4ef6\u540d\u4ee5 .so \u7ed3\u5c3e\uff0c\u6bd4\u5982 libm.so\u3002\u5728 Window \u4e0a\uff0c\u52a8\u6001\u5e93\u7684\u6587\u4ef6\u540d\u4ee5 .dll \u7ed3\u5c3e\uff0c\u6bd4\u5982 libm.dll\u3002

\u52a8\u6001\u94fe\u63a5\u5177\u6709\u4e0a\u9762\u63cf\u8ff0\u7684\u4f18\u70b9\uff0c\u56e0\u6b64 GCC \u5c3d\u53ef\u80fd\u5730\u6267\u884c\u52a8\u6001\u94fe\u63a5\u3002

\u94fe\u63a5\u76f8\u5173\u7684\u95ee\u9898\u53ef\u80fd\u51fa\u73b0\u5728\u94fe\u63a5\u65f6\uff08\u9759\u6001\u94fe\u63a5\uff09\u3001\u7a0b\u5e8f\u8fd0\u884c\u524d\u548c\u8fd0\u884c\u4e2d\uff08\u52a8\u6001\u94fe\u63a5\uff09\u3002\u4e0b\u9762\u65f6\u4e00\u4e9b\u5e38\u89c1\u7684\u95ee\u9898\u3002

\u672a\u5b9a\u4e49\u7684\u5f15\u7528

\u5f53\u540c\u5b66\u4eec\u5f00\u59cb\u4f7f\u7528\u5176\u4ed6\u5e93\u6784\u5efa\u5927\u578b\u9879\u76ee\u65f6\uff0c\u8fd9\u6216\u8bb8\u4f1a\u6210\u4e3a\u6700\u5934\u75bc\u7684\u95ee\u9898\u3002\u9996\u5148\u5e94\u5f53\u9605\u8bfb\u5e93\u7684\u4f7f\u7528\u8bf4\u660e\uff0c\u63a5\u4e0b\u6765\u641c\u7d22\u7f3a\u5931\u7684\u7b26\u53f7\u53ef\u80fd\u4f4d\u4e8e\u54ea\u4e9b\u5e93\u6587\u4ef6\u4e2d\u3002

\u7f3a\u5931 .dll

\u5e38\u7528 Windows \u7684\u540c\u5b66\u591a\u591a\u5c11\u5c11\u89c1\u8fc7\u8fd9\u4e2a\u62a5\u9519\uff0c\u53ef\u4ee5\u53bb\u7f51\u4e0a\u641c\u7d22\u76f8\u5e94 .dll \u6587\u4ef6\u653e\u7f6e\u5230\u6b63\u786e\u7684\u76ee\u5f55\u3002

\u7f3a\u5931 .so

Linux \u4e0a\u7684\u52a8\u6001\u5e93\u4e00\u822c\u901a\u8fc7 apt \u7ba1\u7406\uff0c\u641c\u7d22\u76f8\u5e94\u7684\u5305\u5e76\u5b89\u88c5\u5373\u53ef\u3002

\u4e0b\u9762\u8fd9\u884c\u547d\u4ee4\u5728\u6211\u7684\u7cfb\u7edf\u4e0a\u5b8c\u6210\u4e86 hello \u7a0b\u5e8f\u7684\u6b63\u786e\u94fe\u63a5\uff0c\u4e0d\u4e00\u5b9a\u80fd\u5728\u4f60\u7684\u7cfb\u7edf\u4e0a\u8fd0\u884c\u3002\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u67e5\u627e\u5e93\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u8ba9\u5b83\u6210\u529f\u8fd0\u884c\u3002

ld --output hello --dynamic-linker /lib64/ld-linux-x86-64.so.2  /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crti.o -lc hello.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crtn.o\n
"},{"location":"programming/archive/23fall/lec1/lec1/#_15","title":"\u52a8\u6001\u94fe\u63a5\u8fc7\u7a0b","text":"

\u5982\u679c\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u4f9d\u8d56\u4e8e\u52a8\u6001\u5e93\uff0c\u90a3\u4e48\u7a0b\u5e8f\u8fd0\u884c\u524d\uff0c\u52a8\u6001\u94fe\u63a5\u5668\uff08interpreter\uff09\u4f1a\u88ab\u5148\u52a0\u8f7d\u8fd0\u884c\u3002\u5b83\u5c06\u5bfb\u627e\u9700\u8981\u7684\u52a8\u6001\u5e93\uff0c\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u7136\u540e\u5c06\u63a7\u5236\u6743\u4ea4\u7ed9\u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u3002

ld \u7684\u9009\u9879 --dynamic-linker \u5c31\u6307\u5b9a\u4e86\u52a8\u6001\u94fe\u63a5\u5668\u7684\u8def\u5f84\u3002\u76ee\u524d Linux \u7cfb\u7edf\u4f7f\u7528\u7684\u52a8\u6001\u94fe\u63a5\u5668\u4e00\u822c\u662f /lib64/ld-linux-x86-64.so.2\u3002\u5b83\u4e5f\u662f\u4e00\u4e2a\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c\u7684\u7a0b\u5e8f\uff0c\u4f60\u53ef\u4ee5\u8bd5\u8bd5\u8fd0\u884c\u5b83\uff1a

$ /lib64/ld-linux-x86-64.so.2 --help\nYou have invoked 'ld.so', the program interpreter for dynamically-linked ELF programs.  Usually, the program interpreter is invoked automatically when a dynamically-linked executable is started.\n\nYou may invoke the program interpreter program directly from the command line to load and run an ELF executable file; this is like executing that file itself, but always uses the program interpreter you invoked, instead of the program interpreter specified in the executable file you run.  Invoking the program interpreter directly provides access to additional diagnostics, and changing the dynamic linker behavior without setting environment variables (which would be inherited by subprocesses).\n

\u8be5\u9009\u9879\u5c06\u4f1a\u5728\u53ef\u6267\u884c\u76ee\u6807\u6587\u4ef6\u524d\u9762\u52a0\u4e0a\u5bf9\u52a8\u6001\u94fe\u63a5\u5668\u7684\u8bf7\u6c42\u3002\u4f7f\u7528 readelf \u53ef\u4ee5\u67e5\u770b ELF \u683c\u5f0f\u53ef\u6267\u884c\u76ee\u6807\u6587\u4ef6\u7684\u5934\u90e8\u4fe1\u606f\u3002

$ readelf -l /usr/bin/ls | head -20\n\nElf file type is DYN (Shared object file)\nEntry point 0x6b10\nThere are 13 program headers, starting at offset 64\n\nProgram Headers:\n  Type           Offset             VirtAddr           PhysAddr\n                 FileSiz            MemSiz              Flags  Align\n  PHDR           0x0000000000000040 0x0000000000000040 0x0000000000000040\n                 0x00000000000002d8 0x00000000000002d8  R      0x8\n  INTERP         0x0000000000000318 0x0000000000000318 0x0000000000000318\n                 0x000000000000001c 0x000000000000001c  R      0x1\n      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]\n  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000\n                 0x0000000000003510 0x0000000000003510  R      0x1000\n  LOAD           0x0000000000004000 0x0000000000004000 0x0000000000004000\n                 0x0000000000013111 0x0000000000013111  R E    0x1000\n  LOAD           0x0000000000018000 0x0000000000018000 0x0000000000018000\n                 0x0000000000007530 0x0000000000007530  R      0x1000\n  LOAD           0x000000000001ff70 0x0000000000020f70 0x0000000000020f70\n
"},{"location":"programming/archive/23fall/lec1/lec1/#_16","title":"\u9759\u6001\u94fe\u63a5\u8fc7\u7a0b","text":"

\u8fdb\u884c\u9759\u6001\u94fe\u63a5\u65f6\u9700\u8981\u6ce8\u610f\u547d\u4ee4\u884c\u4e2d\u6587\u4ef6\u7684\u987a\u5e8f\u3002

\u770b\u770b\u4e0b\u9762\u7684\u547d\u4ee4\u884c\u53d1\u751f\u4e86\u4ec0\u4e48\uff1f

$ gcc -static ./libvector.a main2.c\n/tmp/cc9XH6Rp.o: In function `main':\nmain2.c:(.text+0x1a): undefined reference to `vector_add'\n

\u94fe\u63a5\u5668\u68c0\u67e5 libvector.a \u5e93\u6587\u4ef6\u65f6\uff0c\u8fd8\u6ca1\u6709\u8bb0\u5f55\u4efb\u4f55\u7b26\u53f7\u5b9a\u4e49\u548c\u5f15\u7528\uff0c\u56e0\u6b64\u5b83\u88ab\u6574\u4e2a\u4e22\u5f03\u4e86\u3002\u5f53\u94fe\u63a5\u5668\u5f00\u59cb\u68c0\u67e5 main2.c \u65f6\uff0c\u4e0d\u4f1a\u518d\u56de\u53bb\u627e libvector.a \u4e86\u3002

\u603b\u800c\u8a00\u4e4b\uff0c\u9759\u6001\u94fe\u63a5\u65f6\uff0c\u5e93\u6587\u4ef6\u4e00\u822c\u653e\u5728\u672b\u5c3e\u3002\u5982\u679c\u5e93\u6587\u4ef6\u4e4b\u95f4\u6709\u76f8\u4e92\u4f9d\u8d56\uff0c\u4e5f\u9700\u8981\u5bf9\u5b83\u4eec\u8fdb\u884c\u6392\u5e8f\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_17","title":"\u7a0b\u5e8f\u8c03\u8bd5\u6280\u672f","text":"\u6742\u8c08\uff1aBug \u7684\u5178\u6545

\u7f16\u7a0b\u662f\u4e00\u4ef6\u590d\u6742\u7684\u5de5\u4f5c\uff0c\u56e0\u4e3a\u662f\u4eba\u505a\u7684\u4e8b\u60c5\uff0c\u6240\u4ee5\u96be\u514d\u7ecf\u5e38\u51fa\u9519\u3002\u636e\u8bf4\u6709\u8fd9\u6837\u4e00\u4e2a\u5178\u6545\uff1a\u65e9\u671f\u7684\u8ba1\u7b97\u673a\u4f53\u79ef\u90fd\u5f88\u5927\uff0c\u6709\u4e00\u6b21\u4e00\u53f0\u8ba1\u7b97\u673a\u4e0d\u80fd\u6b63\u5e38\u5de5\u4f5c\uff0c\u5de5\u7a0b\u5e08\u4eec\u627e\u4e86\u534a\u5929\u539f\u56e0\u6700\u540e\u53d1\u73b0\u662f\u4e00\u53ea\u81ed\u866b\u94bb\u8fdb\u8ba1\u7b97\u673a\u4e2d\u9020\u6210\u7684\u3002\u4ece\u6b64\u4ee5\u540e\uff0c\u7a0b\u5e8f\u4e2d\u7684\u9519\u8bef\u88ab\u53eb\u505a\u81ed\u866b\uff08Bug\uff09\uff0c\u800c\u627e\u5230\u8fd9\u4e9bBug\u5e76\u52a0\u4ee5\u7ea0\u6b63\u7684\u8fc7\u7a0b\u5c31\u53eb\u505a\u8c03\u8bd5\uff08Debug\uff09\u3002\u6709\u65f6\u5019\u8c03\u8bd5\u662f\u4e00\u4ef6\u975e\u5e38\u590d\u6742\u7684\u5de5\u4f5c\uff0c\u8981\u6c42\u7a0b\u5e8f\u5458\u6982\u5ff5\u660e\u786e\u3001\u903b\u8f91\u6e05\u6670\u3001\u6027\u683c\u6c89\u7a33\uff0c\u8fd8\u9700\u8981\u4e00\u70b9\u8fd0\u6c14\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#bug","title":"Bug \u7684\u7c7b\u578b","text":"

\u8c03\u8bd5\u7684\u6280\u80fd\u6211\u4eec\u5728\u540e\u7eed\u7684\u5b66\u4e60\u4e2d\u6162\u6162\u57f9\u517b\uff0c\u4f46\u9996\u5148\u6211\u4eec\u8981\u533a\u5206\u6e05\u695a\u7a0b\u5e8f\u4e2d\u7684 Bug \u5206\u4e3a\u54ea\u51e0\u7c7b\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_18","title":"\u7f16\u8bd1\u65f6\u9519\u8bef","text":"

\u7f16\u8bd1\u5668\u53ea\u80fd\u7ffb\u8bd1\u8bed\u6cd5\u6b63\u786e\u7684\u7a0b\u5e8f\uff0c\u5426\u5219\u5c06\u5bfc\u81f4\u7f16\u8bd1\u5931\u8d25\uff0c\u65e0\u6cd5\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5bf9\u4e8e\u81ea\u7136\u8bed\u8a00\u6765\u8bf4\uff0c\u4e00\u70b9\u8bed\u6cd5\u9519\u8bef\u4e0d\u662f\u5f88\u4e25\u91cd\u7684\u95ee\u9898\uff0c\u56e0\u4e3a\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u8bfb\u61c2\u53e5\u5b50\u3002\u800c\u7f16\u8bd1\u5668\u5c31\u6ca1\u90a3\u4e48\u5bbd\u5bb9\u4e86\uff0c\u53ea\u8981\u6709\u54ea\u6015\u4e00\u4e2a\u5f88\u5c0f\u7684\u8bed\u6cd5\u9519\u8bef\uff0c\u7f16\u8bd1\u5668\u5c31\u4f1a\u8f93\u51fa\u4e00\u6761\u9519\u8bef\u63d0\u793a\u4fe1\u606f\u7136\u540e\u7f62\u5de5\uff0c\u4f60\u5c31\u5f97\u4e0d\u5230\u4f60\u60f3\u8981\u7684\u7ed3\u679c\u3002\u867d\u7136\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\u7f16\u8bd1\u5668\u7ed9\u51fa\u7684\u9519\u8bef\u63d0\u793a\u4fe1\u606f\u5c31\u662f\u4f60\u51fa\u9519\u7684\u4ee3\u7801\u884c\uff0c\u4f46\u4e5f\u6709\u4e2a\u522b\u65f6\u5019\u7f16\u8bd1\u5668\u7ed9\u51fa\u7684\u9519\u8bef\u63d0\u793a\u4fe1\u606f\u5e2e\u52a9\u4e0d\u5927\uff0c\u751a\u81f3\u4f1a\u8bef\u5bfc\u4f60\u3002\u5728\u5f00\u59cb\u5b66\u4e60\u7f16\u7a0b\u7684\u524d\u51e0\u4e2a\u661f\u671f\uff0c\u4f60\u53ef\u80fd\u4f1a\u82b1\u5927\u91cf\u7684\u65f6\u95f4\u6765\u7ea0\u6b63\u8bed\u6cd5\u9519\u8bef\u3002\u7b49\u5230\u6709\u4e86\u4e00\u4e9b\u7ecf\u9a8c\u4e4b\u540e\uff0c\u8fd8\u662f\u4f1a\u72af\u8fd9\u6837\u7684\u9519\u8bef\uff0c\u4e0d\u8fc7\u4f1a\u5c11\u5f97\u591a\uff0c\u800c\u4e14\u4f60\u80fd\u66f4\u5feb\u5730\u53d1\u73b0\u9519\u8bef\u539f\u56e0\u3002\u7b49\u5230\u7ecf\u9a8c\u66f4\u4e30\u5bcc\u4e4b\u540e\u4f60\u5c31\u4f1a\u89c9\u5f97\uff0c\u8bed\u6cd5\u9519\u8bef\u662f\u6700\u7b80\u5355\u6700\u4f4e\u7ea7\u7684\u9519\u8bef\uff0c\u7f16\u8bd1\u5668\u7684\u9519\u8bef\u63d0\u793a\u4e5f\u5c31\u90a3\u4e48\u51e0\u79cd\uff0c\u5373\u4f7f\u9519\u8bef\u63d0\u793a\u662f\u6709\u8bef\u5bfc\u7684\u4e5f\u80fd\u591f\u7acb\u523b\u627e\u51fa\u771f\u6b63\u7684\u9519\u8bef\u539f\u56e0\u662f\u4ec0\u4e48\u3002\u76f8\u6bd4\u4e0b\u9762\u4e24\u79cd\u9519\u8bef\uff0c\u8bed\u6cd5\u9519\u8bef\u89e3\u51b3\u8d77\u6765\u8981\u5bb9\u6613\u5f97\u591a\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_19","title":"\u8fd0\u884c\u65f6\u9519\u8bef","text":"

\u7f16\u8bd1\u5668\u68c0\u67e5\u4e0d\u51fa\u8fd9\u7c7b\u9519\u8bef\uff0c\u4ecd\u7136\u53ef\u4ee5\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4f46\u5728\u8fd0\u884c\u65f6\u4f1a\u51fa\u9519\u800c\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002\u5bf9\u4e8e\u6211\u4eec\u63a5\u4e0b\u6765\u7684\u51e0\u7ae0\u5c06\u7f16\u5199\u7684\u7b80\u5355\u7a0b\u5e8f\u6765\u8bf4\uff0c\u8fd0\u884c\u65f6\u9519\u8bef\u5f88\u5c11\u89c1\uff0c\u5230\u4e86\u540e\u9762\u7684\u7ae0\u8282\u4f60\u4f1a\u9047\u5230\u8d8a\u6765\u8d8a\u591a\u7684\u8fd0\u884c\u65f6\u9519\u8bef\u3002\u8bfb\u8005\u5728\u4ee5\u540e\u7684\u5b66\u4e60\u4e2d\u8981\u65f6\u523b\u6ce8\u610f\u533a\u5206\u7f16\u8bd1\u65f6\u548c\u8fd0\u884c\u65f6\uff08Run-time\uff09\u8fd9\u4e24\u4e2a\u6982\u5ff5\uff0c\u4e0d\u4ec5\u5728\u8c03\u8bd5\u65f6\u9700\u8981\u533a\u5206\u8fd9\u4e24\u4e2a\u6982\u5ff5\uff0c\u5728\u5b66\u4e60 C \u8bed\u8a00\u7684\u5f88\u591a\u8bed\u6cd5\u65f6\u90fd\u9700\u8981\u533a\u5206\u8fd9\u4e24\u4e2a\u6982\u5ff5\uff0c\u6709\u4e9b\u4e8b\u60c5\u5728\u7f16\u8bd1\u65f6\u505a\uff0c\u6709\u4e9b\u4e8b\u60c5\u5219\u5728\u8fd0\u884c\u65f6\u505a\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_20","title":"\u903b\u8f91\u9519\u8bef\u548c\u8bed\u4e49\u9519\u8bef","text":"

\u7b2c\u4e09\u7c7b\u9519\u8bef\u662f\u903b\u8f91\u9519\u8bef\u548c\u8bed\u4e49\u9519\u8bef\u3002\u5982\u679c\u7a0b\u5e8f\u91cc\u6709\u903b\u8f91\u9519\u8bef\uff0c\u7f16\u8bd1\u548c\u8fd0\u884c\u90fd\u4f1a\u5f88\u987a\u5229\uff0c\u770b\u4e0a\u53bb\u4e5f\u4e0d\u4ea7\u751f\u4efb\u4f55\u9519\u8bef\u4fe1\u606f\uff0c\u4f46\u662f\u7a0b\u5e8f\u6ca1\u6709\u5e72\u5b83\u8be5\u5e72\u7684\u4e8b\u60c5\uff0c\u800c\u662f\u5e72\u4e86\u522b\u7684\u4e8b\u60c5\u3002\u5f53\u7136\u4e0d\u7ba1\u600e\u4e48\u6837\uff0c\u8ba1\u7b97\u673a\u53ea\u4f1a\u6309\u4f60\u5199\u7684\u7a0b\u5e8f\u53bb\u505a\uff0c\u95ee\u9898\u5728\u4e8e\u4f60\u5199\u7684\u7a0b\u5e8f\u4e0d\u662f\u4f60\u771f\u6b63\u60f3\u8981\u7684\uff0c\u8fd9\u610f\u5473\u7740\u7a0b\u5e8f\u7684\u610f\u601d\uff08\u5373\u8bed\u4e49\uff09\u662f\u9519\u7684\u3002\u627e\u5230\u903b\u8f91\u9519\u8bef\u5728\u54ea\u9700\u8981\u5341\u5206\u6e05\u9192\u7684\u5934\u8111\uff0c\u8981\u901a\u8fc7\u89c2\u5bdf\u7a0b\u5e8f\u7684\u8f93\u51fa\u56de\u8fc7\u5934\u6765\u5224\u65ad\u5b83\u5230\u5e95\u5728\u505a\u4ec0\u4e48\u3002

\u901a\u8fc7\u672c\u8282\u4f60\u5c06\u638c\u63e1\u7684\u6700\u91cd\u8981\u7684\u6280\u5de7\u5c31\u662f\u8c03\u8bd5\u3002\u8c03\u8bd5\u7684\u8fc7\u7a0b\u53ef\u80fd\u4f1a\u8ba9\u4f60\u611f\u5230\u4e00\u4e9b\u6cae\u4e27\uff0c\u4f46\u8c03\u8bd5\u4e5f\u662f\u7f16\u7a0b\u4e2d\u6700\u9700\u8981\u52a8\u8111\u7684\u3001\u6700\u6709\u6311\u6218\u548c\u4e50\u8da3\u7684\u90e8\u5206\u3002\u4ece\u67d0\u79cd\u89d2\u5ea6\u770b\u8c03\u8bd5\u5c31\u50cf\u4fa6\u63a2\u5de5\u4f5c\uff0c\u6839\u636e\u638c\u63e1\u7684\u7ebf\u7d22\u6765\u63a8\u65ad\u662f\u4ec0\u4e48\u539f\u56e0\u548c\u8fc7\u7a0b\u5bfc\u81f4\u4e86\u4f60\u6240\u770b\u5230\u7684\u7ed3\u679c\u3002\u8c03\u8bd5\u4e5f\u50cf\u662f\u4e00\u95e8\u5b9e\u9a8c\u79d1\u5b66\uff0c\u6bcf\u6b21\u60f3\u5230\u54ea\u91cc\u53ef\u80fd\u6709\u9519\uff0c\u5c31\u4fee\u6539\u7a0b\u5e8f\u7136\u540e\u518d\u8bd5\u4e00\u6b21\u3002\u5982\u679c\u5047\u8bbe\u662f\u5bf9\u7684\uff0c\u5c31\u80fd\u5f97\u5230\u9884\u671f\u7684\u6b63\u786e\u7ed3\u679c\uff0c\u5c31\u53ef\u4ee5\u63a5\u7740\u8c03\u8bd5\u4e0b\u4e00\u4e2a Bug\uff0c\u4e00\u6b65\u4e00\u6b65\u903c\u8fd1\u6b63\u786e\u7684\u7a0b\u5e8f\uff1b\u5982\u679c\u5047\u8bbe\u9519\u8bef\uff0c\u53ea\u597d\u53e6\u5916\u518d\u627e\u601d\u8def\u518d\u505a\u5047\u8bbe\u3002\u201c\u5f53\u4f60\u628a\u4e0d\u53ef\u80fd\u7684\u5168\u90e8\u5254\u9664\uff0c\u5269\u4e0b\u7684\u2014\u2014\u5373\u4f7f\u770b\u8d77\u6765\u518d\u600e\u4e48\u4e0d\u53ef\u80fd\u2014\u2014\u5c31\u4e00\u5b9a\u662f\u4e8b\u5b9e\u3002\u201d\uff08\u5373\u4f7f\u4f60\u6ca1\u770b\u8fc7\u798f\u5c14\u6469\u65af\u4e5f\u8be5\u770b\u8fc7\u67ef\u5357\u5427\uff09\u3002

\u4e5f\u6709\u4e00\u79cd\u89c2\u70b9\u8ba4\u4e3a\uff0c\u7f16\u7a0b\u548c\u8c03\u8bd5\u662f\u4e00\u56de\u4e8b\uff0c\u7f16\u7a0b\u7684\u8fc7\u7a0b\u5c31\u662f\u9010\u6b65\u8c03\u8bd5\u76f4\u5230\u83b7\u5f97\u671f\u671b\u7684\u7ed3\u679c\u4e3a\u6b62\u3002\u4f60\u5e94\u8be5\u603b\u662f\u4ece\u4e00\u4e2a\u80fd\u6b63\u786e\u8fd0\u884c\u7684\u5c0f\u89c4\u6a21\u7a0b\u5e8f\u5f00\u59cb\uff0c\u6bcf\u505a\u4e00\u6b65\u5c0f\u7684\u6539\u52a8\u5c31\u7acb\u523b\u8fdb\u884c\u8c03\u8bd5\uff0c\u8fd9\u6837\u7684\u597d\u5904\u662f\u603b\u6709\u4e00\u4e2a\u6b63\u786e\u7684\u7a0b\u5e8f\u505a\u53c2\u8003\uff1a\u5982\u679c\u6b63\u786e\u5c31\u7ee7\u7eed\u7f16\u7a0b\uff0c\u5982\u679c\u4e0d\u6b63\u786e\uff0c\u90a3\u4e48\u4e00\u5b9a\u662f\u521a\u624d\u7684\u5c0f\u6539\u52a8\u51fa\u4e86\u95ee\u9898\u3002\u4f8b\u5982\uff0cLinux \u64cd\u4f5c\u7cfb\u7edf\u5305\u542b\u4e86\u6210\u5343\u4e0a\u4e07\u884c\u4ee3\u7801\uff0c\u4f46\u5b83\u4e5f\u4e0d\u662f\u4e00\u5f00\u59cb\u5c31\u89c4\u5212\u597d\u4e86\u5185\u5b58\u7ba1\u7406\u3001\u8bbe\u5907\u7ba1\u7406\u3001\u6587\u4ef6\u7cfb\u7edf\u3001\u7f51\u7edc\u7b49\u7b49\u5927\u7684\u6a21\u5757\uff0c\u4e00\u5f00\u59cb\u5b83\u4ec5\u4ec5\u662f Linus Torvalds \u7528\u6765\u7422\u78e8 Intel 80386 \u82af\u7247\u800c\u5199\u7684\u5c0f\u7a0b\u5e8f\u3002\u636e Larry Greenfield \u8bf4\uff0c\u201cLinus \u7684\u65e9\u671f\u5de5\u7a0b\u4e4b\u4e00\u662f\u7f16\u5199\u4e00\u4e2a\u4ea4\u66ff\u6253\u5370 AAAA \u548c BBBB \u7684\u7a0b\u5e8f\uff0c\u8fd9\u73a9\u610f\u513f\u540e\u6765\u8fdb\u5316\u6210\u4e86 Linux\u3002\u201d\uff08\u5f15\u81ea The Linux User's Guide Beta1 \u7248\uff09\u5728\u540e\u7eed\u7684\u8bfe\u7a0b\u4e2d\u4f1a\u7ed9\u51fa\u66f4\u591a\u5173\u4e8e\u8c03\u8bd5\u548c\u7f16\u7a0b\u5b9e\u8df5\u7684\u5efa\u8bae\u3002

\u6742\u8c08\uff1a\u4e3a\u4ec0\u4e48\u5f88\u591a\u540c\u5b66\u611f\u89c9\u8c03\u8bd5\u7684\u8fc7\u7a0b\u5341\u5206\u714e\u71ac\uff1f

\u6216\u8bb8\u4f60\u4e5f\u4f1a\u5728\u540e\u7eed\u7684\u5b66\u4e60\u4e2d\u4eb2\u8eab\u4f53\u4f1a\u6216\u770b\u5230\uff0c\u540c\u5b66\u4eec\u88ab\u7a0b\u5e8f\u7684 Bug\uff08\u6700\u5178\u578b\u7684\u662f\u6bb5\u9519\u8bef\uff09\u6298\u78e8\u5f97\u7126\u5934\u70c2\u989d\u3002\u8fd9\u53ef\u80fd\u6709\u4ee5\u4e0b\u539f\u56e0\uff1a

"},{"location":"programming/archive/23fall/lec1/lec1/#fprintfstderr","title":"fprintf(stderr) \u662f\u4f60\u6700\u597d\u7684\u670b\u53cb","text":"

\u867d\u7136\u63a5\u4e0b\u6765\u8981\u4ecb\u7ecd\u7684 gdb \u529f\u80fd\u5f3a\u5927\uff0c\u4f46\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u7b80\u5355\u5730\u6253\u5370\u53d8\u91cf\u5c31\u80fd\u5e2e\u4f60\u5b9a\u4f4d\u95ee\u9898\u6240\u5728\u3002

\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528 fprintf(stderr, ...) \u6253\u5370\u8c03\u8bd5\u4fe1\u606f\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5b9a\u4f4d\u5230\u7a0b\u5e8f\u4e2d\u7684\u9519\u8bef\u3002fprintf \u5411\u6307\u5b9a\u7684\u6d41\u8f93\u51fa\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0cstderr \u662f\u6807\u51c6\u9519\u8bef\u6d41\uff0c\u5b83\u4e0d\u4f1a\u88ab\u7f13\u51b2\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u5728\u7a0b\u5e8f\u5d29\u6e83\u65f6\u770b\u5230\u6700\u540e\u7684\u8c03\u8bd5\u4fe1\u606f\uff08\u8fd9\u4e9b\u8f93\u5165\u8f93\u51fa\u7684\u77e5\u8bc6\u4f1a\u5728\u540e\u9762\u7684\u8bfe\u7a0b\u4e2d\u5b66\u5230\uff09\u3002

\u4ee5\u4e00\u4e2a\u5f02\u5e38\u7ec8\u6b62\u7684\u7a0b\u5e8f\u4e3a\u4f8b\uff1a

#include <stdio.h>\n#include <stdlib.h>\n\nint main(void)\n{\n    printf(\"printf \");\n    fprintf(stderr, \"fprintf \");\n    abort();\n}\n

\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a

$ ./debug\nfprintf fish: Job 1, './debug' terminated by signal SIGABRT (Abort)\n

\u53ef\u4ee5\u770b\u5230\u53ea\u6709 fprintf \u51fd\u6570\u7684\u8f93\u51fa\u3002\u5982\u679c\u5728 printf \u8bed\u53e5\u540e\u9762\u52a0\u4e0a\u6362\u884c\u7b26\uff0c\u4f60\u4f1a\u53d1\u73b0 printf \u7684\u8f93\u51fa\u4e5f\u88ab\u6253\u5370\u51fa\u6765\u4e86\u3002\u56e0\u4e3a\u5f53\u8f93\u51fa\u7f13\u51b2\u533a\u9047\u5230 \\n \u65f6\u4e5f\u4f1a\u7acb\u5373\u8f93\u51fa\u3002

\u6b64\u5916\uff0c\u5c06\u9519\u8bef\u4fe1\u606f\u5bfc\u5411\u6807\u51c6\u9519\u8bef\u6d41\u8fd8\u6709\u53e6\u4e00\u4e2a\u597d\u5904\uff0c\u5c31\u662f\u4f60\u53ef\u4ee5\u5206\u522b\u6536\u96c6\u8c03\u8bd5\u4fe1\u606f\u548c\u6b63\u5e38\u8f93\u51fa\u3002\u6bd4\u5982\u4f60\u53ef\u4ee5\u5c06\u8c03\u8bd5\u4fe1\u606f\u91cd\u5b9a\u5411\u5230\u4e00\u4e2a\u6587\u4ef6\uff0c\u800c\u5c06\u6b63\u5e38\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u53e6\u4e00\u4e2a\u6587\u4ef6\u3002

./debug 2> debug.log 1> output.log\n
"},{"location":"programming/archive/23fall/lec1/lec1/#gdb","title":"\u4f7f\u7528 gdb \u8c03\u8bd5\u7a0b\u5e8f","text":"

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u4ee5\u88ab C \u6807\u51c6\u5f03\u7528\u7684\u5e93\u51fd\u6570 gets \u4e3a\u4f8b\uff0c\u7528 gdb \u5bf9\u5176\u8fdb\u884c\u8c03\u8bd5\uff1a

gets.c
char *gets(char *s)\n{\n    int c;\n    char *dest = s;\n    while((c = getchar()) != '\\n' && c != EOF)\n        *dest++ = c;\n    if(c == EOF && dest == s)\n        return NULL;\n    *dest++ = '\\0';\n    return s;\n}\n\nvoid echo()\n{\n    char buf[8];\n    gets(buf);\n    puts(buf);\n}\n
"},{"location":"programming/archive/23fall/lec1/lec1/#_21","title":"\u7f16\u8bd1\u65f6\u5f00\u542f\u8c03\u8bd5\u4fe1\u606f","text":"

\u5728\u7f16\u8bd1\u65f6\uff0c\u4f7f\u7528 -g \u9009\u9879\u5728\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u52a0\u5165\u6e90\u4ee3\u7801\u7684\u4fe1\u606f\uff0c\u6bd4\u5982\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u7b2c\u51e0\u6761\u673a\u5668\u6307\u4ee4\u5bf9\u5e94\u6e90\u4ee3\u7801\u7684\u7b2c\u51e0\u884c\uff0c\u4f46\u5e76\u4e0d\u662f\u628a\u6574\u4e2a\u6e90\u6587\u4ef6\u5d4c\u5165\u5230\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\uff0c\u6240\u4ee5\u5728\u8c03\u8bd5\u65f6\u5fc5\u987b\u4fdd\u8bc1 gdb \u80fd\u627e\u5230\u6e90\u6587\u4ef6\u3002\u8fd9\u4e9b\u4fe1\u606f\u53ef\u4ee5\u5e2e\u52a9\u8c03\u8bd5\u5668\u5b9a\u4f4d\u5230\u6e90\u4ee3\u7801\u7684\u4f4d\u7f6e\u3002

gcc -g -o gets gets.c\n

\u6709\u65f6\uff0c\u56e0\u4e3a GCC \u7684\u7279\u6027\uff0c\u53ef\u80fd\u5bfc\u81f4\u5141\u8bb8\u67d0\u4e9b\u4e0d\u7b26\u5408 C \u6807\u51c6\u7684\u4e8b\u60c5\u53d1\u751f\u3002\u8fd9\u65f6\u4f60\u53ef\u4ee5\u4f7f\u7528 -ansi -pedantic-errors \u6765\u5173\u95ed GCC \u7279\u6027\uff0c\u4e25\u683c\u9075\u5b88 ANSI C\u3002\u8fd9\u6784\u6210\u4e86\u5e38\u7528\u7684\u7f16\u8bd1\u9009\u9879\u3002

gcc -Wall -Werror -ansi -pedantic-errors -g prog1.c -o prog1\n
"},{"location":"programming/archive/23fall/lec1/lec1/#gdb_1","title":"gdb \u7684\u57fa\u672c\u4f7f\u7528","text":"

\u542f\u52a8 gdb \u7a0b\u5e8f\uff1a

GNU gdb (Ubuntu 10.2-6ubuntu1) 10.2\n...\nReading symbols from ./hello...\n(gdb)\n

\u547d\u4ee4\u884c\u7684\u63d0\u793a\u7b26\u4ece $ \u53d8\u6210\u4e86 (gdb)\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u5df2\u7ecf\u8fdb\u5165\u4e86 gdb \u7684\u4ea4\u4e92\u754c\u9762\u3002gdb \u4e2d\u5e38\u7528\u7684\u547d\u4ee4\u5982\u4e0b\uff1a

"},{"location":"programming/archive/23fall/lec1/lec1/#_22","title":"\u68c0\u67e5\u7a0b\u5e8f\u60c5\u51b5","text":"

Linux \u7cfb\u7edf\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u8bbe\u5907\u6587\u4ef6 /dev/zero\uff0c\u5b83\u80fd\u591f\u4f5c\u4e3a\u8f93\u5165\uff0c\u63d0\u4f9b\u65e0\u7a77\u65e0\u5c3d\u7684 0 \u5b57\u8282\u3002\u6211\u4eec\u5c06\u5b83\u4f5c\u4e3a\u8f93\u5165\uff0c\u770b\u770b\u7a0b\u5e8f\u4f1a\u53d1\u751f\u4ec0\u4e48\u3002

(gdb) file gets\nReading symbols from gets...\n(gdb) run < /dev/zero\nStarting program: /mnt/f/Code/_repo/study-assist/docs/programming_lecture/lecture1/code/gets < /dev/zero\n[Thread debugging using libthread_db enabled]\nUsing host libthread_db library \"/lib/x86_64-linux-gnu/libthread_db.so.1\".\n\nProgram received signal SIGSEGV, Segmentation fault.\n0x00005555555551b2 in gets (s=0x7fffffffd760 \"\") at gets.c:8\n8               *dest++ = c;\n

\u56e0\u4e3a\u7a0b\u5e8f\u8bbf\u95ee\u4e86\u975e\u6cd5\u7684\u5730\u5740\u7a7a\u95f4\uff0c\u7cfb\u7edf\u5411\u7a0b\u5e8f\u53d1\u9001\u4fe1\u53f7 SIGSEGV\uff0c\u7a0b\u5e8f\u7ec8\u6b62\u8fd0\u884c\u3002gdb \u4f1a\u81ea\u52a8\u505c\u5728\u53d1\u751f\u9519\u8bef\u7684\u4f4d\u7f6e\uff0c\u8fd9\u91cc\u662f gets.c \u7684\u7b2c 8 \u884c\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 backtrace \u547d\u4ee4\u67e5\u770b\u51fd\u6570\u8c03\u7528\u6808\u3002

(gdb) backtrace\n#0  0x00005555555551b2 in gets (s=0x7fffffffd760 \"\") at gets.c:8\n#1  0x000055555555521b in echo () at gets.c:18\n#2  0x0000000000000000 in ?? ()\n

\u4f7f\u7528 print \u547d\u4ee4\u67e5\u770b\u5404\u4e2a\u53d8\u91cf\u7684\u503c\u3002print/x \u80fd\u591f\u6307\u5b9a\u4ee5\u5341\u516d\u8fdb\u5236\u7684\u5f62\u5f0f\u6253\u5370\u53d8\u91cf\u7684\u503c\u3002

(gdb) print dest\n$1 = 0x7ffffffff001 <error: Cannot access memory at address 0x7ffffffff001>\n(gdb) print s\n$2 = 0x7fffffffd760 \"\"\n(gdb) print dest - s\n$3 = 6305\n(gdb) print c\n$4 = 0\n

gdb \u4e3a\u4f60\u505a\u4e86\u4e00\u4e9b\u63d0\u793a\uff0c\u6bd4\u5982 dest \u73b0\u5728\u6240\u6307\u5411\u7684\u5730\u5740 0x7ffffffff001 \u662f\u7a0b\u5e8f\u65e0\u6cd5\u8bbf\u95ee\u7684\u3002\u68c0\u67e5 dest - s \u7684\u503c\u6211\u4eec\u77e5\u9053\u6b64\u65f6 dest \u6307\u5411\u7684\u5730\u5740\u5df2\u7ecf\u662f s \u540e 6305 \u4e2a\u5b57\u8282\uff0c\u8fdc\u8fdc\u8d85\u51fa\u4e86\u6570\u7ec4 s \u7684\u7a7a\u95f4\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u68c0\u67e5\u5f53\u524d\u8f93\u5165\u7684\u5b57\u7b26 c\uff0c\u5b83\u663e\u7136\u662f 0\u3002

"},{"location":"programming/archive/23fall/lec1/lec1/#_23","title":"\u65ad\u70b9\u8c03\u8bd5","text":"

\u4f7f\u7528 break <filename>:<line> \u53ef\u4ee5\u5728\u6307\u5b9a\u6587\u4ef6\u6307\u5b9a\u884c\u8bbe\u7f6e\u65ad\u70b9\u3002\u5bf9\u4e8e\u5355\u6587\u4ef6\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u7701\u7565\u6e90\u4ee3\u7801\u6587\u4ef6\u540d\u3002break \u8fd8\u53ef\u4ee5\u63a5\u6536\u51fd\u6570\u540d\u548c\u5730\u5740\u4f5c\u4e3a\u53c2\u6570\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u6761\u4ef6\u8868\u8fbe\u5f0f\uff0c\u8bf7\u4f7f\u7528 help break \u67e5\u770b\u8be6\u7ec6\u7528\u6cd5\u3002

\u6211\u4eec\u5728\u7a0b\u5e8f\u7b2c 8 \u884c *dest++=c \u5904\u8bbe\u7f6e\u4e00\u4e2a\u65ad\u70b9\uff0c\u7136\u540e\u8fd0\u884c\u7a0b\u5e8f\u3002

(gdb) b 8\nBreakpoint 1 at 0x11a3: file gets.c, line 8.\n(gdb) r < /dev/zero\nStarting program: /mnt/f/Code/_repo/study-assist/docs/programming_lecture/lecture1/code/gets < /dev/zero\n\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8               *dest++ = c;\n(gdb) print dest - s\n$1 = 0\n

next \u547d\u4ee4\u5c06\u4f1a\u5355\u884c\u6267\u884c\u7a0b\u5e8f\uff0c\u4e14\u4e0d\u4f1a\u8fdb\u5165\u51fd\u6570\u5185\u90e8\uff08\u5373\u628a\u6574\u4e2a\u51fd\u6570\u5f53\u4f5c\u4e00\u884c\uff09\u3002step \u4f1a\u8fdb\u5165\u51fd\u6570\u5185\u90e8\u4e00\u884c\u4e00\u884c\u6267\u884c\u3002continue \u547d\u4ee4\u5c06\u7ee7\u7eed\u6267\u884c\u7a0b\u5e8f\uff0c\u76f4\u5230\u4e0b\u4e00\u4e2a\u65ad\u70b9\u3002

(gdb) next\n7               while((c = getchar()) != '\\n' && c != EOF)\n(gdb) next\nBreakpoint 1,gets (s=0x7fffffffd760 \"\") at gets.c:8\n8               *dest++ = c;\n(gdb) print dest - s\n$2 =1\n(gdb) continue\nContinuing.\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8               *dest++ = c;\n(gdb) print dest - s\n$3 = 2\n

next \u548c step \u547d\u4ee4\u90fd\u53ef\u4ee5\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\uff0c\u8868\u793a\u6267\u884c\u591a\u5c11\u884c\uff0c\u4e14\u4f1a\u5728\u65ad\u70b9\u5904\u505c\u4e0b\u3002continue \u547d\u4ee4\u4e5f\u53ef\u4ee5\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\uff0c\u8868\u793a\u5ffd\u7565\u63a5\u4e0b\u6765\u5730\u591a\u5c11\u4e2a\u65ad\u70b9\u3002

(gdb) next 20\n\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8               *dest++ = c;\n(gdb) print dest - s\n$4 = 3\n(gdb) continue 20\nWill ignore next 19 crossings of breakpoint 1.  Continuing.\n\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8               *dest++ = c;\n(gdb) print dest - s\n$5 = 23\n
\u8c03\u8bd5\u6280\u5de7

\u76f4\u63a5\u6309 Enter \u952e\uff0cgdb \u4f1a\u91cd\u590d\u4e0a\u4e00\u6761\u547d\u4ee4\u3002\u8fd9\u6837\u5c31\u4e0d\u7528\u4e00\u76f4\u8f93\u5165 next \u6216 step \u4e86\u3002

\u5728\u4e00\u4e9b\u66f4\u4e3a\u590d\u6742\u7684\u7a0b\u5e8f\u4e2d\uff0c\u4f7f\u7528 gdb \u8c03\u8bd5\u7684\u4f18\u8d8a\u6027\u5c31\u9010\u6e10\u663e\u73b0\u51fa\u6765\u4e86\u3002\u4f60\u4e0d\u7528\u9891\u7e41\u66f4\u6539\u6e90\u4ee3\u7801\u63d2\u5165 printf \u8bed\u53e5\uff0c\u53ea\u9700\u8981\u5728 gdb \u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u7136\u540e\u9010\u6b65\u6267\u884c\u7a0b\u5e8f\uff0c\u67e5\u770b\u53d8\u91cf\u7684\u503c\uff0c\u5c31\u80fd\u627e\u5230\u9519\u8bef\u6240\u5728\u3002

\u8fdb\u4e00\u6b65\u5b66\u4e60

\u7531\u4e8e\u4e2a\u4eba\u6c34\u5e73\u4e0d\u8db3\u4ee5\u53ca\u65f6\u95f4\u6709\u9650\uff0c\u6ca1\u80fd\u5199\u51fa\u4e00\u4e2a\u4f53\u9a8c\u8f83\u597d\u7684 GDB \u8c03\u8bd5\u5b9e\u9a8c\u3002\u5341\u5206\u5e0c\u671b\u540c\u5b66\u4eec\u5728\u8bfe\u540e\u53bb\u770b\u770b\u8fd9\u7bc7\u6587\u7ae0Linux C \u4e00\u7ad9\u5f0f\u7f16\u7a0b\uff1a\u7b2c 10 \u7ae0 gdb\uff0c\u628a\u8fd9\u8fb9\u7684\u8c03\u8bd5\u5b9e\u4f8b\u90fd\u8fc7\u4e00\u904d\uff5e

"},{"location":"programming/archive/23fall/lec1/lec1/#_24","title":"\u53c2\u8003\u8d44\u6599","text":"\u53c2\u8003\u8d44\u6599 "},{"location":"programming/archive/23fall/lec1/pre/","title":"\u8bfe\u524d\uff1a\u51c6\u5907\u5f00\u53d1\u4e0e\u8c03\u8bd5\u73af\u5883","text":"

Info

\u672c\u6587\u6863\u66f4\u6539\u81ea\u5468\u5065\u5747\u5b66\u957f\u4e3a\u56fe\u7075\u7a0b\u7b97\u8bfe\u7a0b\u51c6\u5907\u7684\u8d44\u6599\uff0c\u611f\u8c22\u5468\u5065\u5747\u5b66\u957f\u7684\u4ed8\u51fa\u3002

\u5185\u5bb9\u63d0\u8981

\u5728\u53c2\u4e0e\u7ebf\u4e0b\u6388\u8bfe\u524d\uff0c\u540c\u5b66\u4eec\u6700\u597d\u80fd\u591f\u5b89\u88c5\u597d\u76f8\u5173\u7684\u5f00\u53d1\u73af\u5883\uff0c\u4ee5\u4fbf\u80fd\u591f\u66f4\u597d\u7684\u8ddf\u968f\u8001\u5e08\u7684\u8bb2\u89e3\u3002

\u540c\u5b66\u4eec\u53ef\u4ee5\u4ece\u53f3\u4fa7\uff08\u7535\u8111\u7aef\uff09\u6216\u5de6\u4fa7\uff08\u624b\u673a\u7aef\uff09\u76ee\u5f55\u8df3\u8f6c\u5230\u81ea\u5df1\u9700\u8981\u7684\u7ae0\u8282\u3002

\u975e\u8ba1\u7b97\u673a\u4e13\u4e1a\u540c\u5b66\uff0c\u4f7f\u7528 Dev-C++ \u7b49 IDE \u6216\u5728\u7ebf IDE \u5373\u53ef\u3002

\u672c\u7bc7\u6587\u7ae0\u63cf\u8ff0\u7684\u5185\u5bb9\u9002\u7528\u4e8e\u8ba1\u7b97\u673a\u4e13\u4e1a\u7684\u540c\u5b66\u3002\u975e\u8ba1\u7b97\u673a\u4e13\u4e1a\u7684\u540c\u5b66\uff0c\u4e0d\u9700\u8981\u638c\u63e1\u547d\u4ee4\u884c\u7684\u4f7f\u7528\uff0c\u4f7f\u7528 IDE \u5373\u53ef\u3002\u5e76\u4e14\u66f4\u52a0\u63a8\u8350\u5728\u7ebf IDE\uff0c\u56e0\u4e3a\u672c\u5730 IDE \u6709\u65f6\u4e5f\u4f1a\u51fa\u9519\u3002\u6700\u5e38\u89c1\u7684\u4e00\u4e2a\u4f8b\u5b50\u662f\uff1a\u8fd0\u884c\u4e86\u4e00\u6b21\u7a0b\u5e8f\uff0c\u6ca1\u6709\u4ee5\u6070\u5f53\u7684\u65b9\u5f0f\u7ed3\u675f\u8fdb\u7a0b\uff0c\u518d\u6b21\u70b9\u51fb\u7f16\u8bd1\u65f6\u7f16\u8bd1\u5668 ld \u5c31\u4f1a\u56e0\u4e3a .exe \u88ab\u5360\u7528\u65e0\u6cd5\u5199\u5165\u800c\u62a5\u9519\uff0c\u4f46\u62a5\u9519\u4fe1\u606f\u5e76\u4e0d\u4f1a\u8868\u660e\u662f\u4e0a\u4e00\u4e2a\u7a0b\u5e8f\u6ca1\u5173\uff0c\u641e\u4e0d\u61c2\u662f\u600e\u4e48\u56de\u4e8b\u3002\u6211\u8fd8\u89c1\u8fc7\u6709\u540c\u5b66\uff0c\u6bcf\u6b21\u7f16\u8bd1\u5b8c\u8fd0\u884c\u7a0b\u5e8f\uff0c\u90fd\u8981\u88ab 360 \u5148\u626b\u63cf\u4e00\u904d\uff0c\u7b49\u4e2a\u534a\u5206\u949f\u624d\u80fd\u663e\u793a\u7a97\u53e3\u3002\u5728\u7ebf IDE \u4e0d\u53d7\u4f60\u7535\u8111\u7684\u5f71\u54cd\uff0c\u4e0d\u4f1a\u4ea7\u751f\u8fd9\u4e9b\u95ee\u9898\u3002

\u4e0b\u9762\u7684\u5757\u4ee5 Online GDB \u4e3a\u4f8b\uff0c\u5c55\u793a\u5728\u7ebf IDE \u7684\u7528\u6cd5\u3002\u914d\u597d\u73af\u5883\u7684\u540c\u5b66\u4e5f\u53ef\u4ee5\u770b\u4e00\u770b\uff0c\u56e0\u4e3a\u4f60\u53ef\u80fd\u5076\u5c14\u4e34\u65f6\u7528\u5230\u4e00\u4e2a\u6ca1\u6709\u914d\u7f6e\u73af\u5883\u7684\u7535\u8111\uff0c\u8fd9\u65f6\u4f7f\u7528\u5728\u7ebf IDE \u6700\u4e3a\u4fbf\u6377\u3002

Online GDB \u7684\u4f7f\u7528

\u53ef\u4ee5\u8df3\u8fc7\u672c\u7bc7\u6587\u7ae0\u7684\u540c\u5b66

\u7b26\u5408\u4ee5\u4e0b\u63cf\u8ff0\u7684\u540c\u5b66\u53ef\u4ee5\u8df3\u8fc7\u672c\u7bc7\u6587\u7ae0\uff1a

\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\u7684\u540c\u5b66\uff0c\u4e5f\u8bf7\u770b\u4e00\u4e0b Shell \u90e8\u5206\u3002

\u6e29\u99a8\u63d0\u793a

"},{"location":"programming/archive/23fall/lec1/pre/#shell","title":"Shell \u4f7f\u7528\u62fe\u9057","text":"

\u672c\u8282\u6211\u4eec\u8981\u8ba4\u8bc6\u4e00\u4e2a\u5373\u5c06\u6210\u4e3a\u4f60\u7684\u8001\u670b\u53cb\u7684\u4e1c\u897f\u2014\u2014Shell\u3002\u4e0b\u9762\u662f\u540c\u5b66\u4eec\u63a5\u4e0b\u6765\u4f1a\u7ecf\u5e38\u89c1\u5230\u7684\u51e0\u4e2a\u540d\u8bcd\uff1a

\u771f\u6b63\u610f\u4e49\u4e0a\u7684 Terminal

\u5728\u8ba1\u7b97\u673a\u53d1\u5c55\u7684\u65e9\u671f\u9636\u6bb5\uff0c\u8fd8\u6ca1\u6709\u50cf\u73b0\u5728\u7684 Windows \u8fd9\u6837\u7684\u56fe\u5f62\u7528\u6237\u754c\u9762\u3002\u90a3\u65f6\u4eba\u4eec\u4f7f\u7528\u7ec8\u7aef\u4e0e\u8ba1\u7b97\u673a\u4ea4\u4e92\u3002

Terminal \u548c Shell \u7684\u4f8b\u5b50

\u8fd9\u5f20\u56fe\u5c55\u793a\u4e86 Windows Terminal \u548c Powershell\u3002

Terminal \u548c Shell \u7684\u5173\u7cfb

\u53ef\u4ee5\u5c06 Terminal \u7406\u89e3\u6210\u663e\u793a\u5668\uff0c\u5c06 Shell \u7406\u89e3\u6210\u7535\u8111\u4e3b\u673a\u3002

\u6742\u8c08\uff1a\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u547d\u4ee4\u884c\u4ea4\u4e92\u754c\u9762\u5462\uff1f

\u5f88\u7b80\u5355\uff0c\u56e0\u4e3a\u6211\u4eec\u4e0d\u4ec5\u662f\u5728\u4f7f\u7528\u8ba1\u7b97\u673a\uff0c\u800c\u4e14\u662f\u5728\u5b66\u4e60\u8ba1\u7b97\u673a\u3002GUI \u81ea\u7136\u662f\u6700\u9002\u5408\u4e0e\u4eba\u4ea4\u4e92\u7684\uff0c\u4f46\u5b83\u4e5f\u662f\u7531 CLI \u642d\u5efa\u8d77\u6765\u7684\u3002\u6bd4\u5982\uff0c\u4f60\u53ef\u80fd\u5728\u4f7f\u7528 Dev-C++ \u6216 Visual Studio \u7b49 IDE \u8fdb\u884c\u7f16\u7a0b\uff0c\u53ea\u9700\u8981\u70b9\u4e00\u4e0b\u6309\u94ae\u5c31\u80fd\u81ea\u52a8\u5b8c\u6210\u7a0b\u5e8f\u7f16\u8bd1\u6b65\u9aa4\u3002\u8fd9\u56fa\u7136\u65b9\u4fbf\uff0c\u4f46\u662f\u5b83\u672c\u8d28\u4e0a\u662f\u5e2e\u4f60\u5199\u597d\u5e76\u6267\u884c\u4e86\u4e00\u7cfb\u5217\u7f16\u8bd1\u547d\u4ee4\uff0c\u5e2e\u4f60\u5b8c\u6210\u4e86\u547d\u4ee4\u884c\u7684\u64cd\u4f5c\u3002\u5f53\u4f60\u5f00\u59cb\u6784\u5efa\u5927\u578b\u9879\u76ee\u65f6\uff0c\u8fd9\u5f53\u7136\u662f\u6700\u9002\u5408\u7684\u65b9\u6cd5\u3002\u4f46\u4f5c\u4e3a\u521d\u5b66\u8005\uff0c\u6211\u4eec\u5e94\u5f53\u8d81\u6b64\u673a\u4f1a\u4e86\u89e3\u5176\u80cc\u540e\u7684\u539f\u7406\u3002

\u603b\u4e4b\uff1a\u5982\u679c\u8981\u5b66\u4e60\u8ba1\u7b97\u673a\uff0c\u90a3\u4e48\u5c31\u9700\u8981\u5b66\u4e60\u4f7f\u7528\u547d\u4ee4\u4e0e\u8ba1\u7b97\u673a\u4ea4\u4e92\uff0c\u8fd9\u6837\u624d\u80fd\u66f4\u597d\u5730\u7406\u89e3\u8ba1\u7b97\u673a\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002\u6b64\u5916\uff0c\u547d\u4ee4\u884c\u4ea4\u4e92\u754c\u9762\u4e5f\u6709\u8bb8\u591a\u6709\u70b9\uff0c\u6bd4\u5982\uff1a

\u6700\u4e3b\u8981\u7684\u662f\uff0c\u4f60\u4eca\u540e\u4f1a\u7528\u5230\u7684\u5f88\u591a\u5de5\u5177\u4e0d\u4e00\u5b9a\u4f1a\u63d0\u4f9b\u56fe\u5f62\u754c\u9762\uff0c\u4f46\u4e00\u5b9a\u4f1a\u63d0\u4f9b\u547d\u4ee4\u884c\u754c\u9762\u3002\u5b66\u4e60 CLI \u4e00\u5f00\u59cb\u786e\u5b9e\u6709\u4e9b\u96be\u5ea6\uff0c\u4f46\u53ea\u8981\u5b66\u4e86\uff0c\u5c31\u4f1a\u53d7\u76ca\u65e0\u7a77\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#_2","title":"\u8fd0\u884c\u4e0e\u7ec8\u7aef","text":"

\u5728 Windows \u4e0a\u5982\u4f55\u6253\u5f00 Terminal \u5462\uff1f

\u8fd0\u884c\u7a97\u53e3

\u4f7f\u7528 Win+R \u7ec4\u5408\u952e\uff0c\u5c06\u4f1a\u51fa\u73b0\u56fe\u4e2d\u7684\u7a97\u53e3\u3002\u53ef\u4ee5\u5728\u5176\u4e2d\u8f93\u5165\u547d\u4ee4\u8fd0\u884c\uff0c\u5373\u4f7f\u662f Windows XP \u90fd\u53ef\u4ee5\u4f7f\u7528\u3002

\u547d\u4ee4\u63d0\u793a\u7b26 CMD

\u5728\u8fd0\u884c\u7a97\u53e3\u4e2d\u8f93\u5165 cmd \u540e\u56de\u8f66\uff0c\u5c31\u4f1a\u51fa\u73b0\u547d\u4ee4\u63d0\u793a\u7b26\u3002\u547d\u4ee4\u63d0\u793a\u7b26\u662f Windows \u6700\u57fa\u672c\u7684 Shell\uff08\u4e0e Linux \u7684 bash \u540c\u7b49\u5730\u4f4d\uff09\uff0c\u4f46\u662f\u529f\u80fd\u53ca\u5176\u6709\u9650\uff0c\u4e00\u822c\u4e0d\u7528\u3002

Powershell

Powershell \u7b80\u79f0 pwsh\uff0c\u662f Windows \u7684\u65b0\u4e00\u4ee3\u547d\u4ee4\u89e3\u91ca\u5668\u3002\u5b83\u7684\u529f\u80fd\u5f3a\u5927\uff0c\u4f46\u8bed\u6cd5\u548c\u6211\u4eec\u5c06\u8981\u5b66\u4e60\u4e14\u6700\u5e38\u7528\u7684 Linux Shell \u5927\u4e0d\u76f8\u540c\u3002\u6211\u4eec\u5728 Windows \u4e0a\u7ecf\u5e38\u4f7f\u7528 pwsh\uff0c\u4f46\u4e0d\u7528\u82b1\u65f6\u95f4\u53bb\u5b66\u4e60\u5b83\u3002

Windows Terminal

\u8fd9\u662f Windows \u4e0a\u6700\u597d\u7684 Terminal\uff0c\u5bf9\u5404\u79cd Shell \u7684\u663e\u793a\u6548\u679c\u90fd\u652f\u6301\u7684\u5f88\u597d\u3002\u5728 Microsoft Store \u4e2d\u641c\u7d22 Terminal\uff0c\u51fa\u73b0\u56fe\u4e2d\u7684\u9009\u9879\uff0c\u7136\u540e\u9009\u62e9\u5b89\u88c5\u5373\u53ef\u3002\u5b83\u5bf9\u5e94\u4e8e macOS \u4e0a\u7684 iTerm\u3002\u4eca\u540e\u5b66\u4e60 ssh \u65f6\uff0c\u4f60\u8fd8\u53ef\u80fd\u4f1a\u63a5\u89e6\u5230 Termius\u3002

\u5728\u6bd4\u8f83\u65b0\u7248\u672c\u7684 Windows \u4e2d\uff0cWin \u952e\u6253\u5f00\u83dc\u5355\u4e4b\u540e\u8f93\u5165\u5b57\u7b26\u80fd\u591f\u641c\u7d22\u5230\u5bf9\u5e94\u7a0b\u5e8f\uff0c\u9664\u4e86\u5e38\u7528\u7684\u5e94\u7528\u7a0b\u5e8f\u4ee5\u5916\uff0c\u542f\u52a8 cmd.exe \u4e5f\u53ef\u4ee5\u8fd9\u6837\u8fdb\u884c\uff0c\u6548\u679c\u548c Win + R \u76f8\u540c\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#wsl","title":"WSL \u5b89\u88c5\u7b80\u5355\u5f15\u5bfc\uff08\u53ef\u9009\uff09","text":"

\u63a8\u8350\u88c5\u4e00\u88c5\uff0c\u5982\u679c\u4e3b\u529b\u673a\u662f Windows \u5728\u4ee5\u540e\u5c06\u5bf9 WSL \u6709\u8f83\u5927\u9700\u6c42

WSL\uff0c\u5168\u79f0 Windows Subsystem for Linux\uff08\u9002\u7528\u4e8e Linux \u7684 Windows \u5b50\u7cfb\u7edf\uff09\uff0c\u662f\u4e00\u9879\u5141\u8bb8\u5f00\u53d1\u8005\u4e0d\u4f9d\u9760\u5355\u72ec\u7684\u865a\u62df\u673a\u6216\u53cc\u542f\u52a8 (dual booting) \u800c\u5728 Windows \u4e0a\u8fd0\u884c Linux \u73af\u5883\u7684\u529f\u80fd\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#ubuntu","title":"\u5b89\u88c5\uff1a\u4ee5 Ubuntu \u4e3a\u4f8b","text":"

\u5728\u8fd9\u91cc\u4ee5\u5728 Windows11 \u4e0a\u5b89\u88c5 WSL2 Ubuntu \u4e3a\u4f8b\u4ecb\u7ecd\u6700\u7b80\u5355\u7684\u5b89\u88c5\u6d41\u7a0b\uff0c\u8be6\u7ec6\u7684\u4fe1\u606f\u53ef\u4ee5\u53c2\u8003\u5b98\u65b9\u6587\u6863 Install Linux on Windows with WSL \u6216\u8005\u5b83\u7684\u4e2d\u6587\u7248\u3002

Ubuntu \u662f Linux \u7684\u4e00\u79cd\u53d1\u884c\u7248\u672c\uff0c\u5728\u8fd9\u91cc\u5c31\u4e0d\u5bf9 Linux \u7684\u4f17\u591a\u53d1\u884c\u7248\u672c\u8fdb\u884c\u4ecb\u7ecd\u548c\u8bc4\u4ef7\u4e86\u3002\u6709\u80fd\u529b\u548c\u60f3\u6cd5\u7684\u540c\u5b66\u53ef\u4ee5\u81ea\u5df1\u5bf9\u7167\u6559\u7a0b\u5b89\u88c5\u5176\u4ed6\u53d1\u884c\u7248\uff0c\u6bd4\u5982\u5728\u7ec8\u7aef\u8f93\u5165 wsl --list --online \u53ef\u4ee5\u770b\u5230\u6240\u6709\u53ef\u4ee5\u9009\u62e9\u7684 Linux \u53d1\u884c\u7248

\u6ce8\u610f\u5b89\u88c5 WSL \u7684\u5148\u51b3\u6761\u4ef6\uff1aWindows \u7248\u672c\u4e0d\u4f4e\u4e8e Windows 10 20H2\uff08Build 19042\uff09\u6216\u8005 Windows 11\u3002\u5982\u679c\u7248\u672c\u592a\u8001\uff0c\u8bf7\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\uff0c\u5982\u679c\u65e0\u6cd5\u66f4\u65b0\u53ef\u4ee5\u8003\u8651\u91cd\u88c5\u7cfb\u7edf\u3002

\u53ef\u4ee5\u4f7f\u7528 winver \u547d\u4ee4\u67e5\u8be2 Windows \u7248\u672c\uff0cWin + R \u8f93\u5165 winver \u6216\u8005\u5728 Win \u952e\u51fa\u73b0\u7684\u83dc\u5355\u680f\u4e2d\u76f4\u63a5\u8f93\u5165 winver \u90fd\u53ef\u4ee5\u542f\u52a8\u3002\u65b0\u4e70\u7684\u7535\u8111\u53ef\u80fd Windows 11 \u5c45\u591a\uff0c\u5982\u679c\u662f Windows 10 \u7684\u7535\u8111\u7248\u672c\u663e\u793a\u53ef\u80fd\u662f 21H2\uff08\u64cd\u4f5c\u7cfb\u7edf\u5185\u90e8\u7248\u672c 19044.3086\uff09\uff0c\u8fd9\u6837\u4e5f\u662f\u7b26\u5408\u5148\u51b3\u6761\u4ef6\u7684\u3002

\u5728 Powershell\uff08\u7ba1\u7406\u5458\uff09\u4e2d\u76f4\u63a5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u81ea\u52a8\u5b89\u88c5\uff08\u6ce8\u610f\uff0c\u6bcf\u4e00\u884c\u547d\u4ee4\u5206\u522b\u6267\u884c\uff0c\u4e0d\u8981\u591a\u884c\u7c98\u8d34\u6267\u884c\uff09\uff1a

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart\ndism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart\nwsl --install\n

\u4e2d\u9014\u53ef\u80fd\u4f1a\u5f39\u51fa\u4e24\u4e2a\u7a97\u53e3\uff0c\u663e\u793a\u6b63\u5728\u4fee\u6539\u4ec0\u4e48\u4e1c\u897f\uff0c\u7edf\u7edf\u9009\u62e9\u201c\u662f\u201d\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5c06\u51fa\u73b0\u5982\u4e0b\u754c\u9762

\u8fd9\u6837\u5c31\u5b8c\u6210\u4e86 WSL2 Ubuntu \u7684\u5b89\u88c5\u3002

\u9519\u8bef\uff1a0x80370114

\u4f7f\u7528\u7ec8\u7aef\u7684\u4e00\u5927\u597d\u5904\u662f\u65b9\u4fbf\u6253\u5f00 WSL\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u70b9\u51fb Ubuntu 22.04.2 LTS \u6216\u8005\u4f7f\u7528 Ctrl + Shift + 5 \u7ec4\u5408\u952e\u5c31\u53ef\u4ee5\u65b9\u4fbf\u5730\u6253\u5f00 Ubuntu 22.04\u3002\u5f53\u7136\u8fd9\u662f\u56e0\u4e3a\u6211\u5b89\u88c5\u7684\u662f Ubuntu 22.04 \u7684\u7f18\u6545\uff0c\u5728\u4f60\u4eec\u7684\u7535\u8111\u4e2d\u663e\u793a\u7684\u5e94\u8be5\u5c31\u662f Ubuntu\u3002

\u5176\u4ed6 WSL \u7684\u4f7f\u7528\u65b9\u6cd5\u7559\u5f85\u4f60\u4eec\u6162\u6162\u63a2\u7d22\u4e86\uff0c\u5728\u6b64\u4e0d\u518d\u8d58\u8ff0\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#c","title":"\u5b89\u88c5 C \u8bed\u8a00\u7f16\u8bd1\u5668","text":"

\u5982\u679c\u5df2\u7ecf\u5b89\u88c5\u597d WSL\uff0c\u90a3\u4e48\u53ef\u4ee5\u8df3\u8fc7\u672c\u8282\uff0c\u56e0\u4e3a\u57fa\u672c\u4e0a\u4e0d\u9700\u8981\u5728 Windows \u4e0a\u518d\u5b89\u88c5\u7f16\u8bd1\u73af\u5883\u4e86\u3002

\u672c\u7bc7\u76f8\u5bf9\u6bd4\u8f83\u590d\u6742\uff0c\u5982\u679c\u5728\u672c\u7bc7\u914d\u7f6e\u9047\u5230\u96be\u4ee5\u89e3\u51b3\u7684\u56f0\u96be\uff0c\u800c\u4f5c\u4e1a/\u5b9e\u9a8c\u622a\u6b62\u65e5\u671f\u5feb\u8981\u5230\u4e86\uff0c\u53ef\u4ee5\u8df3\u8fc7\u672c\u7bc7\u5b89\u88c5 Dev-C++ \u8fdb\u884c\u4e34\u65f6\u5f00\u53d1\u3002

\u5199\u5b8c\u4e86 C \u8bed\u8a00\u4ee3\u7801\uff0c\u6211\u4eec\u9700\u8981\u8ba9\u5b83\u53d8\u6210\u80fd\u8dd1\u7684\u7a0b\u5e8f\uff0c\u8fd9\u5c31\u9700\u8981\u51c6\u5907 C \u8bed\u8a00\u7684\u7f16\u8bd1\u5668\u652f\u6301\u3002\u4ee5\u4e0b\u4e3b\u8981\u4ecb\u7ecd Windows \u7cfb\u7edf\u7684\u914d\u7f6e\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#gcc","title":"\u5c31\u51b3\u5b9a\u662f\u4f60\u4e86\uff0cgcc","text":"

\u81ea\u7531\u8f6f\u4ef6 (free software)\uff0c\u6839\u636e\u81ea\u7531\u8f6f\u4ef6\u57fa\u91d1\u4f1a\u5bf9\u5176\u7684\u5b9a\u4e49\uff0c\u662f\u4e00\u7c7b\u53ef\u4ee5\u4e0d\u53d7\u9650\u5236\u5730\u81ea\u7531\u4f7f\u7528\u3001\u590d\u5236\u3001\u7814\u7a76\u3001\u4fee\u6539\u548c\u5206\u53d1\u7684\uff0c\u5c0a\u91cd\u7528\u6237\u81ea\u7531\u7684\u8f6f\u4ef6\u3002\u2014\u2014\u7ef4\u57fa\u767e\u79d1

gcc\uff0c\u5168\u79f0 GNU Compiler Collection\uff0c\u8457\u540d\u7684\u81ea\u7531\u8f6f\u4ef6\uff0c\u88ab\u8bb8\u591a\u73b0\u4ee3\u7c7b Unix \u64cd\u4f5c\u7cfb\u7edf\u91c7\u7528\u4e3a\u6807\u51c6\u7f16\u8bd1\u5668\uff0c\u4f46\u662f Windows \u4e0a\u5e76\u4e0d\u76f4\u63a5\u652f\u6301\u3002\u6211\u4eec\u60f3\u8981\u5728 Windows \u7cfb\u7edf\u4e0a\u4f7f\u7528\uff0c\u4e00\u822c\u5f97\u4f9d\u8d56 MinGW \u7684 gcc\uff0ctdm-gcc \u4e5f\u662f\u57fa\u4e8e MinGW \u7684 gcc \u6765\u7684\u3002

\u6709\u80fd\u529b\u7684\u540c\u5b66\u63a8\u8350\u5728 Windows \u4e0a\u5f00\u542f WSL\uff0c\u4f7f\u7528 WSL \u8fdb\u884c C \u8bed\u8a00\u5f00\u53d1\u3002WSL \u53ef\u4ee5\u7406\u89e3\u4e3a\u5728 Windows \u7684\u7535\u8111\u4e2d\u6a21\u62df\u4e00\u4e2a Linux \u7684\u5c0f\u7cfb\u7edf\uff0c\u4ece\u800c\u80fd\u65b9\u4fbf\u5730\u63a7\u5236\u73af\u5883\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#windows-tdm-gcc","title":"Windows \u5c0f\u767d\u6559\u7a0b\u4e4b tdm-gcc","text":"

\u524d\u9762\u9009\u62e9\u4e86 WSL \u7684\u540c\u5b66\u53ef\u4ee5\u81ea\u884c\u914d\u7f6e\uff0c\u7136\u540e\u518d\u770b\u7b2c 3 \u8282\u3002Mac \u7528\u6237\u53ef\u4ee5\u76f4\u63a5\u770b\u7b2c 3 \u8282\u3002

\u53ef\u4ee5\u6309\u7167\u8001\u5e08\u7684\u89c6\u9891\u6559\u7a0b\u4e0b\u8f7d tdm-gcc\uff0c\u76ee\u524d\u6700\u65b0\u7248\u4e3a gcc 10.3.0\u3002

\u9700\u8981\u5224\u65ad\u81ea\u5df1\u7684 Windows \u662f 64 \u4f4d\u7cfb\u7edf\u8fd8\u662f 32 \u4f4d\u7cfb\u7edf\uff08\u73b0\u5728\u4e00\u822c\u90fd\u662f 64 \u4f4d\u7cfb\u7edf\uff09\u3002

Windows 11Windows 10

\u70b9\u51fb Win \u952e\uff0c\u8f93\u5165\u201c\u5173\u4e8e\u201d\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002\u6253\u5f00\u201c\u5173\u4e8e\u4f60\u7684\u7535\u8111\u201d\u540e\u5c31\u53ef\u4ee5\u770b\u5230\u7535\u8111\u662f\u4e0d\u662f 64 \u4f4d\u4e86\uff0c\u65b0\u7535\u8111\u4e00\u822c\u90fd\u662f 64 \u4f4d\u3002

\u684c\u9762\u627e\u5230\u201c\u6b64\u7535\u8111\u201d\uff0c\u53f3\u952e\u5c5e\u6027

\u53ef\u4ee5\u770b\u5230\u662f 64 \u4f4d\u7cfb\u7edf\u8fd8\u662f 32 \u4f4d\u7cfb\u7edf\u3002

64 \u4f4d\u7cfb\u7edf\u76f4\u63a5\u4e0b\u8f7d tdm64-gcc-10.3.0-2.exe \u5b89\u88c5\u5373\u53ef\uff0c32 \u4f4d\u5219\u9009\u62e9 tdm-gcc-10.3.0.exe\u3002

\u51c6\u5907\u5b89\u88c5\u3002\u5bf9\u4e8e\u96f6\u57fa\u7840\u7684\u540c\u5b66\uff0c\u7535\u8111\u91cc\u5e94\u8be5\u8fd8\u6ca1\u88c5\u8fc7 tdm-gcc\uff0c\u9009\u62e9 create \u5373\u53ef\u3002

\u63a5\u4e0b\u6765\u5c31\u662f\u6839\u636e 64/32 \u4f4d\u7cfb\u7edf\u9009\u62e9\u5bf9\u5e94\u7684\u7248\u672c

\u9009\u62e9\u5b89\u88c5\u8def\u5f84\uff0c\u63a8\u8350\u96f6\u57fa\u7840\u540c\u5b66\u9009\u62e9\u9ed8\u8ba4\u8def\u5f84\uff08\u5982 64 \u4f4d\u7684 C:\\TDM-GCC-64\uff09

\u63a5\u4e0b\u6765\u662f\u8981\u8ba4\u771f\u8003\u8651\u7684\u9875\u9762\u3002

\u5982\u679c\u5e0c\u671b\u7528\u66f4\u65b0\u7248\u672c\u7684 gcc \u53ef\u4ee5\u4f7f\u7528 winlibs \u7f16\u8bd1\u7684 mingw-gcc\uff0c\u6216\u8005\u4f60\u53ef\u4ee5\u81ea\u5df1\u9009\u62e9\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#gcc_1","title":"\u6d4b\u8bd5 gcc \u662f\u5426\u6b63\u786e\u5b89\u88c5","text":"WindowsWSLmacOS

\u5728\u547d\u4ee4\u63d0\u793a\u7b26/\u7ec8\u7aef\u4e2d\u8f93\u5165 gcc\uff0c\u5e94\u5f53\u51fa\u73b0\u5982\u4e0b\u4fe1\u606f\uff1a

gcc: fatal error: no input files\ncompilation terminated.\n

\u5982\u679c\u6ca1\u6709\uff0c\u53ef\u80fd\u662f\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5 gcc\uff0c\u6216\u8005\u4f60\u524d\u4e00\u6b65 Add to PATH \u6ca1\u6709\u6b63\u5e38\u8fdb\u884c\uff0c\u53ef\u80fd\u9700\u8981\u53c2\u7167 Windows \u4fee\u6539\u73af\u5883\u53d8\u91cf\u8fdb\u884c\u73af\u5883\u53d8\u91cf\u7684\u68c0\u67e5\u3002

\u547d\u4ee4\u63d0\u793a\u7b26/\u7ec8\u7aef\u4e2d\u8f93\u5165 gcc --version\uff0c\u5e94\u5f53\u51fa\u73b0\u7c7b\u4f3c\u5982\u4e0b\u7684\u4fe1\u606f\u3002

gcc.exe (tdm64-1) 9.2.0\nCopyright (C) 2019 Free Software Foundation, Inc.\nThis is free software; see the source for copying conditions.  There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n

\u6211\u7684\u7248\u672c\u663e\u793a\u662f 9.2.0\uff0c\u662f\u56e0\u4e3a\u88c5\u4e86\u65e7\u7248\u672c\u7684 tdm-gcc\uff0c\u4f60\u4eec\u7684\u663e\u793a\u5c06\u4f1a\u662f 10.3.0\u3002

\u5982\u4e0b\u547d\u4ee4\u5b89\u88c5 gcc\u3002\u5982\u679c\u9519\u8bef\uff0c\u5c1d\u8bd5 sudo apt-get update \u540e\u518d\u91cd\u65b0\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\u3002

sudo apt install gcc\n

\u7ec8\u7aef\u4e2d\u8f93\u5165 gcc\uff0c\u5e94\u5f53\u51fa\u73b0\u5982\u4e0b\u4fe1\u606f\uff1a

gcc: fatal error: no input files\ncompilation terminated.\n

\u7ec8\u7aef\u4e2d\u8f93\u5165 gcc --version\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u7c7b\u4f3c\u5982\u4e0b\u7684\u4fe1\u606f\uff1a

gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0\nCopyright (C) 2021 Free Software Foundation, Inc.\nThis is free software; see the source for copying conditions.  There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n

Mac \u7528\u6237\u76f4\u63a5\u4f7f\u7528 gcc -v \uff08\u6216\u8005 xcode-select --install\uff09\u4f1a\u63d0\u793a\u4f60\u5b89\u88c5\u5f00\u53d1\u8005\u5de5\u5177\uff0c\u7136\u540e\u5c31\u4f1a\u81ea\u52a8\u5b89\u88c5 XCode \u5728\u5185\u7684\u4e00\u7cfb\u5217\u5f00\u53d1\u652f\u6301\uff0c\u6700\u540e\u544a\u8bc9\u4f60\u4f60\u5b89\u88c5\u7684 gcc \u5176\u5b9e\u662f clang\uff0c\u672c\u8d28\u4e0a\u662f\u5b83\u5c06 gcc \u4f5c\u4e3a clang \u7684\u522b\u540d (alias) \u4e86\u3002

\u6210\u529f\u5b89\u88c5\u540e\uff0c\u7ec8\u7aef\u8f93\u5165 gcc \u4f1a\u51fa\u73b0\u5982\u4e0b\u4fe1\u606f\uff1a

clang: error: no input files\n

\u4f7f\u7528 gcc --version \u53ef\u80fd\u51fa\u73b0\u4ee5\u4e0b\u4fe1\u606f\uff1a

Apple clang version 14.0.3 (clang-1403.0.22.14.1)\nTarget: x86_64-apple-darwin22.6.0\nThread model: posix\nInstalledDir: /Library/Developer/CommandLineTools/usr/bin\n

gcc \u548c clang \u90fd\u662f C \u8bed\u8a00\u7f16\u8bd1\u5668\uff0c\u53ea\u662f\u7279\u6027\u4e0a\u5b58\u5728\u5dee\u5f02\u3002\u5728\u4f5c\u4e1a\u548c\u5b9e\u9a8c\u4e2d\uff0c\u4e00\u4e2a\u597d\u7684\u9075\u4ece\u6807\u51c6\u7684 C \u4ee3\u7801\uff0c\u7531\u4e0d\u540c\u7684\u7f16\u8bd1\u5668\u7f16\u8bd1\u540e\u4e0d\u5e94\u5f53\u4ea7\u751f\u4e0d\u540c\u7684\u8fd0\u884c\u7ed3\u679c\u3002\u56e0\u6b64\u5982\u679c\u4f60\u4f7f\u7528 clang \u7f16\u8bd1 C \u4ee3\u7801\u8fd0\u884c\u4e0d\u7b26\u5408\u9884\u671f\uff0c\u4ee3\u7801\u51fa\u95ee\u9898\u7684\u6982\u7387\u6bd4 clang \u7279\u6027\u51fa\u95ee\u9898\u7684\u6982\u7387\u5927\u5f88\u591a\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#windows","title":"Windows \u4fee\u6539\u73af\u5883\u53d8\u91cf","text":"

Windows \u7528\u6237\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u51fa\u73b0\u95ee\u9898\u4e86\u624d\u9700\u8981\u770b\u8fd9\u4e00\u5c0f\u8282

\u68c0\u67e5\u4e00\u4e0b\u73af\u5883\u53d8\u91cf\uff0cWin + R \u952e\u8f93\u5165 sysdm.cpl \u540e\u56de\u8f66\uff0c\u4f1a\u51fa\u73b0\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u754c\u9762\uff0c\u9009\u62e9\u201c\u9ad8\u7ea7\u201d\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a

\u6253\u5f00\u73af\u5883\u53d8\u91cf\uff0c\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u6216\u8005\u201c\u7528\u6237\u53d8\u91cf\u201d\u4e2d\u627e\u5230 PATH \u53d8\u91cf\uff0c\u5728\u5176\u4e2d\u589e\u52a0\u4e00\u9879 tdm-gcc \u7684\u8def\u5f84\u3002\u4f8b\u5982\u4f60\u5982\u679c\u9ed8\u8ba4\u5b89\u88c5 tdm-gcc\uff0c\u90a3\u4e48\u8def\u5f84\u53ef\u80fd\u5c31\u662f C:\\TDM-GCC-64\\bin\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#vscode","title":"VSCode \u5b89\u88c5\u4e0e\u914d\u7f6e","text":"

VSCode \u7684\u5168\u79f0\u662f Visual Studio Code\uff0c\u6ce8\u610f\u5b83\u548c Visual Studio \u5b8c\u5168\u662f\u4e24\u4e2a\u4e1c\u897f

\u4e0d\u5efa\u8bae\u5b89\u88c5 Visual Studio\uff0c\u9664\u975e\u4f60\u6e05\u695a\u4f60\u5b89\u88c5\u5b83\u662f\u4e3a\u4e86\u4ec0\u4e48

\u5728\u8fd9\u91cc\u4ec5\u4ecb\u7ecd Visual Studio Code \u7684\u5b89\u88c5\u3002\u9664\u4e86\u8001\u5e08\u7684\u89c6\u9891\u4e4b\u5916\uff0c\u5927\u5bb6\u5b89\u88c5\u914d\u7f6e\u65f6\u8fd8\u53ef\u4ee5\u53c2\u8003 GZTime \u7684\u6559\u7a0b\uff0c\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bf4\u8fd8\u4e0d\u9519\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#_3","title":"\u5b89\u88c5","text":"

VSCode \u76f4\u63a5\u4ece\u5b98\u7f51\u9009\u62e9\u81ea\u5df1\u5e73\u53f0\u5bf9\u5e94\u7684\u5b89\u88c5\u5305\u4e0b\u8f7d\u5c31\u884c

WindowsMac

Windows \u7684 exe \u5b89\u88c5\u53ef\u4ee5\u5168\u9009\u9ed8\u8ba4\u9009\u9879\u4e00\u8def Next\uff0c\u6bd4\u8f83\u719f\u6089\u7684\u540c\u5b66\u53ef\u4ee5\u81ea\u5b9a\u4e49\u9009\u9879\uff1a

Mac \u7684\u5305\u4e0b\u8f7d\u4e0b\u6765\u4e4b\u540e\u62d6\u5165 Application \u6587\u4ef6\u5939\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c

"},{"location":"programming/archive/23fall/lec1/pre/#_4","title":"\u63d2\u4ef6\u5b89\u88c5","text":"

\u6253\u5f00 VSCode \u540e\uff0c\u5728\u5de6\u4fa7\u7ad6\u680f\u5bfb\u627e\u4e0b\u9762\u8fd9\u4e2a\u56fe\u6807\uff1a

\u70b9\u51fb\u8fd9\u4e2a\u56fe\u6807\u5c31\u8fdb\u5165\u4e86\u63d2\u4ef6\u7ba1\u7406\u3002\u5efa\u8bae\u53ef\u4ee5\u5b89\u88c5\u4e0b\u9762\u4e24\u4e2a\u63d2\u4ef6\uff1a

\u5b89\u88c5\u6c49\u5316\u63d2\u4ef6\u540e\u53ef\u80fd\u9700\u8981\u4f60\u624b\u52a8\u5207\u6362\u663e\u793a\u8bed\u8a00\u3002Ctrl + Shift + P\uff0c\u51fa\u73b0\u7684\u641c\u7d22\u6846\u4e2d\u8f93\u5165 Configure\uff0c\u9009\u62e9 Configure Display Language\u3002

\u968f\u540e\u518d\u9009\u62e9\u201c\u4e2d\u6587 (\u7b80\u4f53)\u201d\u5c31\u53ef\u4ee5\u5b8c\u6210\u754c\u9762\u6c49\u5316\u4e86\u3002

\u82f1\u8bed\u57fa\u7840\u4e0d\u592a\u597d\u7684\u540c\u5b66\u6709\u56f0\u96be\u53ef\u4ee5\u4f7f\u7528\uff0c\u82f1\u8bed\u57fa\u7840\u6bd4\u8f83\u597d\u4ee5\u53ca\u60f3\u8981\u5728\u65e5\u5e38\u5b9e\u8df5\u4e2d\u5b66\u4e60\u82f1\u8bed\u7684\u540c\u5b66\u5efa\u8bae\u8df3\u8fc7\u8fd9\u4e00\u6b65\u3002

\u8fd9\u91cc\u53ea\u63d0\u4f9b\u6700\u57fa\u672c\u7684\u63d2\u4ef6\u548c\u4f7f\u7528\u793a\u4f8b\uff0c\u590d\u6742\u7684\u914d\u7f6e\u4e0e\u4f7f\u7528\u5927\u5bb6\u53ef\u4ee5\u53c2\u8003 GZTime \u7684\u6559\u7a0b

"},{"location":"programming/archive/23fall/lec1/pre/#vscode_1","title":"VSCode \u4f7f\u7528\u7684\u4e00\u4e2a\u7b80\u5355\u793a\u4f8b","text":"

\u8fd9\u91cc\u4e3a\u60f3\u8981\u5c3d\u5feb\u4e0a\u624b\u7684\u540c\u5b66\u63d0\u4f9b\u4e00\u4e2a\u7b80\u5355\u7684\u4f7f\u7528\u793a\u4f8b\u3002\u6253\u5f00 VSCode\uff08\u6253\u5f00\u65f6\u6ca1\u6709\u6307\u5b9a\u5de5\u4f5c\u76ee\u5f55\uff09\uff0c\u5c06\u4f1a\u51fa\u73b0\u5982\u4e0b\u7684\u7a97\u53e3\uff1a

\u5de5\u4f5c\u76ee\u5f55\uff0c\u6307\u67d0\u4e2a\u4e13\u95e8\u5b58\u653e\u4f60\u7528\u4e8e\u67d0\u4e2a\u76ee\u7684\u7684\u6587\u4ef6\u7684\u6587\u4ef6\u5939\u3002\u4f8b\u5982\u4f60\u53ef\u80fd\u4f1a\u5efa\u7acb\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u4e13\u95e8\u5b58\u653e\u6240\u6709\u4e0e\u7b2c\u4e00\u6b21\u4f5c\u4e1a\u76f8\u5173\u7684\u4ee3\u7801\u3001\u6587\u6863\u3001\u914d\u7f6e\u6587\u4ef6\u7b49\uff0c\u5728\u4f60\u4e3a\u5b8c\u6210\u7b2c\u4e00\u6b21\u4f5c\u4e1a\u800c\u5de5\u4f5c\u65f6\uff0c\u8fd9\u4e2a\u6587\u4ef6\u5939\u5c31\u662f\u4f60\u7684\u5de5\u4f5c\u76ee\u5f55

\u70b9\u51fb\u5de6\u4fa7\u7684 Open Folder\uff0c\u9009\u62e9\u4e00\u4e2a\u76ee\u5f55\u4f5c\u4e3a\u4f60\u7684\u5de5\u4f5c\u76ee\u5f55\uff0c\u4e00\u822c\u4f1a\u628a\u4f60\u8fd9\u4e2a\u7a97\u53e3\u6240\u8981\u5904\u7406\u7684\u6240\u6709\u6587\u4ef6\u653e\u7f6e\u5728\u8fd9\u91cc\u3002\u9876\u680f Terminal > New Terminal\uff08\u6216\u7ec8\u7aef > \u65b0\u5efa\u7ec8\u7aef\uff09\u6253\u5f00 VSCode \u7684\u5185\u90e8\u7ec8\u7aef\uff0c\u529f\u80fd\u5927\u81f4\u4e0e\u547d\u4ee4\u63d0\u793a\u7b26/\u7ec8\u7aef\u76f8\u540c\u3002

\u4e0b\u56fe\u5c31\u662f\u6253\u5f00\u4e86\u5de5\u4f5c\u76ee\u5f55\u5e76\u65b0\u5efa\u4e86\u7ec8\u7aef\u7684\u754c\u9762\u72b6\u6001\u3002

\u9f20\u6807\u79fb\u52a8\u5230\u5de5\u4f5c\u533a\uff0c\u6309 New File \u952e\u53ef\u4ee5\u65b0\u5efa\u6587\u4ef6\uff0c\u65c1\u8fb9\u6709\u65b0\u5efa\u6587\u4ef6\u5939\u6309\u952e\u3002\u5f53\u7136\uff0c\u76f4\u63a5\u5728\u5de6\u4fa7\u5de5\u4f5c\u76ee\u5f55\u53f3\u952e\u4e5f\u53ef\u4ee5\u65b0\u5efa\u6587\u4ef6/\u6587\u4ef6\u5939\u3002

\u521b\u5efa test.c\uff0c\u8f93\u5165 Hello World \u7684\u4ee3\u7801\u5e76\u4fdd\u5b58\u6587\u4ef6\u3002\u7136\u540e\u5728\u7ec8\u7aef\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5e76\u6267\u884c\uff1a

gcc test.c\n

\u5728\u4e0d\u540c\u7684\u7cfb\u7edf\u5c06\u4f1a\u751f\u6210\u4e0d\u540c\u7684\u7f16\u8bd1\u4ea7\u7269\u3002

WindowsWSL/macOS

\u5c06\u4f1a\u5728\u548c test.c \u540c\u76ee\u5f55\u4e0b\u751f\u6210 a.exe\uff0c\u968f\u540e\u5728\u7ec8\u7aef\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u6267\u884c

./a.exe\n

\u5c06\u4f1a\u5728\u548c test.c \u540c\u76ee\u5f55\u4e0b\u751f\u6210 a.out\uff0c\u968f\u540e\u5728\u7ec8\u7aef\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u6267\u884c

./a.out\n

\u4ee5\u4e0b\u5c55\u793a\u5728 macOS \u4e0a\u7684\u6267\u884c\u7ed3\u679c\uff1a

\u8fd9\u91cc\u6709\u51e0\u4e2a\u6ce8\u610f\u70b9\uff1a

gcc test.c -o hello.exe\n
"},{"location":"programming/archive/23fall/lec1/pre/#vscode-wsl","title":"VSCode + WSL\uff08\u53ef\u9009\uff09","text":"

\u524d\u9762\u9009\u62e9\u5b89\u88c5\u4e86 WSL \u7684\u4f7f\u7528 Windows \u4e3b\u529b\u673a\u7684\u540c\u5b66\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\uff0c\u975e\u5e38\u6709\u7528\u7684\u529f\u80fd

\u4ee5\u4e0b\u5f15\u5bfc\u4e3b\u8981\u6309\u7167 Microsoft \u7684\u5b98\u65b9\u6587\u6863\uff0c\u4e5f\u53ef\u4ee5\u53c2\u8003\u5176\u4e2d\u6587\u7248\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#vscode-wsl_1","title":"\u4ece VSCode \u8fde\u63a5\u5230 WSL","text":"

\u5b89\u88c5 WSL \u63d2\u4ef6\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a

\u6216\u8005\u4f60\u4e5f\u53ef\u4ee5\u50cf\u5b98\u65b9\u6587\u6863\u90a3\u6837\uff0c\u76f4\u63a5\u5b89\u88c5\u6574\u4e2a Remote Development \u6269\u5c55\u5305\uff1a

\u5176\u4e2d\u4e0d\u4ec5\u6709 WSL\uff0c\u8fd8\u5305\u62ec\u53e6\u5916\u4e09\u4e2a\u975e\u5e38\u6709\u7528\u7684\u8fdc\u7a0b\u5f00\u53d1\u63d2\u4ef6\u3002

\u5982\u679c\u9700\u8981\u5728\u672c\u7a97\u53e3\u8fde\u63a5\u5230 WSL\uff0c\u6216\u8fde\u63a5\u5230\u975e\u9ed8\u8ba4\u7684 WSL \u6240\u5b89\u88c5\u7684\u5176\u4ed6 Linux \u53d1\u884c\u7248\uff0c\u53ef\u4ee5\u9009\u62e9\u5176\u4ed6 WSL \u7684\u547d\u4ee4

\u6ce8\u610f\u4e0a\u56fe\u5de6\u4e0b\u89d2\u6240\u663e\u793a\u7684\u72b6\u6001\uff0c\u8868\u660e\u5df2\u7ecf\u8fde\u63a5\u5230 WSL \u6240\u5b89\u88c5\u7684 Ubuntu-22.04\uff0c\u63a5\u4e0b\u6765\u7684\u5f00\u53d1\u64cd\u4f5c\u548c\u4e0a\u4e00\u8282\u5c31\u533a\u522b\u4e0d\u5927\u4e86\u3002

"},{"location":"programming/archive/23fall/lec1/pre/#wsl-vscode","title":"\u4ece WSL \u542f\u52a8 VSCode","text":"

\u786e\u4fdd\u4f60\u5df2\u7ecf\u5c06 VSCode \u6dfb\u52a0\u5230 PATH \u73af\u5883\u53d8\u91cf\u4e2d\u3002\u5982\u679c\u5df2\u7ecf\u6dfb\u52a0\uff0c\u90a3\u4e48\u76f4\u63a5\u5728 WSL \u7684\u547d\u4ee4\u884c\u4e2d\u4f60\u6240\u5e0c\u671b\u4f5c\u4e3a\u5de5\u4f5c\u76ee\u5f55\u7684\u4f4d\u7f6e\u6267\u884c

code .\n

\u5c31\u53ef\u4ee5\u6253\u5f00 VSCode\uff0c\u8fde\u63a5\u5230 WSL \u5e76\u4e14\u6253\u5f00\u8be5\u76ee\u5f55\u4f5c\u4e3a\u5de5\u4f5c\u76ee\u5f55\u3002. \u5728\u8fd9\u91cc\u8868\u793a\u5f53\u524d\u76ee\u5f55\u5373 pwd\uff0c\u5982\u679c\u5c06\u5b83\u66ff\u6362\u6210\u5176\u4ed6\u76ee\u5f55\u7684\u8def\u5f84\u4e5f\u662f\u53ef\u4ee5\u5c06\u5176\u6253\u5f00\u4f5c\u4e3a\u5de5\u4f5c\u76ee\u5f55\u7684\u3002

\u5982\u679c\u4f60\u8fd8\u672a\u5c06 VSCode \u6dfb\u52a0\u5230 PATH \u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u90a3\u8be5\u529f\u80fd\u5c06\u65e0\u6cd5\u4f7f\u7528\uff0c\u9700\u8981\u4f60\u624b\u52a8\u6dfb\u52a0 VSCode \u5230 PATH \u73af\u5883\u53d8\u91cf\u3002\u4f8b\u5982\u4f60\u7684 Windows \u7528\u6237\u540d\u662f ZTM\uff0c\u5e76\u628a VSCode \u5b89\u88c5\u5728\u9ed8\u8ba4\u76ee\u5f55\uff0c\u90a3\u4e48\u9700\u8981\u5c06 C:\\Users\\ZTM\\AppData\\Local\\Programs\\Microsoft VS Code\\bin \u52a0\u5165\u5230 PATH \u73af\u5883\u53d8\u91cf\uff0c\u53c2\u8003 Windows \u4fee\u6539\u73af\u5883\u53d8\u91cf\u7ae0\u8282\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/","title":"\u8bb2\u4e49\uff1aC \u8bed\u8a00\u7684\u7c7b\u578b\u7cfb\u7edf\u4e0e\u5185\u5b58\u6a21\u578b","text":"

\u65bd\u5de5\u4e2d

\u672c\u9875\u9762\u6b63\u5728\u65bd\u5de5\uff1a

Abstract

Tip

\u5728\u672c\u8282\u8bb2\u4e49\u4e2d\uff0c\u82e5\u65e0\u7279\u522b\u8bf4\u660e\uff0c\u6211\u4eec\u9ed8\u8ba4\u91c7\u7528 C99 \u6807\u51c6\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_1","title":"\u524d\u7f6e\uff1a\u6570\u3001\u8fdb\u5236\u4e0e\u6570\u636e","text":"

\u4f60\u53ef\u4ee5\u901a\u8fc7 %x \u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u6765\u6253\u5370\u5341\u516d\u8fdb\u5236\u6570\u3002

printf(\"%x\\n\", 20231029);\nprintf(\"%d\\n\", 0x20231029);\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_2","title":"\u5982\u4f55\u9605\u8bfb\u5b83\u4eec\uff1f","text":"

\u8fd9\u4e9b\u90fd\u662f\u201c\u5341\u201d\uff1a0b1010\uff0c0o12\uff0c0xa\uff0c10\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#ascii","title":"ASCII","text":"

\u6bcf\u4e2a\u5b57\u7b26\u5bf9\u5e94\u4e00\u4e2a\u6570\u5b57\uff0c\u5373\u5176 ASCII \u7801\u3002\u5982 A \u7684 ASCII \u7801\u4e3a 65\uff0ca \u7684 ASCII \u7801\u4e3a 97\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_3","title":"\u7c7b\u578b\u7cfb\u7edf","text":"

\u7c7b\u578b\u662f\u4e0e\u6570\u636e\u76f8\u5173\u7684\u5c5e\u6027\uff0c\u5b83\u51b3\u5b9a\u4e86\u6570\u636e\u7684\u5b58\u50a8\u65b9\u5f0f\u548c\u53ef\u8fdb\u884c\u7684\u64cd\u4f5c\u3002

\u53d8\u91cf\u662f\u6570\u636e\u7684\u8f7d\u4f53\uff0c\u5b83\u662f\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u7684\u4e00\u5757\u7a7a\u95f4\uff0c\u6709\u7c7b\u578b\u548c\u503c\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_4","title":"\u8ba1\u7b97\u673a\u5982\u4f55\u5b58\u50a8\u6570\u636e\uff1f","text":"

\u5728\u4e00\u53f0 s390x \u67b6\u6784\u7684\u8ba1\u7b97\u673a\u4e0a\uff1a

MAGIC_R(0x20231029);\n// =====\n// 0x20231029: 4 (0x4) byte(s)\n// 0000  20 23 10 29\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_5","title":"\u5927\u7aef\u5e8f\u4e0e\u5c0f\u7aef\u5e8f","text":"\u5927\u7aef\u548c\u5c0f\u7aef\u540d\u79f0\u7684\u6765\u6e90

\u6765\u6e90\u4e8e\u300a\u683c\u5217\u4f5b\u6e38\u8bb0\u300b\u4e2d\u7684\u5927\u5c0f\u7aef\u4e4b\u4e89\uff1a

\u6211\u4e0b\u9762\u8981\u544a\u8bc9\u4f60\u7684\u662f\uff0cLilliput \u548c Blefuscu \u8fd9\u4e24\u5927\u5f3a\u56fd\u5728\u8fc7\u53bb 36 \u4e2a\u6708\u91cc\u4e00\u76f4\u5728\u82e6\u6218\u3002\u6218\u4e89\u5f00\u59cb\u662f\u7531\u4e8e\u4ee5\u4e0b\u7684\u539f\u56e0\uff1a\u6211\u4eec\u5927\u5bb6\u90fd\u8ba4\u4e3a\uff0c\u5403\u9e21\u86cb\u524d\uff0c\u539f\u59cb\u7684\u65b9\u6cd5\u662f\u6253\u7834\u9e21\u86cb\u8f83\u5927\u7684\u4e00\u7aef\uff0c\u53ef\u662f\u5f53\u4eca\u7687\u5e1d\u7684\u7956\u7236\u5c0f\u65f6\u5019\u5403\u9e21\u86cb\uff0c\u4e00\u6b21\u6309\u53e4\u6cd5\u6253\u9e21\u86cb\u65f6\u78b0\u5de7\u5c06\u4e00\u4e2a\u624b\u6307\u5f04\u7834\u4e86\u3002\u56e0\u6b64\u4ed6\u7684\u7236\u4eb2\uff0c\u5f53\u65f6\u7684\u7687\u5e1d\uff0c\u5c31\u4e0b\u4e86\u4e00\u9053\u6555\u4ee4\uff0c\u547d\u4ee4\u5168\u4f53\u81e3\u6c11\u5403\u9e21\u86cb\u65f6\u6253\u7834\u9e21\u86cb\u8f83\u5c0f\u7684\u4e00\u7aef\uff0c\u8fdd\u4ee4\u8005\u91cd\u7f5a\u3002\u8001\u767e\u59d3\u4eec\u5bf9\u8fd9\u9879\u547d\u4ee4\u6781\u5176\u53cd\u611f\u3002\u5386\u53f2\u544a\u8bc9\u6211\u4eec\uff0c\u7531\u6b64\u66fe\u7ecf\u53d1\u751f\u8fc76\u6b21\u53db\u4e71\uff0c\u5176\u4e2d\u4e00\u4e2a\u7687\u5e1d\u9001\u4e86\u547d\uff0c\u53e6\u4e00\u4e2a\u4e22\u4e86\u738b\u4f4d\u3002\u8fd9\u4e9b\u53db\u4e71\u5927\u591a\u90fd\u662f\u7531 Blefuscu \u7684\u56fd\u738b\u5927\u81e3\u4eec\u717d\u52a8\u8d77\u6765\u7684\u3002\u53db\u4e71\u5e73\u606f\u540e\uff0c\u6d41\u4ea1\u7684\u4eba\u603b\u662f\u9003\u5230\u90a3\u4e2a\u5e1d\u56fd\u53bb\u5bfb\u6c42\u907f\u96be\u3002\u636e\u4f30\u8ba1\uff0c\u5148\u540e\u51e0\u6b21\u6709 11000 \u4eba\u60c5\u613f\u53d7\u6b7b\u4e5f\u4e0d\u80af\u53bb\u6253\u7834\u9e21\u86cb\u8f83\u5c0f\u7684\u4e00\u7aef\u3002\u5173\u4e8e\u8fd9\u4e00\u4e89\u7aef\uff0c\u66fe\u51fa\u7248\u8fc7\u51e0\u767e\u672c\u5927\u90e8\u8457\u4f5c\uff0c\u4e0d\u8fc7\u5927\u7aef\u6d3e\u7684\u4e66\u4e00\u76f4\u662f\u53d7\u7981\u7684\uff0c\u6cd5\u5f8b\u4e5f\u89c4\u5b9a\u8be5\u6d3e\u4efb\u4f55\u4eba\u4e0d\u5f97\u505a\u5b98\u3002\u201d

\u4e3b\u6d41\u67b6\u6784\uff08\u5982 x86\u3001AMD64\u3001ARM\uff09\u4f7f\u7528\u5c0f\u7aef\u5e8f\u3002\u4e00\u4e9b\u4e0d\u5e38\u89c1\u7684\u67b6\u6784\uff08\u5982 SPARC\uff09\u4f7f\u7528\u5927\u7aef\u5e8f\u3002\u7f51\u7edc\u534f\u8bae\u4f7f\u7528\u5927\u7aef\u5e8f\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_6","title":"\u5148\u6765\u7ec3\u7ec3\u624b","text":"

\u4f60\u5e94\u5f53\u5df2\u7ecf\u77e5\u9053\uff0c\u4e0d\u540c\u7c7b\u578b\u7684\u53d8\u91cf\u4e00\u822c\u5360\u636e\u4e0d\u540c\u7684\u5b57\u8282\u6570\u3002

int i = 0x12345678;\nMAGIC(i);\n\nlong long ll = 0xfedcba9876543210LL;\nMAGIC(ll);\n\ndouble d = 3.14159265358979323;\nMAGIC(d);\n\nfloat f = d;\nMAGIC(f);\n\nchar c = 'A';\nMAGIC(c);\n\nMAGIC_R('A');\n\nMAGIC_R((short)ll);\n\nMAGIC(\"Hello world! I am a l\" \"ong string.\");\n
\u5728\u5c0f\u7aef\u5e8f\u8ba1\u7b97\u673a\u4e0a\u53ef\u80fd\u7684\u8fd0\u884c\u7ed3\u679c
=====\ni: 4 (0x4) byte\n0000  78 56 34 12\n=====\nll: 8 (0x8) byte\n0000  10 32 54 76 98 ba dc fe\n=====\nd: 8 (0x8) byte\n0000  18 2d 44 54 fb 21 09 40\n=====\nf: 4 (0x4) byte\n0000  db 0f 49 40\n=====\nc: 1 (0x1) bytes\n0000  41\n=====\n'A': 4 (0x4) byte <!--(1)!-->\n0000  41 00 00 00\n=====\n(short)ll: 2 (0x2) byte\n0000  10 32\n=====\n\"Hello world! I am a l\" \"ong string.\": 33 (0x21) byte\n0000  48 65 6c 6c 6f 20 77 6f 72 6c 64 21 20 49 20 61\n0010  6d 20 61 20 6c 6f 6e 67 20 73 74 72 69 6e 67 2e\n0020  00\n
  1. \u5176\u7c7b\u578b\u4e3a int\uff0c\u6545\u5360\u7528 4 \u5b57\u8282\u3002
"},{"location":"programming/archive/23fall/lec2/lec2/#_7","title":"\u57fa\u672c\u7c7b\u578b","text":"

\u7c7b\u578b - cppreference.com

\u6574\u6570\u7c7b\u578b\uff1achar short int long long long

\u5176\u4e2d\uff0c\u9664\u4e86 char \u4ee5\u5916\u7684\u7c7b\u578b\u9ed8\u8ba4\u4e3a signed\uff0c\u5373\u6709\u7b26\u53f7\u6570\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cint \u5c31\u662f signed int\u3002\u5c06 signed \u6362\u4e3a unsigned\uff0c\u5c31\u5f97\u5230\u4e86\u65e0\u7b26\u53f7\u6570\u3002

\u90a3\u4e48 char \u5462\uff1f

char signed char unsigned char \u662f\u4e09\u4e2a\u4e0d\u540c\u7684\u7c7b\u578b\uff0c\u5c3d\u7ba1\u5728\u5927\u591a\u6570\u5b9e\u73b0\u4e2d\uff0cchar \u8868\u73b0\u4e3a\u6709\u7b26\u53f7\u6570\u3002

\u5b57\u7b26\u7c7b\u578b\u89e3\u60d1

\u6216\u8bb8\u4f60\u4f1a\u548c\u6211\u540c\u6837\u5bf9\u4ee5\u4e0b\u51e0\u4e2a\u95ee\u9898\u611f\u5230\u56f0\u60d1\uff1a

\u8fd9\u91cc\u5c06\u89e3\u91ca\u524d\u4e24\u4e2a\u95ee\u9898\uff0c\u7b2c\u4e09\u4e2a\u95ee\u9898\u4e0d\u505a\u8981\u6c42\uff0c\u6709\u5174\u8da3\u53ef\u4ee5\u53c2\u770b\u4e2d\u7684\u76f8\u5173\u5185\u5bb9\u3002

\u591a\u5b57\u7b26\u5e38\u91cf\uff08Multicharacter constants\uff09\u7ee7\u627f\u4e8e C \u8bed\u8a00\u7684\u524d\u8eab B \u8bed\u8a00\u3002\u5b83\u4eec\u7684\u4e3b\u8981\u7528\u9014\u662f\u7528\u4e8e\u7f16\u5199\u6c47\u7f16\u8bed\u8a00\uff0c\u56e0\u4e3a\u6c47\u7f16\u8bed\u8a00\u4e2d\u7684\u6307\u4ee4\u901a\u5e38\u662f\u591a\u5b57\u8282\u7684\u3002\u4f8b\u5982\uff0c'abcd' \u53ef\u4ee5\u7528\u4e8e\u8868\u793a\u4e00\u4e2a 32 \u4f4d\u7684\u6307\u4ee4\u3002

\u5728 C \u6807\u51c6\u4e2d\uff0c\u591a\u5b57\u7b26\u5e38\u91cf\u88ab\u5b9a\u4e49\u4e3a int \u7c7b\u578b\uff0c\u957f\u5ea6\u662f 4 \u4e2a\u5b57\u8282\u3002\u5728 C \u8bed\u8a00\u7684\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u591a\u5b57\u7b26\u5e38\u91cf\u901a\u5e38\u662f\u51fa\u4e8e\u8c03\u8bd5\u76ee\u7684\u800c\u5d4c\u5165\u7ed3\u6784\u4e2d\u7684\u9b54\u6570\uff08Magic Numbers\uff09\uff0c\u5c31\u50cf\u6709\u4e9b\u4eba\u4f1a\u4f7f\u7528 0xfeedbeef \u548c 0xdeadbeef \u800c\u4e0d\u662f NULL \u6765\u6807\u8bb0\u6307\u9488\u7684\u672a\u521d\u59cb\u5316\u548c\u5df2\u5220\u9664\u72b6\u6001\u3002\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f\uff0c\u5982\u679c\u7a0b\u5e8f\u51fa\u73b0\u4e86\u9519\u8bef\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6253\u5370\u51fa\u8fd9\u4e9b\u9b54\u6570\u6765\u5b9a\u4f4d\u9519\u8bef\u7684\u4f4d\u7f6e\u3002

\u6211\u4eec\u4f7f\u7528\u65f6\u5e94\u5f53\u907f\u514d\u5c06\u591a\u5b57\u7b26\u5e38\u91cf\u4ece int \u7c7b\u578b\u8f6c\u6362\u4e3a char \u7c7b\u578b\uff0c\u56e0\u4e3a\u8fd9\u4e00\u8f6c\u6362\u8fc7\u7a0b\u662f\u7531\u7f16\u8bd1\u5668\u5b9e\u73b0\u51b3\u5b9a\u7684\u3002\u6bd4\u5982 char a = 'ABCD'\uff0c\u5728 gcc\u3001clang\u3001msvc \u4e0a\u5747\u4e3a a = 'D'\uff0c\u4f46\u662f\u5728 armcc \u4e0a\u4e3a a = 'A'\u3002

\u56e0\u4e3a\u5b83\u4f1a\u8fd4\u56de EOF\uff0c\u800c EOF \u5728\u6807\u51c6\u4e2d\u5b9a\u4e49\u4e3a int \u7c7b\u578b\uff0c\u901a\u5e38\u4e3a (int)-1\u3002

This macro is an integer value that is returned by a number of narrow stream functions to indicate an end-of-file condition, or some other error situation.

\u4e3a\u4ec0\u4e48\u8981\u8fd9\u4e48\u5b9a\u4e49\uff1f\u4ece\u903b\u8f91\u4e0a\u8bf4\uff0cEOF \u5e94\u5f53\u4e0e\u4efb\u4f55\u4e00\u4e2a\u5b57\u7b26\u503c\u90fd\u4e0d\u540c\u3002(char)-1 \u4e5f\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u5b57\u7b26\uff08\u56e0\u4e3a\u5b83\u662f char \u7c7b\u578b\uff0c\u6839\u636e Latin-1 \u7f16\u7801\uff0cchar \u7c7b\u578b\u7684\u6bcf\u4e2a\u53ef\u80fd\u503c\u90fd\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\uff09\uff0c\u6240\u4ee5\u4e0d\u80fd\u7528\u4f5c EOF\uff0c\u5fc5\u987b\u4f7f\u7528 (int)-1\uff0c\u5b83\u4e0e\u524d\u8005\u5bbd\u5ea6\u4e0d\u540c\uff0c\u56e0\u6b64\u662f\u4e0d\u540c\u7684\u503c\u3002

\u8fd8\u8bb0\u5f97\u7684\u5728\u7c7b\u578b\u8f6c\u6362\u4e2d\u63d0\u5230\u7684\u6574\u5f62\u63d0\u5347\u5417\uff1f\u5982\u679c\u6211\u4eec\u8ba9 getchar() \u8fd4\u56de (char)-1\uff0c\u5f53\u51fd\u6570\u63a5\u6536\u5230 (char)-1 \u65f6\uff0c\u5b83\u4f1a\u6267\u884c\u4ece\u65e0\u7b26\u53f7\u6570\u5230\u6709\u7b26\u53f7\u6570\u7684\u8f6c\u6362\uff08\u5373\u4f7f\u5b9e\u73b0\u4e3a\u6709\u7b26\u53f7\u7684 char\uff09\uff0c\u4ece\u800c\u8fd4\u56de (int)255\uff0c\u8fd9\u4e0e EOF \u7684\u5b9a\u4e49\u4e0d\u7b26\u3002

\u53c2\u8003\u8d44\u6599\uff1a

\u6d6e\u70b9\u7c7b\u578b\uff1afloat double long double

\u590d\u6570\u7c7b\u578b

\u5728\u5176\u540e\u52a0\u4e0a _Complex \u5373\u4e3a\u590d\u6570\u7c7b\u578b\uff0c\u5982 double _Complex\u3002\u76f8\u540c\u7684\uff0c\u6709 _Imaginary\u3002

\u662f\u7684\uff0cC \u5728\u8bed\u8a00\u5c42\u9762\u4e0a\u652f\u6301\u590d\u6570\u548c\u865a\u6570\uff0c\u4f46\u5e76\u4e0d\u662f\u6240\u6709\u7684\u7f16\u8bd1\u5668\u90fd\u652f\u6301\u8fd9\u4e00\u7279\u6027\u3002\u4f8b\u5982\uff0cgcc \u548c clang \u76ee\u524d\u5747\u4e0d\u652f\u6301 _Imaginary\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_8","title":"\u5b9a\u957f\u6574\u6570\u7c7b\u578b\u4e0e\u5176\u4ed6\u6574\u6570\u7c7b\u578b","text":"

\u5728 stdint.h \u4e2d\u5b9a\u4e49\uff0c\u5982 int8_t uint8_t int16_t uint16_t int32_t uint32_t int64_t uint64_t\u3002

sizeof \u8fd0\u7b97\u7b26\u4e0e offsetof \u5b8f\u7684\u7ed3\u679c\uff1asize_t\uff0c\u8db3\u591f\u8868\u793a\u4efb\u4f55\u5bf9\u8c61\u7684\u5927\u5c0f\u3002\u5e38\u88ab\u5b9a\u4e49\u4e3a unsigned long\u3002

\u5728 stddef.h \u4e2d\u5b9a\u4e49\uff0cptrdiff_t \u8868\u793a\u4e24\u4e2a\u6307\u9488\u76f8\u51cf\u7684\u7ed3\u679c\u3002\u5e38\u88ab\u5b9a\u4e49\u4e3a long\u3002

\u5982\u4f55\u8f93\u51fa\u8fd9\u4e9b\u6574\u6570\u7c7b\u578b\uff1f

\u5728 inttypes.h \u4e2d\u5b9a\u4e49\u4e86\u4e00\u7cfb\u5217\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0c\u5982 PRId32 \u4e00\u822c\u5c55\u5f00\u4e3a \"d\"\uff0c\u800c PRIu64 \u53ef\u80fd\u5c55\u5f00\u4e3a \"llu\"\u3002

\u8fd9\u4e9b\u5b9a\u4e49\u5728\u4e0d\u540c\u7684\u5e73\u53f0\u4e0a\u53ef\u80fd\u6709\u6240\u4e0d\u540c\u3002\u4f7f\u7528\u8fd9\u4e9b\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u53ef\u4ee5\u4fdd\u8bc1\u5728\u4e0d\u540c\u5e73\u53f0\u4e0a\u8f93\u51fa\u6b63\u786e\u7684\u7ed3\u679c\uff08\u4e14\u4e0d\u4f1a\u5f15\u53d1\u7f16\u8bd1\u5668\u8b66\u544a\uff09\u3002

uint64_t i = 0xdeadbeefcafebabe;\nprintf(\"%\" PRIu64 \"\\n\", i); // \u5e94\u5f53\u5305\u542b inttypes.h\n

\u5bf9\u4e8e size_t \u548c ptrdiff_t\uff0c\u53ef\u4ee5\u4f7f\u7528 %zu \u548c %td\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_9","title":"\u7ed3\u6784\u4f53\u3001\u8054\u5408\u4f53\u3001\u679a\u4e3e\u7c7b\u578b","text":"

\u679a\u4e3e\u7c7b\u578b\u5b9e\u8d28\u4e0a\u662f\u6574\u6570\u7c7b\u578b\u3002\u5b83\u7684\u503c\u662f\u7531\u7f16\u8bd1\u5668\u81ea\u52a8\u5206\u914d\u7684\uff08\u4e00\u822c\u4ece 0 \u5f00\u59cb\uff09\uff0c\u4e5f\u53ef\u624b\u52a8\u6307\u5b9a\u3002

\u7ed3\u6784\u4f53\u7684\u5927\u5c0f\u662f\u5176\u6210\u5458\u5927\u5c0f\u7684\u603b\u548c\uff0c\u52a0\u4e0a\u5bf9\u9f50\u6240\u9700\u7684\u586b\u5145\u5b57\u8282\u3002

struct point {\n  int x;\n  long y;\n};\nstruct point p = {1234, -5678};\nMAGIC(p);\n\nunion un_t {\n  long l;\n  double d;\n};\nunion un_t un;\nun.d = 3.14159265358979323;\nMAGIC(un);\n\nenum en_t { ENA, ENB, ENC = 114514 };\nMAGIC_R(ENA);\nMAGIC_R(ENC);\n\nMAGIC_PTR(&p.x);\nMAGIC_PTR(&p.y);\nMAGIC_PTR(&un.l);\nMAGIC_PTR(&un.d);\n
\u5728\u5c0f\u7aef\u5e8f\u8ba1\u7b97\u673a\u4e0a\u53ef\u80fd\u7684\u8fd0\u884c\u7ed3\u679c
=====\np: 16 (0x10) byte\n0000  d2 04 00 00 00 00 00 00 d2 e9 ff ff ff ff ff ff\n=====\nun: 8 (0x8) byte\n0000  18 2d 44 54 fb 21 09 40\n=====\nENA: 4 (0x4) bytes\n0000  00 00 00 00\n=====\nENC: 4 (0x4) bytes\n0000  52 bf 01 00\n&p.x: 0x16d3cee18\n&p.y: 0x16d3cee20\n&un.l: 0x16d3cee10\n&un.d: 0x16d3cee10\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_10","title":"\u5b57\u7b26\u4e32\uff0c\u6570\u7ec4\uff0c\u51fd\u6570\uff0c\u6307\u9488\u7c7b\u578b","text":"

\u6570\u7ec4\u662f\u4e00\u7cfb\u5217\u76f8\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\u7684\u96c6\u5408\u3002\u6570\u7ec4\u7684\u5927\u5c0f\u662f\u5176\u5143\u7d20\u5927\u5c0f\u7684\u603b\u548c\u3002

int arr[] = { 0xbeef, 0xcafe, 0xdead, 0xface, 0xfeed };\nMAGIC(arr);\n\nchar str1[] = \"Hello world!\";\nconst char *str2 = \"Hello world!\";\nMAGIC(str1);\nMAGIC(str2);\n

\u4ee5 main \u51fd\u6570\u4e3a\u4f8b\uff0c\u5176\u6709\u4e24\u79cd\uff08\u6807\u51c6\u89c4\u5b9a\u7684\uff09\u5f62\u5f0f\uff1a

int main(void);                   // \u7c7b\u578b\u4e3a int(void)\nint main(int argc, char *argv[]); // \u7c7b\u578b\u4e3a int(int, char *[])\n

C \u6807\u51c6\u4e0d\u5141\u8bb8\u5bf9\u51fd\u6570\u7c7b\u578b\u5e94\u7528 sizeof \u8fd0\u7b97\u7b26\u3002

\u6240\u6709\u7684\u6307\u9488\u7c7b\u578b\u90fd\u62e5\u6709\u76f8\u540c\u7684\u5927\u5c0f\u3002\u6211\u4eec\u5c06\u5728\u540e\u9762\u7684\u7ae0\u8282\u4e2d\u8ba8\u8bba\u6307\u9488\u7c7b\u578b\u3002

\u6570\u7ec4\u5230\u6307\u9488\u9000\u5316

"},{"location":"programming/archive/23fall/lec2/lec2/#void","title":"void \u7c7b\u578b","text":"

void \u662f\u4e00\u4e2a\u4e0d\u5b8c\u6574\u7c7b\u578b\uff0c\u5373\u4e0d\u5b58\u5728 void \u7c7b\u578b\u7684\u53d8\u91cf\u3002\u5b83\u4f5c\u4e3a\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\uff0c\u8868\u793a\u51fd\u6570\u6ca1\u6709\u8fd4\u56de\u503c\u3002\u5b83\u4f5c\u4e3a\u51fd\u6570\u7684\u53c2\u6570\u7c7b\u578b\uff0c\u8868\u793a\u51fd\u6570\u4e0d\u63a5\u53d7\u53c2\u6570\u3002

void f(void) { /* \u5b9e\u73b0\u7565\u53bb */ }\nvoid g(void) {\n  return f(); // \u4ec5\u5f53 f \u7684\u8fd4\u56de\u7c7b\u578b\u4e3a void \u65f6\u624d\u80fd\u8fd9\u6837\u5199\n}\n
\u90a3\u4e48 void * \u5462\uff1f

void * \u662f\u4e00\u4e2a\u5b8c\u6574\u7c7b\u578b\uff0c\u5b83\u8868\u793a\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411\u672a\u77e5\u7c7b\u578b\u7684\u5bf9\u8c61\uff08\u5373\uff0c\u201c\u820d\u5f03\u201d\u4e86\u7c7b\u578b\u4fe1\u606f\u7684\u6307\u9488\uff09\u3002

\u4efb\u4f55\u7c7b\u578b\u7684\u6307\u9488\u5747\u53ef\u9690\u5f0f\u8f6c\u6362\u4e3a void * \u7c7b\u578b\uff0c\u4f46\u662f\u53cd\u8fc7\u6765\u4e0d\u884c\u3002\u8fd9\u662f\u56e0\u4e3a void * \u7c7b\u578b\u7684\u6307\u9488\u4e0d\u77e5\u9053\u6307\u5411\u7684\u5bf9\u8c61\u7684\u5927\u5c0f\uff0c\u56e0\u6b64\u4e0d\u80fd\u8fdb\u884c\u89e3\u5f15\u7528\u64cd\u4f5c\u3002

int i = 0x12345678;\nvoid *p = &i;\nprintf(\"%p\\n\", p);\nprintf(\"%d\\n\", *(int *)p);\n
\u4ec0\u4e48\u662f\u4e0d\u5b8c\u6574\u7c7b\u578b\uff1f

\u4e0d\u5b8c\u6574\u7c7b\u578b\u662f\u6307\u53ea\u77e5\u9053\u5176\u5b58\u5728\uff0c\u4f46\u65e0\u6cd5\u77e5\u9053\u5176\u5927\u5c0f\u7684\u7c7b\u578b\u3002\u6bd4\u5982\uff1a

struct incomp;\n

\u6211\u4eec\u53ea\u77e5\u9053 struct incomp \u5b58\u5728\uff0c\u4f46\u662f\u4e0d\u77e5\u9053\u5b83\u7684\u5927\u5c0f\uff08\u56e0\u4e3a\u6ca1\u6709\u7ed9\u51fa\u5176\u5b9a\u4e49\uff09\u3002\u56e0\u6b64\uff0cstruct incomp \u662f\u4e00\u4e2a\u4e0d\u5b8c\u6574\u7c7b\u578b\u3002\u4f46\u662f\u53ef\u4ee5\u58f0\u660e\u6307\u5411 struct incomp \u7c7b\u578b\u7684\u6307\u9488\u3002

void \u7c7b\u578b\u662f\u552f\u4e00\u53ef\u4f5c\u4e3a\u51fd\u6570\u8fd4\u56de\u7c7b\u578b\u7684\u4e0d\u5b8c\u6574\u7c7b\u578b\u3002\u8fd9\u662f C \u8bed\u6cd5\u7684\u4e00\u6761\u7279\u6b8a\u89c4\u5b9a\uff0c\u5176\u610f\u4e49\u5c31\u662f\u6807\u5b9a\u201c\u51fd\u6570\u6ca1\u6709\u8fd4\u56de\u503c\u201d\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#typedef","title":"\u4f7f\u7528 typedef \u4e3a\u73b0\u6709\u7684\u7c7b\u578b\u5b9a\u4e49\u522b\u540d","text":"
int a;\n

\u4f60\u5df2\u7ecf\u5f88\u719f\u6089\u8fd9\u6837\u7684\u58f0\u660e\u4e86\uff0c\u5bf9\u5427\uff1fa \u662f\u4e00\u4e2a int \u7c7b\u578b\u7684\u53d8\u91cf\u3002

typedef int a;\n

\u8fd9\u5c31\u662f\u8bf4\uff0ca \u73b0\u5728\u5c31\u662f int \u7684\u522b\u540d\u3002\u4f60\u53ef\u4ee5\u8fd9\u6837\u4f7f\u7528\u5b83\uff1a

a b; // \u7b49\u4ef7\u4e8e int b;\n

\u6211\u4eec\u4e4b\u524d\u63d0\u5230\u8fc7\u7684 size_t\u3001ptrdiff_t\u3001int8_t \u7b49\u7c7b\u578b\uff0c\u5c31\u662f\u901a\u8fc7 typedef \u5b9a\u4e49\u7684\u3002

\u8003\u8bd5\u4e2d\u8fd8\u4f1a\u8981\u6c42\u4f60\u9605\u8bfb\u4ee3\u7801\u7247\u6bb5\uff0c\u4e3a\u5f62\u53c2\u7b49\u4f4d\u7f6e\u586b\u5199\u7c7b\u578b\u58f0\u660e\u3002\u8bf7\u53c2\u8003\u5386\u5e74\u5377\u603b\u7ed3\u4e2d\u7684\u4f8b\u9898\u3002

C \u4e0e C++ \u7684 struct \u5e76\u4e0d\u5b8c\u5168\u4e00\u81f4

\u5bf9\u4e8e\u7ed3\u6784\u4f53

struct point {\n  int x;\n  int y;\n}\n

\u5728 C++ \u4e2d\uff0c\u6b64\u58f0\u660e\u5f15\u5165\u7684\u65b0\u7c7b\u578b\u540d\u4e3a point\uff0c\u800c\u5728 C \u4e2d\uff0c\u6b64\u58f0\u660e\u5f15\u5165\u7684\u65b0\u7c7b\u578b\u540d\u4e3a struct point\u3002point \u672c\u8eab\u4e0d\u662f\u4e00\u4e2a\u7c7b\u578b\u540d\u3002

\u4e0b\u9762\u7684\u5199\u6cd5\u662f\u5e38\u89c1\u7684\uff1a

typedef struct point point;\n

\u6b64\u5373\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7c7b\u578b\u540d point\uff0c\u5176\u4e3a struct point \u7684\u522b\u540d\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_11","title":"\u5185\u5b58\u6a21\u578b","text":"

\u5728 C \u8bed\u8a00\u7684\u5185\u5b58\u6a21\u578b\u4e2d\uff0c\u5b57\u8282\uff08byte\uff09\u662f\u6700\u5c0f\u7684\u53ef\u5bfb\u5740\u7684\u5185\u5b58\u5355\u5143\uff0c\u5176\u88ab\u5b9a\u4e49\u4e3a\u4e00\u7cfb\u5217\u8fde\u7eed\u7684\u4f4d\uff08bit\uff09\u3002\u53ef\u5bfb\u5740\u610f\u5473\u7740\u6bcf\u4e2a\u5b57\u8282\u90fd\u62e5\u6709\u5176\u7f16\u53f7\uff0c\u5373\u5730\u5740\u3002

MAGIC_PTR(&i);\nMAGIC_PTR(&ll);\nMAGIC_PTR(&d);\nMAGIC_PTR(&f);\n\nMAGIC_SIZED(f, 0x20);\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_12","title":"\u5730\u5740\u548c\u6307\u9488","text":"

\u5730\u5740\u662f\u4e00\u4e2a\u65e0\u7b26\u53f7\u6574\u6570\uff0c\u5b83\u8868\u793a\u5185\u5b58\u4e2d\u7684\u4e00\u4e2a\u5b57\u8282\u3002\u6307\u9488\u662f\u4e00\u4e2a\u53d8\u91cf\uff0c\u5176\u5b58\u50a8\u4e86\u4e00\u4e2a\u5730\u5740\u3002\u7531\u4e8e\u8fd9\u4e2a\u539f\u56e0\uff0c\u6240\u6709\u6307\u9488\u7c7b\u578b\u7684\u5927\u5c0f\u90fd\u662f\u76f8\u540c\u7684\u3002

MAGIC_R(&i);\nMAGIC_PTR(&i);\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_13","title":"\u5bf9\u8c61\u548c\u6807\u8bc6\u7b26","text":"

\u6bcf\u4e2a\u88ab\u5b58\u50a8\u7684\u503c\u90fd\u5360\u7528\u4e00\u5b9a\u7684\u7269\u7406\u5185\u5b58\uff0c\u8fd9\u6837\u7684\u4e00\u5757\u5185\u5b58\u79f0\u4e3a\u5bf9\u8c61\u3002\u5bf9\u8c61\u53ef\u4ee5\u50a8\u5b58\u4e00\u4e2a\u6216\u591a\u4e2a\u503c\u3002\u58f0\u660e\u53d8\u91cf\u65f6\uff0c\u521b\u5efa\u4e86\u4e00\u4e2a\u6807\u8bc6\u7b26\uff08identifier\uff09\uff0c\u5176\u4e0e\u5bf9\u8c61\u76f8\u5173\u8054\u3002

\u6240\u4ee5\uff0c\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\u65f6\u5b9e\u9645\u4e0a\u505a\u4e86\u4e24\u4ef6\u4e8b\uff1a

\u5bf9\u8c61\u7684\u5176\u4ed6\u542b\u4e49

\u201c\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u201d\u4e2d\u7684\u5bf9\u8c61\u6307\u7684\u662f\u201c\u7c7b\u5bf9\u8c61\u201d\u3002C \u8bed\u8a00\u4e2d\u6ca1\u6709\u201c\u7c7b\u5bf9\u8c61\u201d\u8fd9\u4e00\u6982\u5ff5\u3002

\u601d\u7ef4\u8bad\u7ec3\uff1a

int *psi = &i;\n\nMAGIC(i);\nMAGIC_R(*psi);\nMAGIC(psi);\nMAGIC_PTR(&i);\nMAGIC_PTR(&psi);\n
\u5728\u5c0f\u7aef\u5e8f\u8ba1\u7b97\u673a\u4e0a\u53ef\u80fd\u7684\u8fd0\u884c\u7ed3\u679c
=====\ni: 4 (0x4) bytes\n0000  78 56 34 12\n=====\n*psi: 4 (0x4) bytes\n0000  78 56 34 12\n=====\npsi: 8 (0x8) bytes\n0000  4c ae db 6f 01 00 00 00\n&i: 0x16fdbae4c\n&psi: 0x16fdbae08\n

\u6211\u4eec\u53ef\u4ee5\u89c2\u5bdf\u5230\u4ec0\u4e48\uff1f

\u5de6\u503c\u4e0e\u53f3\u503c

\u6307\u4ee3\u5bf9\u8c61\u7684\u8868\u8fbe\u5f0f\u88ab\u79f0\u4e3a\u5de6\u503c\u3002\u8fd9\u4e2a\u672f\u8bed\u6765\u81ea\u4e8e\u8d4b\u503c\u8bed\u53e5\uff0c\u56e0\u4e3a\u8d4b\u503c\u8bed\u53e5\u7684\u5de6\u8fb9\u5fc5\u987b\u662f\u4e00\u4e2a\u5bf9\u8c61\u3002

\u5982\u679c\u53ef\u4ee5\u4f7f\u7528\u5de6\u503c\u6539\u53d8\u5bf9\u8c61\u4e2d\u7684\u503c\uff0c\u90a3\u4e48\u79f0\u4e3a\u53ef\u4fee\u6539\u7684\u5de6\u503c\u3002

const char *pc = \"Good morning my neighbors\";\n

\u53c2\u8003\uff1a\u503c\u7c7b\u522b - cppreference.com

"},{"location":"programming/archive/23fall/lec2/lec2/#_14","title":"\u5185\u5b58\u7ba1\u7406","text":"

C \u7684\u5185\u5b58\u7ba1\u7406\u662f\u4e00\u5927\u75db\u70b9\uff0c\u56e0\u4e3a\u5b83\u672c\u8eab\u5e76\u4e0d\u63d0\u4f9b\u68c0\u67e5\u673a\u5236\uff0c\u4e00\u5207\u90fd\u4f9d\u8d56\u4e8e\u7a0b\u5e8f\u5458\u81ea\u5df1\u3002\u56e0\u6b64\uff0c\u597d\u597d\u638c\u63e1\u5185\u5b58\u7ba1\u7406\u5bf9\u4e8e\u5199\u51fa\u5b89\u5168\u3001\u7a33\u5b9a\u7684\u7a0b\u5e8f\u662f\u975e\u5e38\u5fc5\u8981\u7684\u3002

int *dangling() {\n  int i = 0xdeadbeef;\n  int *p = &i;\n  return p;\n}\n\nint main() {\n  int *pfi = dangling();\n  MAGIC(pfi);\n  MAGIC(*pfi);\n}\n

\u5728\u8fd9\u91cc pfi \u79f0\u4e3a\u60ac\u5782\u6307\u9488\uff08dangling pointer\uff09\uff0c\u5b83\u6307\u5411\u4e86\u4e00\u4e2a\u5df2\u7ecf\u88ab\u9500\u6bc1\u7684\u5bf9\u8c61\u3002\u4f7f\u7528\u60ac\u5782\u6307\u9488\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002

\u5e38\u89c1\u53d8\u5f0f

char *get_a_string() {\n  char str[] = \"Hello world!\";\n  return str;\n}\nint main() {\n  char *str = get_a_string();\n  printf(\"%s\\n\", str);\n}\n

\u95ee\u9898\u51fa\u5728\u54ea\uff1f

str \u4f5c\u4e3a\u4e00\u4e2a\u6570\u7ec4\uff0c\u5176\u751f\u547d\u5468\u671f\u5728 get_a_string \u51fd\u6570\u8fd4\u56de\u65f6\u7ed3\u675f\u3002

\u5b83\u4e0e\u4e0b\u9762\u7684\u7a0b\u5e8f\u6709\u4ec0\u4e48\u533a\u522b\uff1f

char *get_a_string() {\n  char *str = \"Hello world!\";\n  return str;\n}\nint main() {\n  char *str = get_a_string();\n  printf(\"%s\\n\", str);\n}\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_15","title":"\u5b58\u50a8\u671f\u3001\u4f5c\u7528\u57df\u548c\u94fe\u63a5","text":"

\u5b58\u50a8\u671f\u63cf\u8ff0\u5bf9\u8c61\uff0c\u8868\u660e\u5728\u5185\u5b58\u4e2d\u5b58\u50a8\u7684\u65f6\u95f4\u3002

\u4f5c\u7528\u57df\u548c\u94fe\u63a5\u6027\u63cf\u8ff0\u6807\u8bc6\u7b26\uff0c\u8868\u660e\u7a0b\u5e8f\u7684\u54ea\u4e9b\u90e8\u5206\u53ef\u4ee5\u4f7f\u7528\u5b83\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_16","title":"\u5b58\u50a8\u671f","text":"
#include <stdlib.h>\nint global;\nint main() {\n  int automatic;\n  int *allocated = malloc(sizeof(int));\n\n  MAGIC_PTR(&global);\n  MAGIC_PTR(&automatic);\n  MAGIC_PTR(allocated);\n}\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_17","title":"\u4f5c\u7528\u57df","text":"

\u4f5c\u7528\u57df - cppreference.com

"},{"location":"programming/archive/23fall/lec2/lec2/#_18","title":"\u5757\u4f5c\u7528\u57df","text":"Note

\u5728 C99 \u4e4b\u524d\uff0c\u5757\u4f5c\u7528\u57df\u7684\u53d8\u91cf\u5fc5\u987b\u5728\u5757\u7684\u5f00\u5934\u58f0\u660e\u3002

\u5728 C99\uff0c\u5757\u7684\u6982\u5ff5\u88ab\u653e\u5bbd\uff1a\u63a7\u5236\u8bed\u53e5\uff08\u6761\u4ef6\u3001\u5faa\u73af\uff09\u4e5f\u662f\u5757\uff08\u5373\u4f7f\u6ca1\u6709\u4f7f\u7528\u82b1\u62ec\u53f7\uff09\u3002\u6bd4\u5982\uff1a

for(int i = 0;;)\n  function();\n

i \u5177\u6709\u5757\u4f5c\u7528\u57df\uff0c\u662f\u5faa\u73af\u7684\u4e00\u90e8\u5206\u3002

\u66f4\u7cbe\u7ec6\u7684\u5b9a\u4e49\uff1a\u5faa\u73af\u4f53\u662f\u6574\u4e2a\u5faa\u73af\u7684\u5b50\u5757\u3002\u4f60\u53ef\u4ee5\u8fd9\u6837\u60f3\u5b83\uff1a

{\n  for(int i;;) {\n    int i;\n  }\n}\n

\u4e0a\u9762\u7684\u4e24\u4e2a\u540c\u540d\u53d8\u91cf i \u4e0d\u5728\u540c\u4e00\u4e2a\u5757\u4e2d\uff0c\u56e0\u6b64\u4e0d\u662f\u91cd\u590d\u5b9a\u4e49\u3002

Tip

\u540c\u540d\u7684\u53d8\u91cf\uff0c\u5185\u90e8\u8986\u76d6\u5916\u90e8\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_19","title":"\u51fd\u6570\u4f5c\u7528\u57df","text":"

goto \u8bed\u53e5\u7684\u6807\u7b7e\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5373\u4f7f\u6807\u7b7e\u5728\u5185\u5c42\u7684\u5757\u4e2d\uff0c\u5b83\u7684\u4f5c\u7528\u57df\u4e5f\u5ef6\u4f38\u81f3\u6574\u4e2a\u51fd\u6570\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_20","title":"\u51fd\u6570\u539f\u578b\u4f5c\u7528\u57df","text":"

\u51fd\u6570\u539f\u578b\u4e2d\u7684\u53d8\u91cf\u540d\u3002\u4ece\u5b9a\u4e49\u5904\u5230\u51fd\u6570\u539f\u578b\u7ed3\u675f\u3002

\u53ea\u5728\u4f60\u4f7f\u7528 VLA \u65f6\u9700\u8981\u6ce8\u610f\u8fd9\u4e00\u987a\u5e8f\uff1a

void use_VLA(int n, int m, ar[n][m]);\n
"},{"location":"programming/archive/23fall/lec2/lec2/#_21","title":"\u6587\u4ef6\u4f5c\u7528\u57df","text":"

\u5728\u4efb\u4f55\u51fd\u6570\u5916\u5b9a\u4e49\u7684\u53d8\u91cf\u3002\u4ece\u5b9a\u4e49\u5904\u5230\u6587\u4ef6\u672b\u5c3e\u3002

\u8fd9\u6837\u7684\u53d8\u91cf\u79f0\u4e3a\u5168\u5c40\u53d8\u91cf\u3002

\u7ffb\u8bd1\u5355\u5143

\u4f60\u6240\u8ba4\u4e3a\u7684\u591a\u4e2a\u6587\u4ef6\u5bf9\u4e8e\u7f16\u8bd1\u5668\u6765\u8bf4\u53ef\u80fd\u662f\u4e00\u4e2a\u6587\u4ef6\u3002\u6bd4\u5982\u5934\u6587\u4ef6\uff1a\u9884\u5904\u7406\u65f6\uff0c\u5934\u6587\u4ef6\u88ab\u63d2\u5165\u3002\u5bf9\u4e8e\u7f16\u8bd1\u5668\u6765\u8bf4\uff0c\u5b83\u770b\u5230\u7684\u662f\u5355\u4e2a\u6587\u4ef6\u3002

\u8fd9\u6837\u7684\u5355\u4e2a\u6587\u4ef6\u79f0\u4e3a\u4e00\u4e2a\u7ffb\u8bd1\u5355\u5143\u3002\u6bcf\u4e2a\u7ffb\u8bd1\u5355\u5143\u5bf9\u5e94\u4e00\u4e2a\u6e90\u6587\u4ef6\u548c\u5b83 include \u7684\u6587\u4ef6\u3002

\u521a\u624d\u6211\u4eec\u8bf4\u7684\u6587\u4ef6\u4f5c\u7528\u57df\u5176\u5b9e\u662f\u5728\u6574\u4e2a\u7ffb\u8bd1\u5355\u5143\u53ef\u89c1\u3002

\u7531\u4e8e\u8bb2\u4e49\u4e2d\u6d89\u53ca\u5230\u7684\u5185\u5bb9\u8f83\u591a\uff0c\u65e0\u6cd5\u5728\u4e00\u8282\u8bfe\u5185\u5168\u90e8\u8bb2\u89e3\u3002\u540e\u7eed\u7684\u8bb2\u4e49\u5c06\u4f1a\u968f\u56de\u653e\u94fe\u63a5\u66f4\u65b0\u800c\u66f4\u65b0\u3002

"},{"location":"programming/archive/23fall/lec2/lec2/#_22","title":"\u94fe\u63a5","text":""},{"location":"programming/archive/23fall/lec2/lec2/#_23","title":"\u9605\u8bfb\u548c\u64b0\u5199\u7c7b\u578b\u58f0\u660e","text":""},{"location":"programming/archive/23fall/lec2/pre/","title":"\u8bfe\u524d\uff1aMAGIC \u51fd\u6570","text":"

\u8bf7\u590d\u5236\u6b64\u4efd\u7a0b\u5e8f\u5230\u4f60\u7684\u7f16\u8f91\u5668\u4e2d\u3002\u6211\u4eec\u5c06\u4f1a\u76f4\u63a5\u5728\u8fd9\u4efd\u7a0b\u5e8f\u7684\u57fa\u7840\u4e0a\u8fdb\u884c\u6388\u8bfe\u3002

\u4e0d\u9700\u8981\u8bfb\u61c2\u5e76\u7406\u89e3\u8fd9\u6bb5\u7a0b\u5e8f\u7684\u610f\u4e49\u3002\u611f\u5174\u8da3\u7684\u540c\u5b66\u53ef\u81ea\u884c\u7814\u7a76\u3002

#define _STR0(x) #x\n#define _STR(x) _STR0(x)\n#define _MAGIC0(name, val, size) _magic_print((name), (const uint8_t *)(val), (size))\n#define MAGIC(v) _MAGIC0(_STR(v), (&v), sizeof(v));\n#define MAGIC_R(v)                      \\\n  ({                                    \\\n    __typeof__(v) _v = v;               \\\n    _MAGIC0(_STR(v), (&_v), sizeof(v)); \\\n  });\n#define MAGIC_SIZED(v, size) _MAGIC0(_STR(v), (&v), (size));\n#define MAGIC_PTR(v) fprintf(stderr, \"%s: %p\\n\", _STR(v), (void *)(v));\n\nstatic void _magic_print(const char *name, const uint8_t *ptr, size_t size) {\n  fprintf(stderr, \"=====\\n%s: %zu (%#zx) byte%s\", name, size, size, (\"s\") + (size == 1));\n  for (size_t i = 0; i < size; i++) {\n    if (i % 16 == 0)\n      fprintf(stderr, \"\\n%0*zx \", 4, i);\n    fprintf(stderr, \" %02hhx\", ptr[i]);\n  }\n  fprintf(stderr, \"\\n\");\n}\n\nint main() {\n  // start our journey here...\n  MAGIC_R(0x12345678);\n\n}\n
"},{"location":"programming/archive/23fall/lec3/lec3/","title":"\u8bb2\u4e49\uff1aI/O \u4e0e\u6587\u4ef6","text":"

\u5185\u5bb9\u63d0\u8981

"},{"location":"programming/archive/23fall/lec3/lec3/#c","title":"C \u7684\u8f93\u5165\u8f93\u51fa\u6a21\u578b","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_1","title":"\u7f13\u51b2","text":"

\u5e7f\u4e49\u7684\u7f13\u51b2\u533a\u662f\u5185\u5b58\u7a7a\u95f4\u7684\u4e00\u90e8\u5206\uff0c\u5728\u5185\u5b58\u4e2d\u9884\u7559\u4e86\u4e00\u5b9a\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c\u7528\u6765\u6682\u65f6\u4fdd\u5b58\u8f93\u5165\u548c\u8f93\u51fa\u7b49 I/O \u64cd\u4f5c\u7684\u4e00\u4e9b\u6570\u636e\uff0c\u8fd9\u4e9b\u9884\u7559\u7684\u7a7a\u95f4\u5c31\u53eb\u505a\u7f13\u51b2\u533a\uff1b\u800c buffer \u7f13\u51b2\u533a\u548c Cache \u7f13\u5b58\u533a\u90fd\u5c5e\u4e8e\u7f13\u51b2\u533a\u7684\u4e00\u79cd\u3002

buffer \u7f13\u51b2\u533a\u548c cache \u7f13\u5b58\u533a

C \u8bed\u8a00\u4e2d\uff0c\u7528\u6237\u8f93\u5165\u7684\u5b57\u7b26\u88ab\u6536\u96c6\u5e76\u50a8\u5b58\u5728\u7f13\u51b2\u533a\uff08buffer\uff09\u4e2d\uff0c\u6309\u4e0b Enter \u952e\u540e\u7a0b\u5e8f\u624d\u80fd\u4f7f\u7528\u7528\u6237\u8f93\u5165\u7684\u5b57\u7b26\u3002

\u4e0e\u4e4b\u5bf9\u5e94\u5730\uff0c\u65e0\u7f13\u51b2\u8f93\u5165\u7684\u7a0b\u5e8f\u80fd\u591f\u7acb\u5373\u4f7f\u7528\u7528\u6237\u8f93\u5165\u7684\u5185\u5bb9\u3002

stdin,stdout,stderr \u7684\u7f13\u51b2\u7c7b\u578b

Unix\u7ea6\u5b9astdin\u4e0estdout\u82e5\u4e0e\u7ec8\u7aef\u5173\u8054\u5219\u4e3a\u884c\u7f13\u51b2\uff0c\u800cstderr\u4e3a\u65e0\u7f13\u51b2\u3002

\u4e3a\u4ec0\u4e48\u8981\u6709\u7f13\u51b2\u533a\uff1f

\u867d\u7136\u7f13\u51b2\u8f93\u5165\u597d\u5904\u5f88\u591a\uff0c\u4f46\u662f\u67d0\u4e9b\u4ea4\u4e92\u5f0f\u7a0b\u5e8f\u4e5f\u9700\u8981\u65e0\u7f13\u51b2\u8f93\u5165\u3002\u4f8b\u5982\u5728\u6e38\u620f\u4e2d\uff0c\u73a9\u5bb6\u7684\u8f93\u5165\u9700\u8981\u7acb\u5373\u53cd\u5e94\u5728\u5c4f\u5e55\u4e0a\uff0c\u800c\u4e0d\u662f\u7b49\u5f85\u7528\u6237\u6309\u4e0b Enter \u952e\u3002

C \u6807\u51c6\u89c4\u5b9a\uff1a\u8f93\u5165\u662f\u7f13\u51b2\u7684\u3002\u4f60\u80fd\u89e3\u91ca\u4e3a\u4ec0\u4e48 C \u6807\u51c6\u8981\u89c4\u5b9a\u8f93\u5165\u662f\u7f13\u51b2\u7684\u5417\uff1f

\u4e3a\u4ec0\u4e48 C \u6807\u51c6\u89c4\u5b9a\u8f93\u5165\u662f\u7f13\u51b2\u7684\uff1f

\u4e00\u4e9b\u8ba1\u7b97\u673a\u4e0d\u5141\u8bb8\u65e0\u7f13\u51b2\u8f93\u5165\u3002ANSI\u6ca1\u6709\u63d0\u4f9b\u8c03\u7528\u65e0\u7f13\u51b2\u8f93\u5165\u7684\u6807\u51c6\u65b9\u5f0f\uff0c\u8fd9\u610f\u5473\u7740\u662f\u5426\u80fd\u8fdb\u884c\u65e0\u7f13\u51b2\u8f93\u5165\u53d6\u51b3\u4e8e\u8ba1\u7b97\u673a\u7cfb\u7edf\u3002

\u5982\u679c\u4f60\u7684\u8ba1\u7b97\u673a\u5141\u8bb8\u65e0\u7f13\u51b2\u8f93\u5165\uff0c\u90a3\u4e48\u4f60\u6240\u7528\u7684C\u7f16\u8bd1\u5668\u5f88\u53ef\u80fd\u4f1a\u63d0\u4f9b\u4e00\u4e2a\u65e0\u7f13\u51b2\u8f93\u5165\u7684\u9009\u9879\u3002\u4f8b\u5982\uff0c\u8bb8\u591aIBM PC\u517c\u5bb9\u673a\u7684\u7f16\u8bd1\u5668\u90fd\u4e3a\u652f\u6301\u65e0\u7f13\u51b2\u8f93\u5165\u63d0\u4f9b\u4e00\u7cfb\u5217\u7279\u6b8a\u51fd\u6570\uff0c\u5176\u539f\u578b\u5728conio.h\u4e2d\u3002\u5728Unix\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528iotcl()\u51fd\u6570\u6307\u5b9a\u5f85\u8f93\u5165\u7684\u7c7b\u578b\uff0c\u7136\u540e\u4f7f\u7528getchar()\u6267\u884c\u76f8\u5e94\u64cd\u4f5c\u3002\u5728ANSI C\u4e2d\uff0c\u7528setbuf()\u548csetbufv()\u63a7\u5236\u7f13\u51b2\uff0c\u4f46\u662f\u8fd9\u4e24\u4e2a\u51fd\u6570\u53ef\u80fd\u4e0d\u8d77\u4f5c\u7528\u3002

\u6211\u53ef\u4ee5\u66f4\u6539\u8f93\u5165\u65b9\u5f0f\u5417\uff1f

UNIX \u5e93\u4e2d\u6709 ioctl() \u51fd\u6570\u7528\u4e8e\u6307\u5b9a\u5f85\u8f93\u5165\u7684\u7c7b\u578b\uff0c\u4f46\u8fd9\u4e0d\u5c5e\u4e8e C \u6807\u51c6\u3002

ANSI C \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 setbuf() \u548c setvbuf() \u63a7\u5236\u7f13\u51b2\uff0c\u4f46\u53d7\u9650\u4e8e\u7cfb\u7edf\u7684\u8bbe\u7f6e\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_2","title":"\u6d41","text":"

C \u5e93\u63d0\u4f9b\u7684\u8f93\u5165\u8f93\u51fa\u65b9\u5f0f\u79f0\u4e3a\u6807\u51c6 I/O\uff0c\u5b83\u4eec\u662f\u5efa\u7acb\u5728\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u5e95\u5c42 I/O \u4e0a\u7684\u3002\u5e95\u5c42 I/O \u4e4b\u95f4\u5e38\u5e38\u4f1a\u6709\u4e00\u4e9b\u5dee\u5f02\uff1a

\u5404\u4e2a\u7cfb\u7edf\u7684\u6587\u4ef6\u5dee\u5f02

\u5dee\u5f02 UNIX Windows MacOS \u6362\u884c\u7b26 \\n LF \\r\\n CRLF \\n (\u8f83\u65e9\u7684 MacOS \u4f7f\u7528 \\r)LF \u6587\u4ef6\u7ed3\u675f\u7b26 ^D ^Z ^D

\u6ce8\uff1a\u5982 ^Z \u4ee3\u8868 Ctrl+Z\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8be5\u7ec4\u5408\u952e\u7ed3\u675f\u952e\u76d8\u8f93\u5165\u3002

\u6587\u4ef6\u7ed3\u5c3e\u4e5f\u4e0d\u4e00\u5b9a\u7531\u6587\u4ef6\u7ed3\u675f\u7b26\u6807\u8bb0\u3002\u4e8b\u5b9e\u4e0a\uff0cUNIX \u7cfb\u7edf\u50a8\u5b58\u6587\u4ef6\u5927\u5c0f\u4fe1\u606f\uff0c\u4f9d\u636e\u6587\u4ef6\u5927\u5c0f\u4fe1\u606f\u51b3\u5b9a\u6587\u4ef6\u672b\u5c3e\u3002

\u4ece\u6982\u5ff5\u4e0a\u770b\uff0cC \u5904\u7406\u7684\u662f\u6d41\u800c\u4e0d\u662f\u6587\u4ef6\u3002\u4e0d\u540c\u5c5e\u6027\u548c\u4e0d\u540c\u79cd\u7c7b\u7684\u8f93\u5165\uff0c\u7531\u5c5e\u6027\u66f4\u7edf\u4e00\u7684\u6d41\u6765\u8868\u793a\u3002\u6d41\u544a\u8bc9\u6211\u4eec\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u5904\u7406\u6587\u4ef6\u7684\u65b9\u5f0f\u6765\u5904\u7406\u952e\u76d8\u8f93\u5165\u3002

C \u8bed\u8a00\u4e2d I/O \u6d41\u7531File\u7c7b\u578b\u7684\u5bf9\u8c61\u8868\u793a\uff0c\u8be5\u5bf9\u8c61\u53ea\u80fd\u901a\u8fc7FILE*\u7c7b\u578b\u7684\u6307\u9488\u8bbf\u95ee\u53ca\u64cd\u4f5c\u3002\u6bcf\u4e2a\u6d41\u90fd\u4e0e\u5916\u90e8\u7684\u7269\u7406\u8bbe\u5907\u76f8\u5173\u8054\u3002

\u6d41

\u6d41\u5c31\u662f\u4e00\u7cfb\u5217\u8fde\u7eed\u7684\u5b57\u8282\u3002

\u6253\u5f00\u6587\u4ef6\u7684\u8fc7\u7a0b\u5c31\u662f\u628a\u6d41\u4e0e\u6587\u4ef6\u76f8\u5173\u8054\uff0c\u8bfb\u5199\u90fd\u901a\u8fc7\u6d41\u6765\u5b8c\u6210\u3002

getchar() \u548c scanf() \u7b49\u51fd\u6570\u8bfb\u53d6\u5230\u6587\u4ef6\u7ed3\u5c3e\u65f6\u4f1a\u8fd4\u56de\u4e00\u4e2a\u7279\u6b8a\u7684\u503c EOF\uff0c\u5728 stdio.h \u4e2d\u5b9a\u4e49\u4e86\uff1a

#define EOF (-1) \n
\u4f60\u80fd\u89e3\u91ca\u4e3a\u4ec0\u4e48\u8981\u628a\u5b83\u5b9a\u4e3a -1 \u5417\uff1f

The value of EOF is -1 because it has to be different from any return value from getchar that is an actual character. So getchar returns any character value as an unsigned char, converted to int, which will therefore be non-negative.

\u56e0\u6b64\uff0c\u5982\u679c\u4f60\u5728\u7ec8\u7aef\u4e2d\u8fdb\u884c\u8f93\u5165\uff0c\u53ef\u4ee5\u4f7f\u7528Ctrl+Z(Windows)\u6216\u8005Ctrl+D(unix-style systems)\u4f5c\u4e3aEOF\u7ed3\u675f\u8f93\u5165\u3002

\u7531\u4ee5\u4e0a\u4e24\u90e8\u5206\uff0c\u6211\u4eec\u53ef\u4ee5\u77e5\u9053\u5728 C \u7684\u952e\u76d8\u8f93\u5165\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u7528Enter\u5904\u7406\u7f13\u51b2\u533a\u4e2d\u7684\u5185\u5bb9\uff0c\u7528Ctrl+Z\u6216\u8005Ctrl+D\u7ed3\u675f\u8f93\u5165\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_3","title":"\u6807\u51c6\u6d41","text":"

\u5728\u6807\u51c6\u5934\u6587\u4ef6<stidio.h>\u4e2d\uff0c\u5b9a\u4e49\u4e86\u4e09\u4e2a\u6587\u672c\u6d41\u3002

#define stdin  /* \u7531\u5b9e\u73b0\u5b9a\u4e49 */\n#define stdout /* \u7531\u5b9e\u73b0\u5b9a\u4e49 */\n#define stderr /* \u7531\u5b9e\u73b0\u5b9a\u4e49 */\n

\u8fd9\u4e09\u4e2a\u6587\u672c\u6d41\u662f\u9884\u5b9a\u4e49\u7684\u3002\u8fd9\u4e9b\u6d41\u5728\u7a0b\u5e8f\u542f\u52a8\u65f6\u9690\u5f0f\u6253\u5f00\uff0c\u4e14\u4e3a\u65e0\u53d6\u5411\u7684\u3002

  1. \u4e0e\u6807\u51c6\u8f93\u5165\u6d41\u5173\u8054\uff0c\u7528\u4e8e\u8bfb\u53d6\u4f20\u7edf\u7684\u8f93\u5165\u3002\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u5f53\u4e14\u4ec5\u5f53\u80fd\u786e\u5b9a\u6d41\u4e0d\u5f15\u7528\u4ea4\u4e92\u5f0f\u8bbe\u5907\u65f6\u8be5\u6d41\u4e3a\u5b8c\u5168\u7f13\u51b2\u3002
  2. \u4e0e\u6807\u51c6\u8f93\u51fa\u6d41\u5173\u8054\uff0c\u7528\u4e8e\u5199\u5165\u4f20\u7edf\u7684\u8f93\u51fa\u3002\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u5f53\u4e14\u4ec5\u5f53\u80fd\u786e\u5b9a\u6d41\u4e0d\u5f15\u7528\u4ea4\u4e92\u5f0f\u8bbe\u5907\u65f6\u8be5\u6d41\u4e3a\u5b8c\u5168\u7f13\u51b2\u3002
  3. \u4e0e\u6807\u51c6\u9519\u8bef\u6d41\u5173\u8054\uff0c\u7528\u4e8e\u5199\u5165\u8bca\u65ad\u8f93\u51fa\u3002\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u8be5\u6d41\u4e0d\u4e3a\u5b8c\u5168\u7f13\u51b2\u3002

\u6587\u4ef6\u63cf\u8ff0\u7b26

\u5f53\u4e00\u4e2a\u7a0b\u5e8f\u6210\u529f\u5411\u64cd\u4f5c\u7cfb\u7edf\u8bf7\u6c42\u8bbf\u95ee\u4e00\u4e2a\u6253\u5f00\u7684\u6587\u4ef6, \u5185\u6838\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6307\u5411\u5185\u6838\u4e2d\u5168\u5c40\u6587\u4ef6\u8868(global file table)\u4e2d\u7684\u5165\u53e3\u70b9(entry)\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26. \u6587\u4ef6\u8868\u5165\u53e3\u70b9\u5305\u542b\u5982: \u6587\u4ef6\u7684inode(\u786c\u76d8\u4e2d\u7684\u4f4d\u7f6e), \u5b57\u8282\u504f\u79fb\u91cf(byte offset), \u4ee5\u53ca\u5bf9\u8fd9\u4e2a\u6570\u636e\u6d41\u7684\u8bbf\u95ee\u9650\u5236(\u53ea\u8bfb, \u53ea\u5199\u7b49)\u3002

\u6587\u4ef6\u63cf\u8ff0\u7b26: \u662f\u8ba1\u7b97\u673a\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u88ab\u6253\u5f00\u6587\u4ef6\u7684\u552f\u4e00\u6807\u8bc6. \u5b83\u7528\u6765\u63cf\u8ff0\u4e00\u79cd\u6570\u636e\u8d44\u6e90, \u4ee5\u53ca\u8fd9\u4e2a\u6570\u636e\u8d44\u6e90\u53ef\u4ee5\u5982\u4f55\u88ab\u8bbf\u95ee\u5230\u3002

\u5728 Unix \u7cfb\u7edf\u5f53\u4e2d, \u524d\u4e09\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b260, 1, 2 \u9ed8\u8ba4\u4e3a stdin stdout stderr

"},{"location":"programming/archive/23fall/lec3/lec3/#_4","title":"\u5b57\u7b26\u8f93\u5165\u8f93\u51fa","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_5","title":"\u91cd\u5b9a\u5411","text":"

\u5728\u5f00\u59cb\u4ecb\u7ecd\u5b57\u7b26\u8f93\u5165\u8f93\u51fa\u524d\uff0c\u5148\u4ecb\u7ecd\u7cfb\u7edf\u7684\u91cd\u5b9a\u5411\u3002

\u91cd\u5b9a\u5411\u662f\u6307\u6539\u53d8\u6807\u51c6\u8f93\u5165\u8f93\u51fa\u7684\u76ee\u7684\u5730\u3002\u5728 UNIX \u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528>\u548c<\u6765\u91cd\u5b9a\u5411\u8f93\u5165\u8f93\u51fa\u3002

\u4f8b\u5982\uff0cls > ls.txt \u5c06ls\u7684\u8f93\u51fa\u91cd\u5b9a\u5411\u5230ls.txt\u6587\u4ef6\u4e2d\uff0ccat < ls.txt\u5c06ls.txt\u6587\u4ef6\u7684\u5185\u5bb9\u91cd\u5b9a\u5411\u5230cat\u547d\u4ee4\u4e2d\u3002

\u91cd\u5b9a\u5411\u7684\u76ee\u7684\u5730\u53ef\u4ee5\u662f\u6587\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u662f\u5176\u4ed6\u7a0b\u5e8f\u3002

\u4f8b\u5982\uff0cls | cat\u5c06ls\u7684\u8f93\u51fa\u91cd\u5b9a\u5411\u5230cat\u547d\u4ee4\u4e2d\u3002

\u66f4\u8fdb\u4e00\u6b65\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528>>\u6765\u8ffd\u52a0\u8f93\u51fa\u91cd\u5b9a\u5411\uff0c<<\u6765\u8ffd\u52a0\u8f93\u5165\u91cd\u5b9a\u5411\u3002

\u7ed3\u5408\u4e0a\u4e00\u8282\u8bb2\u7684\u5185\u5bb9\uff0c\u4f60\u53ef\u4ee5\u8bf4\u51fa2>\u548c2>>\u7684\u4f5c\u7528\u5417\uff1f

"},{"location":"programming/archive/23fall/lec3/lec3/#_6","title":"\u65e0\u683c\u5f0f\u8f93\u5165/\u8f93\u51fa","text":"

\u5728\u5b57\u7b26 I/O \u4e2d\uff0c\u6211\u4eec\u5e38\u4f7f\u7528\u4ee5\u4e0b\u51fd\u6570\u6765\u5904\u7406\u5b57\u7b26\uff0c\u8fd9\u4e9b\u51fd\u6570\u4f4d\u4e8e<stdio.h>\u5934\u6587\u4ef6\u4e2d\u3002<wchar.h> \u5934\u6587\u4ef6\u63d0\u4f9b\u4e86\u5177\u6709\u5bbd\u5b57\u7b26\u8f93\u5165/\u8f93\u51fa\u529f\u80fd\u7684\u51fd\u6570\u3002

e.g.

echo_eof.c
/* echo_eof.c -- repeats input to end of file */\n#include <stdio.h>\nint main(void)\n{\n    int ch;\n\n    while ((ch = getchar()) != EOF)\n    putchar(ch);\n\n    return 0;\n}\n

\u7ed3\u5408\u91cd\u5b9a\u5411\u8fd0\u7b97\u7b26\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528echo_eof < echo_eof.c\u6765\u6d4b\u8bd5\u8be5\u7a0b\u5e8f\u3002

$ echo_eof < echo_eof.c\n$ echo_eof < echo_eof.c > echo_eof.txt\n$ echo_eof < echo_eof.c | cat\n

\u7a84\u5b57\u7b26\u65e0\u683c\u5f0f\u8f93\u5165\u8f93\u51fa\u51fd\u6570\uff0c\u5b9a\u4e49\u4e8e <stdio.h> \u5934\u6587\u4ef6\u4e2d\uff1a

\u529f\u80fd \u51fd\u6570 \u5931\u8d25\u8fd4\u56de\u503c int getchar(void) int getc(FILE *stream) int fgetc(FILE *stream) \u5355\u5b57\u7b26\u8f93\u5165 EOF char *fgets(char *s, int size, FILE *stream) char *gets_s( char *str, rsize_t n) \u5b57\u7b26\u4e32\u8f93\u5165 NULL int ungetc(int c, FILE *stream) \u653e\u56de\u6587\u4ef6\u6d41 EOF int putchar(int c) int putc(int c, FILE *stream) int fputc(int c, FILE *stream) \u5355\u5b57\u7b26\u8f93\u51fa EOF int puts(const char *s) int fputs(const char *s, FILE *stream) \u5b57\u7b26\u4e32\u8f93\u51fa EOF

\u6ce8\u610f

\u90a3\u4e48\u8fd9\u662f\u5426\u4f1a\u9020\u6210 EOF \u4e0d\u80fd\u88ab\u8bc6\u522b\uff0c\u800c\u662f\u88ab\u770b\u4f5c\u5b57\u7b26\u5462\uff1f
#define EOF (-1) // unsigned char\u8f6c\u6362\u6210int\u540e\uff0c\u503c\u90fd\u5927\u4e8e\u7b49\u4e8e0\n

\u5bbd\u5b57\u7b26\u8f93\u5165\u8f93\u51fa\u5b9a\u4e49\u4e8e <wchar.h> \u5934\u6587\u4ef6\u4e2d\uff0c\u533a\u522b\u5728\u4e8e\u5176\u4e00\u4e2a\u5b57\u7b26\u7684\u957f\u5ea6\u4e0d\u540c\u3002C \u8bed\u8a00\u4e2d\u6709\u4e00\u79cd\u7c7b\u578bwchar_t,\u5176\u957f\u5ea6\u53d6\u51b3\u4e8e\u7f16\u8bd1\u5668\uff1a

\u5728\u4f7f\u7528\u5bbd\u5b57\u7b26\u524d\uff0c\u9700\u8981\u5728\u5b57\u7b26\u548c\u5b57\u7b26\u4e32\u524d\u52a0\u4e0aL\u524d\u7f00\uff0c\u4f8b\u5982L'c'\u548cL\"string\"\uff0c\u672a\u52a0\u524d\u7f00\u7684\u5b57\u7b26\u548c\u5b57\u7b26\u4e32\u4e3a\u7a84\u5b57\u7b26\u3002 \u5bf9\u4e8e\u5bbd\u5b57\u7b26/\u5b57\u7b26\u4e32\u8bfb\u5199\u51fd\u6570\uff0c\u5176\u4f7f\u7528\u65b9\u6cd5\u4e0e\u7a84\u5b57\u7b26\u7c7b\u4f3c\u3002

\u529f\u80fd \u51fd\u6570 \u5931\u8d25\u8fd4\u56de\u503c int getwchar(void) int getwc(FILE *stream) int fgetwc(FILE *stream) \u5355\u5b57\u7b26\u8f93\u5165 EOF char *fgetws(char *s, int size, FILE *stream) \u5b57\u7b26\u4e32\u8f93\u5165 NULL int ungetwc(int c, FILE *stream) \u653e\u56de\u6587\u4ef6\u6d41 EOF int putwchar(int c) int fputwc(int c, FILE *stream)` \u5355\u5b57\u7b26\u8f93\u51fa EOF int fputws(const char *s, FILE *stream) \u5b57\u7b26\u4e32\u8f93\u51fa EOF"},{"location":"programming/archive/23fall/lec3/lec3/#_7","title":"\u683c\u5f0f\u5316\u8f93\u5165\u8f93\u51fa","text":"

\u5728\u6807\u5934<stdio.h>\u548c<wchar.h>\u4e2d\uff0c\u5b9a\u4e49\u4e86\u4e00\u7cfb\u5217\u683c\u5f0f\u5316\u8f93\u5165\u8f93\u51fa\u51fd\u6570\uff0c\u8fd9\u4e9b\u51fd\u6570\u53ef\u4ee5\u7528\u4e8e\u8bfb\u5199\u683c\u5f0f\u5316\u7684\u6570\u636e\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_8","title":"\u683c\u5f0f\u5b57\u7b26\u4e32","text":"

\u683c\u5f0f\u5b57\u7b26\u4e32const char *format\u7531\u666e\u901a\u591a\u5b57\u8282\u5b57\u7b26\uff08\u9664\u4e86%\uff09\u548c\u8f6c\u6362\u6307\u793a\u6784\u6210\uff0c\u524d\u8005\u88ab\u590d\u5236\u5230\u8f93\u51fa\u6d41\u800c\u65e0\u66f4\u6539\u3002\u6bcf\u4e2a\u8f6c\u6362\u6307\u793a\u62e5\u6709\u4e0b\u5217\u683c\u5f0f\uff1a

"},{"location":"programming/archive/23fall/lec3/lec3/#printf","title":"printf()\u4e2d\u8f6c\u6362\u8bf4\u660e\u7684\u610f\u4e49","text":"

\u8f6c\u6362\u8bf4\u660e\u5b9e\u9645\u4e0a\u662f\u5728\u5c06\u4ee5\u4e8c\u8fdb\u5236\u5b58\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u4e2d\u7684\u503c\u8f6c\u6362\u6210\u4e00\u4e9b\u5217\u5b57\u7b26\u4fbf\u4e8e\u663e\u793a\u3002\u8f6c\u6362\u5b9e\u9645\u4e0a\u662f\u4e00\u79cd\u7ffb\u8bd1\u8bf4\u660e\u3002

\u4f8b\u5982\uff1ad\uff1a\u5c06\u4e00\u4e2a\u6709\u7b26\u53f7\u7684\u5341\u8fdb\u5236\u6574\u6570\u8f6c\u6362\u6210\u5341\u8fdb\u5236\u6570\u3002

\u4e0b\u9762\u8ba8\u8bba\u51e0\u79cd\u8f6c\u6362\u8bf4\u660e\u7684\u60c5\u51b5\uff1a

  1. \u8f6c\u6362\u4e0d\u5339\u914d

    \u8f6c\u6362\u8bf4\u660e\u4e0e\u5f85\u6253\u5370\u7684\u503c\u4e0d\u5339\u914d\u53ef\u80fd\u5bfc\u81f4\u6570\u636e\u9519\u8bef\u6216\u8005\u51fa\u73b0\u672a\u5b9a\u4e49\u7684\u884c\u4e3a\u3002

    e.g.

    wrong_cnv.c

    #include <stdio.h>\n#define num 336\n#define b 65618\nint main(void)\n{\n    printf(\"num as short and unsigned short:  %hd %hu\\n\", num,num);\n    printf(\"-num as short and unsigned short: %hd %hu\\n\", -num,-num);\n    printf(\"num as int and char: %d %c\\n\", num, num);\n    printf(\"b as int, short, and char: %d %hd %c\\n\",b, b, b);\n\n    float n1 = 3.0;\n    double n2 = 3.0;\n    long n3 = 2000000000;\n    long n4 = 1234567890;\n    printf(\"%.1e %.1e %.1e %.1e\\n\", n1, n2, n3, n4);\n    printf(\"%ld %ld\\n\", n3, n4);\n    printf(\"%ld %ld %ld %ld\\n\", n1, n2, n3, n4);\n    return 0;\n}\n
    \u8be5\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c\u4e3a (\u7531\u4e8e\u5b9e\u73b0\u662f\u672a\u5b9a\u4e49\u7684\uff0c\u90e8\u5206\u7ed3\u679c\u56e0\u7cfb\u7edf\u548c\u7f16\u8bd1\u5668\u800c\u5f02)\uff1a
        num as short and unsigned short:  336 336\n    -num as short and unsigned short: -336 65200\n    num as int and char: 336 P\n    b as int, short, and char: 65618 82 R\n    3.0e+00 3.0e+00 2.0e+09 1.2e+09\n    2000000000 1234567890\n    0 1074266112 0 1074266112\n
    \u4f60\u80fd\u89e3\u91ca\u4e3a\u4ec0\u4e48\u4f7f\u7528%ld \u8f93\u51fa long \u7c7b\u578b\u7684\u503c\u65f6\uff0c\u4e5f\u4f1a\u51fa\u73b0\u9519\u8bef\u5417\uff1f

  2. printf()\u7684\u8fd4\u56de\u503c

    printf()\u51fd\u6570\u8fd4\u56de\u6253\u5370\u7684\u5b57\u7b26\u6570\uff0c\u82e5\u51fa\u73b0\u9519\u8bef\u5219\u8fd4\u56de\u8d1f\u503c\u3002

  3. \u6253\u5370\u957f\u7684\u5b57\u7b26\u4e32

    \u4e0d\u80fd\u5728\u53cc\u5f15\u53f7\u62ec\u8d77\u6765\u7684\u5b57\u7b26\u4e32\u4e2d\u95f4\u65ad\u884c\u3002

    e.g.

    longstrg.c
    #include <stdio.h>\nint main(void)\n{\n    printf(\"Here's one way to print a \");\n    printf(\"long string.\\n\");\n    printf(\"Here's another way to print a \\\n    long string.\\n\");\n    printf(\"Here's the newest way to print a \"\n    \"long string.\\n\"); /* ANSI C */\n    /*\n    printf(\"Here's wrong way to print a\n    long string.\\n\");\n    */\n    return 0;\n}\n
"},{"location":"programming/archive/23fall/lec3/lec3/#scanf","title":"scanf()","text":"

\u5728\u524d\u9762\u6211\u4eec\u4ecb\u7ecd\u4e86printf()\u4e2d\u7684\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u548c\u8f6c\u6362\u8bf4\u660e\uff0cscanf()\u4e2d\u4e5f\u6709\u7c7b\u4f3c\u7684\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u548c\u8f6c\u6362\u8bf4\u660e\u3002

\u590d\u6742\u7684\u4f7f\u7528\u65b9\u6cd5\u8bf7\u67e5\u9605scanf\u3002

\u4e0b\u9762\u4ecb\u7ecd\u4e00\u4e9bscanf()\u7684\u7279\u6027\uff1a

  1. scanf()\u8981\u5c06\u8bfb\u53d6\u7684\u5185\u5bb9\u5b58\u50a8\u5230\u5bf9\u5e94\u53d8\u91cf\u5730\u5740\u4e2d\uff0c\u800c\u4e0d\u662f\u53d8\u91cf\u540d\u3002\u56e0\u6b64\uff0cscanf()\u7684\u53c2\u6570\u5e94\u8be5\u662f\u53d8\u91cf\u7684\u5730\u5740\u3002

    e.g. scanf.c
    #include <stdio.h>\n#include <stdio.h>\nint main(void)\n{\n    int a;\n    float b;\n    char str[30];\n    int c[10];\n\n    scanf(\"%d %f\", &a, &b); // \u8bfb\u53d6\u6574\u6570\u548c\u6d6e\u70b9\u6570\n    scanf(\"%s\", str);       // \u8bfb\u53d6\u5b57\u7b26\u4e32\n    scanf(\"%d\", c);        // \u8bfb\u53d6\u6574\u6570\u6570\u7ec4\n    return 0;\n}\n
  2. scanf() \u51fd\u6570\uff0c\u9664\u4e86 %c \u4ee5\u5916\u7684\u8f6c\u6362\u8bf4\u660e\uff0c\u90fd\u4e0d\u4f1a\u8bfb\u53d6\u7a7a\u767d\u5b57\u7b26\uff08\u7a7a\u683c\u3001\u5236\u8868\u7b26\u548c\u56de\u8f66\uff09\u3002

    \u5178\u578b\u95ee\u9898\uff1a\u6362\u884c\u7b26\u95ee\u9898

    e.g.

    confusing_scanf.c
    #include <stdio.h>\nint main(void)\n{\n    char c[100] = {0};\n    scanf(\"%s\\n\",&c);\n    printf(\"%s\",c);\n}\n
  3. scanf()\u4e2d\u7684\u8f93\u5165\u8fc7\u7a0b

    \u5047\u8bbescanf()\u6839\u636e%d\u8f6c\u6362\u8bfb\u53d6\u4e00\u4e2a\u6574\u6570\uff0cscanf()\u51fd\u6570\u6bcf\u6b21\u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26\uff0c\u8df3\u8fc7\u6240\u6709\u7684\u7a7a\u767d\u5b57\u7b26\uff0c\u76f4\u5230\u9047\u5230\u7b2c\u4e00\u4e2a\u975e\u7a7a\u767d\u5b57\u7b26\u624d\u5f00\u59cb\u8bfb\u53d6\u3002scanf()\u5e0c\u671b\u627e\u5230\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u6216\u8005\u4e00\u4e2a\u7b26\u53f7\uff0c\u82e5\u627e\u5230\uff0c\u5219\u4f1a\u7ee7\u7eed\u5bfb\u627e\u4e0b\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u6216\u8005\u7b26\u53f7\uff0c\u76f4\u5230\u9047\u5230\u4e00\u4e2a\u975e\u6570\u5b57\u5b57\u7b26\uff0c\u6b64\u65f6scanf()\u4f1a\u5c06\u8bfb\u53d6\u7684\u5b57\u7b26\u653e\u56de\u8f93\u5165\u6d41\u4e2d\uff0c\u7136\u540e\u5c06\u8bfb\u53d6\u7684\u5b57\u7b26\u8f6c\u6362\u6210\u6574\u6570\u3002

    \u5982\u679c\u7b2c\u4e00\u4e2a\u975e\u7a7a\u767d\u5b57\u7b26\u4e0d\u662f\u6570\u5b57\u6216\u8005\u6b63\u8d1f\u53f7\uff0cscanf()\u4f1a\u505c\u5728\u90a3\u91cc\uff0c\u5e76\u628a\u5b57\u7b26\u653e\u56de\u8f93\u5165\u4e2d\uff0c\u4e0d\u4f1a\u628a\u503c\u8d4b\u7ed9\u76f8\u5e94\u53d8\u91cf\u3002C \u8bed\u8a00\u89c4\u5b9a\u4e86\u5728\u7b2c 1 \u4e2a\u51fa\u9519\u7684\u5730\u65b9\u505c\u6b62\u8bfb\u53d6\u8f93\u5165\u3002

    \u5982\u679c\u4f7f\u7528%s\u8f6c\u6362\u8bf4\u660e\uff0cscanf()\u4f1a\u8df3\u8fc7\u7a7a\u767d\u5f00\u59cb\u8bfb\u53d6\u9664\u7a7a\u767d\u4ee5\u5916\u7684\u6240\u6709\u5b57\u7b26\uff0c\u76f4\u5230\u9047\u5230\u7a7a\u767d\u5b57\u7b26\u4e4b\u540e\u5c06\u7a7a\u767d\u7b26\u91cd\u65b0\u653e\u56de\u8f93\u5165\u540e\u7ed3\u675f\u3002

  4. \u683c\u5f0f\u5b57\u7b26\u4e32\u4e2d\u7684\u666e\u901a\u5b57\u7b26

    scanf()\u4e2d\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u767d\u610f\u5473\u7740\u8df3\u8fc7\u4e0b\u4e00\u4e2a\u8f93\u5165\u9879\u524d\u7684\u6240\u6709\u7a7a\u767d\u3002

    \u9664\u4e86%c\u5176\u4ed6\u8f6c\u6362\u8bf4\u660e\u90fd\u4f1a\u81ea\u52a8\u8df3\u8fc7\u5f85\u8f93\u5165\u503c\u524d\u9762\u7684\u6240\u6709\u7a7a\u767d\u3002

    \u4ee5\u4e0b\u4ee3\u7801\u6709\u4ec0\u4e48\u533a\u522b\uff1f

    scanf(\"%d %d\", &n,&m);\nscanf(\"%d%d\", &n,&m);\n\nscanf(\"%c\", &c);\nscanf(\" %c\", &c);\n
  5. scanf()\u7684\u8fd4\u56de\u503c

    \u8bfb\u53d6\u6210\u529f\u5219\u8fd4\u56de\u8bfb\u53d6\u7684\u9879\u6570\u3002\u6ca1\u6709\u8bfb\u53d6\u4efb\u4f55\u9879\u5219\u8fd4\u56de 0\u3002\u5f53scanf()\u8bfb\u53d6\u5230\u6587\u4ef6\u672b\u5c3e\u5219\u8fd4\u56deEOF\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_9","title":"\u5b9e\u4f8b","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_10","title":"\u5b89\u5168\u7684\u8f93\u5165\u51fd\u6570","text":"

\u5199\u4e00\u4e2a\u5b89\u5168\u7684\u8f93\u5165\u51fd\u6570

\u4f17\u6240\u5468\u77e5\uff0cC\u8bed\u8a00\u7684gets\u51fd\u6570\u662f\u4e00\u4e2a\u975e\u5e38\u4e0d\u5b89\u5168\u7684\u51fd\u6570(\u8bf7\u53c2\u8003\u7cfb\u7edf\u77e5\u8bc6\u62fe\u90571)\uff0c\u5728C11\u4e2d\u88ab\u5f03\u7528\uff0c\u8f6c\u4e3agets_s()\u3002gets()\u6781\u6709\u53ef\u80fd\u9020\u6210\u7f13\u51b2\u533a\u6ea2\u51fa\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u5199\u4e00\u4e2a\u5b89\u5168\u7684\u8f93\u5165\u51fd\u6570\u3002

s_gets.c
char * s_gets(char* st, int n)\n{\n    char * ret_val;\n    int i = 0;\n\n    ret_val = fgets(st, n, stdin);\n    if (ret_val)\n    {\n        while (st[i] != '\\n' && st[i] != '\\0)\n            i++;\n        if (st[i] == '\\n')\n            st[i] = '\\0';\n        else //must have words[i] == '\\0'\n            while (getchar() != '\\n')\n                continue;\n    }\n    return ret_val;\n}\n

\u8fd9\u4e2a\u51fd\u6570\u6765\u81ea\u300aC Primer Plus\u300b\uff0c\u4e5f\u662f\u4e66\u4e2d 13 \u7ae0\u4ee5\u540e\u4e00\u76f4\u4f7f\u7528\u7684\u8f93\u5165\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u793a\u8303\u4e86\u5982\u4f55\u4f7f\u7528\u5b89\u5168\u7684 fgets() \u51fd\u6570\uff0c\u5e76\u5c06\u8f93\u5165\u7edf\u4e00\uff0c\u5e76\u5904\u7406\u5269\u4f59\u7684\u5b57\u7b26\u3002

\u5728\u6d89\u53ca\u884c\u7684\u8f93\u5165\u65f6\uff0c\u4e00\u5b9a\u8981\u6ce8\u610f\u7edf\u4e00\u884c\u7ed3\u5c3e\u7684\u5f62\u5f0f\u3002\u8fd9\u5bf9\u4e8e\u6362\u884c\u7b26\uff0c\u7279\u522b\u662f\u6587\u4ef6\u7ed3\u5c3e\u5904\u859b\u5b9a\u8c14\u7684\u6362\u884c\u7b26\uff0c\u6709\u5f88\u5927\u4f5c\u7528\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_11","title":"\u68c0\u67e5\u8f93\u5165","text":"

\u53ef\u4ee5\u4f7f\u7528scanf() \u7684\u8fd4\u56de\u503c\u6765\u68c0\u67e5\u8f93\u5165\u662f\u5426\u6b63\u786e\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_12","title":"\u6587\u4ef6\u7f16\u7801\u4e0e\u6587\u4ef6\u8f93\u5165\u8f93\u51fa","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_13","title":"\u57fa\u7840\u6982\u5ff5","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_14","title":"\u4ec0\u4e48\u662f\u6587\u4ef6\uff1f","text":"

\u7b80\u5355\u7684\u8bf4\uff0c\u6587\u4ef6\u662f\u5728\u786c\u76d8\u4e0a\u7684\u4e00\u6bb5\u5df2\u547d\u540d\u7684\u50a8\u5b58\u533a\u3002

\u5bf9\u64cd\u4f5c\u7cfb\u7edf\u800c\u8a00\uff0c\u6587\u4ef6\u66f4\u52a0\u590d\u6742\u3002\u6587\u4ef6\u662f\u5177\u6709\u7b26\u53f7\u540d\u7684\uff0c\u5728\u903b\u8f91\u4e0a\u5177\u6709\u5b8c\u6574\u610f\u4e49\u7684\u4e00\u7ec4\u76f8\u5173\u4fe1\u606f\u9879\u7684\u5e8f\u5217\u3002\u6587\u4ef6\u8fd8\u5305\u62ec\u4e86\u4e00\u4e9b\u989d\u5916\u6570\u636e\uff0c\u4fbf\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u786e\u5b9a\u6587\u4ef6\u7684\u79cd\u7c7b\u3002

c_file.c
#include<stdio.h>\n#include<string.h>\n\nint main(int argc, char *argv[]){\n    const char *str = \"ckc-agc programming lec3\";\n\n    FILE *fp1 = fopen(\"test1.txt\", \"wb+\");\n    FILE *fp2 = fopen(\"test2.txt\", \"w+\");\n    fprintf(fp1, \"%s\\n%s\\n\", str, argv[0]);\n    fprintf(fp2, \"%s\\n%s\\n\", str, argv[0]);\n    fwrite(str, sizeof(char), strlen(str), fp1);\n\n    // fseek(fp1, 0, SEEK_SET);\n    // fprintf(fp1, \"%s\\n\", \"SEEK_SET\");\n    fseek(fp1, 0, SEEK_END);\n    fprintf(fp1, \"%s\\n\", \"SEEK_END\");\n\n    rewind(fp1);\n    fprintf(fp1, \"%s\\n\", \"rewind\");\n\n    fclose(fp1);\n    fclose(fp2);\n}\n
file c_file.c\nfile c_file.o\nfile c_file\nobjdump -h -s -d c_file.o\nobjdump -h -s c_file\n

\u5bf9\u4e8e C \u8bed\u8a00\u6765\u8bf4\uff0cC \u628a\u6587\u4ef6\u770b\u4f5c\u8fde\u7eed\u7684\u5b57\u8282\uff0c\u6bcf\u4e2a\u5b57\u8282\u90fd\u80fd\u88ab\u5355\u72ec\u8bfb\u53d6\u3002\u8fd9\u4e0e UNIX \u73af\u5883\u4e2d\u7684\u6587\u4ef6\u7ed3\u6784\u76f8\u5bf9\u5e94\u3002\u4fbf\u4e8e\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\uff0cC \u63d0\u4f9b\u4e24\u79cd\u6587\u4ef6\u6a21\u5f0f\uff1a\u6587\u672c\u6a21\u5f0f\u548c\u4e8c\u8fdb\u5236\u6a21\u5f0f\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_15","title":"\u6587\u4ef6\u7f16\u7801","text":"

\u5b57\u7b26\u7f16\u7801\u662f\u628a\u5b57\u7b26\u96c6\u4e2d\u7684\u5b57\u7b26\u7f16\u7801\u4e3a\u6307\u5b9a\u96c6\u5408\u4e2d\u67d0\u4e00\u5bf9\u8c61\uff08\u4f8b\u5982\uff1abit \u6d41\uff09\uff0c\u4ee5\u4fbf\u6587\u672c\u5728\u8ba1\u7b97\u673a\u4e2d\u5b58\u50a8\u548c\u901a\u8fc7\u901a\u4fe1\u7f51\u7edc\u7684\u4f20\u9012\u3002

\u5e38\u89c1\u7684\u6587\u4ef6\u5b57\u7b26\u96c6/\u7f16\u7801\uff1a

\u73b0\u5728\u5728\u5185\u5b58\u4e2d\u901a\u5e38\u4ee5 UTF-16(Windows API \u5927\u91cf\u504f\u597d UTF-16 LE \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u4f5c\u4e3a\u53c2\u6570) \u6765\u50a8\u5b58\uff0c\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\u66ff\u6362\u4e3a UTF-8 \u7b49\u683c\u5f0f\uff0c\u53ef\u4ee5\u538b\u7f29\u7a7a\u95f4\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_16","title":"\u6587\u672c\u6a21\u5f0f\u548c\u4e8c\u8fdb\u5236\u6a21\u5f0f","text":"

\u6240\u6709\u6587\u4ef6\u7684\u5185\u5bb9\u90fd\u4ee5\u4e8c\u8fdb\u5236\u5f62\u5f0f\u5b58\u50a8\u3002\u4f46\u662f\uff0c\u5982\u679c\u6587\u4ef6\u6700\u521d\u4f7f\u7528\u4e8c\u8fdb\u5236\u7f16\u7801\u7684\u5b57\u7b26 (\u4f8b\u5982 ASCII \u7801) \u8868\u793a\u6587\u672c\uff0c\u8be5\u6587\u4ef6\u5c31\u662f\u6587\u672c\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u6587\u672c\u5185\u5bb9\u3002\u5982\u679c\u6587\u4ef6\u4e2d\u7684\u4e8c\u8fdb\u5236\u503c\u4ee3\u8868\u53ca\u5176\u8bed\u8a00\u4ee3\u7801\u6216\u6570\u503c\u6570\u636e\uff0c\u8be5\u6587\u4ef6\u662f\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u4e8c\u8fdb\u5236\u5185\u5bb9\u3002

Unix \u4f7f\u7528\u540c\u4e00\u79cd\u6587\u4ef6\u683c\u5f0f\u5904\u7406\u6587\u672c\u6587\u4ef6\u548c\u4e8c\u8fdb\u5236\u6587\u4ef6\u7684\u5185\u5bb9\u3002Unix \u76ee\u5f55\u4e2d\u6709\u4e00\u4e2a\u7edf\u8ba1\u6587\u4ef6\u5927\u5c0f\u7684\u8ba1\u6570\uff0c\u7a0b\u5e8f\u53ef\u4ee5\u6839\u636e\u8be5\u8ba1\u6570\u786e\u5b9a\u662f\u5426\u8bfb\u5230\u6587\u4ef6\u5c3e\u3002

C \u8bed\u8a00\u63d0\u4f9b\u4e24\u79cd\u8bbf\u95ee\u6587\u4ef6\u7684\u9014\u5f84\uff1a\u4e8c\u8fdb\u5236\u6a21\u5f0f\u548c\u6587\u672c\u6a21\u5f0f\u3002\u5728\u4e8c\u8fdb\u5236\u6a21\u5f0f\u4e2d\uff0c\u7a0b\u5e8f\u53ef\u4ee5\u8bbf\u95ee\u6587\u4ef6\u7684\u6bcf\u4e2a\u5b57\u8282\uff0c\u800c\u5728\u6587\u672c\u6a21\u5f0f\u4e2d\uff0c\u7a0b\u5e8f\u6240\u89c1\u7684\u5185\u5bb9\u548c\u6587\u4ef6\u7684\u5b9e\u9645\u5185\u5bb9\u4e0d\u540c\u3002\u7a0b\u5e8f\u4ee5\u6587\u672c\u6a21\u5f0f\u8bfb\u53d6\u6587\u4ef6\u65f6\uff0c\u628a\u672c\u5730\u73af\u5883\u8868\u793a\u7684\u884c\u672b\u5c3e\u6216\u6587\u4ef6\u7ed3\u5c3e\u6620\u5c04\u6210 C \u6a21\u5f0f\u3002

\u8fd9\u544a\u8bc9\u6211\u4eec\u6587\u672c\u548c\u4e8c\u8fdb\u5236\u6a21\u5f0f\u4e0d\u80fd\u968f\u610f\u6df7\u7528\uff0c\u5426\u5219\u53ef\u80fd\u4f1a\u51fa\u73b0\u6b63\u786e\u6027\u4e0a\u7684\u95ee\u9898\u3002

I/O \u7ea7\u522b

\u4e8b\u5b9e\u4e0a\u6211\u4eec\u9664\u4e86\u9009\u62e9\u5904\u7406\u6587\u4ef6\u7684\u6a21\u5f0f\uff0c\u8fd8\u80fd\u591f\u9009\u62e9I/O\u7684\u7ea7\u522b\u3002\u5e95\u5c42I/O\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684I/O\u670d\u52a1\u3002\u6807\u51c6\u9ad8\u7ea7I/O\u4f7f\u7528C\u5e93\u7684\u6807\u51c6\u5305\u548cstdio.h\u5934\u6587\u4ef6\u5b9a\u4e49\u3002\u6807\u51c6\u9ad8\u7ea7I/O\u4f7f\u7528\u5e95\u5c42I/O\u670d\u52a1\uff0c\u4f46\u662f\u5b83\u4eec\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7ea7\u522b\u7684\u63a5\u53e3\u3002\u56e0\u4e3a\u65e0\u6cd5\u4fdd\u8bc1\u6240\u6709\u7684\u64cd\u4f5c\u7cfb\u7edf\u90fd\u9002\u7528\u76f8\u540c\u7684\u5e95\u5c42I/O\u6a21\u578b\uff0cC\u6807\u51c6\u53ea\u652f\u6301\u6807\u51c6I/O\u5305\u3002

\u6807\u51c6\u6587\u4ef6

C\u7a0b\u5e8f\u4f1a\u81ea\u52a8\u6253\u5f003\u4e2a\u6587\u4ef6\uff0c\u5b83\u4eec\u88ab\u79f0\u4e3a\u6807\u51c6\u8f93\u5165\uff08standard input\uff09\u3001\u6807\u51c6\u8f93\u51fa\uff08standard output\uff09\u548c\u6807\u51c6\u9519\u8bef\u8f93\u51fa\uff08standard error output\uff09\u3002\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6807\u51c6\u8f93\u5165\u662f\u7cfb\u7edf\u7684\u666e\u901a\u8f93\u5165\u8bbe\u5907\uff0c\u901a\u5e38\u4e3a\u952e\u76d8\uff1b\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u662f\u7cfb\u7edf\u7684\u666e\u901a\u8f93\u51fa\u8bbe\u5907\uff0c\u901a\u5e38\u4e3a\u663e\u793a\u5c4f\u3002

\u901a\u5e38\uff0c\u6807\u51c6\u8f93\u5165\u4e3a\u7a0b\u5e8f\u63d0\u4f9b\u8f93\u5165\uff0c\u5b83\u662f getchar()\u548c scanf()\u4f7f\u7528\u7684\u6587\u4ef6\u3002\u7a0b\u5e8f\u901a\u5e38\u8f93\u51fa\u5230\u6807\u51c6\u8f93\u51fa\uff0c\u5b83\u662fputchar()\u3001puts()\u548cprintf()\u4f7f\u7528\u7684\u6587\u4ef6\u3002\u524d\u6587\u63d0\u5230\u7684\u91cd\u5b9a\u5411\u628a\u5176\u4ed6\u6587\u4ef6\u89c6\u4e3a\u6807\u51c6\u8f93\u5165\u6216\u6807\u51c6\u8f93\u51fa\u3002\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u63d0\u4f9b\u4e86\u4e00\u4e2a\u903b\u8f91\u4e0a\u4e0d\u540c\u7684\u5730\u65b9\u6765\u53d1\u9001\u9519\u8bef\u6d88\u606f\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f7f\u7528\u91cd\u5b9a\u5411\u628a\u8f93\u51fa\u53d1\u9001\u7ed9\u6587\u4ef6\u800c\u4e0d\u662f\u5c4f\u5e55\uff0c\u90a3\u4e48\u53d1\u9001\u81f3\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u7684\u5185\u5bb9\u4ecd\u7136\u4f1a\u88ab\u53d1\u9001\u5230\u5c4f\u5e55\u4e0a\u3002\u8fd9\u6837\u5f88\u597d\uff0c\u56e0\u4e3a\u5982\u679c\u628a\u9519\u8bef\u6d88\u606f\u53d1\u9001\u81f3\u6587\u4ef6\uff0c\u5c31\u53ea\u80fd\u6253\u5f00\u6587\u4ef6\u624d\u80fd\u770b\u5230\u3002

\u7406\u89e3\uff1a\u6807\u51c6I/O\u4e2d\u7528FILE\uff08\u6d41\uff09\u8868\u793a\u4e00\u4e2a\u6253\u5f00\u7684\u6587\u4ef6

"},{"location":"programming/archive/23fall/lec3/lec3/#_17","title":"\u6d41\u548c\u6587\u4ef6","text":"

C \u6807\u51c6\u662f\u8fd9\u6837\u63cf\u8ff0\u4e24\u79cd\u6d41\u7684\uff1a

\u5173\u4e8e\u6587\u4ef6\u52a8\u4f5c\uff1a

"},{"location":"programming/archive/23fall/lec3/lec3/#_18","title":"\u7c7b\u578b\u548c\u5b8f","text":"

\u5728 <stdio.h> \u4e2d\u6709\u5982\u4e0b\u4e0e\u6587\u4ef6\u76f8\u5173\u7684\u7c7b\u578b\u548c\u5b8f\uff1a

"},{"location":"programming/archive/23fall/lec3/lec3/#_19","title":"\u51fd\u6570","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_20","title":"\u6587\u4ef6\u64cd\u4f5c","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_21","title":"\u6587\u4ef6\u8bbf\u95ee","text":""},{"location":"programming/archive/23fall/lec3/lec3/#mode","title":"mode \u5b57\u7b26\u4e32\u7684\u542b\u4e49","text":"flag meaning r read w write (new or cut) a append (new or append) b binary + update

\u6ce8\u610f\u4e0a\u9762\u8bcd\u8bed\u7684\u542b\u4e49\uff0cupdate \u548c append \u80fd\u5199\u5165\u7684\u8303\u56f4\u5e94\u8be5\u662f\u4e0d\u540c\u7684\u3002

\u5bf9\u4e8e UNIX \u8fd9\u79cd\u53ea\u6709\u4e00\u79cd\u6587\u4ef6\u7c7b\u578b\u7684\u7cfb\u7edf\uff0c\u5e26 b \u4e0e\u5426\u7684\u6a21\u5f0f\u662f\u76f8\u540c\u7684\u3002 C11 \u4e2d\u65b0\u589e\u4e86 x\uff0c\u5e26\u8be5\u5b57\u6bcd\u7684\u5199\u6a21\u5f0f\u6253\u5f00\u5b58\u5728\u6587\u4ef6\u4f1a\u5931\u8d25\uff08\u76f8\u5f53\u4e8e\u52a0\u4e86\u4fdd\u62a4\uff09\uff0c\u4e14\u5141\u8bb8\u72ec\u5360\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#_22","title":"\u683c\u5f0f\u5316\u8f93\u5165/\u8f93\u51fa","text":"

fprintf,fscanf,vfprintf,vprintf,vsprintf

"},{"location":"programming/archive/23fall/lec3/lec3/#_23","title":"\u5b57\u7b26\u8f93\u5165/\u8f93\u51fa","text":"

fgetc,fgets,fputc,fputs,getc,getchar,gets_s/(gets),putc,putchar,puts,ungetc

\u5176\u4e2d\uff0cfgetc() \u4e0e getc() \u8fd9\u7c7b\u51fd\u6570\u7684\u4e0d\u540c\u662f\u540e\u8005\u53ef\u80fd\u88ab\u5b9e\u73b0\u4e3a\u5b8f\u3002

"},{"location":"programming/archive/23fall/lec3/lec3/#io_1","title":"\u76f4\u63a5 I/O","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_24","title":"\u6587\u4ef6\u5b9a\u4f4d","text":""},{"location":"programming/archive/23fall/lec3/lec3/#_25","title":"\u5176\u4ed6","text":"

\u4ee5\u4e0b\u4e24\u4e2a\u51fd\u6570\u7528\u4e8e\u5904\u7406\u66f4\u5927\u578b\u7684\u6587\u4ef6\uff08long \u65e0\u6cd5\u8868\u793a\u7684\u504f\u79fb\u503c\uff09

"},{"location":"programming/archive/23fall/lec3/pre/","title":"\u8bfe\u524d\uff1a\u4e00\u4e9b\u6837\u4f8b","text":"

\u628a\u8bb2\u4e49\u91cc\u7684\u5c0f\u7a0b\u5e8f\u548c\u547d\u4ee4\u884c\u8dd1\u4e00\u8dd1\uff0c\u601d\u8003\u4e00\u4e0b\u7559\u4e0b\u7684\u95ee\u9898\uff5e

  1. \u91cd\u5b9a\u5411\u8fd0\u7b97\u7b26

    echo_eof.c
    /* echo_eof.c -- repeats input to end of file */\n#include <stdio.h>\nint main(void)\n{\n    int ch;\n\n    while ((ch = getchar()) != EOF)\n    putchar(ch);\n\n     return 0;\n}\n
    echo_eof < echo_eof.c\necho_eof < echo_eof.c > echo_eof.txt\necho_eof < echo_eof.c | cat\n
  2. \u5173\u4e8e\u683c\u5f0f\u5316\u5b57\u7b26\u4e32

    printf.c
    #include <stdio.h>\n\nint main()\n{\n    // \u7c7b\u578b\n    printf(\"%5d\\n\", 1000);  // \u9ed8\u8ba4\u53f3\u5bf9\u9f50\uff0c\u5de6\u8fb9\u8865\u7a7a\u683c\n    printf(\"%-5d\\n\", 1000); // \u5de6\u5bf9\u9f50\uff0c\u53f3\u8fb9\u8865\u7a7a\u683c\n    printf(\"%+d %+d\\n\", 1000, -1000); // \u8f93\u51fa\u6b63\u8d1f\u53f7\n    printf(\"% d % d\\n\", 1000, -1000); // \u6b63\u53f7\u7528\u7a7a\u683c\u66ff\u4ee3\uff0c\u8d1f\u53f7\u8f93\u51fa\n    printf(\"%x %#x\\n\", 1000, 1000); // \u8f93\u51fa 0x\n    printf(\"%.0f %#.0f\\n\", 1000.0, 1000.0); // \u5f53\u5c0f\u6570\u70b9\u540e\u4e0d\u8f93\u51fa\u503c\u65f6\u4f9d\u7136\u8f93\u51fa\u5c0f\u6570\u70b9\n    printf(\"%g %#g\\n\", 1000.0, 1000.0); // \u4fdd\u7559\u5c0f\u6570\u70b9\u540e\u540e\u7684 0\n    printf(\"%05d\\n\", 1000); // \u524d\u9762\u8865 0\n\n    // \u5bbd\u5ea6\n    double a = 3.141592653589;\n    int x = 5;\n    printf(\"%.*f\", x, a);\n\n    // \u7cbe\u5ea6\n    printf(\"%.8d\\n\", 1000);           // \u4e0d\u8db3\u6307\u5b9a\u5bbd\u5ea6\u8865\u524d\u5bfc 0\uff0c\u6548\u679c\u7b49\u540c\u4e8e%06d\n    printf(\"%.8f\\n\", 1000.123456789); // \u8d85\u8fc7\u7cbe\u5ea6\uff0c\u622a\u65ad\n    printf(\"%.8f\\n\", 1000.123456);    // \u4e0d\u8db3\u7cbe\u5ea6\uff0c\u8865\u540e\u7f6e 0\n    printf(\"%.8g\\n\", 1000.123456);    // \u6700\u5927\u6709\u6548\u6570\u5b57\u4e3a 8 \u4f4d\n    printf(\"%.8s\\n\", \"abcdefghij\");   // \u8d85\u8fc7\u6307\u5b9a\u957f\u5ea6\u622a\u65ad\n\n    // \u7c7b\u578b\u957f\u5ea6\n    printf(\"%hhd\\n\", 'A');               // \u8f93\u51fa\u6709\u7b26\u53f7 char\n    printf(\"%hhu\\n\", 'A' + 128);         // \u8f93\u51fa\u65e0\u7b26\u53f7 char\n    printf(\"%hd\\n\", 32767);              // \u8f93\u51fa\u6709\u7b26\u53f7\u77ed\u6574\u578b short int\n    printf(\"%hu\\n\", 65535);              // \u8f93\u51fa\u65e0\u7b26\u53f7\u77ed\u6574\u578b unsigned short int\n    printf(\"%ld\\n\", 0x7fffffffffffffff); // \u8f93\u51fa\u6709\u7b26\u53f7\u957f\u6574\u578b long int\n    printf(\"%lu\\n\", 0xffffffffffffffff); // \u8f93\u51fa\u6709\u7b26\u53f7\u957f\u6574\u578b unsigned long int\n}\n
  3. \u5173\u4e8eprintf()

    wrong_cnv.c
    #include <stdio.h>\n#define num 336\n#define b 65618\nint main(void)\n{\n    printf(\"num as short and unsigned short:  %hd %hu\\n\", num,num);\n    printf(\"-num as short and unsigned short: %hd %hu\\n\", -mnum,-mnum);\n    printf(\"num as int and char: %d %c\\n\", num, num);\n    printf(\"b as int, short, and char: %d %hd %c\\n\",b, b, b);\n\n    float n1 = 3.0;\n    double n2 = 3.0;\n    long n3 = 2000000000;\n    long n4 = 1234567890;\n    printf(\"%.1e %.1e %.1e %.1e\\n\", n1, n2, n3, n4);\n    printf(\"%ld %ld\\n\", n3, n4);\n    printf(\"%ld %ld %ld %ld\\n\", n1, n2, n3, n4);\n    return 0;\n}\n

    \u8be5\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c\u4e3a (\u7531\u4e8e\u5b9e\u73b0\u662f\u672a\u5b9a\u4e49\u7684\uff0c\u90e8\u5206\u7ed3\u679c\u56e0\u7cfb\u7edf\u548c\u7f16\u8bd1\u5668\u800c\u5f02)\uff1a

    num as short and unsigned short:  336 336\n-num as short and unsigned short: -336 65200\nnum as int and char: 336 P\nb as int, short, and char: 65618 336 R\n3.0e+00 3.0e+00 2.0e+09 1.2e+09\n2000000000 1234567890\n0 1074266112 0 1074266112\n

    \u4f60\u80fd\u89e3\u91ca\u4e3a\u4ec0\u4e48\u4f7f\u7528%ld \u8f93\u51fa long \u7c7b\u578b\u7684\u503c\u65f6\uff0c\u4e5f\u4f1a\u51fa\u73b0\u9519\u8bef\u5417\uff1f

  4. \u5173\u4e8escanf()

    confusing_scanf.c
    #include <stdio.h>\nint main(void)\n{\n    char c[100] = {0};\n    scanf(\"%s\\n\",&c);\n    printf(\"%s\",c);\n}\n

    \u8fd9\u4e2a\u7a0b\u5e8f\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u5947\u602a\uff1f

  5. \u6587\u4ef6

    c_file.c
    #include<stdio.h>\n#include<string.h>\n\nint main(int argc, char *argv[]){\n    const char *str = \"ckc-agc programming lec3\";\n\n    FILE *fp1 = fopen(\"test1.txt\", \"wb+\");\n    FILE *fp2 = fopen(\"test2.txt\", \"w+\");\n    fprintf(fp1, \"%s\\n%s\\n\", str, argv[0]);\n    fprintf(fp2, \"%s\\n%s\\n\", str, argv[0]);\n    fwrite(str, sizeof(char), strlen(str), fp1);\n\n    // fseek(fp1, 0, SEEK_SET);\n    // fprintf(fp1, \"%s\\n\", \"SEEK_SET\");\n    fseek(fp1, 0, SEEK_END);\n    fprintf(fp1, \"%s\\n\", \"SEEK_END\");\n\n    rewind(fp1);\n    fprintf(fp1, \"%s\\n\", \"rewind\");\n\n    fclose(fp1);\n    fclose(fp2);\n}\n
    file c_file.c\nfile c_file.o\nfile c_file\nobjdump -h -s -d c_file.o\nobjdump -h -s c_file\n
"},{"location":"programming/archive/23fall/lec4/after/","title":"\u8bfe\u540e\u6269\u5c55\uff1aC \u6807\u51c6\u5e93\u7684\u5b9e\u73b0","text":"

\u65bd\u5de5\u4e2d

\u672c\u9875\u9762\u6b63\u5728\u7f16\u8f91\u4e2d\u3002

"},{"location":"programming/archive/23fall/lec4/after/#c_1","title":"\u540e\u534a\uff1aC \u6807\u51c6\u5e93\u7684\u5b9e\u73b0","text":"

\u6742\u8c08\uff1a\u4e3a\u4ec0\u4e48\u8981\u5b66\u4e60 C \u6807\u51c6\u5e93\uff1f

\u7406\u8bba\u4e0a\uff0c\u5b66\u4e60\u5b8c\u4efb\u4f55\u7f16\u7a0b\u8bed\u8a00\u7684\u57fa\u672c\u8bed\u6cd5\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u7528\u5b83\u6765\u7f16\u7a0b\u89e3\u51b3\u4efb\u4f55\u5b9e\u9645\u95ee\u9898\u4e86\u3002\u4f46\u662f\uff0c\u8bed\u8a00\u6240\u884d\u751f\u51fa\u7684\u4efb\u4f55\u80fd\u63d0\u9ad8\u751f\u4ea7\u529b\u7684\u5e93\uff0c\u5176\u91cd\u8981\u6027\u5f80\u5f80\u4f1a\u8fdc\u8fdc\u8d85\u8fc7\u8be5\u8bed\u8a00\u672c\u8eab\u3002\u5b66\u4e60\u4e00\u95e8\u8bed\u8a00\u5e76\u5b66\u4e60\u5176\u5e93\u7684\u5b9e\u73b0\uff0c\u8fd9\u6837\u624d\u80fd\u719f\u7ec3\u5730\u9a7e\u9a6d\u8bed\u8a00\u5de5\u5177\uff0c\u4e86\u89e3\u5e93\u6240\u63d0\u4f9b\u7684\u529f\u80fd\u548c\u5c40\u9650\u6027\uff0c\u8fdb\u800c\u5728\u7279\u5b9a\u7684\u5e94\u7528\u8981\u6c42\u4e0b\u6269\u5c55\u5e93\u3002

\u5c3d\u7ba1 C \u8bed\u8a00\u53ca\u5176\u6240\u9644\u5e26\u7684\u6807\u51c6\u5e93\u4e2d\u9690\u85cf\u7740\u592a\u591a\u7684\u6666\u6da9\u9677\u9631\uff0c\u4f46\u6211\u4eec\u4e0d\u5f97\u4e0d\u82b1\u5927\u529b\u6c14\u201c\u8fc7\u5206\u94bb\u7814\u201d\u5b83\u3002\u5b66\u4e60 C \u6807\u51c6\u5e93\u672c\u8eab\u7684\u5b9e\u73b0\uff0c\u5c31\u662f\u5b66\u4e60 C \u8bed\u8a00\u6700\u597d\u7684\u6559\u6750\uff0c\u56e0\u4e3a\u5176\u5b9e\u73b0\u8fc7\u7a0b\u5c06\u4f1a\u628a\u4f7f\u7528 C \u8bed\u8a00\u7f16\u5199\u5177\u6709\u5de5\u4e1a\u5f3a\u5ea6\u7684\u5065\u58ee\u4ee3\u7801\u6240\u9700\u7684\u6280\u5de7\u5c55\u73b0\u5f97\u6dcb\u6f13\u5c3d\u81f4\u3002

C \u6807\u51c6\u5e93\u53ef\u4ee5\u5206\u4e3a 3 \u7ec4\u3002\u5982\u4f55\u6b63\u786e\u548c\u719f\u7ec3\u5730\u4f7f\u7528\u5b83\u4eec\uff0c\u53ef\u4ee5\u76f8\u5e94\u5730\u533a\u5206\u51fa 3 \u79cd\u5c42\u6b21\u7684 C \u7a0b\u5e8f\u5458\uff1a

\u53ef\u4ee5\u770b\u5230\uff0cC \u7a0b\u5e8f\u8bbe\u8ba1\u8fd9\u95e8\u8bfe\u7a0b\u5bf9\u5927\u5bb6\u7684\u8981\u6c42\u5c31\u662f\u300c\u5408\u683c\u7a0b\u5e8f\u5458\u300d\u3002\u6211\u4eec\u5728\u8bfe\u7a0b\u4e2d\u7684\u6781\u5c11\u90e8\u5206\u4ee3\u7801\u4f1a\u770b\u89c1 <assert.h> \u548c <time.h>\uff0c\u8fd9\u4e24\u4e2a\u5e93\u4e5f\u4f1a\u5bf9\u4f60\u7684\u7f16\u7a0b\u6709\u6240\u5e2e\u52a9\uff0c\u4f18\u79c0\u7684\u540c\u5b66\u53ef\u4ee5\u4ee5\u300c\u719f\u7ec3\u7a0b\u5e8f\u5458\u300d\u6765\u8981\u6c42\u81ea\u5df1\u3002\u4eca\u540e\u5927\u591a\u6570\u540c\u5b66\u6216\u8bb8\u90fd\u4f1a\u8f6c\u5411\u5b66\u4e60 C++\uff0c\u5927\u6982\u53ea\u6709\u505a\u5b89\u5168\u3001\u7cfb\u7edf\u3001\u5d4c\u5165\u5f0f\u4e4b\u7c7b\u7684\u540c\u5b66\u4f1a\u9700\u8981\u505a\u5230\u300c\u4f18\u79c0\u7a0b\u5e8f\u5458\u300d\u7684\u5730\u6b65\u3002

\u5b66\u4e60 C \u6807\u51c6\u5e93\u524d\u4f60\u5e94\u8be5\u5177\u5907\u7684\u77e5\u8bc6

\u5b66\u4e60 C \u6807\u51c6\u5e93\u65f6\uff0c\u6211\u4eec\u4f1a\u63a5\u89e6\u5230\u5f88\u591a C \u6807\u51c6\u4e2d\u7684\u89c4\u8303\u6027\u7684\u4e25\u8c28\u5730\u8bed\u53e5\uff0c\u521d\u8bfb\u65f6\u53ef\u80fd\u8ba9\u4f60\u89c9\u5f97\u975e\u5e38\u62d7\u53e3\u548c\u96be\u4ee5\u7406\u89e3\uff0c\u8ba9\u6211\u4eec\u6765\u8bfb\u51e0\u6761\u3002

"},{"location":"programming/archive/23fall/lec4/after/#c_2","title":"\u6742\u9879\uff1aC \u6807\u51c6\u5bf9\u5e93\u7684\u5b9e\u73b0\u8981\u6c42","text":"

\u5728\u4f7f\u7528\u65f6\u4e0d\u5fc5\u5728\u610f\uff0c\u4f46\u9700\u8981\u77e5\u9053\u7684\u4e00\u4e2a\u70b9\u662f\uff1a\u6807\u51c6\u5e93\u4e2d\u7684\u67d0\u4e9b\u51fd\u6570\u53ef\u80fd\u88ab\u4f5c\u4e3a\u5b8f\u5b9e\u73b0\u4e86\u3002\u4f46\u65e0\u8bba\u5982\u4f55\uff0c\u6807\u51c6\u5e93\u4e00\u5b9a\u4f1a\u63d0\u4f9b\u4e00\u4e2a\u51fd\u6570\u7248\u672c\u7684\u5b9e\u73b0\u3002

\u5982\u679c\u4e00\u4e2a\u51fd\u6570\u65e2\u63d0\u4f9b\u4e86\u5b8f\u7248\u672c\u53c8\u63d0\u4f9b\u4e86\u51fd\u6570\u7248\u672c\uff0c\u4f60\u77e5\u9053\u5982\u4f55\u4f7f\u7528\u6307\u5b9a\u7684\u7248\u672c\u5417\uff1f

\u4f8b\u5982\uff0c\u5bf9\u4e8e\u4ee5\u4e0b\u4e24\u79cd\u7248\u672c\uff0c\u4f60\u77e5\u9053\u4f60\u5728\u4f7f\u7528\u7684\u662f\u5b8f\u8fd8\u662f\u51fd\u6570\u5417\uff1f

#define isalnum(c) ...\nint isalnum(int c);\n

\u6807\u51c6\u5e93\u4e2d\u7684\u4e00\u4e9b\u51fd\u6570\uff0c\u53ef\u80fd\u540c\u65f6\u63d0\u4f9b\u4e86\u5b8f\u548c\u51fd\u6570\u7684\u7248\u672c\u3002

atoi() \u7684\u4f7f\u7528\u65b9\u5f0f

  1. \u53ef\u80fd\u751f\u6210\u4e00\u4e2a\u5b8f\u51fd\u6570\uff1a
    #include <stdlib.h>\nconst char *str;\ni = atoi(str);\n
  2. \u751f\u6210\u4e00\u4e2a\u5b9e\u9645\u51fd\u6570\u5f15\u7528\uff1a
    #include <stdlib.h>\n#undef atoi\nconst char *str;\ni = atoi(str);\n
    \u6216\u8005
    #include <stdlib.h>\nconst char *str;\ni = (atoi)(str);\n
"},{"location":"programming/archive/23fall/lec4/after/#stdioh","title":"<stdio.h> \u7684\u5b9e\u73b0\uff1a\u7cfb\u7edf\u8c03\u7528\u4e0e\u5185\u6838\u7f16\u7a0b","text":"

\u5728\u6211\u4e2a\u4eba\u770b\u6765\uff0c<stdio.h> \u7684\u5b9e\u73b0\u6700\u5177\u6311\u6218\u6027\u3002\u4f60\u9700\u8981\u5bf9\u5b9e\u73b0\u5bf9\u5e94\u7684\u64cd\u4f5c\u7cfb\u7edf\u6709\u4e00\u5b9a\u7684\u4e86\u89e3\uff0c\u624d\u80fd\u7f16\u5199\u51fa\u5b8c\u5584\u7684\u4ee3\u7801\u3002

\u672c\u8282\u4ee5 UNIX \u548c POSIX \u89c4\u8303\u7684\u7cfb\u7edf\u8c03\u7528\u4e3a\u51c6\u3002

\u4e00\u4e9b\u5386\u53f2\u7684\u80cc\u666f\uff1a\u6587\u4ef6\u3001\u8bbe\u5907\u548c ioctl
  1. \u6df7\u4e71\u7684\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf

\u6216\u8bb8\u4f60\u5f88\u96be\u60f3\u8c61\uff0cUNIX \u4e4b\u524d\u7684\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf\u4e3a\u6587\u4ef6\u8d4b\u4e88\u4e86\u5f88\u591a\u7c7b\u578b\u4e0a\u7684\u6982\u5ff5\u548c\u3001\u4f5c\u4e86\u5f88\u591a\u533a\u5206\uff0c\u800c\u4e0d\u662f\u6211\u4eec\u73b0\u5728\u6240\u5e7f\u6cdb\u63a5\u53d7\u7684\u300c\u6587\u4ef6\u5c31\u662f\u4e00\u7cfb\u5217\u8fde\u7eed\u7684\u5b57\u8282\u300d\u7684\u6982\u5ff5\u3002\u8fd9\u8fb9\u6709\u4e00\u6bb5\u63cf\u8ff0\uff0c\u4f60\u53ef\u4ee5\u770b\u770b\uff1a

Typically source code was a distinguished type, different from data. Compilers could read source, compiled programs could read and write 'data.' Thus the creation and inspection of Fortran programs was often walled off from the creation and inspection of other files, with completely different ways to edit and print them. This ruled out the use of programs to generate (or even simply copy) Fortran programs.

  1. \u4e0d\u7edf\u4e00\u7684\u6587\u672c\u8868\u793a\u548c\u8bbe\u5907\u4ea4\u4e92

\u65e9\u671f\u7a0b\u5e8f\u7684\u8f93\u5165\u8f93\u51fa\u65e0\u6cd5\u72ec\u7acb\u4e8e\u8bbe\u5907\u3002\u6bd4\u5982\uff0c\u5728\u4e0a\u4e2a\u4e16\u7eaa 60 \u5e74\u4ee3\u7684 FORTRAN IV \u4e2d\uff0c\u5728\u78c1\u5e26\u673a\u4e0a\u9700\u8981\u7528 READ INPUT TAPE 5\uff0c\u8bfb\u53d6\u78c1\u76d8\u4e0a\u9700\u8981\u7528 READ INPUT DISK 1\u3002\u8fd9\u6837\u7684\u4ee3\u7801\u5728\u4e0d\u540c\u7684\u8bbe\u5907\u4e0a\u9700\u8981\u4fee\u6539\uff0c\u975e\u5e38\u4e0d\u65b9\u4fbf\u3002UNIX \u5c06\u8fd9\u4e9b\u6df7\u4e71\u7684\u8bbe\u5907\u4ea4\u4e92\u5c01\u88c5\u5728\u8bbe\u5907\u5904\u7406\u7a0b\u5e8f\u4e2d\u3002\u5728 UNIX \u7cfb\u7edf\u770b\u6765\uff0c\u5916\u56f4\u8bbe\u5907\u6709\u4e09\u79cd\u7c7b\u578b\uff1a\u5b57\u7b26\u8bbe\u5907\uff08Character devices\uff09\u3001\u5757\u8bbe\u5907\uff08Block devices\uff09\u548c\u7f51\u7edc\u8bbe\u5907\uff08Network devices\uff09\u3002\u8fd9\u4e09\u79cd\u8bbe\u5907\u90fd\u88ab\u62bd\u8c61\u4e3a\u6587\u4ef6\uff0c\u4f7f\u7528\u7edf\u4e00\u7684\u6587\u4ef6\u64cd\u4f5c\u63a5\u53e3\u3002

\u5728 Ken Thompson \u4e3a UNIX \u8bbe\u8ba1\u7edf\u4e00\u7684\u5185\u90e8\u6587\u672c\u5f62\u5f0f\u524d\uff0c\u6587\u672c\u8868\u793a\u4e5f\u662f\u5341\u5206\u6df7\u4e71\u7684\u3002\u7ed3\u675f\u4e00\u884c\u662f\u4f7f\u7528\u56de\u8f66\u8fd8\u662f\u56de\u8f66\u52a0\u6362\u884c\uff0c\u8fd8\u662f\u6362\u884c\u7b26\uff0c\u8fd8\u662f\u66f4\u795e\u5947\u7684\u5b57\u7b26\uff1f\u7ec8\u7aef\u80fd\u4e0d\u80fd\u8bc6\u522b\u548c\u5c55\u5f00\u5236\u8868\u7b26\uff1f\u600e\u6837\u7528\u952e\u76d8\u6807\u5fd7\u6587\u4ef6\u7ed3\u675f\uff1f\u8fd9\u4e9b\u95ee\u9898\u7684\u7b54\u6848\u548c\u7ec8\u7aef\u7684\u751f\u4ea7\u5382\u5546\u4e00\u6837\u591a\u3002UNIX \u4f7f\u7528\u7cfb\u7edf\u8c03\u7528 ioctl \u6765\u8bbe\u7f6e\u4e00\u4e2a\u8bbe\u5907\u7684\u5404\u79cd\u53c2\u6570\uff0c\u8d1f\u8d23\u5bf9\u5185\u90e8\u6362\u884c\u7ea6\u5b9a\u548c\u5404\u79cd\u7ec8\u7aef\u4e4b\u95f4\u7684\u9700\u8981\u8f6c\u6362\u7684\u5b57\u7b26\u8fdb\u884c\u5904\u7406\u3002

UNIX Devices Drivers

\u9884\u5907\u77e5\u8bc6\uff1aUNIX \u7cfb\u7edf\u8c03\u7528

"},{"location":"programming/archive/23fall/lec4/lec4/","title":"\u7b80\u660e C \u6807\u51c6\u5e93","text":"

\u6458\u8981

\u8003\u8651\u5230\u8bfe\u7a0b\u6559\u5b66\u8fdb\u5ea6\uff0c\u672c\u8282\u8bfe\u4e0d\u518d\u8bb2\u89e3 C \u6807\u51c6\u5e93\u7684\u5b9e\u73b0\u3002

\u672c\u6b21\u8f85\u5b66\u7684\u76ee\u7684\u662f\uff1a

\u4ece\u5386\u5e74\u5377\u6765\u770b\uff0c\u5bf9\u6807\u51c6\u5e93\u7684\u8003\u5bdf\u5185\u5bb9\u4ec5\u9650\u4e8e\u4e0b\u9762\u7684\u8fd9\u4e9b\u5e93\uff0c\u672c\u8282\u8bfe\u4e5f\u4ec5\u53d9\u8ff0\u4e0b\u9762\u8fd9\u4e9b\u5e93\uff1a

"},{"location":"programming/archive/23fall/lec4/lec4/#c_1","title":"\u5bfc\u5f15\uff1aC \u6807\u51c6\u5e93\uff0c\u5b66\u4e9b\u4ec0\u4e48\uff1f","text":""},{"location":"programming/archive/23fall/lec4/lec4/#_1","title":"\u4e3a\u4ec0\u4e48\u8981\u5b66\u6807\u51c6\u5e93\uff1f","text":"

\u6709\u4e00\u4e2a\u7c97\u6d45\u7684\u7406\u7531\uff0c\u5c31\u662f\u56fe\u65b9\u4fbf\u3002\u5047\u8bbe\u6709\u4e0b\u9762\u8fd9\u4e2a\u58f0\u660e\u5728 main \u51fd\u6570\u4e2d\u6570\u7ec4\uff1a

int a[100];\n

\u6211\u4eec\u77e5\u9053\uff0c\u8fd9\u4e2a\u6570\u7ec4\u4e0d\u4f1a\u88ab\u521d\u59cb\u5316\u3002\u5982\u679c\u60f3\u8981\u628a\u8fd9\u4e2a\u6570\u7ec4\u5168\u90e8\u7f6e\u4e3a 0\uff0c\u4f60\u4f1a\u600e\u4e48\u5199\u5462\uff1f

\u9996\u5148\u4f1a\u6709\u7684\u60f3\u6cd5\u80af\u5b9a\u662f\uff1a

for (int i = 0; i < 100; ++i)\n    a[i] = 0;\n

\u5176\u5b9e\u6807\u51c6\u5e93\u63d0\u4f9b\u4e86\u4e00\u4e2a\u51fd\u6570 memset\uff0c\u7528\u6765\u8bbe\u7f6e\u4e00\u6bb5\u5185\u5b58\u7684\u503c\uff1a

memset(a, 0, sizeof(a));\n

\u662f\u4e0d\u662f\u5f88\u65b9\u4fbf\u5462\uff1f

\u518d\u6765\u4e00\u4e2a\u4f8b\u5b50\uff0c\u628a\u8f93\u5165\u4e2d\u6240\u6709\u7684\u5c0f\u5199\u5b57\u6bcd\u8f6c\u6362\u6210\u5927\u5199\u5b57\u6bcd\u3002\u5047\u8bbe\u8f93\u5165\u5df2\u7ecf\u5b58\u50a8\u5728 char \u6570\u7ec4 str \u4e2d\uff0c\u6839\u636e\u73b0\u6709\u7684\u77e5\u8bc6\uff0c\u4f60\u4f1a\u4e0d\u4f1a\u8fd9\u6837\u5199\uff1a

for(int i = 0; i < strlen(str); ++i)\n    if ('a' <= str[i] && str[i] <= 'z')\n        str[i] -= 'a' - 'A';\n

\u5176\u5b9e\u6807\u51c6\u5e93\u63d0\u4f9b\u4e86\u5224\u65ad\u5b57\u7b26\u5927\u5c0f\u5199\u7684\u51fd\u6570\uff0c\u4e5f\u63d0\u4f9b\u4e86\u8f6c\u6362\u5927\u5c0f\u5199\u7684\u51fd\u6570\uff1a

for(int i = 0; i < strlen(str); ++i)\n    if (islower(str[i]))\n        str[i] = toupper(str[i]);\n

\u4e0b\u9762\u7684\u8fd9\u6bb5\u4ee3\u7801\uff0c\u662f\u4e0d\u662f\u6bd4\u4e0a\u9762\u7684\u4ee3\u7801\u7b80\u6d01\uff0c\u5e76\u4e14\u4e00\u773c\u770b\u8fc7\u53bb\u5c31\u80fd\u660e\u767d\u610f\u601d\u5462\uff1f

\u603b\u800c\u8a00\u4e4b\uff0cC \u6807\u51c6\u5e93\u529f\u80fd\u5f3a\u5927\uff0c\u5b83\u7684\u91cd\u8981\u6027\u548c\u8bed\u8a00\u672c\u8eab\u4e00\u6837\u3002\u5b66\u4f1a\u4f7f\u7528\u6807\u51c6\u5e93\uff0c\u8ba9\u4f60\u5c11\u9020\u8f6e\u5b50\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3001\u7b80\u6d01\u6027\u548c\u6b63\u786e\u6027\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_2","title":"\u6807\u51c6\u5e93\u91cc\u6709\u4ec0\u4e48\uff1f","text":"

\ud83d\udca1\u5728\u4f60\u7684\u5370\u8c61\u4e2d\uff0c\u6807\u51c6\u5e93\u662f\u4ec0\u4e48\u6837\u7684\uff1f\u91cc\u9762\u6709\u4ec0\u4e48\u4e1c\u897f\uff1f

\u6bcf\u4e00\u4e2a\u6807\u51c6\u5e93\u4f1a\u5b9a\u4e49\u8fd9\u4e9b\u5185\u5bb9\uff1a

\u51e0\u4e2a\u8033\u719f\u80fd\u8be6\u7684\u4f8b\u5b50\uff0c\u4f60\u80fd\u8bf4\u8bf4\u5b83\u4eec\u662f\u4ec0\u4e48\u5417\uff1f

\u63a5\u4e0b\u6765\u7684\u6bcf\u4e00\u8282\u662f\u4e00\u4e2a\u6807\u51c6\u5e93\uff0c\u4f1a\u5206\u4e3a\u80cc\u666f\u3001\u5185\u5bb9\u3001\u4f7f\u7528\u4e09\u4e2a\u90e8\u5206\u3002\u5176\u4e2d\u300c\u80cc\u666f\u300d\u90e8\u5206\u4f1a\u4ecb\u7ecd\u4e00\u4e9b\u524d\u7f6e\u77e5\u8bc6\uff0c\u300c\u5185\u5bb9\u300d\u90e8\u5206\u4f1a\u4ecb\u7ecd\u6807\u51c6\u5e93\u4e2d\u7684\u5185\u5bb9\uff0c\u300c\u4f7f\u7528\u300d\u90e8\u5206\u4f1a\u4ecb\u7ecd\u4e00\u4e9b\u4f7f\u7528\u7684\u4f8b\u5b50\u3002\u300c\u5185\u5bb9\u300d\u6a21\u5757\u4e2d\u4ee3\u7801\u6bb5\u5185\u88ab\u6ce8\u91ca\u6389\u7684\u5185\u5bb9\uff0c\u8868\u793a\u4e0d\u4f5c\u8981\u6c42\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_3","title":"\u80cc\u666f\u77e5\u8bc6","text":"

\u4e3a\u4e86\u80fd\u8ddf\u4e0a\u63a5\u4e0b\u6765\u7684\u5185\u5bb9\uff0c\u786e\u8ba4\u4e00\u4e0b\u5927\u5bb6\u90fd\u6709\u7684\u77e5\u8bc6\uff1a

"},{"location":"programming/archive/23fall/lec4/lec4/#ctypeh","title":"<ctype.h>","text":"

\u5934\u6587\u4ef6 <ctype.h> \u58f0\u660e\u4e86\u51e0\u4e2a\u53ef\u4ee5\u7528\u4e8e\u8bc6\u522b\u548c\u8f6c\u6362\u5b57\u7b26\u7684\u51fd\u6570\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#ascii","title":"\u80cc\u666f\uff1aASCII \u5b57\u7b26\u96c6","text":"

ASCII \u5b57\u7b26\u96c6\u4e2d\u7684\u6570\u5b57\u548c\u5b57\u6bcd\u5927\u5bb6\u5e94\u8be5\u90fd\u5f88\u719f\u4e86\uff0c\u8fd9\u8fb9\u518d\u5bf9\u4e24\u7c7b\u5927\u5bb6\u63a5\u89e6\u6bd4\u8f83\u5c11\u7684\u5b57\u7b26\u5206\u7c7b\u7b80\u5355\u505a\u4e2a\u4ecb\u7ecd\u3002

\u5c0f\u63d0\u793a

\u4f60\u771f\u7684\u9700\u8981\u53bb\u8bb0\u8fd9\u4e9b\u5b57\u7b26\u7684\u7f16\u7801\u5417\uff1f

\u9009\u62e9\u586b\u7a7a\u4e4b\u7c7b\u7684\u9898\u76ee\u53ef\u80fd\u4f1a\u8003\u5230\uff0c\u4f46\u4e5f\u662f\u6709\u6280\u5de7\u7684\u3002\u4f60\u6700\u591a\u9700\u8981\u8bb0\u5fc6\u7684\u662f\u5927\u5c0f\u5199\u5b57\u6bcd\u4e4b\u95f4\u76f8\u5dee 32\uff0c\u4f46\u53ea\u8981\u9898\u76ee\u4e0d\u662f\u8ba9\u4f60\u5fc5\u987b\u586b\u6570\u5b57\uff0c\u4f60\u5c31\u53ef\u4ee5\u7528 'a' - 'A' \u6765\u4ee3\u66ff\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_4","title":"\u5185\u5bb9","text":"

\u8fd9\u4e2a\u5934\u6587\u4ef6\u4e2d\u53ea\u6709\u51fd\u6570\uff0c\u6ca1\u6709\u7279\u522b\u7684\u7c7b\u578b\u548c\u5b8f\u3002

\u8fd9\u4e9b\u51fd\u6570\u7684\u610f\u4e49\u548c\u7528\u6cd5\u975e\u5e38\u663e\u7136\uff0c\u56e0\u6b64\u6211\u4e5f\u4e0d\u505a\u6ce8\u91ca\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_5","title":"\u4f7f\u7528","text":"

<ctype.h> \u4e2d\u7684\u51fd\u6570\u5bf9 ASCII \u5b57\u7b26\u5927\u81f4\u4f5c\u4e86\u5982\u4e0b\u5212\u5206\uff1a

\u63a7\u5236\u5b57\u7b26\u90a3\u4e9b\u4e0d\u7528\u7ba1\uff0c\u4e0d\u8981\u6c42\u7684\u51fd\u6570\u4e0d\u7528\u7ba1\u3002\u53ea\u8981\u8bb0\u5f97 isspace \u548c isblank \u7684\u533a\u522b\u5c31\u884c\u4e86\u3002

isspace \u548c isblank \u7684\u533a\u522b

"},{"location":"programming/archive/23fall/lec4/lec4/#ctypeh_1","title":"<ctype.h> \u7684\u5b9e\u73b0\uff1a\u5b8f\u4e0e\u4f4d\u8fd0\u7b97","text":"

\u9605\u8bfb\u672c\u8282\u9700\u8981\u5177\u5907\u7684\u77e5\u8bc6

\u77e5\u9053\u53ef\u4ee5\u7528\u4f4d\u6765\u6807\u5fd7\u67d0\u4e9b\u72b6\u6001\u3002\u4e0e\u6216\u975e\u7b49\u4f4d\u8fd0\u7b97\u7684\u6982\u5ff5\u3002

\u77e5\u9053\u5b8f\u51fd\u6570\u662f\u600e\u4e48\u5c55\u5f00\u7684\u3002

\u4e0d\u77e5\u9053\uff1f\u901f\u901a\u4e00\u4e0b\uff01

\u9996\u5148\u4f60\u5e94\u8be5\u5bf9\u4e8c\u8fdb\u5236\u6709\u4e00\u5b9a\u6982\u5ff5\u3002\u5047\u5982\u6211\u4eec\u6709 4 \u4e2a\u4e8c\u8fdb\u5236\u4f4d 0000\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u7528\u5b83\u6765\u6807\u8bb0 4 \u79cd\u72b6\u6001\u3002\u6211\u4eec\u4e0d\u59a8\u8bbe\uff1a

\uff08\u6ce8\u610f\uff0c\u6700\u53f3\u4fa7\u7684\u4f4d\u662f\u6700\u4f4e\u4f4d\uff0c\u6700\u5de6\u4fa7\u7684\u4f4d\u662f\u6700\u9ad8\u4f4d\u3002\uff09

\u90a3\u4e48\u5bf9\u4e8e\u5b57\u7b26 c\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u4e8c\u8fdb\u5236\u4e32 1010 \u6765\u8868\u793a\u5b83\u7684\u5c5e\u6027\u3002

\u4f7f\u7528\u4f4d\u8fd0\u7b97\u548c\u63a9\u7801\u53ef\u4ee5\u5224\u65ad\u5c5e\u6027\u3002\u6bd4\u5982\uff0c\u6211\u4eec\u8981\u5224\u65ad\u4e00\u4e2a\u5b57\u7b26\u662f\u5426\u662f\u6570\u5b57\uff0c\u628a\u5b83\u7684\u4e32\u4e0e\u63a9\u7801 0001 \u8fdb\u884c\u4e0e\u8fd0\u7b97\u3002\u56e0\u4e3a 0001 \u4e2d\u524d\u4e09\u4f4d\u90fd\u662f 0\uff0c\u7ed3\u679c\u80af\u5b9a\u4e5f\u662f 0\u3002\u800c\u6700\u540e\u4e00\u4f4d\u662f 1\uff0c\u7ed3\u679c\u5c06\u7531\u53c2\u4e0e\u8fd0\u7b97\u7684\u4e32\u51b3\u5b9a\u3002\u63a9\u7801\u4e2d\u7684\u524d\u4e09\u4f4d\u597d\u50cf\u628a\u90a3\u4e9b\u65e0\u5173\u7684\u4f4d\u201c\u63a9\u76d6\u201d\u6389\u4e86\u3002\u6700\u540e\u7ed3\u679c\u5982\u679c\u662f\u96f6\uff0c\u90a3\u4e48\u5c31\u8bf4\u660e\u4e0d\u5177\u6709\u8be5\u5c5e\u6027\uff1b\u5982\u679c\u975e\u96f6\uff0c\u5c31\u8bf4\u660e\u5177\u6709\u8be5\u5c5e\u6027\u3002

\u63a5\u4e0b\u6765\u662f\u5b8f\u3002\u5b8f\u662f\u7eaf\u7cb9\u7684\u5b57\u7b26\u66ff\u6362\u3002\u5982\u679c\u5b8f\u4f7f\u7528\u4e86\u5706\u62ec\u53f7\uff0c\u90a3\u4e48\u5b83\u5c31\u662f\u4e00\u4e2a\u51fd\u6570\u5b8f\uff1a

#define MEAN(X, Y) (((X) + (Y)) / 2)\n

\u90a3\u4e48\u53ea\u8981\u7f16\u8bd1\u5668\u770b\u5230\u4ee3\u7801\u4e2d\u6709 MEAN \u540e\u8ddf\u4e00\u4e2a\u5706\u62ec\u53f7\uff0c\u5c31\u4f1a\u5f00\u59cb\u5339\u914d\u548c\u66ff\u6362\u3002\u6bd4\u5982\uff0cMEAN(1, 2) \u5c06\u88ab\u66ff\u6362\u4e3a (((1) + (2)) / 2)\u3001MEAN(a, b) \u5c06\u88ab\u66ff\u6362\u4e3a (((a) + (b)) / 2)\u3002

\ud83e\udd1a\u505c\u4e00\u505c\uff0c\u5148\u522b\u770b\u4e0b\u9762\u7684\u5185\u5bb9\u3002\u601d\u8003\u4e00\u4e0b\uff0c\u4f60\u4f1a\u600e\u4e48\u5b9e\u73b0\u4e0a\u9762\u7684\u90a3\u4e9b\u51fd\u6570\uff1f

\u4f60\u4f1a\u4e0d\u4f1a\u5728\u60f3\u8fd9\u6837\u7684\u4ee3\u7801\uff1a

int isalnum(int c)\n    { /* test for alphanumeric character */\n    return (('0' <= c && c <= '9') ||\n            ('a' <= c && c <= 'z') ||\n            ('A' <= c && c <= 'Z'));\n    }\n

<ctype.h> \u4e2d\u7684\u51fd\u6570\u901a\u5e38\u4f7f\u7528\u5b8f\u6765\u5b9e\u73b0\u3002\u4f7f\u7528\u5b8f\u5b9e\u73b0\u65f6\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u56e0\u7d20\uff1a

<ctype.h> \u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e2a\u67e5\u627e\u8868 _Ctype\uff0c\u4e24\u4e2a\u6620\u5c04\u8868 _Tolower \u548c _Toupper\u3002\u6bcf\u4e2a\u5b57\u7b26\u90fd\u88ab\u7f16\u5165\u67e5\u627e\u8868\u4e2d\uff0c\u4f7f\u7528\u4f4d\u8fd0\u7b97\u5c31\u80fd\u5224\u65ad\u51fa\u5b57\u7b26\u7684\u7c7b\u578b\u3002

ctype.h
#define _DI 0x20 /* '0'-'9' */\n#define _LO 0x10 /* 'a'-'z' */\n#define _UP 0x02 /* 'A'-'Z' */\n#define _XA 0x200 /* 'a'-'z', 'A'-'Z' */\nextern const short *_Ctype, *_Tolower, *_Toupper;\n#define isalnum(c) (_Ctype[(int)(c)] & (_DI|_LO|_UP|_XA))\n#define tolower(c) _ToLower[(int)(c)]\n

\u8bfb\u4e00\u4e0b\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u60f3\u8c61\u4e00\u4e0b _Ctype \u8fd9\u4e2a\u67e5\u627e\u8868\u7684\u6837\u5b50\u3002

\u8003\u8003\u4f60\uff0c\u5bf9\u4e8e ASCII \u5b57\u7b26\u96c6\uff0c\u8fd9\u4e2a\u67e5\u627e\u8868\u6709\u591a\u5927\uff1f

\u4f60\u80fd\u60f3\u4e00\u60f3\u6620\u5c04\u8868\u7684\u5b9e\u73b0\u5417\uff1f

\u540c\u6837\uff0c\u7ed9\u51fa\u51fd\u6570\u7248\u672c\u7684\u5b9e\u73b0\uff1a

isalnum.c
#include <ctype.h>\n\nint isalnum(int c)\n    { /* test for alphanumeric character */\n    return (_Ctype[c] & (_DI|_LO|_UP|_XA));\n    }\n

\u4e0b\u9762\u4e24\u5e45\u56fe\u5206\u522b\u5c55\u793a\u4e86 _Ctype \u548c _Toupper \u7684\u6837\u5b50\uff1a

_Ctype

_Toupper

\u975e\u5e38\u5730\u7b80\u5355\uff0c\u5bf9\u5427\uff1f\u8fd9\u53ef\u6bd4 'a' <= c && c <= 'z' \u8fd9\u6837\u7684\u5224\u65ad\u8981\u5feb\u5f97\u591a\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#mathh","title":"<math.h>","text":""},{"location":"programming/archive/23fall/lec4/lec4/#_6","title":"\u80cc\u666f\u77e5\u8bc6\uff1a\u51fd\u6570\u7684\u5b9a\u4e49\u57df\u4e0e\u503c\u57df","text":"

\u8fd8\u8bb0\u5f97 double \u8868\u793a\u7684\u8303\u56f4\u5417\uff1f

\u4ece\u4e0a\u56fe\u4f60\u53ef\u4ee5\u770b\u5230\uff0c\u6d6e\u70b9\u6570\u6240\u80fd\u8868\u793a\u7684\u6570\u503c\uff0c\u5b9e\u9645\u4e0a\u662f\u6570\u8f74\u4e0a\u7684\u4e00\u4e2a\u4e2a\u70b9\u3002\u6bd5\u7adf\u53ea\u6709 64 \u4e2a bit \u561b\uff0c\u53ea\u80fd\u7f16\u7801\u6709\u9650\u4e2a\u70b9\u3002

double \u7c7b\u578b\uff088 \u5b57\u8282 IEEE \u6d6e\u70b9\u6570\uff09\u6240\u80fd\u8868\u793a\u7684\u6781\u9650\u503c\u4e3a\uff1a

\u6211\u4eec\u90fd\u77e5\u9053\u6570\u5b66\u51fd\u6570\u6709\u5b9a\u4e49\u57df\u548c\u503c\u57df\uff0c<math.h> \u4e2d\u7684\u51fd\u6570\u4e5f\u6709\uff0c\u53ea\u662f\u5927\u5bb6\u5e73\u5e38\u4f7f\u7528\u7684\u65f6\u5019\u53ef\u80fd\u4e0d\u592a\u5173\u6ce8\u7f62\u4e86\u3002

\u56e0\u4e3a\u6211\u4eec\u6ca1\u6709\u5b66 C \u7684\u9519\u8bef\u5904\u7406\uff0c\u6240\u4ee5\u6211\u4eec\u4e0d\u77e5\u9053\u600e\u4e48\u6355\u83b7\u8fd9\u4e9b\u9519\u8bef\u3002\u6709\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u5b66\u4e60 <error.h> \u4e2d\u7684\u5185\u5bb9\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_7","title":"\u5185\u5bb9","text":""},{"location":"programming/archive/23fall/lec4/lec4/#_8","title":"\u4f7f\u7528","text":""},{"location":"programming/archive/23fall/lec4/lec4/#stringh","title":"<string.h>","text":""},{"location":"programming/archive/23fall/lec4/lec4/#_9","title":"\u80cc\u666f\u77e5\u8bc6\uff1a\u5b57\u7b26\u4e32","text":"

\u5b57\u7b26\u4e32\u548c\u5b57\u7b26\u6570\u7ec4\u4e00\u5b9a\u8981\u533a\u522b\u5f00\u6765\u3002\u5b57\u7b26\u4e32\u662f\u4ee5\u7a7a\u5b57\u7b26 \\0 \u7ed3\u5c3e\u7684\u5b57\u7b26\u6570\u7ec4\u3002

char name[13] = \"StudyTonight\";\nchar name[10] = {'c','o','d','e','\\0'};\n

<string.h> \u7684\u51fd\u6570\u53ea\u8d1f\u8d23\u64cd\u4f5c\u5b57\u7b26\u4e32\uff0c\u4e0d\u8d1f\u8d23\u64cd\u4f5c\u5b57\u7b26\u6570\u7ec4\uff01

\u8fd8\u8bb0\u5f97\u6570\u7ec4\u4f20\u5165\u51fd\u6570\u7684\u65f6\u5019\u4f1a\u9000\u5316\u6210\u6307\u9488\u5417\uff1f\u51fd\u6570\u65e0\u6cd5\u83b7\u77e5\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u56e0\u6b64\u7a7a\u5b57\u7b26\u662f\u5e2e\u52a9\u51fd\u6570\u5224\u65ad\u5b57\u7b26\u4e32\u7ed3\u675f\u3001\u907f\u514d\u8d8a\u754c\u7684\u552f\u4e00\u65b9\u6cd5\u3002

\u5f53\u7136\uff0cstrn \u7cfb\u5217\u51fd\u6570\u63d0\u4f9b\u4e86\u6307\u5b9a\u957f\u5ea6\u7684\u53c2\u6570\u3002

\u4f60\u80fd\u60f3\u8d77\u54ea\u4e9b\u4e1c\u897f\u662f\u5b57\u7b26\u4e32\u5417\uff1f

"},{"location":"programming/archive/23fall/lec4/lec4/#_10","title":"\u5185\u5bb9","text":""},{"location":"programming/archive/23fall/lec4/lec4/#_11","title":"\u4f7f\u7528","text":"

\u4f7f\u7528\u524d\uff0c\u81ea\u5df1\u8ba1\u7b97\u5b57\u7b26\u4e32\u957f\u5ea6\u548c\u5269\u4f59\u7a7a\u95f4\uff0c\u8fd9\u662f\u7f16\u7a0b\u8005\u7684\u8d23\u4efb\u3002\u6216\u8005\u4f7f\u7528\u5e26 n \u7684\u51fd\u6570\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#stdlibh","title":"<stdlib.h>","text":"

\u5934\u6587\u4ef6 <stdlib.h> \u662f\u4e00\u4e2a\u5927\u6742\u70e9\uff0c\u4e3a\u4e86\u5b9a\u4e49\u548c\u58f0\u660e\u90a3\u4e9b\u6ca1\u6709\u660e\u663e\u5f52\u5c5e\u7684\u5b8f\u548c\u51fd\u6570\u3002\u6211\u4eec\u4ec5\u4ecb\u7ecd\u5e38\u7528\u7684\u90e8\u5206\uff1a\u6574\u5f62\u6570\u5b66\u3001\u7b97\u6cd5\u3001\u6587\u672c\u8f6c\u6362\u3001\u73af\u5883\u63a5\u53e3\u548c\u5b58\u50a8\u5206\u914d\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_12","title":"\u80cc\u666f\uff1a\u6307\u9488\u7684\u6982\u5ff5","text":"

\u8bf7\u5148\u9605\u8bfb\u6307\u9488\u7b14\u8bb0\u3002

\u8fd9\u91cc\u518d\u5f3a\u8c03\u4e00\u4e0b\u58f0\u660e\u548c malloc \u7684\u533a\u522b\uff1a

\u4f60\u80fd\u89e3\u91ca\u4e00\u4e0b\u58f0\u660e\u7684\u65f6\u5019\u5185\u5b58\u53d1\u751f\u4e86\u4ec0\u4e48\u53d8\u52a8\u5417\uff1f

\u4e0b\u9762\u7684\u4ee3\u7801\u6bb5\uff0c\u6bcf\u4e00\u884c\u6267\u884c\u65f6\uff0c\u53d1\u751f\u4e86\u4ec0\u4e48\uff1f\u6709\u5185\u5b58\u88ab\u5206\u914d\u5417\uff1f

int p;\nint *q;\nq = &p;\nq = (int *)malloc(sizeof(int));\n

\u6709\u4e00\u4f4d\u540c\u5b66\u5199\u51fa\u4e86\u4e0b\u9762\u8fd9\u6837\u9519\u8bef\u7684\u4ee3\u7801\uff0c\u4f60\u80fd\u6307\u51fa\u9519\u8bef\u5417\uff1f

// \u4e00\u4e2a\u9519\u8bef\u7684\u94fe\u8868\u5934\u63d2\u5165\u51fd\u6570\nstruct Node* create_linked_list() {\n    struct Node* head = NULL;\n    struct Node* current = (struct Node*)malloc(sizeof(struct Node));\n    while (1) {\n        int data;\n        printf(\"\u8bf7\u8f93\u5165\u8282\u70b9\u503c\uff08\u8f93\u5165-1\u9000\u51fa\uff09\uff1a\");\n        scanf(\"%d\", &data);\n        if (data == -1) {\n            break;\n        }\n        current->data = data;\n        current->next = NULL;\n        if (head == NULL) {\n            head = current;\n        } else {\n            head->next = current;\n        }\n    }\n    return head;\n}\n
"},{"location":"programming/archive/23fall/lec4/lec4/#_13","title":"\u5185\u5bb9","text":""},{"location":"programming/archive/23fall/lec4/lec4/#_14","title":"\u4f7f\u7528","text":""},{"location":"programming/archive/23fall/lec4/lec4/#stdioh","title":"<stdio.h>","text":"

\u5173\u4e8e\u6587\u4ef6\u8f93\u5165\u8f93\u51fa......

\u8fd9\u8fb9\u5217\u51fa\u4e86\u6587\u4ef6\u8f93\u5165\u8f93\u51fa\u7684\u5185\u5bb9\uff0c\u7ed9\u5927\u5bb6\u590d\u4e60\u7684\u65f6\u5019\u53c2\u8003\u7528\u3002\u54b1\u4eec\u8fd9\u8282\u8bfe\u4e0d\u8bb2\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_15","title":"\u80cc\u666f\u77e5\u8bc6\uff1a\u6d41","text":"\u80cc\u666f\u6545\u4e8b\uff1a\u65e9\u671f\u8ba1\u7b97\u673a\u6df7\u4e71\u7684\u8f93\u5165\u8f93\u51fa\u6a21\u578b

\u65e9\u671f\u7a0b\u5e8f\u7684\u8f93\u5165\u8f93\u51fa\u65e0\u6cd5\u72ec\u7acb\u4e8e\u8bbe\u5907\u3002\u6bd4\u5982\uff0c\u5728\u4e0a\u4e2a\u4e16\u7eaa 60 \u5e74\u4ee3\u7684 FORTRAN IV \u4e2d\uff0c\u5728\u78c1\u5e26\u673a\u4e0a\u9700\u8981\u7528 READ INPUT TAPE 5\uff0c\u8bfb\u53d6\u78c1\u76d8\u4e0a\u9700\u8981\u7528 READ INPUT DISK 1\u3002\u8fd9\u6837\u7684\u4ee3\u7801\u5728\u4e0d\u540c\u7684\u8bbe\u5907\u4e0a\u9700\u8981\u4fee\u6539\uff0c\u975e\u5e38\u4e0d\u65b9\u4fbf\u3002UNIX \u7cfb\u7edf\u5c06\u8fd9\u4e9b\u6df7\u4e71\u7684\u8bbe\u5907\u4ea4\u4e92\u5c01\u88c5\u5728\u8bbe\u5907\u5904\u7406\u7a0b\u5e8f\u4e2d\u3002\u5728 UNIX \u7cfb\u7edf\u770b\u6765\uff0c\u5916\u56f4\u8bbe\u5907\u6709\u4e09\u79cd\u7c7b\u578b\uff1a\u5b57\u7b26\u8bbe\u5907\uff08Character devices\uff09\u3001\u5757\u8bbe\u5907\uff08Block devices\uff09\u548c\u7f51\u7edc\u8bbe\u5907\uff08Network devices\uff09\u3002\u8fd9\u4e09\u79cd\u8bbe\u5907\u90fd\u88ab\u62bd\u8c61\u4e3a\u6587\u4ef6\uff0c\u4f7f\u7528\u7edf\u4e00\u7684\u6587\u4ef6\u64cd\u4f5c\u63a5\u53e3\u3002

\u5728 Ken Thompson \u4e3a UNIX \u8bbe\u8ba1\u7edf\u4e00\u7684\u5185\u90e8\u6587\u672c\u5f62\u5f0f\u524d\uff0c\u6587\u672c\u8868\u793a\u4e5f\u662f\u5341\u5206\u6df7\u4e71\u7684\u3002\u7ed3\u675f\u4e00\u884c\u662f\u4f7f\u7528\u56de\u8f66\u8fd8\u662f\u56de\u8f66\u52a0\u6362\u884c\uff0c\u8fd8\u662f\u6362\u884c\u7b26\uff0c\u8fd8\u662f\u66f4\u795e\u5947\u7684\u5b57\u7b26\uff1f\u7ec8\u7aef\u80fd\u4e0d\u80fd\u8bc6\u522b\u548c\u5c55\u5f00\u5236\u8868\u7b26\uff1f\u600e\u6837\u7528\u952e\u76d8\u6807\u5fd7\u6587\u4ef6\u7ed3\u675f\uff1f\u8fd9\u4e9b\u95ee\u9898\u7684\u7b54\u6848\u548c\u7ec8\u7aef\u7684\u751f\u4ea7\u5382\u5546\u4e00\u6837\u591a\u3002UNIX \u4f7f\u7528\u7cfb\u7edf\u8c03\u7528 ioctl \u6765\u8bbe\u7f6e\u4e00\u4e2a\u8bbe\u5907\u7684\u5404\u79cd\u53c2\u6570\uff0c\u8d1f\u8d23\u5bf9\u5185\u90e8\u6362\u884c\u7ea6\u5b9a\u548c\u5404\u79cd\u7ec8\u7aef\u4e4b\u95f4\u7684\u9700\u8981\u8f6c\u6362\u7684\u5b57\u7b26\u8fdb\u884c\u5904\u7406\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_16","title":"\u6d41\u7684\u6982\u5ff5","text":"

\u5404\u79cd\u8f93\u5165\u8f93\u51fa\u8bbe\u5907\u5b9e\u5728\u662f\u592a\u591a\u4e86\uff08\u7ec8\u7aef\u3001\u78c1\u5e26\u9a71\u52a8\u5668\u3001\u7ed3\u6784\u5316\u5b58\u50a8\u8bbe\u5907......\uff09\u3002\u4e3a\u4e86\u7edf\u4e00\u6982\u5ff5\uff0cC \u8bed\u8a00\u4e2d\u7684\u8f93\u5165\u548c\u8f93\u51fa\u8bbe\u5907\u5168\u90fd\u548c\u903b\u8f91\u6570\u636e\u6d41\u76f8\u5bf9\u5e94\u3002

\u6d41\u5c31\u662f\u5b57\u7b26\u5e8f\u5217\u3002

\u4e0d\u7ba1\u7cfb\u7edf\u3001\u786c\u4ef6\u662f\u600e\u4e48\u5b9e\u73b0\u7684\u3002\u8f93\u5165\u8f93\u51fa\u5230\u4e86 C \u7a0b\u5e8f\u8fd9\u91cc\uff0c\u5c31\u7edf\u4e00\u4e3a\u903b\u8f91\u4e0a\u7684\u6d41\u4e86\u3002

\u6d41\u5173\u8054\u5230\u4e00\u4e2a\u7279\u5b9a\u7684\u6587\u4ef6\u3002

"},{"location":"programming/archive/23fall/lec4/lec4/#_17","title":"\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6","text":"

\u8ba1\u7b97\u673a\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u53ef\u4ee5\u5206\u4e3a\u4e24\u7c7b\uff1a

\u4e8c\u8fdb\u5236\u6587\u4ef6\u5b58\u50a8\u7684\u5185\u5bb9\u6bd4\u8f83\u590d\u6742\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4e0d\u6562\u968f\u610f\u53d8\u52a8\u3002\u4f46\u6587\u672c\u6587\u4ef6\u5185\u5bb9\u7b80\u5355\uff0c\u5404\u7c7b\u64cd\u4f5c\u7cfb\u7edf\u65e9\u5c31\u6709\u4e86\u81ea\u5df1\u7684\u5904\u7406\u65b9\u5f0f\u3002

\u5373\u4f7f\u5230\u4eca\u5929\uff0c\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u5904\u7406\u6587\u672c\u6587\u4ef6\u7684\u65b9\u5f0f\u4ecd\u7136\u5177\u6709\u5dee\u5f02\u3002

\u5dee\u5f02 UNIX Windows MacOS \u6362\u884c\u7b26 \\n LF \\r\\n CRLF \\n (\u8f83\u65e9\u7684 MacOS \u4f7f\u7528 \\r)LF \u6587\u4ef6\u7ed3\u675f\u7b26 ^DCtrl+D ^ZCtrl+Z ^DCtrl+D

\u90fd\u662f\u5386\u53f2\u7684\u9505\uff01

\u751a\u81f3\u6709\u7684\u64cd\u4f5c\u7cfb\u7edf\u8fd9\u6837\u5904\u7406\u6587\u672c\u6587\u4ef6\uff1a

"},{"location":"programming/archive/23fall/lec4/lec4/#_18","title":"\u6d41\u7684\u7c7b\u578b","text":"

C \u8bed\u8a00\u63d0\u4f9b\u4e24\u79cd\u6d41\uff1a\u6587\u672c\u6d41\u548c\u4e8c\u8fdb\u5236\u6d41\u3002

\u4e3e\u4e2a\u4f8b\u5b50

\u8fd9\u662f\u4e00\u4e2a MS-DOS \u4e0a\u7684\u6587\u672c\u6587\u4ef6\u3002\u5982\u679c\u4f5c\u4e3a\u4e8c\u8fdb\u5236\u6d41\u6253\u5f00\uff0c\u7a0b\u5e8f\u4f1a\u770b\u89c1\u4ee5\u4e0b\u5b57\u8282\uff1a

Rebecca clutched the\\r\\n\njewel-encrusted scarab\\r\\n\nto her heaving bosom.\\r\\n\n^Z\n

\u5982\u679c\u4f5c\u4e3a\u6587\u672c\u6d41\u6253\u5f00\uff0c\u7a0b\u5e8f\u4f1a\u770b\u89c1\u4ee5\u4e0b\u5b57\u8282\uff1a

Rebecca clutched the\\n\njewel-encrusted scarab\\n\nto her heaving bosom.\\n\n
"},{"location":"programming/archive/23fall/lec4/lec4/#_19","title":"\u5185\u5bb9","text":""},{"location":"programming/archive/23fall/lec4/lec4/#_20","title":"\u4f7f\u7528","text":"

\u4ee5\u4e0b\u662f\u8bfe\u5185\u5185\u5bb9\uff0c\u4ec5\u5217\u51fa\uff0c\u4e0d\u505a\u8be6\u7ec6\u4ecb\u7ecd\uff1a

\u4e0b\u9762\u5bf9\u51e0\u4e2a\u77e5\u8bc6\u70b9\u4f5c\u4e00\u70b9\u89c4\u8303\u4ecb\u7ecd\uff1a

\u8f6c\u6362\u8bf4\u660e

\u89c4\u8303\u7684\u8bf4\u660e\u8bf7\u770b\u8fd9\u91cc\uff1a

printf \u7684\u8f6c\u6362\u8bf4\u660e

\u8f6c\u6362\u8bf4\u660e\u4e2d\uff0c% \u540e\u9762\u8981\u8ddf 4 \u4e2a\u7ec4\u6210\u90e8\u5206\u3002\u9664\u4e86\u6700\u540e\u4e00\u4e2a\u90e8\u5206\uff0c\u5176\u4ed6\u90fd\u662f\u53ef\u9009\u7684\uff1a

%[\u6807\u5fd7][\u6700\u5c0f\u5b57\u6bb5\u5bbd\u5ea6][.\u7cbe\u5ea6][h/l/L]\u6307\u5b9a\u8f6c\u6362\u7c7b\u578b\u7684\u5b57\u7b26\n

\u4e3e\u4e2a\u4f8b\u5b50

scanf \u7684\u8f6c\u6362\u8bf4\u660e

\u666e\u904d\u8bef\u533a

\u9488\u5bf9\u540c\u5b66\u4eec\u666e\u904d\u7684\u8bef\u533a\u505a\u51e0\u70b9\u5f3a\u8c03\u8bf4\u660e\uff1a

\u8f93\u5165\u8f93\u51fa\u51fd\u6570\u7684\u8fd4\u56de\u503c

\u5927\u5bb6\u5e73\u5e38\u4f7f\u7528\u53ef\u80fd\u4e0d\u592a\u5173\u6ce8\u3002\u4f46\u8fd8\u662f\u6709\u8003\u5bdf\u7684\u53ef\u80fd\uff1a

\u6587\u4ef6\u5b9a\u4f4d\uff08\u4e0d\u505a\u4ecb\u7ecd\uff09 "},{"location":"programming/archive/23fall/lec5/lec5/","title":"\u6307\u9488\u53ca\u94fe\u8868\u76f8\u5173\u77e5\u8bc6\u70b9\u590d\u4e60","text":"

\u6458\u8981

\u8003\u8651\u5230\u672c\u6b21\u8f85\u5b66\u65f6\u95f4\u5df2\u8fd1\u671f\u672b\uff0c\u539f\u5148\u5b89\u6392\u7684\u4ecb\u7ecd\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u5185\u5bb9\u5df2\u7ecf\u4e0d\u592a\u5408\u9002\uff0c\u56e0\u6b64\u672c\u6b21\u8f85\u5b66\u65f6\u95f4\u5c06\u4e3b\u8981\u4ecb\u7ecd\u671f\u672b\u8003\u8bd5\u7684\u90e8\u5206\u91cd\u70b9\u77e5\u8bc6\uff0c\u4ee5\u8bb2\u89e3\u6307\u9488\u4e0e\u94fe\u8868\u4e3a\u4e3b\u3002

\u672c\u6b21\u8f85\u5b66\u7684\u4e3b\u8981\u5185\u5bb9\uff1a

\u5176\u4e2d\u6211\u4eec\u8f85\u5b66\u5b66\u957f\u5199\u7684\u4e13\u9898\u7b14\u8bb0 \u2014\u2014 \u4e13\u9898\u7b14\u8bb0 - \u6307\u9488\u6982\u89c8 \u5df2\u7ecf\u5bf9\u6307\u9488\u8fdb\u884c\u4e86\u8be6\u7ec6\u7684\u4ecb\u7ecd\u3002\u672c\u6b21\u8f85\u5b66\u4e0d\u4f1a\u6df1\u6316\u6307\u9488\u7684\u5185\u5b58\u6a21\u578b\u7b49\u7ec6\u8282\uff0c\u4e3b\u8981\u662f\u9488\u5bf9\u5386\u5e74\u5377\u9898\u76ee\uff0c\u4ee5\u53ca\u8f85\u5b66\u7fa4\u4e2d\u540c\u5b66\u4eec\u6240\u95ee\u7684\u6307\u9488\u76f8\u5173\u7684\u95ee\u9898\uff0c\u8fdb\u884c\u4ee5\u5907\u8003\u4e3a\u76ee\u7684\u7684\u590d\u4e60\u3002

"},{"location":"programming/archive/23fall/lec5/lec5/#_2","title":"\u6307\u9488\u7684\u57fa\u672c\u64cd\u4f5c","text":""},{"location":"programming/archive/23fall/lec5/lec5/#_3","title":"\u6307\u9488\u7684\u58f0\u660e","text":"

\u58f0\u660e\u4e00\u4e2a\u6307\u9488\uff1a

VariableType *pointerName;\n

\u5176\u4e2d VariableType \u4e3a\u6307\u9488\u6307\u5411\u7684\u53d8\u91cf\u7c7b\u578b\uff0cpointerName \u4e3a\u6307\u9488\u7684\u540d\u79f0\u3002

\u4f8b\u5982\uff1aint *p; \u58f0\u660e\u4e86\u4e00\u4e2a\u6307\u5411 int \u7c7b\u578b\u53d8\u91cf\u7684\u6307\u9488\uff0c\u6307\u9488\u7684\u540d\u79f0\u4e3a p\u3002

\u6ce8\u610f

\u9650\u5b9a\u7b26\u5bf9\u6307\u9488\u7684\u9650\u5b9a

\u9650\u5b9a\u7b26\u5728 C \u8bed\u8a00\u4e2d\u7528\u4e8e\u9650\u5b9a\u53d8\u91cf\u7684\u7c7b\u578b\uff0c\u6700\u5e38\u7528\u7684\u4e3a const \u9650\u5b9a\u7b26\u3002

\u5728\u6307\u9488\u58f0\u660e\u4e2d\uff0c\u9650\u5b9a\u7b26\u51fa\u73b0\u7684\u4f4d\u7f6e\u51b3\u5b9a\u4e86\u9650\u5b9a\u7b26\u662f\u5bf9\u6307\u9488\u672c\u8eab\u7684\u9650\u5b9a\uff0c\u8fd8\u662f\u5bf9\u6307\u9488\u6307\u5411\u7684\u53d8\u91cf\u7684\u9650\u5b9a\u3002

int n;\nconst int * pc = &n; // pc \u662f\u6307\u5411 const int \u7684\u975e const \u6307\u9488\n// *pc = 2; // \u9519\u8bef\uff1a\u4e0d\u80fd\u901a\u8fc7\u4e0d\u5e26\u8f6c\u578b\u7684 pc \u4fee\u6539 n\npc = NULL; // OK\uff1apc \u81ea\u8eab\u53ef\u4fee\u6539\n\nint * const cp = &n; // cp \u662f\u4e00\u4e2a\u6307\u5411\u975e const \u7684 int \u7684 const \u6307\u9488\n*cp = 2; // OK\uff1a\u901a\u8fc7 cp \u4fee\u6539 n\n// cp = NULL; // \u9519\u8bef\uff1acp \u81ea\u8eab\u4e0d\u80fd\u4fee\u6539\n

\u5927\u4f53\u53ea\u9700\u8981\u8bb0\u4f4f\uff1a\u9650\u5b9a\u7b26\u4f1a\u5bf9\u7d27\u968f\u5176\u540e\u7684\u5bf9\u8c61\u8fdb\u884c\u9650\u5b9a\u5373\u53ef\u3002

\u8fdb\u9636\u4e00\u70b9\u7684\u4f8b\u5b50\uff1a

int * const * pcp = &cp; // \u6307\u5411\u6307\u5411\u975e const \u7684 int \u7684 const \u6307\u9488\u7684\u975e const \u6307\u9488\n
"},{"location":"programming/archive/23fall/lec5/lec5/#_4","title":"\u591a\u7ea7\u6307\u9488\u7684\u58f0\u660e","text":"

\u5bf9\u591a\u7ea7\u6307\u9488\u7684\u58f0\u660e\uff0c\u53ef\u4ee5\u7528\u9012\u5f52\u7684\u65b9\u5f0f\u7406\u89e3\u3002

\u5bf9\u4e8e\u6307\u5411 int \u7c7b\u578b\u7684\u4e00\u7ea7\u6307\u9488\uff0c\u5176 VariableType \u4e3a int\uff1b\u5bf9\u4e8e\u4e8c\u7ea7\u6307\u9488 int **p\uff0c\u5373\u6307\u5411\u6307\u5411 int \u7c7b\u578b\u7684\u6307\u9488\u7684\u6307\u9488\uff0c\u5176 VariableType \u4e3a int *\u3002

\u4f8b

int var = 1;\nint *p1 = &var;\nint **p = &p;\n

\u4ed6\u4eec\u7684\u6307\u5411\u5173\u7cfb\u662f\uff1a

(int **)p -> (int *)p1 -> (int)var\n
"},{"location":"programming/archive/23fall/lec5/lec5/#_5","title":"\u6307\u9488\u6570\u7ec4\u4e0e\u6570\u7ec4\u6307\u9488","text":"

\u5f88\u5bb9\u6613\u641e\u6df7\uff0c\u9700\u8981\u6280\u5de7\u6765\u8bc6\u522b\u3002

\u6bd4\u5982\u4e0b\u9762\u4e24\u6761\u58f0\u660e\uff1a

char *p[10]; // \u5927\u5c0f\u4e3a 10 \u7684\u6570\u7ec4\uff0c\u6570\u7ec4\u5143\u7d20\u662f\u6307\u5411 char \u7c7b\u578b\u7684\u6307\u9488\n\nchar (*p)[10]; // \u6307\u9488\uff0c\u6307\u5411\u5927\u5c0f\u4e3a 10 \u7684 char \u6570\u7ec4\n

\u7262\u8bb0\u987a\u65f6\u9488\u87ba\u65cb\u6cd5\u5219\uff08Clockwise/Spiral Rule\uff09\uff08\u8be6\u89c1\u8f85\u5b66\u7fa4\u7fa4\u6587\u4ef6\u4e2d\u7684\u201c\u6d45\u8c08 C \u8bed\u8a00\u7684\u6570\u636e\u7c7b\u578b.pdf\u201d\uff09\u3002

\u4e8e\u662f\uff0c\u4e0a\u9762\u7684\u4e24\u6761\u58f0\u660e\u5c31\u53ef\u4ee5\u516c\u5f0f\u5316\u5730\u89e3\u91ca\uff1a

\u4e0a\u4e00\u8282\u7684\u591a\u7ea7\u6307\u9488\u58f0\u660e\u540c\u6837\u53ef\u4ee5\u7528\u8fd9\u4e2a\u6cd5\u5219\u8fdb\u884c\u89e3\u91ca\u3002

"},{"location":"programming/archive/23fall/lec5/lec5/#_6","title":"\u6307\u9488\u7684\u4f7f\u7528","text":""},{"location":"programming/archive/23fall/lec5/lec5/#_7","title":"\u6307\u9488\u7684\u89e3\u5f15\u7528","text":"

\u89e3\u5f15\u7528\u8fd0\u7b97\u7b26 * \u7684\u4e00\u822c\u5f62\u5f0f\u4e3a\uff1a

* \u6307\u9488\u8868\u8fbe\u5f0f\n

\u7ed3\u679c\u4e3a\u6307\u4ee3\u88ab\u6307\u5411\u5bf9\u8c61\u7684\u5de6\u503c\u8868\u8fbe\u5f0f\uff0c\u5373\u53ef\u4ee5\u88ab\u8d4b\u503c\u3002

\u8bb0\u4f4f a[b] \u7b49\u4ef7\u4e8e *(a + b)\u3002\u8fd9\u4e2a trick \u5728\u4e00\u4e9b\u9898\u76ee\u4e2d\u5f88\u6709\u7528\u3002

\u4f8b\u9898

Given the declaration: int a[3][3]={1,2,3,4,5,6,7,8,9}; , the value of a[-1][5] is _____.

Answer

\u89e3\u7b54\u6765\u81ea\uff1axg \u2014\u2014 \u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66\u5e38\u95ee\u9898\u76ee\u53ca\u89e3\u6790 v1.1.pdf

a[-1] \u7b49\u4ef7\u4e8e *(a - 1)\uff0ca - 1 \u4f1a\u4ee5 3 \u4e2a int \u4e3a\u5355\u4f4d\u5411\u5de6\u79fb\u52a8\uff0c\u5373

    0 0 0 1 2 3 4 5 6 7 8 9\n    ^\n    |\np = *(a - 1)\n

\u4ee4 p = *(a - 1)\uff0c\u5219\u8981\u6c42\u7684\u503c\u53d8\u4e3a p[5]\uff0c\u7b49\u4ef7\u4e8e *(p + 5)\u3002\u5c06\u4e0a\u8ff0\u6307\u9488\u53f3\u79fb 5 \u4e2a int \u5355\u4f4d\uff0c\u5f97\u5230 3\u3002

\u91ce\u6307\u9488

\u5f53\u6307\u9488\u58f0\u660e\u65f6\u672a\u521d\u59cb\u5316\uff0c\u4e14\u8fd8\u672a\u88ab\u8d4b\u503c\uff0c\u5219\u8fd9\u4e2a\u6307\u9488\u6307\u5411\u65e0\u6cd5\u786e\u5b9a\uff0c\u88ab\u79f0\u4e3a \u91ce\u6307\u9488\u3002

\u91ce\u6307\u9488\u53ef\u80fd\u6307\u5411\u4efb\u610f\u5185\u5b58\uff0c\u5bf9\u5176\u8fdb\u884c\u8bbf\u95ee\u53ef\u80fd\u4f1a\u5bfc\u81f4\u975e\u6cd5\u5185\u5b58\u8bbf\u95ee\uff0c\u4ea7\u751f\u6bb5\u9519\u8bef\u3002

\u5728\u8003\u9898\u4e2d\uff0c\u5c1d\u8bd5\u8bbf\u95ee\u91ce\u6307\u9488\u662f\u9519\u8bef\u7684\u64cd\u4f5c\u3002\u5728\u81ea\u5df1\u5199\u4ee3\u7801\u65f6\u4e5f\u7edd\u4e0d\u80fd\u51fa\u73b0\u91ce\u6307\u9488\u8bbf\u95ee\u3002

\u4f8b\u9898

For the declarations: char *s, str[10]; , statement _____ is completely correct.

A. strcpy(s, \"hello\");

B. str=\"hello\"+1

C. s=*&(str+1)

D. s=str+1

\u9009\u9879 A \u5c31\u662f\u7ecf\u5178\u7684\u91ce\u6307\u9488\u8bbf\u95ee\u3002

"},{"location":"programming/archive/23fall/lec5/lec5/#_8","title":"\u53d6\u5740\u64cd\u4f5c","text":"

\u53d6\u5740\u8fd0\u7b97\u7b26 & \u65e9\u5728\u5927\u5bb6\u5b66\u4e60\u8f93\u5165\u8f93\u51fa\u7684\u65f6\u5019\u5c31\u5df2\u7ecf\u63a5\u89e6\u8fc7\u4e86\u3002\u5728\u4f7f\u7528 scanf \u5bf9 int \u7b49\u7c7b\u578b\u7684\u53d8\u91cf\u8fdb\u884c\u8bfb\u5165\u7684\u65f6\u5019\uff0c\u4f7f\u7528\u7684\u662f\u5982\u4e0b\u5f62\u5f0f\uff1a

int a;\nscanf(\"%d\", &a);\n

\u8fd9\u91cc\u7684 & \u5bf9 a \u8fdb\u884c\u53d6\u5740\u64cd\u4f5c\uff0c\u5bf9 a \u7684\u5730\u5740\u800c\u4e0d\u662f a \u7684\u503c\u8fdb\u884c\u8bfb\u5165\u3002

\u4e00\u822c\u5730\uff0c\u53d6\u5740\u8fd0\u7b97\u7b26\u6709\u5982\u4e0b\u51e0\u79cd\u5f62\u5f0f\uff1a

\u89e3\u5f15\u7528\u4e0e\u53d6\u5740\u64cd\u4f5c\u7684\u5e94\u7528

\u8f93\u5165\u4e00\u4e2a 64 \u4f4d\u65e0\u7b26\u53f7\u6574\u6570 x\uff0c\u6c42 x \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u7684 01 \u4e32\u6240\u8868\u793a\u7684 double \u7c7b\u578b\u53d8\u91cf\u7684\u503c\u3002

Answer
unsigned long long x;\nscanf(\"%llu\", &x);\nprintf(\"%lf\\n\", *((double *)&x));\n
"},{"location":"programming/archive/23fall/lec5/lec5/#_9","title":"\u901a\u8fc7\u6307\u9488\u8fdb\u884c\u6210\u5458\u8bbf\u95ee","text":"

\u5bf9\u4e8e\u7ed3\u6784\u4f53\u7c7b\u578b\u7684\u6307\u9488\uff0cC \u8bed\u8a00\u63d0\u4f9b\u4e86\u4e00\u4e2a\u8fd0\u7b97\u7b26 ->\uff0c\u7528\u4e8e\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u7ed3\u6784\u4f53\u6210\u5458\u3002

struct Point { int x, y; }; // \u5b9a\u4e49\u7ed3\u6784\u4f53 Point\nstruct Point point = { 1, 2 }; // \u5b9a\u4e49\u7ed3\u6784\u4f53\u53d8\u91cf point\n\nstruct Point *p = &point; // p \u6307\u5411 point \u7ed3\u6784\u4f53\np->x = 3; // \u901a\u8fc7\u6307\u9488 p \u8bbf\u95ee\u7ed3\u6784\u4f53\u6210\u5458 x\n// \u7b49\u4ef7\u4e8e (*p).x = 3;\n
"},{"location":"programming/archive/23fall/lec5/lec5/#_10","title":"\u6570\u7ec4\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362","text":"

\u9690\u5f0f\u8f6c\u6362

\u6570\u7ec4\u5230\u6307\u9488\u8f6c\u6362

\u4efb\u4f55\u6570\u7ec4\u7c7b\u578b\u7684\u5de6\u503c\u8868\u8fbe\u5f0f\uff0c\u5728\u7528\u4e8e\u5f02\u4e8e\u4e0b\u5217\u8bed\u5883\u65f6

\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u975e\u5de6\u503c\u6307\u9488\u7684\u8f6c\u6362\u3002

\u2014\u2014 cppreference-\u9690\u5f0f\u8f6c\u6362

\u7b80\u5355\u6765\u8bf4\uff1a\u7262\u8bb0\u6570\u7ec4\u540d \u4e0d\u7b49\u4e8e \u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u7684\u6307\u9488\uff0c\u5f53\u6570\u7ec4\u540d\u88ab\u53d6\u5740\u8fd0\u7b97\u7b26 & \u4f5c\u7528\uff0c\u6216\u8005\u4f5c\u4e3a sizeof \u7684\u64cd\u4f5c\u6570\u65f6\uff0c\u4e0d\u4f1a\u53d1\u751f\u9690\u5f0f\u8f6c\u6362\u3002

\u8fd9\u91cc\u8981\u6ce8\u610f\u7684\u4e00\u70b9\u662f\uff0c\u5c06\u6570\u7ec4\u4f5c\u4e3a\u53c2\u6570\u4f20\u7ed9\u51fd\u6570\u65f6\uff0c\u51fd\u6570\u7684\u5f62\u53c2\u53ea\u80fd\u662f\u6307\u9488\uff0c\u800c\u4e0d\u80fd\u662f\u6570\u7ec4\uff0c\u6b64\u65f6\u6570\u7ec4\u540d\u4f1a\u53d1\u751f\u9690\u5f0f\u8f6c\u6362\u3002

\u6570\u7ec4\u7c7b\u578b\u7528\u4e8e\u51fd\u6570\u5f62\u53c2

\u5f53\u6570\u7ec4\u7c7b\u578b\u7528\u4e8e\u51fd\u6570\u5f62\u53c2\u5217\u8868\u65f6\uff0c\u5b83\u4f1a\u8f6c\u6362\u6210\u5bf9\u5e94\u7684\u6307\u9488\u7c7b\u578b\uff1aint f(int a[2])\u3001int f(int a[])\u3001int f(int *a) \u58f0\u660e\u540c\u4e00\u4e2a\u51fd\u6570\u3002

\u56e0\u4e3a\u51fd\u6570\u5b9e\u9645\u53c2\u6570\u7c7b\u578b\u4e3a\u6307\u9488\u7c7b\u578b\uff0c\u4f7f\u7528\u6570\u7ec4\u5b9e\u53c2\u7684\u51fd\u6570\u8c03\u7528\u4f1a\u8fdb\u884c\u4e00\u4e2a\u6570\u7ec4\u5230\u6307\u9488\u8f6c\u6362\uff1b\u88ab\u8c03\u7528\u51fd\u6570\u65e0\u6cd5\u83b7\u5f97\u5b9e\u53c2\u6570\u7ec4\u7684\u5927\u5c0f\uff0c\u5fc5\u987b\u663e\u5f0f\u4f20\u9012\u3002

\u89c1 \u6bcf\u65e5\u4e00\u9898-29\u3002

Warning

\u53ea\u6709\u6570\u7ec4\u7c7b\u578b\u7528\u4e8e\u51fd\u6570\u5f62\u53c2\u5217\u8868\u65f6\uff0ca[] \u548c *a \u624d\u662f\u7b49\u4ef7\u7684\u3002

\u6bd4\u5982\u4f7f\u7528\u5b57\u7b26\u4e32\u5e38\u91cf\u521d\u59cb\u5316\u5b57\u7b26\u4e32\uff1a

\u521b\u5efa\u6307\u5411\u5b57\u7b26\u4e32\u5e38\u91cf\u7684\u6307\u9488\uff0c\u5185\u5bb9\u4e0d\u80fd\u66f4\u6539\uff0c

char *s = \"hello\"; // s \u7c7b\u578b\u4e3a char * \uff0c\u6307\u5411\u5b57\u7b26\u4e32\u5e38\u91cf\ns = \"he11o\"; // OK\n

\u521b\u5efa char \u6570\u7ec4\uff0c\u5185\u5bb9\u88ab\u5b57\u7b26\u4e32\u5e38\u91cf\u521d\u59cb\u5316\uff0c\u5185\u5bb9\u53ef\u4ee5\u66f4\u6539\uff0c

char s[] = \"hello\"; // s \u7c7b\u578b\u4e3a char [6] \uff0c\u6570\u7ec4\u5185\u5bb9\u662f \"hello\\0\" \u7684\u62f7\u8d1d\n// s[] = \"he11o\"; // wrong\n

Question

\u4e0b\u5217\u4ee3\u7801\u7684 val_x \u548c val_y \u7684\u7c7b\u578b\u4e00\u6837\u5417\uff1f

int a[10], *p = a;\nType1 val_x = &a;\nType2 val_y = &p;\n

Question

\u4e0b\u5217\u4ee3\u7801\u7684 size_x \u548c size_y \u5927\u5c0f\u4e00\u6837\u5417\uff1f

int a[10], *p = a;\nsize_t size_x = sizeof a;\nsize_t size_y = sizeof p;\n
"},{"location":"programming/archive/23fall/lec5/lec5/#_11","title":"\u6307\u9488\u7684\u503c\u4e0e\u6307\u9488\u7684\u5730\u5740","text":"

\u6307\u9488\u7684\u503c\uff0c\u53c8\u79f0\u4e3a\u6307\u9488\u6240\u6307\u5411\u7684\u5185\u5b58\u533a\u3002

\u5728\u8ba1\u7b97\u673a\u4e2d\uff0c\u5185\u5b58\u4e2d\u7684\u6240\u6709\u5b57\u8282\u90fd\u62e5\u6709\u4e00\u4e2a\u552f\u4e00\u7f16\u53f7\uff0c\u4e5f\u5373\u5185\u5b58\u5730\u5740\u3002\u6307\u9488\u6307\u5411\u67d0\u4e00\u6570\u636e\u7684\u5730\u5740\uff0c\u5373\u6307\u9488\u53d8\u91cf\u5b58\u50a8\u4e86\u8fd9\u4e2a\u6570\u636e\u7684\u5185\u5b58\u5730\u5740\u7684\u7f16\u53f7\u3002

\u6307\u9488\u6240\u5360\u7684\u5b57\u8282\u6570

\u73b0\u5728\u4e00\u822c\u7684\u8ba1\u7b97\u673a\u57fa\u672c\u90fd\u662f 64 \u4f4d\u7cfb\u7edf\uff0c\u4f7f\u7528 64 \u4f4d\u957f\u7684\u5185\u5b58\u5730\u5740\uff0c\u5373\u5185\u5b58\u5730\u5740\u7684\u7f16\u53f7\u662f\u4e00\u4e2a 64 \u4f4d\u6574\u6570\u3002\u5728 64 \u4f4d\u7cfb\u7edf\u4e2d\u4f7f\u7528 sizeof \u8fd0\u7b97\u7b26\u6c42\u6307\u9488\u7684\u5927\u5c0f\u65f6\uff0c\u5f97\u5230\u7684\u7ed3\u679c\u4e3a 8\u3002

\u6ce8\u610f\uff0c\u4e00\u822c\u6765\u8bf4\u65e0\u6cd5\u9884\u6d4b\u5730\u5740\u7684\u503c\uff0c\u56e0\u4e3a\u5185\u5b58\u5730\u5740\u53d6\u51b3\u4e8e\u7cfb\u7edf\u7684\u5185\u5b58\u5206\u914d\u60c5\u51b5\u3002\u4f46\u90e8\u5206\u60c5\u51b5\u4e0b\u53ef\u4ee5\u786e\u5b9a\u5185\u5b58\u5730\u5740\u7684\u76f8\u5bf9\u4f4d\u7f6e\uff0c\u6bd4\u5982\u540c\u4e00\u6570\u7ec4\u4e2d\u5143\u7d20\u5728\u5185\u5b58\u4e2d\u8fde\u7eed\u3002

\u6b64\u5916\uff0c\u6307\u9488\u540c\u6837\u4e5f\u662f\u4e00\u4e2a\u5728\u5185\u5b58\u4e2d\u6709\u5bf9\u5e94\u5b58\u50a8\u7a7a\u95f4\u7684\u53d8\u91cf\uff0c\u4e5f\u6709\u81ea\u5df1\u7684\u5185\u5b58\u5730\u5740\u3002\u5728\u6307\u9488\u7684\u5185\u5b58\u5730\u5740\u4e2d\uff0c\u5b58\u50a8\u7684\u5185\u5bb9\u662f\u5176\u6307\u5411\u7684\u5185\u5bb9\u7684\u5185\u5b58\u5730\u5740\u3002

\u7c7b\u6bd4\u7406\u89e3

\u5047\u5982\u6709\u4e00\u4e2a\u5f88\u957f\u7684\u6570\u7ec4\uff0c\u5b58\u50a8\u4e86\u4e00\u4e9b\u6570\u636e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u4e0b\u6807\u53bb\u8bbf\u95ee\u6570\u636e\u3002\u5c06\u6570\u7ec4\u4e0b\u6807\u5f53\u4f5c\u6570\u636e\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u53ef\u4ee5\u4ece\u6570\u7ec4\u4e2d\u7684\u67d0\u4e00\u4f4d\u7f6e\u53bb\u8bbf\u95ee\u5176\u5b58\u50a8\u7684\u6570\u7ec4\u4e0b\u6807\u7684\u4f4d\u7f6e\u7684\u6570\u636e\uff0c\u8fd9\u5c31\u53ef\u4ee5\u770b\u4f5c\u662f\u7b80\u5355\u7684\u6307\u9488\u3002

\u4e0b\u6807    31       32       33       34      ...     X\narr   data0    data1    data2    data3    ....    32\n                 ^                                |\n                 +--------------------------------+\n

Question

\u90a3\u4e48\u5c31\u6709\u540c\u5b66\u95ee\u4e86\uff1a\u65e2\u7136\u6307\u9488\u7684\u503c\u662f 64 \u4f4d\u6574\u6570\uff0c\u90a3\u80fd\u7528\u5173\u7cfb\u8fd0\u7b97\u7b26\u6bd4\u8f83\u5927\u5c0f\u5417\uff1f

\u7b54\u6848\u662f\uff1a\u90e8\u5206\u60c5\u51b5\u4e0b\u53ef\u4ee5\u3002

\u5173\u7cfb\u8fd0\u7b97\u7b26\u8fdb\u884c\u6307\u9488\u6bd4\u8f83

\u6839\u636e cppreference-\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff0c\u5f53\u8fdb\u884c\u6307\u9488\u6bd4\u8f83\u7684\u65f6\u5019\uff0c\u6709\u4ee5\u4e0b\u8981\u6c42\uff1a

\u4e24\u6307\u9488\u5fc5\u987b\u662f\u517c\u5bb9\u7c7b\u578b\u7684\u6307\u9488\u3002\u4e14\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u4e4b\u4e00\uff1a

\u9664\u6b64\u4e4b\u5916\uff0c\u6307\u9488\u7684\u6bd4\u8f83\u7ed3\u679c\u662f\u672a\u5b9a\u4e49\u7684\u3002

\u6307\u9488\u7684\u8ba1\u7b97

\u6d89\u53ca\u6307\u9488\u7684\u52a0\u51cf\u53ea\u6709\u4e24\u79cd\u60c5\u51b5\uff1a

\u4f8b\u9898

\u4ee5\u4e0b\u4ee3\u7801\u7684\u8f93\u51fa\u4e3a _____\u3002

int a[] = {1, 2, 3, 4, 5};\nint *p = a, *q = &a[2];\nprintf(\"%lu\\n\", q - p);\n
"},{"location":"programming/archive/23fall/lec5/lec5/#_12","title":"\u4e00\u4e9b\u9898\u76ee","text":"

\u9898\u76ee 1

The following code fragment will output _____.

char *week[]={\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"}, **pw=week;\nchar c1, c2;\nc1 = (*++pw)[1];\nc2 = *++pw[1];\nprintf(\"%c#%c#\", c1, c2);\n
Answer
       \"Mon\\0\"   \"Tue\\0\"   \"Wed\\0\"   \"Thu\\0\"   \"Fri\\0\"   \"Sat\\0\"   \"Sun\\0\"\n        ^         ^         ^         ^         ^         ^         ^\n        |         |         |         |         |         |         |\nweek: week[0]   week[1]   week[2]   week[3]   week[4]   week[5]   week[6]\n        ^\n        |\n       pw\n

\u9898\u76ee 2

For definitions:

char s[2][3] = {\"ab\", \"cd\"}, *p = (char *)s;\n

the expression _____ is correct and its value is equivalent to the element s[1][1].

A. *(s + 3)

B. *s + 2

C. p[1][1]

D. *++p + 2

Answer
s:    \"ab\\0\"     \"cd\\0\"\n      ^\n      |\ns(\u9690\u5f0f\u8f6c\u6362)(char *[3])\n\ns:    \"ab\\0\"     \"cd\\0\"\n       ^\n       |\n  p = (char *)s\n
"},{"location":"programming/archive/23fall/lec5/lec5/#_13","title":"\u94fe\u8868","text":""},{"location":"programming/archive/23fall/lec5/lec5/#_14","title":"\u57fa\u7840\u77e5\u8bc6\u548c\u603b\u7ed3","text":"

\u94fe\u8868\u662f\u4e00\u79cd\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u901a\u8fc7\u8282\u70b9\u7684\u5f62\u5f0f\u5b58\u50a8\u6570\u636e\u3002\u6bcf\u4e2a\u8282\u70b9\u5305\u542b\u6570\u636e\u90e8\u5206\u548c\u6307\u5411\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684\u6307\u9488\u3002\u94fe\u8868\u53ef\u4ee5\u662f\u5355\u5411\u7684\u4e5f\u53ef\u4ee5\u662f\u53cc\u5411\u7684\uff0c\u6211\u4eec\u5148\u770b\u770b\u5355\u5411\u94fe\u8868\uff1a

\u5355\u5411\u94fe\u8868\u7684\u4e00\u79cd\u5b9a\u4e49\u65b9\u5f0f

typedef struct Node {\n    int data;\n    struct Node* next;\n} Node;\n

\u597d\u4e86\uff0c\u6211\u4eec\u5df2\u7ecf\u628a\u94fe\u8868\u7ed9\u5b9a\u4e49\u51fa\u6765\u4e86\u3002\u4f46\u662f\u4f60\u4f1a\u597d\u5947\uff0c\u6211\u4eec\u4e0d\u662f\u53ea\u5b9a\u4e49\u51fa\u4e86\u8282\u70b9\u5417\uff1f\u600e\u4e48\u5df2\u7ecf\u5b9a\u4e49\u5b8c\u4e86\uff1f\u4e8b\u5b9e\u4e0a\uff0c\u8fd9\u51e0\u4e4e\u5c31\u5df2\u7ecf\u662f\u94fe\u8868\u7684\u5b8c\u6574\u7ed3\u6784\u4e86\u2014\u2014\u56e0\u4e3a\u94fe\u8868\u5c31\u662f\u7b80\u5355\u7684\u94fe\u8868\u8282\u70b9\u7684\u4e32\u8054\u3002

\u5927\u5bb6\u90fd\u5df2\u7ecf\u77e5\u9053\u4e86\u94fe\u8868\u7684\u7ed3\u6784\uff0c\u662f\u7c7b\u4f3c\u4e8e\u4e0b\u9762\u8fd9\u6837\u7684\uff1a

\u6240\u4ee5\uff0c\u94fe\u8868\u5176\u5b9e\u5c31\u662f\u4ee5\u4e0b\u7684\u4e1c\u897f\u7684\u7ed3\u5408\uff1a

\u6211\u4eec\u600e\u4e48\u77e5\u9053\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u662f\u4ec0\u4e48\u5462\uff1f\u6211\u4eec\u89c4\u5b9a\uff0c\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u6307\u5411\u7684\u4f4d\u7f6e\u5c31\u662f NULL\uff0c\u4e5f\u5c31\u662f 0\u3002\u8fd9\u6837\uff0c\u53ea\u8981\u5224\u65ad\u8282\u70b9\u7684 .next \u662f\u5426\u662f NULL\uff0c\u5c31\u53ef\u4ee5\u77e5\u9053\u8fd9\u4e2a\u8282\u70b9\u662f\u4e0d\u662f\u5c3e\u8282\u70b9\u4e86\u3002\u597d\u4e86\uff0c\u6240\u4ee5\u6211\u4eec\u53ea\u9700\u8981\u82e5\u5e72\u4e2a Node\uff0c\u7136\u540e\u5c06\u4ed6\u4eec\u4e32\u8054\u2014\u2014\u4e5f\u5c31\u662f\u901a\u8fc7 next \u8fde\u63a5\uff0c\u5c31\u5f97\u5230\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u94fe\u8868\u3002

\u63a5\u4e0b\u6765\u8ba9\u6211\u4eec\u56de\u5fc6\u4e00\u4e0b\u94fe\u8868\u7684\u5404\u79cd\u64cd\u4f5c\u7684\u5b9e\u73b0\u5427\uff01\u4e0d\u8fc7\u5927\u5bb6\u5728\u5e73\u65f6\u505a\u9898\u7684\u65f6\u5019\u5e94\u8be5\u90fd\u611f\u89c9\u5230\u4e86\uff0c\u94fe\u8868\u6709\u5f88\u591a\u5f88\u591a\u96be\u4ee5\u7422\u78e8\u7684\u7ec6\u8282\u548c\u7279\u6b8a\u60c5\u51b5\uff01\u600e\u4e48\u529e\u5462\uff1f\u51b7\u9759\u4e0b\u6765\u603b\u7ed3\uff0c\u65e0\u975e\u5c31\u662f\u8fd9\u51e0\u79cd\uff1a

\u8fd9\u4e9b\u60c5\u51b5\u5982\u679c\u6ca1\u6709\u8003\u8651\u6e05\u695a\uff0c\u5f88\u53ef\u80fd\u5728\u5199\u4ee3\u7801\u7684\u8fc7\u7a0b\u4e2d\u51fa\u73b0 segmentation fault\uff0c\u4e5f\u5c31\u662f\u6bb5\u9519\u8bef\u3002\u8fd9\u6781\u5927\u6982\u7387\u662f\u56e0\u4e3a\uff0c\u4f60\u8bbf\u95ee\u4e86 NULL \u4f4d\u7f6e\u7684\u4e00\u4e9b\u4fe1\u606f\u3002\u6bd4\u5982\u5f53\u524d\u8282\u70b9\u6307\u9488 p \u6307\u5411\u4e86 NULL\uff0c\u4f46\u662f\u4f60\u5374\u8bbf\u95ee\u4e86 p->data \u6216\u8005 p->next\uff0c\u5c31\u4f1a\u62a5\u9519\u4e86\u3002

"},{"location":"programming/archive/23fall/lec5/lec5/#_15","title":"\u5355\u5411\u94fe\u8868\u7684\u5404\u79cd\u7ecf\u5178\u64cd\u4f5c","text":"

\u521b\u5efa\u4e00\u4e2a\u8282\u70b9 p\uff0c\u5176\u6743\u503c\u4e3a w\uff0c\u5e76\u8fd4\u56de\u8fd9\u4e2a\u8282\u70b9\u7684\u6307\u9488

\u53ea\u9700\u8981\u4f7f\u7528 malloc \u5373\u53ef\u3002

Node *create(int w){\n    Node* newNode = (Node*)malloc(sizeof(Node));\n    newNode->next = NULL;\n    newNode->data = w;\n    return newNode;\n}\n

\u4e00\u4e2a\u7ec6\u8282

\u6ce8\u610f\uff0cmalloc \u51fd\u6570\u5185\u90e8\u9700\u8981\u5f00\u7684\u8282\u70b9\u5927\u5c0f\u662f sizeof(Node) \u800c\u4e0d\u662f sizeof(Node*)\uff0c\u60f3\u60f3\u4e3a\u4ec0\u4e48\uff1f

\u5728\u94fe\u8868\u7684\u5934\u90e8/\u5c3e\u90e8\u63d2\u5165\u4e00\u4e2a\u8282\u70b9 p\uff0c\u5e76\u8fd4\u56de\u65b0\u94fe\u8868\u7684\u5934\u90e8

\u5148\u770b\u5934\u90e8\u63d2\u5165\u3002

\u9996\u5148\uff0c\u7279\u6b8a\u60c5\u51b5 \\(1\\)\uff0c\u539f\u5148\u94fe\u8868\u662f\u7a7a\u7684\uff0c\u90a3\u80af\u5b9a\u662f\u628a head \u8d4b\u503c\u4e3a\u65b0\u8282\u70b9\u561b\u3002

\u53d1\u73b0\u53ea\u5269\u4e0b\u7279\u6b8a\u60c5\u51b5 \\(2\\)\uff0c\u90a3 head \u4e5f\u8981\u8d4b\u503c\u4e3a\u65b0\u8282\u70b9\uff0c\u7136\u540e\u65b0\u8282\u70b9\u8fde\u5411\u8001 head \u3002

Node *insertAtHead(Node* head, Node* p) {\n    if (!head) return p; // \u53ef\u4ee5\u53d1\u73b0\uff0c\u8fd9\u53e5\u8bdd\u4e0d\u5199\u4e5f\u6ca1\u6709\u5f71\u54cd \n    p->Next = head;\n    return p;\n}\n

\u4e00\u4e2a\u7ec6\u8282

\u4e3a\u4ec0\u4e48 if \u91cc\u662f !head\uff1f

\u7136\u540e\u662f\u5c3e\u90e8\u63d2\u5165\u3002\u9996\u5148\u8fd8\u662f\u7279\u6b8a\u60c5\u51b5 \\(1\\)\uff0c\u5904\u7406\u5b8c\u4ee5\u540e\u53ea\u5269\u4e0b\u7279\u6b8a\u60c5\u51b5 \\(3\\) \uff0c\u90a3\u4e48\u6211\u4eec\u53ea\u9700\u8981\u627e\u5230\u5c3e\u8282\u70b9\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u63d2\u5165\u4e86\uff0c\u6700\u540e\u8fd4\u56de\u7684\u4e5f\u53ea\u662f\u539f\u672c\u7684 head\u3002

Node *insertAtEnd(Node* head, Node* p) {\n    if (!head) return p;\n    Node* last = head;\n    while (last->next) {\n        last = last->next;\n    }\n    last->next = p;\n    return head;\n}\n

\u5220\u9664\u6743\u503c\u4e3a key \u7684\u8282\u70b9\uff0c\u5982\u679c\u6709\u591a\u4e2a\uff0c\u5219\u5220\u9664\u6700\u9760\u8fd1\u5f00\u5934\u7684\uff0c\u6ca1\u6709\u5219\u4e0d\u5220\u9664\uff0c\u8fd4\u56de\u65b0\u94fe\u8868\u7684\u5934\u90e8

\u6700\u7e41\u7410\u6700\u590d\u6742\u7684\u4e00\u4e2a\u64cd\u4f5c\uff0c\u4e5f\u662f\u65b0\u624b\u7684\u5669\u68a6\u3002\u4e0d\u8fc7\u6309\u7167\u4e09\u6b65\u8d70\u5c31\u597d\u4e86\u3002

\u5148\u5904\u7406\u4e00\u4e0b\u7279\u6b8a\u60c5\u51b5 \\(1\\) \u3002

Node *deleteNode(Node* head, int key) {\n    if (!head) return NULL;\n}\n

\u7136\u540e\u60c5\u51b5 \\(2\\) \u5462\uff0c\u5934\u7ed3\u70b9\u4f1a\u53d1\u751f\u53d8\u5316\u3002

Node *deleteNode(Node* head, int key) {\n    if (!head) return NULL;\n    if (head->data == key){\n        node* tmp = head->next; //\u8fd9\u4e48\u505a\u662f\u56e0\u4e3a free \u4ee5\u540e\uff0chead->next \u5c31\u4e0d\u80fd\u83b7\u53d6\u4e86\u3002\n        free(head);\n        return tmp;\n    }\n}\n

\u5269\u4e0b\u60c5\u51b5 \\(3\\) \u8fd8\u8981\u7279\u6b8a\u5224\u65ad\u3002\u6211\u4eec\u5148\u627e\u5230\u8981\u5220\u9664\u7684\u4f4d\u7f6e\u3002\u56de\u5fc6\u4e00\u4e0b\u5220\u9664\u7684\u8fc7\u7a0b\uff0c\u6211\u4eec\u9700\u8981\u8bb0\u5f55\u5f53\u524d\u9700\u8981\u88ab\u5220\u9664\u7684\u8282\u70b9\u7684\u6307\u9488 prev\uff1a

Node *deleteNode(Node* head, int key) {\n    if (!head) return NULL;\n    if (head->data == key){\n        node* temp = head->next; //\u8fd9\u4e48\u505a\u662f\u56e0\u4e3a free \u4ee5\u540e\uff0chead->next \u5c31\u4e0d\u80fd\u83b7\u53d6\u4e86\u3002\n        free(head);\n        return tmp;\n    }\n    node* temp = head, prev = NULL;\n    while (temp && temp->data != key) {\n        prev = temp;\n        temp = temp->next;\n    }\n    if (!temp) return head;\n    prev->next = temp->next; //\u4e8b\u5b9e\u4e0a\u76f4\u63a5\u5220\u9664\u5c31\u597d\u4e86\uff0c\u4e0d\u9700\u8981\u5173\u7cfb\u60c5\u51b5 3 \u4e86\uff0c\u4e0d\u8fc7\u7279\u5224\u4e00\u4e0b\u4e5f\u4e0d\u9519\u3002\n    free(temp);\n    return head;\n}\n

\u6ce8\u610f\uff01

\u7406\u8bba\u8003\u8bd5\u5199\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u4e00\u5b9a\u4e0d\u8981\u5fd8\u8bb0 free \u88ab\u5220\u9664\u7684\u8282\u70b9\uff01\uff01\uff01\u5c0f\u5fc3\u6263\u5206\uff01\uff01\uff01

\u4e0a\u673a\u4e0d free \u5012\u662f\u6ca1\u5173\u7cfb\uff08\u6307\u8fd8\u80fd\u901a\u8fc7\uff09\uff0c\u4f46\u8fd8\u662f\u5efa\u8bae\u517b\u6210\u826f\u597d\u7684\u4e60\u60ef\uff0c\u9632\u6b62\u5185\u5b58\u6cc4\u6f0f\uff01

"},{"location":"programming/archive/23fall/lec5/lec5/#_16","title":"\u53cc\u5411\u94fe\u8868","text":"

\u5176\u5b9e\u6ca1\u4ec0\u4e48\u53ef\u4ee5\u8bb2\u7684\uff0c\u4e5f\u5c31\u662f\u5728 struct \u7684\u5b9a\u4e49\u4e2d\u52a0\u5165\u4e86 prev\uff0c\u53ef\u4ee5\u8ba9\u6211\u4eec\u65b9\u4fbf\u7684\u83b7\u53d6\u4e0a\u4e00\u4e2a\u8282\u70b9\u7684\u6307\u9488\uff0c\u8fd9\u6837\u5220\u9664\u8fc7\u7a0b\u4e2d\u5c31\u4e0d\u9700\u8981\u5355\u72ec\u5f00\u53d8\u91cf\u8bb0\u5f55\u4e86\u3002

\u53cc\u5411\u94fe\u8868\u7684\u4e00\u79cd\u5b9a\u4e49\u65b9\u5f0f

typedef struct Node {\n    int data;\n    struct Node* prev, next;\n} Node;\n

\u7279\u522b\u7684\uff0c\u5934\u7ed3\u70b9\u7684 prev \u662f NULL\u3002

\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u9898\u5427~

\u9898\u76ee 3

To delete p from a doubly linked list, we must do:

A. p->prev=p->prev->prev; p->prev->next=p;

B. p->next->prev=p; p->next=p->next->next;

C. p->prev->next=p->next; p->next->prev=p->prev;

D. p->next=p->prev->prev; p->prev=p->next->next;

Answer

C.

"},{"location":"programming/archive/23fall/lec5/lec5/#_17","title":"\u6808\u548c\u961f\u5217","text":"

\u8fd9\u4e00\u90e8\u5206\u7684\u5185\u5bb9\u76f8\u4fe1\u5927\u5bb6\u5728\u8bfe\u4e0a\u5df2\u7ecf\u6709\u5f88\u597d\u7684\u7406\u89e3\u4e86\uff0c\u4f46\u662f\u4f1a\u51fa\u4e00\u4e9b\u548c\u94fe\u8868\u7ed3\u5408\u7684\u6709\u96be\u5ea6\u7684\u7406\u8bba\u9898\u548c\u7f16\u7a0b\u9898\uff0c\u6240\u4ee5\u7b80\u5355\u5e26\u8fc7\u4e00\u4e0b\uff1a

\u901a\u5e38\u9898\u76ee\u4f1a\u4f7f\u7528\u5355\u5411\u94fe\u8868\u6765\u5b9e\u73b0\u6808\u548c\u961f\u5217\u3002\u4e0d\u8fc7\u5f88\u591a\u9898\u76ee\u5176\u5b9e\u4f1a\u4e0d\u544a\u8bc9\u4f60\uff0c\u94fe\u8868\u54ea\u4e00\u6bb5\u8868\u793a\u6808\u9876\uff0c\u54ea\u4e00\u6bb5\u8868\u793a\u961f\u5934\uff0c\u54ea\u4e00\u6bb5\u8868\u793a\u961f\u5c3e\u3002

\u4e00\u4e2a\u95ee\u9898

\u5982\u679c\u662f\u53cc\u5411\u94fe\u8868\u5176\u5b9e\u6ca1\u6709\u8fd9\u4e48\u591a\u70e6\u607c\uff0c\u4f46\u662f\u73b0\u5728\u662f\u5355\u5411\u7684\u3002\u600e\u4e48\u5224\u65ad\u94fe\u8868\u7684\u5934\u4ee3\u8868\u6808/\u961f\u5217\u7684\u54ea\u4e2a\u90e8\u5206\u5462\uff1f

\u6808\u9876\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u6211\u4eec\u53ea\u9700\u8981\u8bb0\u5f55\u4e00\u4e0b\u94fe\u8868\u7684\u5934\u6307\u9488 head\uff0c\u5728\u4e0a\u9762\u64cd\u4f5c\uff0c\u53ef\u4ee5\u76f4\u63a5\u5b8c\u6210\u5bf9\u6808\u7684\u6a21\u62df\uff0c\u6240\u4ee5\u94fe\u8868\u7684\u5934\u4ee3\u8868\u6808\u9876\u3002

\u90a3\u961f\u5217\u5462\uff1f\u6211\u4eec\u4e0d\u59a8\u8bd5\u4e00\u4e0b\uff0c\u5047\u8bbe\u94fe\u8868\u5934\u90e8\u4ee3\u8868\u961f\u5c3e\uff0c\u90a3\u4e48\u961f\u5217\u7684\u5165\u961f\u64cd\u4f5c\u5f88\u597d\u5b9e\u73b0\uff0c\u4f46\u662f\uff0c\u51fa\u961f\u9700\u8981\u5728\u94fe\u8868\u5c3e\u90e8\u8fdb\u884c\u64cd\u4f5c\u3002\u6709\u4e00\u4e2a\u5f88\u76f4\u89c2\u7684\u65b9\u6cd5\u5c31\u662f\u540c\u65f6\u8bb0\u5f55\u5e76\u7ef4\u62a4\u94fe\u8868\u7684\u5c3e\u6307\u9488 tail\uff0c\u4f46\u662f\uff0c\u5220\u9664\u7684\u8bdd\uff0c\u6211\u4eec\u9700\u8981\u77e5\u9053\u5c3e\u6307\u9488\u7684\u524d\u9a71\u8282\u70b9...

\u6240\u4ee5\u4e00\u4e9b\u9898\u76ee\u7684\u5b9e\u73b0\uff0c\u9ed8\u8ba4\u4e86\u94fe\u8868\u7684\u5934\u90e8\u4ee3\u8868\u961f\u5934\u3002\u770b\u4e00\u4e0b\u8fd9\u4e2a\u9898\u76ee\uff1a

\u9898\u76ee 4

Represent a queue by a singly linked list. Given the current status of the linked list as 1->2->3 where x->y means y is linked after x. Now if 4 is enqueued and then a dequeue is done, the resulting status must be:

A. 1->2->3

B. 2->3->4

C. 4->1->2

D. the solution is not unique

Answer

B.

\u8fd9\u91cc\u9700\u8981\u989d\u5916\u63d0\u4e00\u4e2a\u53eb\u505a\u5faa\u73af\u961f\u5217\u7684\u4e1c\u897f\u3002\u5b83\u662f\u961f\u5217\u7684\u4e00\u79cd\u53d8\u4f53\uff0c\u901a\u5e38\u4f7f\u7528\u6570\u7ec4\u6765\u5b9e\u73b0\uff0c\u7528\u6765\u8282\u7ea6\u961f\u5217\u7684\u7a7a\u95f4\u3002\u5faa\u73af\u961f\u5217\u662f\u628a\u987a\u5e8f\u961f\u5217\u9996\u5c3e\u76f8\u8fde\uff0c\u628a\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u8868\u4ece\u903b\u8f91\u4e0a\u770b\u6210\u4e00\u4e2a\u73af\u3002\u901a\u5e38\u7528\u4e24\u4e2a\u53d8\u91cf\u4ee3\u8868\u5f53\u524d\u5faa\u73af\u961f\u5217\u5b58\u50a8\u7684\u7a7a\u95f4\uff1a\u4e00\u4e2a\u662f\u5c3e rear\uff0c\u4e00\u4e2a\u662f\u5934front\u3002\u4e0d\u8fc7\u8fd9\u4e2a\u662f\u5f00\u533a\u95f4\u8fd8\u662f\u95ed\u533a\u95f4\u5462\uff0c\u8fd8\u5f97\u770b\u5177\u4f53\u5b9e\u73b0\u65b9\u5f0f\u548c\u9898\u5e72\u8981\u6c42\uff0c\u5927\u5bb6\u6700\u597d\u7ffb\u7ffb\u8001\u5e08\u7684 PPT\uff0c\u770b\u770b\u4e0a\u8bfe\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff0c\u4e07\u4e00\u9898\u76ee\u6ca1\u6709\u7ed9\u51fa\u5b9e\u73b0\u65b9\u5f0f\u5c31\u6309\u7167\u8001\u5e08\u8bb2\u7684\u4e3a\u4e3b\u5427\u3002

\u9898\u76ee 5

Suppose that an array of size 6 is used to store a circular queue, and the values of front and rear are 0 and 4, respectively. Now after 2 dequeues and 2 enqueues, what will the values of front and rear be?

A. 2 and 0

B. 2 and 2

C. 2 and 4

D. 2 and 6

Answer

A.

\u5173\u4e8e\u7f16\u7a0b\u90e8\u5206\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u8fd9\u4e2a\u6bcf\u65e5\u4e00\u9898\u3002

"},{"location":"programming/common/faq/","title":"\u5e38\u89c1\u95ee\u9898","text":"

\u8fd9\u91cc\u5206\u6a21\u5757\u6c47\u603b\u4e86\u7a0b\u8bbe\u8f85\u5b66\u7fa4\u4e2d\u7684\u5e38\u89c1\u95ee\u9898\u53ca\u5176\u89e3\u7b54\u3002

"},{"location":"programming/common/faq/#_2","title":"\u57fa\u672c\u6570\u636e\u7c7b\u578b\u3001\u8fd0\u7b97\u7b26\u3001\u8868\u8fbe\u5f0f\u548c\u8bed\u53e5","text":"\u6709\u5e03\u5c14\u7c7b\u578b\u5417\uff1f

Author\uff1a\u6731\u5b9d\u6797

\u5e03\u5c14\u7c7b\u578b\u7684\u5386\u53f2\uff1a

\u56e0\u6b64\uff0c\u4ece C23 \u4ee5\u540e\uff0c\u6211\u4eec\u7ec8\u4e8e\u6709\u4e86 bool \u7c7b\u578b\u3002bool\u3001true\u3001false \u5168\u90fd\u6210\u4e3a\u4e86 C \u7684\u5173\u952e\u5b57\u3002

\u5173\u4e8e\u5e03\u5c14\u7c7b\u578b\u7684\u4f7f\u7528\uff1a

\u6d6e\u70b9\u6570\u662f\u5982\u4f55\u5b58\u50a8\u7684\uff1f\u4e3a\u4ec0\u4e48\u5b83\u4e0d\u7cbe\u786e\uff1f

Author\uff1a\u6731\u5b9d\u6797

\u4e0b\u9762\u7684\u5185\u5bb9\u6765\u81ea\u300a\u8ba1\u7b97\u673a\u79d1\u5b66\u5bfc\u8bba\u300b\uff0c\u8bf7\u5b8c\u6574\u9605\u8bfb\u4ee5\u4e86\u89e3\u6d6e\u70b9\u6570\u7684\u5b58\u50a8\u65b9\u5f0f\u3002

\u5982\u679c\u4f60\u8bfb\u5b8c\u4e86\u4e0a\u9762\u7684\u5185\u5bb9\uff0c\u4f60\u5e94\u8be5\u80fd\u7406\u89e3\u6d6e\u70b9\u6570\u5b58\u50a8\u4e0d\u7cbe\u786e\u7684\u539f\u56e0\uff1a

\u6709\u4e00\u4e2a\u7ecf\u5178\u7684\u4f8b\u5b50\uff1a0.1 + 0.2 == 0.3 \u662f\u9519\u7684\u3002\u8fd9\u4e00\u4f8b\u5b50\u5728\u6bcf\u65e5\u4e00\u9898\u4e2d\u4e5f\u6709\u63d0\u53ca\u3002\u90a3\u4e48\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5462\uff1f\u53ea\u8981\u5c06\u8bef\u5dee\u63a7\u5236\u5728\u4e00\u5b9a\u8303\u56f4\u5185\u5373\u8ba4\u4e3a\u6b63\u786e\uff0c\u6bd4\u5982\uff1a

if(fabs(a - b) < 1e-6) {\n  // a \u548c b \u76f8\u7b49\n}\n
"},{"location":"programming/common/faq/#_3","title":"\u6570\u7ec4\u3001\u5b57\u7b26\u4e32","text":""},{"location":"programming/common/faq/#_4","title":"\u5faa\u73af\u3001\u5206\u652f\u548c\u8df3\u8f6c","text":""},{"location":"programming/common/faq/#_5","title":"\u51fd\u6570\u3001\u6807\u51c6\u5e93\u4e0e\u9884\u5904\u7406\u5668","text":""},{"location":"programming/common/faq/#io","title":"\u6587\u4ef6 I/O","text":""},{"location":"programming/common/faq/#_6","title":"\u6307\u9488\u3001\u5b58\u50a8\u7c7b\u522b\u3001\u94fe\u63a5\u548c\u5185\u5b58\u7ba1\u7406","text":""},{"location":"programming/common/faq/#_7","title":"\u7ed3\u6784\u548c\u5176\u4ed6\u6570\u636e\u5f62\u5f0f","text":""},{"location":"programming/common/daily/2023/","title":"2023-2024","text":"

\u4e3a\u4e86\u8ba9\u540c\u5b66\u4eec\u9002\u5e94\u671f\u672b\u8003\u8bd5\uff0c\u6bcf\u65e5\u4e00\u9898\u7684\u9898\u9762\u90fd\u5c06\u4f7f\u7528\u82f1\u6587\u63cf\u8ff0\u3002

"},{"location":"programming/common/daily/2023/#december","title":"December","text":""},{"location":"programming/common/daily/2023/#10-i-love-pointer","title":"\u300c10\u300d I Love pointer","text":"

What is the output of the following program on a 64-bit system?

    char str[3][10]={\"\",\"ILoveCKC\",\"ILoveZJU\"};\n    printf(\"%lu#%lu\\n\",strlen(str[0]),sizeof(str[0]));\n    printf(\"%lu#%lu\\n\",strlen(str),sizeof(str));\n    printf(\"%d#%c\\n\",str[1][-10],str[1][10]); // Don't write this in your own code.\n    printf(\"%s\\n\",(**str == (*(str + 1) + 8)[1] ? \"True\" : \"False\"));\n    printf(\"%s\",&str[1][9] == &((*(str + 1) + 8)[1]) ? \"True\" : \"False\");\n
Answer
    0#10\n    0#30\n    0#I\n    True\n    True\n
  1. strlen(str[0]) returns the length of the string pointed to by str[0], which is 0. sizeof(str[0]) returns the size of the array str[0], which is 10.
  2. strlen(str) returns the length of the string pointed to by str, which is 0. sizeof(str) returns the size of the array str, which is 30. In fact, str[0]'s value is same as str's value.
  3. str[1][-10] is equivalent to *(str[1] - 10) which is equivalent to **(str + 1 * 10 - 10) which is equivalent to ** str. So str[1][-10]'s value is '\\0'. str[1][10] is equivalent to *(str[1] + 10) which is equivalent to **(str + 1 * 10 + 10) which is equivalent to ** (str + 20) So str[1][10]'s value is 'I'.
  4. (*(str + 1) + 8)[1] is the same as str[1][9]. So **str == (*(str + 1) + 8)[1] is true.

\u4f9b\u9898\u4eba\uff1a\u80e1\u80b2\u73ae

"},{"location":"programming/common/daily/2023/#9-sizeof-all-in-one","title":"\u300c9\u300d sizeof All in One","text":"

What is the output of the following program on a 64-bit system?

char str[][3] = {'L', 'o', 'v', 'e', 'C', 'K', 'C'};\nprintf(\"%d \", (int)sizeof(str));\nprintf(\"%d \", (int)sizeof(&str));\nprintf(\"%d \", (int)sizeof(*str));\nprintf(\"%d \", (int)sizeof(str + 1));\nprintf(\"%d \", (int)sizeof(*str + 1));\nprintf(\"%d \", (int)sizeof(*(str + 1)));\nprintf(\"%d\", (int)sizeof(*(*(str + 1) + 1)));\n
Answer

9 8 3 8 8 3 1.

This is a comprehensive problem combining sizeof and pointer.

  1. When the object is an array name, the return value is the total size of the whole array. At initialization, the third row of the array will be filled to a 1-D array of length 3 automatically: char str[][3] = {{'L', 'o', 'v'}, {'e', 'C', 'K'}, {'C', '\\0', '\\0'}};. Therefore the value of sizeof(str) equals to 3 * 3 * 1 = 9 since sizeof(char) = 3.
  2. In the expression &str, & represents the address-of operator and the return value is the address of the entire array. That, of course, can be regarded as a pointer and hence sizeof(&str) equals 8 (Bytes), the size of a pointer on a 64-bit system.
  3. Now let's focus on str. We know that str is an array of char [3]. In the view of pointer, str is also a pointer to the first element (Note that the element here is an array of length 3). Hence *str is equivalent to str[0] which is an 1D array of length 3. So the output of sizeof(*str) is 3 * 1 = 3.
  4. In the previous discussion we know that str is a pointer to array of length 3 (char (*)[3] actually), so str + 1 is also a pointer and the output is 8.
  5. *str (equivalent to str[0]), will be converted to int * when added by 1. Therefore *str + 1 is a pointer to str[0][1] and 8 will be output again.
  6. From discussion 3 and 4 it's not difficult to find *(str + 1) an array of length 3 (str[1]), so 3 is the answer.
  7. *(*(str + 1) + 1) is classical equivalence of str[1][1]. Therefore sizeof(*(*(str + 1) + 1)) equals to sizeof(char), namely 1.

\u4f9b\u9898\u4eba\uff1a\u5f90\u82e5\u79ba

"},{"location":"programming/common/daily/2023/#8-j-lost","title":"\u300c8\u300d J lost","text":"

Given the following program:

void xqc(char c[], int i);\n\nint main(void) {\n    char c[] = \"I am a Man of Fortune\";\n    char d[] = \"and I must seek my Fortune\";\n\n    xqc(c + 1, ~1694);\n    xqc(d - ~3, -65);\n    printf(\"%s, %s\\n\", c, d);\n}\n\nvoid xqc(char c[], int i) {\n    c = c - 1;\n    c[0] = ' ';\n    c[1] = (i & 1) + 'I';\n}\n

Which of the following is correct?

A. This program fails to compile, because you cannot assign to an array in line 13.

B. Because of the call-by-value, function xqc cannot modify the character arrays in function main.

C. Change 1694 in line 7 to 1994, and the result of the program is the same.

D. This program outputs I am a Man of Fortune, and J must seek my Fortune.

Answer

C.

A: Inside function xqc, c is a pointer type char * rather than an array type, because when an array type is used in a function parameter list, it actually is the corresponding pointer type. Therefore, the assignment in line 13 is valid, and it means \"to move the pointer c one position backward\".

B: The function xqc can modify the character arrays in function main, because it takes the address of the character arrays as parameters. The function xqc can modify the contents of the character arrays through the pointers.

C: The ~ operator is the bitwise NOT operator. The ~1694 is equivalent to -1695. The ~3 is equivalent to -4. Therefore, the calls to function xqc are equivalent to:

xqc(c + 1, -1695);\nxqc(d - -4, -65);\n

And i & 1 gets the last bit of i. Both -1695 and -65 are odd numbers, so i & 1 is 1, and the character 1 + 'I', which is 'J', is assigned. Changing 1694 to 1994 does not change the result of the program, because ~1994 is -1995, and -1995 is also an odd number.

D: This program outputs \u00a0Jam a Man of Fortune, and J must seek my Fortune.

Tip

You don't need to calculate the exact value of ~1694. All you need to know is that the last bit of 1694 is 0 (since it is an even number), and the bitwise NOT operator will reverse that last bit. Therefore, ~1694 is an odd number, and i & 1 is 1. Ditto for ~1994.

\u4f9b\u9898\u4eba\uff1a\u674e\u82f1\u7426

"},{"location":"programming/common/daily/2023/#7-the-difference-between-strlen-and-sizeof","title":"\u300c7\u300d The difference between strlen and sizeof","text":"
#include <stdio.h>\n#include <string.h>\nint main()\n{\n char arr1[] = \"abcd\";\n char arr2[] = {'a', 'b', 'c', 'd'};\n printf(\"%d\\n\", sizeof(arr1));\n printf(\"%d\\n\", sizeof(arr2));\n printf(\"%d\\n\", strlen(arr1));\n printf(\"%d\\n\", strlen(arr2));\n return 0;\n}\n

What are the results?

A. 4, 4, 4, 4 B. 5, 4, 4, 4 C. 4, 4, 4, indeterminable D. 5, 4, 4, indeterminable Answer

D.

arr1 has \\0 at the end, but arr2 doesn't.

The sizeof operator returns the size of its operand in bytes. In this case, the size of arr1 is 5, because it contains 4 characters and a null character \\0. The size of arr2 is 4, because it contains just 4 characters. The \\0 is absent in arr2.

The strlen function returns the length of the string, that is, the number of characters in the string before the null character \\0. In this case, the length of arr1 is 4, because it contains 4 characters before the null character \\0. But the length of arr2 is indeterminable, because it does not contain a null character \\0. The strlen function will continue to read memory until it finds a null character \\0, resulting totally random result. If there is no null character \\0 in the memory, the behavior is undefined.

\u4f9b\u9898\u4eba\uff1a\u534e\u5c55\u8f89\uff0c\u674e\u82f1\u7426

"},{"location":"programming/common/daily/2023/#6-stack-and-queue-adapted-from-fds-mid-term-exam","title":"\u300c6\u300d Stack and Queue (adapted from FDS mid-term exam)","text":"

Given an empty stack S and an empty queue Q. Push elements {1, 2, 3, 4, 5, 6, 7} one by one onto S. If each element that is popped from S is enqueued onto Q immediately, and if the dequeue sequence is {3, 2, 4, 6, 7, 5, 1}, then the minimum size of S should be:

A. 5 B. 4 C. 3 D. 7 Answer

C.

Stack is LIFO (Last In, First Out), queue is FIFO (First In, First Out). So dequeue sequence of queue is also the enqueue sequence. If enqueue sequence of Q is {3, 2, 4, 6, 7, 5, 1}, all operation of stack S must be the following:

In the process, there are at most 3 nodes in stack S, so the minimum size of S should be 3.

\u4f9b\u9898\u4eba\uff1a\u59da\u96ea\u6d9b

"},{"location":"programming/common/daily/2023/#5-monotonic-stacks","title":"\u300c5\u300d Monotonic stacks","text":"

Monotonic stacks are a specialized version of the standard stack data structure, designed to maintain elements in a pre-defined sorted order. Unlike regular stacks, which allow push and pop operations without any constraints, monotonic stacks enforce an order - either increasing or decreasing - on the elements. This means that elements are either strictly increasing or strictly decreasing from the top to the bottom of the stack.

The core operations of a monotonic stack, namely push, are modified to maintain the stack\u2019s order. During a push operation, elements that break the monotonic property are removed from the stack before the new element is added.

For example, now we have a decreasing monotonic stack, where elements closer to the top have the smaller values:

[5,4,2,1]\n       ^\n       |\n       top\n

We push a data with the value \\(3\\), and because \\(1,2\\) is smaller than \\(3\\), we remove them. And finally it will be:

[5,4,3]\n     ^\n     |\n     top\n

Now, your task is to create an decreasing monotonic stack in the C language.

typedef struct Node {\n    int data;\n    struct Node* next;\n} Node;\n\ntypedef struct Stack {\n    Node* top;\n} Stack;\n\nStack* createStack() {\n    Stack* stack = (Stack*)malloc(sizeof(Stack));\n    /* (1) */;\n    return stack;\n}\n\nvoid push(Stack* stack, int data) {\n    while (/* (2) */) {\n        Node* temp = stack->top;\n        stack->top = temp->next;\n        /* (3) */;\n    }\n    Node* newNode = (Node*)malloc(sizeof(Node));\n    newNode->data = data;\n    /* (4) */;\n    stack->top = newNode;\n}\n\nint pop(Stack* stack) {\n    if (isEmpty(stack)) {\n        printf(\"Stack is empty\\n\");\n        return -1;\n    }\n    Node* temp = stack->top;\n    int popped = temp->data;\n    stack->top = temp->next;\n    free(temp);\n    return popped;\n}\n
Answer

\u5355\u8c03\u6808\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u6808\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd\u4e25\u683c\u5c0f\u4e8e\u6216\u5927\u4e8e\u5b83\u4e0b\u9762\u7684\u5143\u7d20\u3002\u5927\u5bb6\u5728\u540e\u7eed\u7684\u8bfe\u7a0b\u4e2d\u6709\u53ef\u80fd\u4f1a\u63a5\u89e6\u5230\u4ed6\u7684\u4e00\u4e9b\u5e94\u7528\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u9010\u4e00\u770b\u770b\u8fd9\u4e9b\u9898\u76ee\u600e\u4e48\u586b\u5199\uff1a

\u7b2c\u4e00\u7a7a\uff1a\u8fd9\u91cc\u9700\u8981\u521d\u59cb\u5316\u6808\u9876\u5143\u7d20\u3002\u7531\u4e8e\u6808\u662f\u7a7a\u7684\uff0c\u6240\u4ee5\u6808\u9876\u5e94\u8be5\u8bbe\u7f6e\u4e3a NULL\u3002

stack->top = NULL;\n

\u7b2c\u4e8c\u7a7a\uff1a\u8fd9\u662f\u6700\u96be\u7684\u4e00\u7a7a\u3002\u6839\u636e\u9898\u610f\uff0c\u8fd9\u4e00\u5c42\u5faa\u73af\u7684\u76ee\u7684\u662f\uff1a\u79fb\u9664\u6240\u6709\u5c0f\u4e8e\u6216\u7b49\u4e8e\u65b0\u5143\u7d20\u7684\u6808\u9876\u5143\u7d20\uff0c\u4ee5\u7ef4\u6301\u6808\u7684\u5355\u8c03\u6027\u3002\u4f46\u662f\u8fd8\u6709\u4e00\u79cd\u60c5\u51b5\uff1a\u5982\u679c\u6808\u672c\u8eab\u662f\u7a7a\u7684\uff0c\u6216\u8005\u6240\u6709\u5143\u7d20\u90fd\u6bd4\u65b0\u5143\u7d20\u5c0f\uff0c\u90a3\u5fc5\u987b\u5f97\u9000\u51fa\u5faa\u73af\u3002

while (stack->top != NULL && stack->top->data <= data)\n

\u7b2c\u4e09\u7a7a\uff1a\u4e0d\u5927\u5bb9\u6613\u60f3\u5230\u3002\u5728\u79fb\u9664\u6808\u9876\u5143\u7d20\u540e\uff0c\u5e94\u8be5\u91ca\u653e\u8be5\u8282\u70b9\u5360\u7528\u7684\u5185\u5b58\u3002

free(temp);\n

\u4e3a\u4ec0\u4e48\u51fa\u8fd9\u4e2a\uff1f\u56e0\u4e3a wk \u660e\u786e\u8bf4\u8fc7\uff0c\u8003\u8bd5\u8003\u8fd9\u4e2a\u586b\u7a7a\uff0c\u4e0d\u5199 free \u5c31\u5c11 2 \u5206\uff0c\u6240\u4ee5\u51fa\u4e86\u8fd9\u4e2a\u7a7a\u6765\u8ba9\u5927\u5bb6\u6ce8\u610f\u3002

\u7b2c\u56db\u7a7a\uff1a\u8fd9\u91cc\u9700\u8981\u5c06\u65b0\u8282\u70b9\u7684 next \u6307\u9488\u6307\u5411\u4e4b\u524d\u7684\u6808\u9876\u5143\u7d20\uff0c\u7136\u540e\u5c06\u6808\u9876\u6307\u9488\u6307\u5411\u65b0\u8282\u70b9\uff0c\u8fd9\u6837\u65b0\u8282\u70b9\u5c31\u6210\u4e3a\u4e86\u65b0\u7684\u6808\u9876\u3002

newNode->next = stack->top;\n

\u4f9b\u9898\u4eba\uff1a\u8c22\u96c6

"},{"location":"programming/common/daily/2023/#4-command-line-arguments","title":"\u300c4\u300d Command Line Arguments","text":"

If you run the following command in the terminal:

./a.out this is a test\n

Please describe what will the program see in argv and argc.

Answer

argv is an array of pointers to strings, and argc is the number of strings in argv. The argv array contains the following strings:

argv[0] = \"./a.out\"\nargv[1] = \"this\"\nargv[2] = \"is\"\nargv[3] = \"a\"\nargv[4] = \"test\"\n

The argc is 5, because there are 5 strings in argv.

The argv array is terminated by a null pointer, so argv[5] is a null pointer.

For more information about argv and argc, see cppreference-argc, argv.

\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797

"},{"location":"programming/common/daily/2023/#3-sizeof-struct","title":"\u300c3\u300d sizeof struct","text":"

Consider the following code fragment:

struct A {\n    char a[10];\n    int b;\n\n};\ntypedef struct A A;\n\nstruct B {\n    char *a;\n    int b;\n};\ntypedef struct B* B;\n

What is the value of sizeof(A) and sizeof(B)?

Answer

sizeof(A) is 16, and sizeof(B) is 8 (on a 64-bit modern system).

The sizeof operator returns the size of its operand in bytes. The size of a structure type is as large as the sum of the sizes of its members.

You may think the size of A is 14, because the size of char[10] is 10, and the size of int is 4. However, to improve performance of memory access, C standard allows the compiler to add padding bytes after each member of a structure, and the padding strategy is implementation specific. A common strategy is to align each member to the size of its type, that is to say, make their memory address to be a multiple of the size of the member. For example, on a 64-bit system, the address of a 4-byte integer must be a multiple of 4.

Therefore, The size of A is 16. The compiler will add 2 padding bytes after char[10], to make the address of int a multiple of 4 in struct A.

The size of B is 8, because B is a pointer and the size of pointer is 8. The size of type to which B points does not affect the size of B. Notice that type B is not equivalent to type struct B.

For more information about sizeof operator, see cppreference-sizeof.

\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797\u3001\u5b59\u5146\u6c5f

"},{"location":"programming/common/daily/2023/#2-print-non-printable-characters","title":"\u300c2\u300d Print Non-printable Characters","text":"

Write a program to convert unprintable characters (characters with ASCII codes between 0x00~0x1f and 0x7f) in the input string to hexadecimal format for output.

Requirements:

Sample Input:

Hello\nWorld!\n

Sample Output:

Hello\\0x0aWorld!\n
Answer
#include <stdio.h>\n#include <ctype.h>\n\nconst char* hex_digits = \"0123456789abcdef\";\n\nint main(void) {\n    char temp;\n    while((temp = getchar()) != EOF) {\n        if (isprint(temp)) {\n            putchar(temp);\n        } else {\n            putchar('\\\\');\n            putchar('0');\n            putchar('x');\n            putchar(hex_digits[temp >> 4]);\n            putchar(hex_digits[temp & 0xf]);\n        }\n    }\n    return 0;\n}\n

If you are not familiar with bitwise operations, the 14th and 15th lines in the above code fragment can be written in a more understandable form:

putchar(hex_digits[temp / 16]);\nputchar(hex_digits[temp % 16]);\n

\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797

"},{"location":"programming/common/daily/2023/#1-hello-cat","title":"\u300c1\u300d Hello, Cat","text":"

After executing the following code fragment, the output should be __.

#include <stdio.h>\n#include <string.h>\nint main()\n{\n    char s1[10] = \"Hello\\0Ow<\";\n    char s2[10] = \"world\";\n    char *s3 = s1 + 2;\n    char *s4 = s2 + 3;\n    strcat(s3, s4);\n    printf(\"%s, %s; %s, %s.\\n\", s1, s2, s3, s4);\n    return 0;\n}\n

A. Hello, world; llold, ld.

B. Hello, world; lloldw<, ld.

C. Hellold, world; llold, ld.

D. Helloldw<, world; lloldw<, ld.

Answer

C.

The strcat function appends a copy of the string pointed to by s4 to the end of the string pointed to by s3. The s3 and s4 pointers point to the third character of s1 and the fourth character of s2, respectively. Therefore, the strcat function appends the string \"ld\" to the end of the string \"Hellold\", resulting in \"Helloldld\", and the printf function prints \"Hellold, world; llold, ld.\".

When the strcat function appends the string \"ld\" after \"Hello\", it overwrites the null character '\\0' at the end of the string \"Hello\" and write a new null character '\\0' at the end of the string \"Helloldld\". Therefore, the character w and < after the null character '\\0' in s1 are not printed.

\u4f9b\u9898\u4eba\uff1a\u90d1\u4fca\u8fbe

"},{"location":"programming/common/daily/2023/#november","title":"November","text":""},{"location":"programming/common/daily/2023/#30-basic-doubly-linked-list","title":"\u300c30\u300d Basic Doubly Linked List","text":"

Please fill in the blanks to complete the following code fragment.

#include <stdio.h>\n#include <stdlib.h>\n\ntypedef struct Node {\n    int data;\n    struct Node *prev, *next;\n} Node;\ntypedef struct Node *List;\n\nList createEmptyList() {\n    List list = (List)malloc(sizeof(Node));\n    list->prev = list->next = NULL;\n    return list;\n}\n\nvoid insertFront(List list, int data) {\n    Node *node = (Node *)malloc(sizeof(Node));\n    node->data = data;\n    node->prev = /* 1 */;\n    node->next = /* 2 */;\n    list->next->prev = /* 3 */;\n    list->next = /* 4 */;\n}\n\nint main(){\n    List list = createEmptyList();\n    insertFront(list, 1);\n    insertFront(list, 2);\n    insertFront(list, 3);\n    for (Node *node = /* 5 */; node != NULL; node = node->next)\n        printf(\"%d \", node->data);\n    return 0;\n}\n
Answer
  1. list
  2. list->next
  3. node
  4. node
  5. list->next

Notice this is a doubly linked list with a dummy node. The dummy node is a special node that does not store any data. It is used to simplify the implementation of the linked list. In this case, the dummy node is list.

The insertFront function inserts a new node with data at the front of the list. The new node is inserted between the dummy node and the first node of the list. The insertFront function takes two steps:

  1. Create a new node and set its data to data.
  2. Insert the new node between the dummy node and the first node of the list.

If you want to iterate over the list, you should start from the first node of the list, which is list->next.

\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797

"},{"location":"programming/common/daily/2023/#29-soyo-size","title":"\u300c29\u300d Soyo Size","text":"

On a 64-bit machine, the output of the following code fragment is __.

void print_soyo(char soyo[]) {\n    printf(\"%lu\\n\", sizeof(soyo));\n}\n\nint main() {\n    char soyo[] = \"Soyosan\\0Love\";\n    print_soyo(soyo);\n    return 0;\n}\n
A. 13 B. 7 C. 8 D. 4 Answer

C.

When an array type is used in a function parameter list, it is transformed to the corresponding pointer type: int f(int a[]) and int f(int *a) declare the same function. See cppreference-Array to pointer conversion for more information.

So the parameter soyo in function print_soyo is actually a pointer, and the size of a pointer is variable depending on the architecture. On a 64-bit machine, the size of a pointer is 8 bytes, and on a 32-bit machine, the size of a pointer is 4 bytes. Therefore, the output of this program is 8.

\u4f9b\u9898\u4eba\uff1a\u82cf\u715c\u7a0b

"},{"location":"programming/common/daily/2023/#28-naughty-pointer","title":"\u300c28\u300d Naughty Pointer","text":"

The following code fragment prints out __.

int a[2][3] = {1, 2, 3, 4, 5, 6};\nint(*p)[3] = *a + 1;\nprintf(\"%d\", *(*(p + 1) + 1));\n
Answer

6.

Obviously, the type of p is declared as int (*)[3], which is a pointer to an array of 3 integers. We know that in the initializer, a will be converted to a pointer to its first element, so *a is equivalent to a[0], which is an array of 3 integers. Then, the type of *a will be converted from int [3] to int * again. Therefore, adding 1 to *a will make it point to the next integer, which is a[0][1].

You may notice that the type of *a + 1 is not the same as pointer p. In fact, its type is casted to int (*)[3] when assigned to p. Trying to figure out the \"meaning\" of p now may become more difficult. Instead, just remember the value of pointer p is the address of a[0][1].

Now consider the expression *(*(p + 1) + 1). First, since the type of p is int (*)[3], adding 1 to p will make it point to the next array of 3 integers; that is to say, the value of p will be the address of the third integer after a[0][1], which is a[1][1]. So *(p + 1) is just equivalent to &a[1][1]. Then, adding 1 to *(p + 1) will make it point to the next integer, which is a[1][2]. Thus, the value of *(*(p + 1) + 1) is a[1][2], which is 6.

\u4f9b\u9898\u4eba\uff1a\u5b59\u5146\u6c5f

"},{"location":"programming/common/daily/2023/#27-i-love-scanf","title":"\u300c27\u300d I Love scanf","text":"

After entering the following inputs, does the program operate normally? If it does, what should be the output?

int a;\nchar c1, c2;\nchar s[7];\nscanf(\"%d%c %c%s\\n\", &a, &c1, &c2, s);\nprintf(\"%d#%c#%c#%s\", a, c1, c2, s);\n
#input: there is no space after the last character\n20231127\n ckc-agc\ndaily_problem\n
Answer

The program operates normally and the output is:

20231127#\n#c#kc-agc\n

The scanf function reads input from the standard input stream, which is usually the keyboard. The format string of scanf is \"%d%c %c%s\\n\". The first %d matches the integer 20231127, the second %c matches the character '\\n' because %c won't miss any character including ' ' and '\\n'. The space in formatting string will ignore every blank character, so the third %c matches the character 'c', and the fourth %s matches the string \"kc-agc\", whose length is 7. When you print \\n after line2, scanf will not stop, because '\\n' in formatting string will ignore every blank character. So until you enter a non-blank character and use enter to send it to the program from buffer, scanf will stop.

\u4f9b\u9898\u4eba\uff1a\u80e1\u80b2\u73ae

"},{"location":"programming/common/daily/2023/#26-broken-strcpy","title":"\u300c26\u300d Broken strcpy()","text":"

Does this strcpy() implementation do its job?

void my_strcpy(char *s, const char *t) {\n    do {\n        *s++ = *t++;\n    } while (*t);\n}\n
Answer

No, it's broken. This implementation does not terminate the string pointed to by s. To correctly copy a string, the character used in assignment must be the same character used in loop condition.

What does that mean? Suppose t = \"Hello\", then:

See the problem? The null byte '\\0' is not copied to s, therefore it's left unterminated. Any attempt to use s as a string will result in undefined behavior.

Worse still, what happens if t is an empty string i.e. t = \"\"?

\u4f9b\u9898\u4eba\uff1a\u674e\u82f1\u7426

"},{"location":"programming/common/daily/2023/#25-i-love-strcat","title":"\u300c25\u300d I Love Strcat","text":"

The following code fragment prints out __.

#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nvoid my_strcat(char *s1, char *s2, char *s3) {\n    size_t len1 = strlen(s1);\n    size_t len2 = strlen(s2);\n    s3 = malloc(len1 + len2 + 1);\n    memcpy(s3, s1, len1);\n    memcpy(s3 + len1, s2, len2);\n    s3[len1 + len2] = 0;\n    printf(\"%s\\n\", s3);\n}\n\nint main() {\n    char s1[] = \"I love \";\n    char s2[] = \"cats!\";\n    char s3[] = \"\";\n    my_strcat(s1, s2, s3);\n    printf(\"%s\\n\", s3);\n}\n

A. I love cats!\\n\\n

B. \\n\\n

C. \\nI love cats!\\n

D. I love cats!\\nI love cats!\\n

Answer

A.

The function my_strcat is supposed to concatenate s1 and s2 and store the result in s3. However, the function does not work as expected. The problem lies in the line s3 = malloc(len1 + len2 + 1);. The function my_strcat takes s3 as a parameter, which is a pointer to a char array. When the function is called, the value of s3 is copied to the function's local variable s3. Therefore, the malloc function allocates memory for the local variable s3, not the original s3 in main. The memory allocated for the local variable s3 is not used after the function returns, so it is a memory leak. The original s3 in main is not modified, so it is still an empty string.

You may think that the problem can be solved by simply deleting the line s3 = malloc(len1 + len2 + 1);. However, this will cause another problem. s3 is initialized as an empty string, which means that it is a pointer to a char array with only one element, the null character \\0. The memory allocated for s3 is not enough to store the concatenated string. Therefore, this will cause a buffer overflow.

\u4f9b\u9898\u4eba\uff1a\u6885\u654f\u70ab

"},{"location":"programming/common/daily/2023/#24-pointer-array","title":"\u300c24\u300d Pointer Array","text":"

The output of the following code fragment is __.

#include <stdio.h>\nint main()\n{\n char* a[] = { \"the\",\"one\",\"is\",\"unknown\" };\n char** pa = a;\n pa++;\n printf(\"%c%s\\n\", *(*pa + 1), *pa);\n return 0;\n}\n
A. none B. tone C. tthe D. nis Answer

A.

a[] is an array of pointers, which stores the addresses of three strings, and pa points to the address of the first element of a, as shown below:

Pointer operations take precedence over addition, so *(*pa + 1) equals to n.

In summary, the code fragment prints out none.

\u4f9b\u9898\u4eba\uff1a\u534e\u5c55\u8f89

"},{"location":"programming/common/daily/2023/#23-typedef-and-string","title":"\u300c23\u300d typedef and String","text":"

The preprocessing of this program is as follows:

#define MAX_SIZE 10000\n\ntypedef struct Bookcase{\n    char* book[10];\n} *PtrToBookcase;\n\ntypedef PtrToBookcase Lib_data_base[MAX_SIZE];\n

After executing the following code fragment, the output should be __.

Lib_data_base library;\n*(library) = (PtrToBookcase)malloc(sizeof(struct Bookcase));\n(*library)->book[0] = \"C Programming Book\";\nfor(int i = 0; i < 3; i++)\n    printf(\"%.2s\\n\", library[0]->book[0] + strlen(library[0]->book[0]) - i - 1));\nfree(library[0]);\n
Answer

Output is:

k\nok\noo\n

The address pointed to by library[0]->book[0] plus (strlen(library[0]->book[0])-i-1) * sizeof(char) will be eventually passed to %.2s and placed into the output stream.

Thus, when i=0, i=1, and i=2, the strings passed to %.2s are \"k\\0\", \"ok\\0\", and \"ook\\0\", respectively. Among these, the length of the third string \"ook\\0\" exceeds 2, so only the first two characters \"oo\" will be output.

This question involves multiple concepts, primarily focusing on both the proper usage of typedef and issues related to pointer output with char* in C. The analysis will be divided into two parts: typedef and char*. If you are already familiar with typedef, you can directly skip this section.

typedef

In the C language, typedef is used to create new names for existing data types.

When using typedef, errors can occur in the specification of its usage. One common misunderstanding is to interpret typedef (type_name) (new_name), which is correct only in a few cases, such as typedef int Integer.

However, the correct understanding should be: if you need to redefine a type, first write the declaration statement of that type: type variable_name, then replace variable_name with the alias you want, and finally add typedef in front of the entire statement.

For example, after int array[10], where the type of the variable array is int [10], you can rename array to the alias IntegerList and add typedef at the front, resulting in typedef int IntegerList[10].

After this, you can directly use the alias IntegerList to define variables of type int [10], such as IntegerList a;, which is equivalent to decelaration: int a[10].

Returning to the question, let's analyze the two typedef statements in the question.

The first one creates an alias for a structure variable. If we initially want to declare a variable of type struct Bookcase*, we would write it like this:

struct Bookcase {\n    char* book[10];\n} *Bookcase1;\n

Following the rules of typedef, replace the variable name Bookcase1 with the alias PtrToBookcase and add typedef at the beginning of the entire statement, resulting in the form seen in the question:

typedef struct Bookcase {\n    char* book[10];\n} *PtrToBookcase;\n

This statement means giving an alias, PtrToBookcase, to the type struct Bookcase*.

The second typedef is very similar to the example we mentioned earlier, typedef int IntegerList[10];. It first declares PtrToBookcase Ptr1[MAX_SIZE], then replaces the variable name Ptr1 with the alias Lib_data_base, and adds typedef at the front. Therefore, its meaning is to give an alias, Lib_data_base, to the type PtrToBookcase [MAX_SIZE]. Consequently, the subsequent Lib_data_base library actually creates an array of PtrToBookcase, named library, with MAX_SIZE elements.

char*

After understanding typedef, let's now explore the issue related to string output in this program. There are two potentially confusing elements in this code: %.2s and library[0]->book[0]+strlen(library[0]->book[0])-i-1.

%.2s is relatively straightforward: It is used to control the output of strings. %s would directly output the characters stored at the memory location pointed to by a char* type pointer and all characters in consecutive memory until encountering the '\\0' character. The additional .2 in %.2s is used to limit the length of the output string. If the string length is less than or equal to 2, it will be output normally. If it exceeds 2, only the first two characters will be output.

library[0]->book[0]+strlen(library[0]->book[0])-i-1 involves operations on a char* type pointer. library[0]->book[0] is a char* type pointer. Adding n to it effectively shifts the pointer to a position n * sizeof(char) bytes forward from the current address. Subtracting n from it shifts the pointer to a position n * sizeof(char) bytes backward from the current address.

\u4f9b\u9898\u4eba\uff1a\u59da\u96ea\u6d9b

"},{"location":"programming/common/daily/2023/#october","title":"October","text":""},{"location":"programming/common/daily/2023/#29-precedence","title":"\u300c29\u300d Precedence","text":"

The output of the following code fragment is __.

int x = 1, y = 2;\nprintf(\"%d\\n\", y << 1 - 1 > 2 || !(x++ > --y) ? x : y);\n
Answer

The answer is 2.

Several operators appear in this problem, listed in order of operation precedence from top to bottom:

See more about operator precedence at cppreference.com.

Knowing this, let's break down the expression from the innermost to the outermost parts.

  1. 1 - 1 evaluates to 0, and y << 0 has the value 2.
  2. 2 > 2 is false, thus the value of the Logical OR depends on the right part.
  3. x++ assigns the value of x (1) to the expression and then increments x by 1, making x equal to 2.
  4. --y decreases the value of y (2) by 1, so y becomes 1.
  5. x++ > --y is equivalent to 1 > 1, which is false, so this part equals 0.
  6. !(x++ > --y) negates false, so this part equals 1, making the condition of the Ternary conditional true.
  7. Since x has the value of 2 and y has the value of 1, the output will be 2.

\u4f9b\u9898\u4eba\uff1a\u5f90\u82e5\u79ba

"},{"location":"programming/common/daily/2023/#27-or-in-switch","title":"\u300c27\u300d Or in switch","text":"

What will happen when compiling and executing the following code fragment with input 5?

char ch;\nscanf(\"%c\", &ch);\nswitch (ch) {\n    case 0 || 2 || 4 || 6 || 8:\n        printf(\"even digit \");\n    case 1 || 3 || 5 || 7 || 9:\n        printf(\"odd digit \");\n    default:\n        printf(\"not a digit \");\n}\n

A. It will print odd digit.

B. It will print odd digit not a digit.

C. It will print not a digit.

D. It cannot be compiled.

Answer

D.

The compiler will tell you that case label value has already appeared in this switch. There are many problems in this code fragment, and the most important one is that 0 || 2 || 4 || 6 || 8 will not behave as expected in case statement. It will be evaluated as 1 because 0 || 2 || 4 || 6 || 8 is equivalent to ((((0 || 2) || 4) || 6) || 8). The result of 0 || 2 is 1, so the result of 0 || 2 || 4 is 1, and so on. Therefore, the case statement will be evaluated as case 1. The same problem exists in case 1 || 3 || 5 || 7 || 9, which will also be evaluated as case 1. The correct way to write this code fragment is:

char ch;\nscanf(\"%c\", &ch);\nswitch (ch) {\n    case '0': case '2': case '4': case '6': case '8':\n        printf(\"even digit \"); break;\n    case '1': case '3': case '5': case '7': case '9':\n        printf(\"odd digit \"); break;\n    default:\n        printf(\"not a digit \");\n}\n

For more information about switch statement, see cppreference-Switch statement.

\u4f9b\u9898\u4eba\uff1a\u90d1\u4fca\u8fbe

"},{"location":"programming/common/daily/2023/#26-bitwize-operator","title":"\u300c26\u300d Bitwize Operator","text":"

Which of the following options can achieve a swapping effect for pair(*,*)? Note that ^ represents XOR operation. For binary numbers, 0 XOR 0 = 0, 0 XOR 1 = 1, 1 XOR 0 = 1, 1 XOR 1 = 0.

A. (x, y): x ^= y ^= x ^= y;

B. (a[x], a[y]): a[x] ^= a[y] ^= a[x] ^= a[y];

C. (x, y): x -= y += x -= y;

D. (a[x], a[y]): a[x] -= a[y] += a[x] -= a[y];

Answer

A.

\u4f9b\u9898\u4eba\uff1a\u7a0b\u6615\u5b87

"},{"location":"programming/common/daily/2023/#25-eternal-binary-search","title":"\u300c25\u300d Eternal Binary-Search","text":"

After executing the following code fragment, the output should be __.

int ok[50000];\nfor (int i = 0; i <= 19268; ++i) ok[i] = 1;\nfor (int i = 19269; i <= 49999; ++i) ok[i] = 0;\nint l = 0, r = 49999;\nwhile (l < r){\n    int mid = (l + r) / 2;\n    if (ok[mid]) l = mid;\n    else r = mid - 1;\n}\nprintf (\"the ok_maximum is %d\", l);\n
Answer

In fact, this code fragment has no output because it is stuck in an endless loop. Let's see what happens: At first the code executes perfectly, l increasing and r decreasing constantly. However, when the value of r-l reduce to 1, the value of l and r will never change again. That's because mid equals to l and ok[mid] is true (Think about it. why?), so l = mid will be execute, again and again with no value change.

Binary Search is a very simple, common and useful algorithm that you will learn soon. However, when using Binary Search, it is easy to write a wrong code. It is said that only 10% of the programmers can write a exactly correct code. Hence, you need to pay special attention to this algorithm. A small change can possibly change the code correctness. For example, modifying the int mid = (l + r) / 2; to int mid = (l + r + 1) / 2; makes the code correct.

\u4f9b\u9898\u4eba\uff1a\u90d1\u6db5\u6587

"},{"location":"programming/common/daily/2023/#24-nested-switch-confusing-default-and-break","title":"\u300c24\u300d Nested switch, Confusing default and break","text":"

After executing the following code fragment, the output should be __.

int x = 1, y = 1;\nswitch (x) {\n    case 1:\n        switch (y) {\n            default:\n                printf(\"three \");\n            case 1:\n                printf(\"one \");\n            case 2:\n                printf(\"two \");\n                break;\n        }\n    case 2: case 3:\n        printf(\"four \");\n        break;\n    default:\n        printf(\"five \");\n}\n
Answer

one two four

The syntax of switch statement is:

switch (expression) {\n    case constant-expression:\n        statements\n    case constant-expression:\n        statements\n    default:\n        statements\n}\n

The expression must have an integral or enumerated type, or be of a class type in which the class has a single conversion function to an integral or enumerated type. The constant-expression for each case must be a constant expression of the same type as the expression, and no two of the constant expressions associated with the same switch statement shall have the same value after conversion.

The switch statement evaluates expression, then looks for the case constant-expression whose value is equal to the value of expression (after conversion). If such a case is found, the statements following that case are executed until a break statement is encountered. If no case is found whose value is equal to the value of the expression, and if there is a default label, the statements following the default label are executed. Otherwise, the statements of the switch statement are skipped.

If some case labels are not followed by break statements, the execution of the switch statement falls through to the next case label. You can use this behavior to execute multiple statements for a particular case label or to execute statements for more than one case label.

\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797

"},{"location":"programming/common/daily/2023/#23-prefix-or-postfix","title":"\u300c23\u300d Prefix OR Postfix","text":"

After executing the following code fragment, the value of variable x is __.

int x;\nfor (x = 0; x-- < 9 || ++x < 10; ++x) {\n    x++;\n}\n
Answer

11

  1. The result of the increment and decrement operators

    Increment and decrement operators have postfix form x++ (or x--), and prefix form ++x (or --x).

    • The result of the postfix forms is the value of x.
    • The result of the prefix forms is the value of x + 1 for ++x (or x - 1 for --x).

    For more information, see cppreference-Increment/decrement operators

  2. Logical OR ||

    The logical OR expression has the form lhs || rhs, in which rhs is only evaluated if lhs compares equal to \u200b0\u200b.

    For more information, see cppreference-Logical operators

When x < 9, each loop will cause x to increase by 1. Note that only x-- < 9 is evaluated in each loop now.

Now x is equal to 9 before the cond-expression of the for loop. First, x-- < 9 is evaluated, which compares equal to 0, and causes x to decrease by 1. Then x is equal to 8 and ++x < 10 is evaluated, which compares equal to 1 and causes x to increase by 1. Loop continues.

Then, x is equal to 11 before the cond-expression of the for loop. Now x-- < 9 and ++x < 10 both compare equal to 0, so the loop ends. x firstly decreases by 1 and then increases by 1, so the final value of x is 11.

\u4f9b\u9898\u4eba\uff1a\u82cf\u715c\u7a0b

"},{"location":"programming/common/daily/2023/#22-string-comparison","title":"\u300c22\u300d String Comparison","text":"

What's wrong with this code snippet?

char a[] = {\"abcd\"};\nchar b[] = {\"abcd\"};\nchar c[] = {\"ABCD\"};\n\nif(a > b) printf(\"[1] YES\\n\");\nelse printf(\"[1] NO\\n\");\nif(a > c) printf(\"[2] YES\\n\");\nelse printf(\"[2] NO\\n\");\n
Answer

Actually, the output of this program is unpredictable.

  1. To compare two strings, you should use strcmp function in <string.h> header file. Learn how to use the function by yourself.
  2. In the code snippet above, a, b and c are all arrays of char, so a > b and a > c are actually comparing the addresses of these arrays. You may think that the array declared later has a larger address, but this is not always true. It depends on the design of the architecture that the stack grows towards higher memory addresses or towards lower memory addresses. So the output of this program is unpredictable. For more information on this, see StackOverflow: Is the order of memory addresses of successively declared variables always descending?

\u4f9b\u9898\u4eba\uff1a\u6768\u7433\u73a5

"},{"location":"programming/common/daily/2023/#21-addition","title":"\u300c21\u300d Addition","text":"

After executing the following code fragment, the output should be __.

double a = 0.1, b = 0.2;\nif (a + b == 0.3)\n    printf(\"Equal.\\n\");\nelse\n    printf(\"Not equal.\\n\");\n
Answer

Not equal.

In C (and many other programming languages), floating-point arithmetic is not always exact due to the way numbers are represented in binary. This means that sometimes, tiny errors can be introduced and accumulated when performing mathematical operations on floating-point numbers.

In this case, when adding 0.1 and 0.2 together, the result is not precisely 0.3 due to these inaccuracies. Thus, directly comparing floating-point numbers with == can lead to unexpected results.

To deal with such issues in real programs, check if the difference between two floating-point numbers is smaller than a tiny threshold.

For more information about floating-point numbers, search for IEEE 754.

\u4f9b\u9898\u4eba\uff1a\u5b59\u5146\u6c5f

"},{"location":"programming/common/daily/2023/#20-bad-for","title":"\u300c20\u300d Bad for","text":"

After executing the following code fragment, the output should be __.

unsigned int x , y; // 'int' occupies 4 bytes\nfor (x = 2, y = 1; x = y; y++)\n    ;\nprintf(\"%d\", x-1);\n
Hint

Review Oct.\u300c18\u300d & \u300c16\u300d may help you get right answer.

Answer

-1.

Notice that the condition of for is x = y, not x == y. So for loop will terminate until y = 0. You should consider overflow in unsigned int variable.

When we execute ++ for unsigned int y in for loop, we will get 0x111...1(\\(2^{32}-1\\)) as the max unsigned int, and then we will get 0x00...0 as 0 because of overflow. So x gets the value of y(0) and terminates for. In printf, x-1 is 0x11...1. When you use %d to print, it will be considered as a signed interger, so the answer is -1, not \\(2^{32}-1\\).

\u4f9b\u9898\u4eba\uff1a\u80e1\u80b2\u73ae

"},{"location":"programming/common/daily/2023/#19-isprime","title":"\u300c19\u300d IsPrime?","text":"

What's wrong with this code snippet?

int d;\nscanf(\"%d\", &d);\n\n// determine if d is a prime number\nfor (int i = 2; i <= d; i++) {\n  if (d % i == 0) {\n    printf(\"%d is a composite\\n\", d);\n    exit(0);\n  }\n}\nprintf(\"%d is a prime\\n\", d);\n
Answer

Notice the condition of the for loop: i <= d, which means i will eventually be equal to d. Therefore d % i == 0 evaluates to 1, reporting composite for every input greater than 1.

\u4f9b\u9898\u4eba\uff1a\u674e\u82f1\u7426

"},{"location":"programming/common/daily/2023/#18-bad-if-else","title":"\u300c18\u300d Bad if-else","text":"

After executing the following code fragment, the output is __.

int x = 0;\nint y = -2;\nif(x > 0) y = 1;\nelse if(x < 0) y = -1;\nelse if(x = 0) y = 0;\nprintf(\"%d\", y);\n
A. 1 B. 0 C. -1 D. -2 Answer

D.

Notice that the condition of if in line 5 is x = 0, not x == 0. The former means \"0 is assigned to x\", and then the if sentence won't be executed since it is equivalent to if(0). Thus the value of y is its initial value, -2.

\u4f9b\u9898\u4eba\uff1a\u6885\u654f\u70ab

"},{"location":"programming/common/daily/2023/#17-character","title":"\u300c17\u300d Character","text":"

Given: char c = '@';, the value of expression 'A' <= c <= 'Z' is __.

Answer

1.

To solve this problem you do not need to remember ASCII code. This problem is about operator precedence. The expression 'A' <= c <= 'Z' is equivalent to (('A' <= c) <= 'Z'). No matter what the value of c is, the expression ('A' <= c) will be evaluated to 1 or 0, which is less than 'Z'. Therefore, the value of the expression 'A' <= c <= 'Z' is 1.

But in other problems you may need to remember some key ASCII codes:

Character ASCII Code '0' 48 'A' 65 'a' 97

Upper case is prior to lower case. The difference between 'A' and 'a' is 32. So if you want to convert a lowercase letter to uppercase, you can use c - 32. Or an easier way: c - 'a' + 'A'.

\u6765\u81ea\uff1aC \u5927 13 \u5e74\u671f\u672b

"},{"location":"programming/common/daily/2023/#16-overflow","title":"\u300c16\u300d Overflow","text":"

For code below:

unsigned short sht = 0;\nsht--;\n

What will be the value of sht after the execution?

A. -1 B. 65535 C. 32767 D. 65536 Answer

B.

Remember that unsigned short is an unsigned integer type, so it will not be negative. Instead, it will be the largest value of unsigned short type. The largest value of unsigned short type is 65535, because unsigned short is 16-bit long.

\u6765\u81ea\uff1aC \u5927 13 \u5e74\u671f\u672b

"},{"location":"programming/common/exam/","title":"\u5386\u5e74\u5377","text":"

\u5386\u5e74\u5377\u5178\u578b\u9898\u76ee\u7b54\u7591\u96c6\u6b63\u5728\u6574\u7406\u4e2d\u3002

"},{"location":"programming/common/exam/#_2","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u4e0e\u7b97\u6cd5\u57fa\u7840","text":"

\u6682\u65e0

"},{"location":"programming/common/exam/#_3","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u57fa\u7840\u4e0e\u5b9e\u9a8c","text":"

\u6682\u65e0

"},{"location":"programming/common/exam/#2013-20182020","title":"\u3010\u5df2\u505c\u5f00\u3011\u7a0b\u5e8f\u8bbe\u8ba1\u57fa\u7840\uff082013-2018+2020\uff09","text":"

\u8be5\u8bfe\u7a0b\u5df2\u4e8e 2022-2023 \u5b66\u5e74\u505c\u5f00\u3002

\u5e74\u4efd \u8bd5\u5377 \u7b54\u6848 2013 \u8bd5\u5377 \u7b54\u6848 2014 \u8bd5\u5377 \u7b54\u6848 2015 \u8bd5\u5377 \u7b54\u6848 2016 \u8bd5\u5377 \u7b54\u6848 2017 \u8bd5\u5377 \u7b54\u6848 2018 \u8bd5\u5377 \u7b54\u6848 2020 \u6a21\u62df\u5377 1 \u53ca\u7b54\u6848 \u6a21\u62df\u5377 2 \u53ca\u7b54\u6848 \u6a21\u62df\u5377 3 \u53ca\u7b54\u6848"},{"location":"programming/common/exam/#c-2013-2019","title":"\u3010\u5df2\u505c\u5f00\u3011C \u7a0b\u5e8f\u8bbe\u8ba1\u4e13\u9898\uff082013-2019\uff09","text":"

\u8be5\u8bfe\u7a0b\u5df2\u4e8e 2022-2023 \u5b66\u5e74\u505c\u5f00\u3002

\u5e74\u4efd \u8bd5\u5377 \u7b54\u6848 2013 \u8bd5\u5377 \u7b54\u6848 2014 \u8bd5\u5377 \u7b54\u6848 2015 \u8bd5\u5377 \u7b54\u6848 2016 \u8bd5\u5377 \u7b54\u6848 2017 \u8bd5\u5377 \u7b54\u6848 2018 \u8bd5\u5377 \u7b54\u6848 2019 \u8bd5\u5377 \u7b54\u6848"},{"location":"programming/common/exam/exam/","title":"\u5386\u5e74\u5377\u7ecf\u5178\u9898\u76ee\u89e3\u6790","text":""},{"location":"programming/common/exam/exam/#_2","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u57fa\u7840\u5e38\u95ee\u9898\u76ee\u96c6\u53ca\u89e3\u6790","text":"

C \u8bed\u8a00\u6742\u9879 \u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66\u5e38\u95ee\u9898\u76ee\u96c6\u53ca\u89e3\u6790 - \u9e64\u7fd4\u4e07\u91cc\u7684\u7b14\u8bb0\u672c \u662f @\u9e64\u7fd4\u4e07\u91cc 2022 \u5e74\u4e3a\u7afa\u9662\u8f85\u5b66\u73ed\u6574\u7406\u7684\u7a0b\u5e8f\u8bbe\u8ba1\u57fa\u7840\u5e38\u89c1\u95ee\u9898\u76ee\u96c6\u53ca\u89e3\u6790\u3002

"},{"location":"programming/common/exam/exam/#_3","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u4e13\u9898\u5386\u5e74\u5377\u7ecf\u5178\u9898\u76ee\u89e3\u6790","text":"

\u56fe\u5f62\u5e93\u76f8\u5173\u5185\u5bb9\u5df2\u4e0d\u518d\u51fa\u73b0\u5728\u8bfe\u7a0b\u4e2d

\u76ee\u524d\uff0c\u8bfe\u6539\u5df2\u7ecf\u5220\u53bb\u4e86\u56fe\u5f62\u5e93\u76f8\u5173\u5185\u5bb9\uff0c\u8fd9\u90e8\u5206\u5185\u5bb9\u4e0d\u4f1a\u518d\u51fa\u73b0\u5728\u6559\u5b66\u548c\u8003\u8bd5\u4e2d\uff0c\u6211\u4eec\u4e5f\u4f1a\u9010\u6b65\u5c06\u5176\u79fb\u9664\u3002

"},{"location":"programming/common/exam/exam/#_4","title":"\u7b97\u6cd5\u590d\u6742\u5ea6\u5206\u6790","text":""},{"location":"programming/common/exam/exam/#_5","title":"\u540e\u7f00\u8868\u8fbe\u5f0f","text":"

\u8fd9\u4e1c\u897f\u524d\u4e24\u4e09\u5e74\u90fd\u8003\u4e86\uff0c\u9700\u8981\u4e86\u89e3\u4e00\u4e0b\u3002\u5173\u4e8e\u8868\u8fbe\u5f0f\u6811\u7684\u76f8\u5173\u5185\u5bb9\u8bf7\u53c2\u89c1\uff1a

\u5728\u524d\u7f00\u3001\u4e2d\u7f00\u3001\u540e\u7f00\u8868\u8fbe\u5f0f\u4e4b\u95f4\u8fdb\u884c\u8f6c\u6362\u7684\u6700\u597d\u65b9\u6cd5\u662f\u5c06\u5176\u60f3\u8c61\u6210\u4e00\u4e2a\u6811\u72b6\u7ed3\u6784\u3002

\u503c\u5f97\u4e00\u63d0\u7684\u662f\u540e\u7f00\u8868\u8fbe\u5f0f\u5177\u6709\u51e0\u4e2a\u65b9\u4fbf\u7684\u6027\u8d28\uff1a

"},{"location":"programming/common/exam/exam/#2020-2021","title":"2020-2021 \u5e74\u5377","text":"

\u6ce8\u610f\u8fd9\u91cc\u7684 typedef struct{char * name;} *T; \u628a T \u5b9a\u4e49\u4e3a struct{char * name;}*; \u7684\u522b\u540d\u3002\u4e0b\u4e00\u4e2a\u8bed\u53e5\u5373\u58f0\u660e\u53d8\u91cf t \u4e3a\u8be5\u7c7b\u578b\u3002

\u51fd\u6570\u540d\u3001\u6570\u7ec4\u540d\u90fd\u4e0d\u662f\u6307\u9488\u54e6\uff0c\u867d\u7136\u5b83\u4eec\u5e38\u5e38\u9000\u5316\u6210\u6307\u9488\u3002

C \u8bed\u8a00\u4e2d\u4e00\u5171\u6709 5 \u4e2a\u5b58\u50a8\u7c7b\u522b\u9650\u5b9a\u7b26\uff0c\u8bf7\u56de\u5fc6\u5b83\u4eec\u7684\u4f5c\u7528\uff1a

\u5176\u5b9e typedef \u6309\u8bed\u6cd5\u529f\u80fd\u4e5f\u88ab\u5206\u5728\u8fd9\u4e00\u7c7b\uff0c\u6211\u4eec\u4e0d\u7ba1\u5b83\u3002

\u5728\u4efb\u4f55\u58f0\u660e\u4e2d\uff0c\u53ea\u80fd\u540c\u65f6\u5b58\u5728\u6700\u591a\u4e00\u4e2a\u5b58\u50a8\u7c7b\u522b\u9650\u5b9a\u7b26\u3002\u8fd9\u4e0e const\u3001volatile\u3001restrict \u7b49\u7c7b\u578b\u9650\u5b9a\u7b26\u4e0d\u540c\uff0c\u5b83\u4eec\u53ef\u4ee5\u540c\u65f6\u5b58\u5728\u3002

\u89c1 2019 \u5e74\u9009\u62e9\u9898 6

\u8fd9\u79cd\u9898\u901a\u7528\u7684\u65b9\u6cd5\u5c31\u662f\u6bcf\u4e2a\u9009\u9879\u5c1d\u8bd5\u4e00\u904d\u3002\u53ea\u8981\u5bf9\u6808\u3001\u961f\u5217\u64cd\u4f5c\u719f\u6089\u7684\u8bdd\uff0c\u4e00\u4e2a\u4e2a\u8bd5\u5f88\u5feb\u5c31\u51fa\u6765\u4e86\u3002

\u5982\u679c\u4f60\u7684\u7b54\u6848\u548c\u53c2\u8003\u7b54\u6848\u4e0d\u4e00\u6837\uff0c\u4e5f\u662f\u6709\u5bf9\u7684\u53ef\u80fd\u7684\uff0c\u5c31\u50cf\u4e2d\u7f00\u8868\u8fbe\u5f0f\u90a3\u6837\uff0c\u4e8c\u5143\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\u6570\u662f\u53ef\u4ee5\u6362\u5e8f\u7684\uff08

\u6ce8\u610f\u8fd9\u9053\u9898\u4e2d\u7684 ^ \u8fd0\u7b97\u7b26\u7684\u53f3\u7ed3\u5408\u95ee\u9898\uff0c\u52a0\u4e0a\u62ec\u53f7\u540e\u53d8\u6210 d^(e^f) \u800c\u4e0d\u662f (d^e)^f\uff0c\u8f6c\u6362\u6210\u540e\u7f00\u8868\u8fbe\u5f0f\u53ea\u80fd\u662f def^^\uff0c\u800c fed^^ \u4e4b\u7c7b\u7684\u5168\u662f\u9519\u7684\u3002

\u89c1\u5e38\u89c1\u95ee\u9898 - \u7b97\u6cd5\u590d\u6742\u5ea6

\u5f15\u7528\u4e00\u4e0b ztgg \u7684\u89e3\u91ca\uff1a

\u5982\u679c\u7b2c\u4e00\u4e2a while \u5faa\u73af\u8bfb\u4e0d\u61c2\u4e00\u5b9a\u8981\u627e\u540c\u5b66/\u8001\u5e08\u95ee\u6e05\u695a\u634f\uff0c\u961f\u5217\u7684\u4f7f\u7528\u662f\u5f88\u57fa\u672c\u7684\u3002\u8bf7\u601d\u8003\u8fd9\u4e2a while \u5faa\u73af\u4e3a\u4ec0\u4e48\u9700\u8981\u9010\u4e2a malloc() \u5462\uff1f

\u4e2d\u95f4\u90a3\u4e2a while \u5faa\u73af\u6709\u70b9\u8ff7\u60d1\u3002\u5b83\u5176\u5b9e\u53ea\u662f\u5728\u5c06 eQueue \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u653e\u5230 dQueue \u65f6\u540c\u65f6\u628a\u540e\u9762\u4e00\u4e2a\u5143\u7d20\u6362\u5230\u961f\u5c3e\u53bb\u3002\u7406\u89e3\u5230\u8fd9\u91cc\u5c31\u80fd\u505a\u5bf9\u5566\u3002

\u8fd9\u51e0\u4e2a\u7a7a\u90fd\u9700\u8981\u82b1\u4e00\u4f1a\u513f\u65f6\u95f4\u6765\u63a8\u65ad\u7684\uff1a

\u60f3\u8c61\u4e00\u4e2a\u89e3\u8c1c\u573a\u666f\uff1a\u5982\u679c\u4f60\u548c\u4f60\u7684\u670b\u53cb\u8d70\u5728\u4e00\u6761\u8def\u4e0a\uff0c\u4f60\u4eec\u8981\u600e\u4e48\u505a\u624d\u80fd\u5224\u65ad\u6709\u6ca1\u6709\u9047\u5230\u9b3c\u6253\u5899\uff08\u5373\u5728\u539f\u8def\u7ed5\u5708\uff09 \uff1f

\u7b54\u6848\u5f88\u7b80\u5355\uff1a\u4e00\u4e2a\u4eba\u8d70\u5feb\u70b9\uff0c\u4e00\u4e2a\u4eba\u8d70\u6162\u70b9\u3002\u5982\u679c\u8fd9\u6761\u8def\u6709\u5c3d\u5934\uff0c\u5148\u8d70\u7684\u4eba\u4e00\u5b9a\u4f1a\u5148\u5230\u8fbe\u5c3d\u5934\uff1b\u5982\u679c\u6ca1\u6709\u5230\u8fbe\u5c3d\u5934\uff0c\u90a3\u4e48\u4ed6\u4e00\u5b9a\u4f1a\u91cd\u65b0\u770b\u89c1\u4f60\u3002

LoopDetect() \u51fd\u6570\u7684\u601d\u8def\u4e5f\u7c7b\u4f3c\uff1a\u4f7f\u7528\u4e24\u4e2a\u6307\u9488 fast \u548c late\uff0cfast \u6bcf\u6b21\u6b65\u8fdb\u4e24\u4e2a\u8282\u70b9\uff0clate \u6bcf\u6b21\u6b65\u8fdb\u4e00\u4e2a\u8282\u70b9\u3002\u6700\u540e\u7ec8\u6b62\u65f6\u53ea\u6709\u4e24\u79cd\u6761\u4ef6\uff1afast \u65e0\u6cd5\u7ee7\u7eed\u6b65\u8fdb\u6216 fast \u5728\u524d\u8fdb\u7684\u8def\u4e0a\u770b\u89c1 late\u3002\u524d\u8005\u8868\u660e\u6ca1\u6709\u5faa\u73af\uff0c\u540e\u8005\u8868\u660e\u6709\u5faa\u73af\u3002

\u770b\u5230\u8fd9\u9053\u9898\u4f60\u6709\u6ca1\u6709\u60f3\u8d77\u5b57\u7b26\u4e32\u53bb\u7a7a\u683c\u7684\u4e00\u4e2a\u4f8b\u7a0b\uff1f

char *a;\nfor(int i = 0, j = 0; i < length; i++){\n    if(a[i] != ' ')\n        a[j++] = a[i];\n}\n

\u6709\u5e8f\u6570\u7ec4\u53bb\u91cd\u4e0e\u8fd9\u4e2a\u7b97\u6cd5\u4e5f\u6709\u4e9b\u7c7b\u4f3c\uff0c\u53ea\u662f\u6bd4\u8f83\u6761\u4ef6\u6362\u6210 a[i]!=a[j] \u4e86\u800c\u5df2\u3002

"},{"location":"programming/common/exam/exam/#2019-2020","title":"2019-2020 \u5e74\u5377","text":"

\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1a\u4f5c\u4e3a\u51fd\u6570\u4f5c\u4e3a\u5f62\u53c2\uff0c\u4f1a\u81ea\u52a8\u9000\u5316\u6210\u51fd\u6570\u6307\u9488\uff0c\u5c31\u50cf\u6570\u7ec4\u540d\u4f5c\u4e3a\u5f62\u53c2\u81ea\u52a8\u9000\u5316\u6210\u6307\u9488\u90a3\u6837\u3002\u8fd9\u53e5\u8bdd\u5728\u4e0b\u9762\u7684\u82f1\u6587\u90e8\u5206\u63d0\u5230\u4e86\u3002

The type of a function is determined using the following rules. [...] After determining the type of each parameter, any parameter of type \u201carray of T\u201d or of function type T is adjusted to be \u201cpointer to T\u201d. [...]

As mentioned in dcl.fct of the working draft (emphasis mine):

The type of a function is determined using the following rules. [...] After determining the type of each parameter, any parameter of type \u201carray of T\u201d or of function type T is adjusted to be \u201cpointer to T\u201d. [...]

Because of that, the following function:

void f(void());\n

Has the same type of:

void f(void(*)());\n

Thus the definitions below are identical:

void f(void(g)());\nvoid f(void(*g)());\n

Correct me if I'm wrong, AFAIK function names are pointers just like array names so in the first example you are passing function object and compiler does implicit conversion, in the second example you are directly passing function pointer which is explicit conversion.

\u540c\u6837\u4f9d\u636e\u4e0a\u9762\u7684\u8bb2\u89e3\u80fd\u591f\u9009\u51fa\u6b63\u786e\u7b54\u6848

\u6211\u89c9\u5f97 D \u9879\u7684\u8868\u8ff0\u672c\u6765\u5c31\u5f88\u6df7\u4e71\u3002\u51fd\u6570\u53c2\u6570\u5982\u679c\u4e3a void \u5c31\u8868\u793a\u51fd\u6570\u4e0d\u63a5\u6536\u53c2\u6570\uff0c\u8fd9\u5c31\u662f void \u5173\u952e\u5b57\u7684\u4f5c\u7528\uff0c\u800c\u4e0d\u662f\u9009\u9879\u4e2d\u8bf4\u7684\u4ec0\u4e48\u201c\u51fd\u6570\u6709\u4e00\u4e2a void \u7c7b\u578b\u7684\u53c2\u6570\u201d\u3002

\u8bf7 WK \u73ed\u540c\u5b66\u4e00\u5b9a\u8981\u53bb\u770b\u8f85\u5b66\u7fa4\u91cc\u5176\u4ed6\u8001\u5e08\u7684\u56fe\u5f62\u5e93\u8bfe\u4ef6

\u5982\u679c\u7a0b\u5e8f\u4ee3\u7801\u6709\u9519\uff0c\u5c31\u52c7\u6562\u5730\u5199\u201c\u8be5\u6bb5\u7a0b\u5e8f\u53ef\u80fd\u8fd0\u884c\u5931\u8d25\u201d\u3002

\u6ce8\u610f\uff0c\u5408\u5e76\u6570\u7ec4\u7684\u65f6\u5019\u90e8\u5206\u53bb\u91cd\u4e86\u3002\u5982\u679c\u79bb\u5f00\u4e86\u7b2c\u4e00\u4e2a while \u5faa\u73af\uff0c\u5219\u4e0d\u4f1a\u53bb\u91cd\u3002

\u8ba9\u6211\u4eec\u770b main() \u51fd\u6570\u7684\u7b2c\u4e00\u884c\u7684\u8868\u8fbe\u5f0f\uff1a

WK \u73ed\u540c\u5b66\u5e94\u5f53\u8865\u5145\u9605\u8bfb libgraphics \u5e93\u4e2d\u7684\u4e00\u4e9b\u5185\u5bb9\uff0c\u6211\u4eec\u76f4\u63a5\u8bfb\u6e90\u7801\u5427\uff1a

\u7b2c 15 \u7a7a\u6709\u610f\u601d\uff0cFreeBlock(PopStack(stack)) \u7684\u5d4c\u5957\u5199\u6cd5\u3002

\u8fd9\u7c7b\u7b97\u6cd5\u8bbe\u8ba1\u9898\u76ee\uff0c\u600e\u4e48\u7b80\u6d01\u600e\u4e48\u6765\uff0c\u4ee5 OI \u7801\u98ce\u53bb\u5199\u662f\u6700\u5408\u9002\u7684\u3002\u4e0d\u8981\u8bd5\u56fe\u5f04\u5b8c\u5584\u7684\u4ea4\u4e92\uff0c\u90a3\u662f\u6d6a\u8d39\u65f6\u95f4\u3002

\u4ee5\u4e0b\u662f\u6211\u81ea\u5df1\u505a\u7684\u65f6\u5019\u5199\u7684\uff0c\u4f5c\u4e3a\u4e00\u4e2a\u4e0d\u597d\u7684\u53c2\u8003\uff08

\u7406\u89e3\u9519\u9898\u610f\u4e86\uff0c\u539f\u6765 order \u4e0d\u662f\u65b9\u5411\u800c\u662f\u5206\u5f62\u6b21\u5e8f\u3002

\u5c31\u7528\u6807\u7b54\u7684\u65b9\u6cd5\uff0c\u5c06\u5076\u6570\u8282\u70b9\u79fb\u52a8\u5230\u53e6\u4e00\u4e2a\u94fe\u8868\uff0c\u518d\u5408\u5e76\u4e24\u4e2a\u94fe\u8868\u3002

"},{"location":"programming/common/exam/exam/#2018-2019","title":"2018-2019 \u5e74\u5377","text":"

\u50cf\u8fd9\u79cd\u9012\u5f52\u8ba1\u7b97\uff0c\u5c31\u8001\u8001\u5b9e\u5b9e\u628a\u51fd\u6570\u9012\u5f52\u5c55\u5f00\u5427\u3002\u5c55\u5f00\u8fc7\u7a0b\u4e2d\u8bb0\u5f97\u4f9d\u6b21\u8bb0\u4e0b\u5df2\u7ecf\u8ba1\u7b97\u5b8c\u7684 f(0)\u3001f(1) \u7b49\u503c\uff0c\u65b9\u4fbf\u540e\u7eed\u8ba1\u7b97\u3002

\u8fd9\u9053\u9898\u6211\u7684\u60f3\u6cd5\u633a\u5947\u8469\u7684\uff0c\u6211\u662f\u60f3\u53ea\u8981\u5168\u90e8\u6392\u5e8f\u4e00\u904d \\(O(N\\log N)\\)\uff0c\u7136\u540e\u7528 \\(O(1)\\) \u7684\u65f6\u95f4\u68c0\u67e5\u4e00\u4e0b\u5934\u3001\u4e2d\u95f4\u3001\u5c3e\u90e8\u7684\u5143\u7d20\u4e0d\u5c31\u597d\u4e86\u5417\uff08doge

\u524d\u7f00\u9012\u589e\u8fd0\u7b97\u7b26\u5148\u9012\u589e\u518d\u4f7f\u7528\u3002

\u672c\u9898\u82f1\u6587\u6709\u70b9\u70eb\u5634\uff0c\u6211\u7ffb\u8bd1\u4e00\u4e0b\uff1a

\u4e3a\u4e86\u7528\u7c7b\u4f3c T p \u7684\u65b9\u5f0f\u58f0\u660e\u4e00\u4e2a\u6307\u9488 p\uff0c\u8bf7\u5199\u51fa\u590d\u5408\u7c7b\u578b T \u7684\u5b9a\u4e49\u3002p \u662f\u4e00\u4e2a\u51fd\u6570\u7684\u6307\u9488\uff0c\u8be5\u51fd\u6570\u63a5\u6536 (char *, double) \u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a int *\u3002

\u8bfb\u61c2\u9898\u76ee\u5269\u4e0b\u7684\u5c31\u4e0d\u7528\u8bf4\u5566\u3002

\u6ce8\u610f\uff1axx-bit system\uff08n \u4f4d\u7cfb\u7edf\uff09\u6307\u7684\u662f\u8fd9\u4e2a\u7cfb\u7edf\u7684\u6307\u9488\u957f\u5ea6\u6709 \\(n\\) \u6bd4\u7279\uff0c\\(8\\) \u6bd4\u7279\u4e3a\u4e00\u4e2a\u5b57\u8282\u3002\u6545\u672c\u9898\u7684\u6240\u6709\u6307\u9488\u90fd\u662f \\(4\\) \u5b57\u8282\u3002

\u4ee5\u4e0b\u662f\u5404\u7c7b\u578b\u7684\u5927\u5c0f\uff1a

\u4ece\u4e0a\u9762\u518d\u6b21\u770b\u5230\uff0c\u6570\u7ec4\u540d\u5e76\u4e0d\u80fd\u7b80\u5355\u88ab\u770b\u4f5c\u6307\u9488\uff0c\u5b83\u8fd8\u5305\u542b\u6570\u7ec4\u7684\u7c7b\u578b\u4fe1\u606f\u3002

\u8fd9\u9053\u9898\u7b54\u6848\u611f\u89c9\u6709\u70b9\u95ee\u9898\u554a\u3002\u53cd\u6b63\u53ea\u8981\u77e5\u9053\u8fd4\u56de\u7684\u65f6\u5019 p \u6307\u5411 \\(2\\) \u8fd9\u4e2a\u8282\u70b9\u5c31\u7b97\u5bf9\u4e86\uff0c\u9898\u76ee\u8bf4 node \u90a3\u5e94\u8be5\u4e0d\u7528\u5427\u540e\u9762\u7684\u8282\u70b9\u90fd\u5199\u51fa\u6765\u5427\u3002

\u8fd9\u4e2a\u51fd\u6570\u5408\u5e76\u4e86\u4e24\u4e2a\u94fe\u8868\uff0c\u6309\u5347\u5e8f\u5408\u5e76\u3002

HEAD \u662f\u4e00\u4e2a\u4e34\u65f6\u4f7f\u7528\u7684\u54d1\u8282\u70b9\u3002

\u8c03\u7528\u540e\uff0c\u539f\u6765\u7684\u4e24\u4e2a\u6307\u9488\u6307\u7684\u4f4d\u7f6e\u4e0d\u53d8\uff0cl1 \u4ecd\u7136\u6307\u5411 \\(1\\) \u8fd9\u4e2a\u8282\u70b9\u3002\u4f46\u8282\u70b9\u4e4b\u95f4\u7684\u8fde\u63a5\u53d8\u4e86\uff0c\u8fd9\u65f6 l1 \u540e\u9762\u94fe\u4e0a\u4e86\u4ece l2 \u5408\u5e76\u8fdb\u6765\u7684\u5176\u4ed6\u8282\u70b9\u3002\u6240\u4ee5\u53ef\u4ee5\u770b\u4f5c\u201c\u94fe\u8868\u201d l1 \u53d1\u751f\u4e86\u6539\u53d8\u3002

\u8fd9\u662f\u4e00\u4e2a\u53cc\u5411\u7684\u6808\u3002\u6bcf\u6b21\u5165/\u51fa\u6808\u65f6\uff0c\u9700\u8981\u7528 Tag \u53c2\u6570\u6307\u5b9a\u662f\u54ea\u4e00\u5934\u3002\u4ece\u6570\u7ec4\u7684\u89d2\u5ea6\u6765\u770b\uff0cTop1 \u662f\u5de6\u8fb9\uff08\u5934\u90e8\uff09\u90a3\u5934\uff0cTop2 \u662f\u53f3\u8fb9\uff08\u5c3e\u90e8\uff09\u90a3\u5934\u3002

\u8bfb\u8fd9\u79cd\u9898\u65f6\uff0c\u6211\u63a8\u8350\u5148\u8bfb main() \u4e2d\u7684\u5185\u5bb9\uff0c\u5373\u89c2\u5bdf\u9898\u76ee\u7ed9\u7684\u6570\u636e\u7ed3\u6784\u662f\u600e\u4e48\u88ab\u4f7f\u7528\u7684\u3002\u7136\u540e\u4e0d\u660e\u767d\u7684\u5730\u65b9\u518d\u53bb\u770b\u5177\u4f53\u5b9e\u73b0\u7684\u4ee3\u7801\uff0c\u5176\u4ed6\u90e8\u5206\u5c31\u4e00\u70b9\u90fd\u4e0d\u7528\u770b\u3002\u6bd4\u5982\u8fd9\u9053\u9898\uff1a

\u8fd9\u4e2a\u4e1c\u897f\uff0c\u4fdd\u9669\u8d77\u89c1\u63a8\u8350\u624b\u5de5\u6a21\u62df\uff0c\u800c\u4e14\u624b\u5de5\u6a21\u62df\u51e0\u6b21\u540e\u4f60\u5c31\u77e5\u9053\u8fd9\u4e2a\u51fd\u6570\u5728\u5e72\u561b\u4e86\u3002

\u5176\u5b9e\u8fd9\u4e2a\u51fd\u6570\u7684\u4f5c\u7528\u662f\uff1a\u8c03\u7528\u540e\u4fdd\u8bc1\u6570\u7ec4 a[k] \u5de6\u4fa7\u7684\u5143\u7d20\u90fd\u6bd4 a[k] \u5c0f\uff0c\u53f3\u4fa7\u90fd\u6bd4 a[k] \u5927\u3002\u6700\u540e\u8fd4\u56de a[k] \u4e0a\u7684\u5143\u7d20\u3002\u4f46\u4e0d\u4f1a\u4fdd\u8bc1\u5176\u4ed6\u5143\u7d20\u4e4b\u95f4\u7684\u76f8\u5bf9\u987a\u5e8f\u3002

\u5177\u4f53\u7684\u64cd\u4f5c\u5c31\u662f\uff1a\u6bcf\u8f6e\u5faa\u73af\u628a\u7b2c a[k] \u4f4d\u7f6e\u4e0a\u7684\u5143\u7d20\u63d0\u51fa\u6765\u4f5c\u4e3a x\uff0c\u7136\u540e\u7528 i \u548c j \u5206\u522b\u4ece\u5de6\u53f3\u904d\u5386\u5e76\u4ea4\u6362\u4e24\u4fa7\u4e0d\u7b26\u5408\u8981\u6c42\u7684\u6570\u3002\u4ea4\u6362\u5b8c\u6210\u540e\uff0c\u6570\u7ec4\u4e2d\u6bd4 x \u5c0f\u7684\u6570\u90fd\u5728\u76f8\u5bf9\u5de6\u8fb9\u7684\u4f4d\u7f6e\uff0c\u6bd4 x \u5927\u7684\u6570\u90fd\u5728\u76f8\u5bf9\u53f3\u8fb9\u7684\u4f4d\u7f6e\u3002

\u5982\u679c\u4f60\u5bf9\u5feb\u6392\u6bd4\u8f83\u719f\u6089\uff0c\u90a3\u4e48\u8fd9\u5c31\u662f\u201c\u5982\u679c\u76ee\u6807\u4f4d\u7f6e\u4e0d\u5728\u7684\u4e00\u8fb9\u76f4\u63a5\u820d\u5f03\u201d\u7684\u5feb\u6392\u3002\u76f8\u5f53\u4e8e\u672c\u6765\u5feb\u6392\u533a\u95f4\u5f62\u6210\u4e00\u9897\u6811\uff0c\u4f46\u662f\u73b0\u5728\u5c31\u53ea\u8d70\u4e00\u6761\u8def\uff0c\u53ea\u6392 a[k] \u6240\u5728\u7684\u90a3\u4e9b\u533a\u95f4\u5957\u3002

\u672c\u8d28\u4e0a\u8fd8\u662f\u7528\u6570\u7ec4\u5b9e\u73b0\u5faa\u73af\u961f\u5217\uff0c\u53ea\u4e0d\u8fc7\u672c\u9898\u8fdb\u884c\u4e86\u6bd4\u8f83\u5b8c\u5584\u7684\u5c01\u88c5\u3002

\u5982\u679c\u8fd8\u4e0d\u77e5\u9053\u5faa\u73af\u961f\u5217\u662f\u4ec0\u4e48\u4e1c\u897f\uff0c\u53bb\u7f51\u4e0a\u641c\u4e00\u641c\u3002\u5faa\u73af\u961f\u5217\u7684\u8981\u70b9\u5c31\u662f\uff1a\u6240\u6709\u52a0\u6cd5\u64cd\u4f5c\u5168\u90e8\u8981\u5957\u4e0a\u4e00\u6b21\u53d6\u6a21\u64cd\u4f5c\u3002\u672c\u9898\u6ce8\u610f\u4e00\u4e0b\u95f4\u63a5\u6210\u5458\u8fd0\u7b97\u7b26 -> \u7684\u4f7f\u7528\u3002

\u6b64\u5916\u5faa\u73af\u961f\u5217\u7684 rear \u4e5f\u6709\u4e0d\u540c\u5b9e\u73b0\u65b9\u6cd5\uff0c\u5728\u672c\u9898\u4e2d\uff0c\u5b83\u6807\u5fd7\u961f\u5217\u5c3e\u90e8\u7684\u540e\u4e00\u4e2a\u5143\u7d20\uff0c\u4e5f\u5c31\u662f\u4e0b\u4e00\u4e2a\u5143\u7d20\u5e94\u8be5\u63d2\u5165\u7684\u5730\u65b9\uff1b\u5728\u53e6\u4e00\u4e9b\u5b9e\u73b0\u4e2d\uff0c\u5b83\u76f4\u63a5\u6807\u5fd7\u961f\u5217\u5c3e\u90e8\u7684\u5143\u7d20\u3002\u6bd4\u5982\u5982\u679c\u672c\u9898\u5728\u521b\u5efa\u6570\u7ec4\u7684\u65f6\u5019 Q->rear = maxsize - 1\uff0c\u8fd9\u4e9b\u7a7a\u5e94\u8be5\u4f5c\u600e\u6837\u7684\u6539\u53d8\u5462\uff1f

\u53c2\u89c1\u5e38\u89c1\u95ee\u9898 - \u56fe\u5f62\u5e93 - \u8ba1\u65f6\u5668

\u60f3\u8c61\u8fd9\u6837\u4e00\u4e2a\u60c5\u5883\uff1a\u8fd8\u662f\u60f3\u8c61\u4f60\u548c\u4f60\u7684\u670b\u53cb\u7ad9\u5728\u9898\u76ee\u6240\u793a\u7684\u4e24\u4e2a\u94fe\u8868\u7684\u8d77\u59cb\u5904\u3002\u8fd9\u4e24\u4e2a\u94fe\u8868\u6709\u53ef\u80fd\u76f8\u4ea4\uff0c\u4f60\u4eec\u60f3\u8981\u5c3d\u5feb\u627e\u5230\u4f1a\u5408\u70b9\uff0c\u600e\u4e48\u529e\u5462\uff1f\u800c\u4e14\u4e00\u4e2a\u6709\u7528\u7684\u4fe1\u606f\u662f\uff0c\u4f60\u4eec\u90fd\u77e5\u9053\u81ea\u5df1\u79bb\u7ec8\u70b9\u8fd8\u6709\u591a\u8fdc\u3002

\u5982\u679c\u76f8\u4ea4\uff0c\u4f60\u4eec\u80af\u5b9a\u6709\u516c\u5171\u5b50\u94fe\u8868\u3002\u5269\u4e0b\u4e0d\u540c\u7684\u90e8\u5206\u5c31\u662f\u4f60\u4eec\u5404\u81ea\u5b50\u94fe\u8868\u7684\u957f\u5ea6\u3002\u56e0\u6b64\uff0c\u4f60\u4eec\u5e94\u5f53\u5148\u76f8\u5bf9\u7ec8\u70b9\u5bf9\u9f50\u5f7c\u6b64\u7684\u4f4d\u7f6e\uff0c\u4f7f\u81ea\u5df1\u5269\u4f59\u7684\u5b50\u94fe\u8868\u7684\u7684\u957f\u5ea6\u76f8\u7b49\u3002\u63a5\u4e0b\u6765\u4ee5\u76f8\u540c\u7684\u901f\u5ea6\u524d\u8fdb\uff0c\u5982\u679c\u4f60\u4eec\u5728\u67d0\u5904\u4f1a\u5408\u4e86\uff0c\u90a3\u4e48\u8fd9\u4e00\u5b9a\u662f\u516c\u5171\u5b50\u94fe\u8868\u7684\u8d77\u59cb\u5904\u3002

\u53c2\u7b54\u4e2d\uff0clPtr \u6307\u5411\u8f83\u957f\u7684\u94fe\u8868\uff0csPtr \u6307\u5411\u8f83\u77ed\u7684\u94fe\u8868\uff0cnumLeftNodes \u5c31\u662f\u4e24\u94fe\u8868\u8282\u70b9\u6570\u7684\u5dee\u503c\uff0clPtr=lPtr->next \u7684 for \u5faa\u73af\u5c31\u662f\u5728\u5bf9\u9f50\u4e24\u4eba\u7684\u4f4d\u7f6e\u3002

\u5faa\u73af\u7ec8\u6b62\u7684\u6761\u4ef6\u662f\uff1a\u5176\u4e2d\u67d0\u4eba\u8d70\u5230\u4e86\u5c3d\u5934 NULL\uff0c\u6216\u4e24\u4eba\u76f8\u9047 lPtr==sPtr\u3002\u8fd4\u56de\u6700\u7ec8\u4f4d\u7f6e\u5373\u53ef\u3002

\u8fd9\u9898\u7b80\u5355\uff0c\u4e0d\u4f5c\u89e3\u6790\u3002\u53c2\u7b54\u4e2d\u6f0f\u4e86\u68c0\u67e5 minPos == rh \u7684\u60c5\u51b5\uff0c\u60f3\u60f3\u8fd9\u6837\u4f1a\u9020\u6210\u4ec0\u4e48\u540e\u679c\uff1f

"},{"location":"programming/common/exam/exam/#2017-2018","title":"2017-2018 \u5e74\u5377","text":"

\u8fd9\u9053\u9898\u65f6\uff0c\u6211\u9009\u7684\u662f D \u9879\u3002\u56e0\u4e3a\u6211\u8bb0\u5fc6\u4e2d\u7684\u5192\u6ce1\u6392\u5e8f\u662f\u8fd9\u6837\u7684\uff1a

void bubble_sort(int *arr, int len) {\n int i, j, tmp;\n for (i = 0; i < len - 1; i++) {\n     for (j = len - 1; j > i; j--) {//Bubble\n         if (arr[j] < arr[j - 1]) {\n             tmp = arr[j];\n             arr[j] = arr[j - 1];\n             arr[j - 1] = tmp;\n         }\n     }\n }\n}\n

\u4e0a\u9762\u8fd9\u6837\u7684\u5199\u6cd5\u5bf9\u4e8e\u4efb\u4f55\u60c5\u51b5\u7684\u590d\u6742\u5ea6\u90fd\u662f \\(O(n^2)\\)\u3002\u4f46\u662f\u5192\u6ce1\u6392\u5e8f\u666e\u904d\u4f1a\u4f5c\u8fd9\u6837\u7684\u4f18\u5316\uff1a

\u56e0\u6b64\u53ef\u4ee5\u5728\u5916\u5faa\u73af\u5f00\u5934\u6dfb\u52a0 bool flag = 0;\uff0c\u7ed3\u5c3e\u6dfb\u52a0 if(!flag)break;\uff0c\u4ea4\u6362\u64cd\u4f5c\u4e2d\u6dfb\u52a0 flag=true \u5373\u53ef\u5c06\u6700\u4f18\u60c5\u51b5\u4f18\u5316\u81f3 \\(O(n)\\)\u3002

\u5148\u60f3\u60f3\u81ea\u5df1\u4f1a\u600e\u4e48\u8c03\u7528\u8fd9\u4e2a fun \u51fd\u6570\u624d\u80fd\u5f97\u5230 void \u7c7b\u578b\uff1a

\u5f97\u5230\u4e86\u7b54\u6848\uff1avoid (*fun(int))(int)\u3002

\u5176\u5b9e\u8fd9\u662f\u4e00\u4e2a\u7ecf\u5178\u7684\u7b97\u6cd5\uff1a\u6240\u6709\u8fde\u7eed\u5b50\u5217\u5143\u7d20\u7684\u548c\u4e2d\u6700\u5927\u8005\u3002\u5728\u7f51\u4e0a\u53ef\u4ee5\u641c\u5230\u5f88\u591a\u8be5\u7b97\u6cd5\u7684\u539f\u7406\u4ecb\u7ecd\uff0c\u8bf7\u53bb\u770b\u4e00\u770b\uff0c\u770b\u5b8c\u5c31\u80fd\u7acb\u523b\u660e\u767d\u8fd9\u6bb5\u4ee3\u7801\u4e86\u3002

thisp \u88ab\u653e\u7f6e\u5728\u6700\u5927\u5b50\u5217\u7684\u5f00\u5934\uff0cmaxp \u88ab\u653e\u7f6e\u5728\u6700\u5927\u5b50\u5217\u7684\u672b\u5c3e\u3002

\u57fa\u4e8e\u6bd4\u8f83\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u5927\u6982\u90fd\u80fd\u4f18\u5316\u5230\u6700\u4f18\u60c5\u51b5\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u5427\uff1f

\u8fd9\u9898\u86ee\u5751\u7684\uff0c\u6211\u770b\u4e86\u597d\u4e00\u4f1a\u513f\u624d\u660e\u767d\u7b2c (7)(8) \u7a7a\u5728\u5e72\u561b\u3002\u5b83\u5176\u5b9e\u5c31\u662f\u5148\u628a\u524d\u9762\u7684\u9ad8\u6b21\u9879\u63d0\u516c\u56e0\u5f0f\uff0c\u7136\u540e\u5728\u9010\u6b65\u5411\u540e\u6c42\u548c\u7684\u8fc7\u7a0b\u7ed9\u5b83\u6574\u4f53\u4e58\u4e0a \\(x\\)\u3002\u6bd4\u5982 \\(3x^4+2x^2+1\\) \u53ef\u4ee5\u8fd9\u6837\u8ba1\u7b97\uff1a

\u8fd9\u6837\u505a\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u51cf\u5c11\u4e86\u8ba1\u7b97\u4e58\u79ef\u7684\u6b21\u6570\u3002

\u540c\u6837\u6ce8\u610f -> \u8fd0\u7b97\u7b26\u7684\u4f7f\u7528\u3002

"},{"location":"programming/common/exam/exam/#2016-2017","title":"2016-2017 \u5e74\u5377","text":"

\u6ce8\u610f\u9898\u76ee\u4e2d\u8bf4\u660e\u4e86\u6808\u9876\u6307\u9488\u4f4d\u4e8e N\uff0c\u8fd9\u4e2a\u6808\u662f\u4ece\u6570\u7ec4\u7684\u5c3e\u90e8\u5f00\u59cb\u7d2f\u79ef\u7684\u3002

\u7b80\u5355\u51fd\u6570\u6307\u9488\uff0c\u76f4\u63a5\u8fd9\u6837\u8bb0\uff1atypedef \u8fd4\u56de\u7c7b\u578b (*\u65b0\u540d\u5b57)(\u53c2\u6570\u5217\u8868)

\u548c\u524d\u4e00\u5e74\u7684\u4f8f\u5112\u6392\u5e8f\u6709\u70b9\u50cf\uff0c\u6709\u5e8f\u60c5\u51b5\u4e5f\u662f\u4e00\u904d\u8fc7\uff0c\u6700\u4f18\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u662f \\(O(n)\\)\u3002

\u8fc7\u7a0b\u4e2d\uff0c\u8be5\u94fe\u8868\u987a\u5e8f\u88ab\u91cd\u65b0\u6392\u5217\u3002\u6bd4 x \u5c0f\u7684\u8282\u70b9\u4f9d\u6b21\u79fb\u52a8\u5230 root \u4e3a\u9996\u7684\u5e26\u54e8\u5175\u94fe\u8868\u4e2d\uff0c\u5927\u7684\u4f9d\u6b21\u79fb\u52a8\u5230 pivot \u4e3a\u9996\u7684\u54e8\u5175\u94fe\u8868\u4e2d\uff0c\u6700\u540e\u5c06\u4e24\u4e2a\u94fe\u8868\u5408\u5e76\uff0c\u8fd4\u56de\u5408\u5e76\u540e\u7684\u94fe\u8868\u3002

\u672c\u9898\u5176\u5b9e\u5c31\u662f\u5728\u4ece\u5c0f\u5230\u8fbe\u6c42\u56e0\u6570\u3001\u7ea6\u53bb\u8fd9\u4e2a\u56e0\u6570\u3001\u6c42\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u56e0\u6570...\u3002\u6a21\u62df\u4e00\u904d\u5373\u53ef\u3002

\u6392\u5e8f\u539f\u7406\u9898\u76ee\u5df2\u7ecf\u8bb2\u6e05\u695a\u4e86\uff0c\u8fd9\u91cc\u8bb2\u4e00\u4e0b\u5faa\u73af\u4e2d\u51e0\u4e2a\u53d8\u91cf\u7684\u4f5c\u7528\uff1a

\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0c\u8fd9\u4e24\u4e2a\u94fe\u8868\u90fd\u662f\u96c6\u5408\uff0c\u8fd9\u610f\u5473\u7740\u5176\u4e2d\u7684\u5143\u7d20\u90fd\u662f\u552f\u4e00\u7684\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u8003\u8651\u91cd\u590d\u5143\u7d20\u7684\u60c5\u51b5\uff0c\u4e0d\u9700\u8981\u5b8c\u6574\u904d\u5386 \\(A\\)\u3002

"},{"location":"programming/common/exam/exam/#2015-2016","title":"2015-2016 \u5e74\u5377","text":"

\u5b8f\u5c55\u5f00\u53ea\u662f\u7b80\u5355\u7684\u6587\u672c\u66ff\u6362\u3002

\u4ece\u4e0a\u9762\u7684\u5c55\u5f00\u4e2d\u6211\u4eec\u770b\u5230\uff0c\u5b8f\u51fd\u6570\u7684\u5c55\u5f00\u987a\u5e8f\u5e76\u4e0d\u91cd\u8981\u3002\u6700\u7ec8\u7ed3\u679c\u5e94\u5f53\u4e00\u81f4\u3002

"},{"location":"programming/common/notes/funcptr/","title":"\u51fd\u6570\u6307\u9488\u8ba4\u8bfb","text":"

\u9996\u5148\uff0c\u8ba9\u6211\u4ecb\u7ecd\u4e00\u4e0b\u4e24\u4e2a\u60f9\u4eba\u559c\u7231\u7684\u5c0f\u5bb6\u4f19\u3002

int function(int arg)\n{\n    return 2 * arg;\n}\n

\u4e00\u822c\u901a\u8fc7\u51fd\u6570\uff0c\u7c7b\u578b\u662f int (int)\u3002

int (*func_ptr)(int);\n

\u829d\u58eb\u4ec0\u4e48\uff1f\u829d\u58eb\u51fd\u6570\u6307\u9488\uff0c\u7c7b\u578b\u662f int (*)(int)\u3002

\u90a3\u4e48\uff0c\u8fd9\u4e24\u4e2a\u5c0f\u5bb6\u4f19\u80fd\u5e72\u4ec0\u4e48\u5462\uff1f

func_ptr = &function;\nfunc_ptr = function;\n

\u524d\u8005\u662f\u4ec0\u4e48\uff1f\u6307\u9488\u3002\u6ca1\u9519\uff0c\u5e73\u5e73\u65e0\u5947\u7684\u53d6\u5730\u5740\u64cd\u4f5c\uff0c\u6d12\u6d12\u6c34\u5566\u3002 \u540e\u8005\u662f\u4ec0\u4e48\uff1f\u6211\u4eec\u77e5\u9053\u6307\u9488\u7684\u503c\u5b9e\u9645\u4e0a\u662f\u67d0\u5757\u5185\u5b58\u5730\u5740\uff0c\u4e0d\u8003\u8651\u5947\u6280\u6deb\u5de7\u7684\u8bdd\uff0c\u5c06\u6240\u6307\u5bf9\u8c61\u7684\u503c\u8d4b\u503c\u7ed9\u6307\u9488\u662f\u6ca1\u6709\u610f\u4e49\u7684\u3002\u4f46\u662f\uff0c\u5c06\u51fd\u6570\u6307\u4ee3\u5668 function \u8d4b\u503c\u7ed9\u51fd\u6570\u6307\u9488 func_ptr\uff0c\u5374\u6ca1\u6709\u4ea7\u751f\u4efb\u4f55\u95ee\u9898\u3002

\u574f\u4e86\uff0c\u81ea\u52a8\u64ad\u653e\u5988\u5988\u751f\u7684\uff0c\u5927\u8111\u8981\u6253\u9ad8\u7aef\u5c40\u4e86\u3002\u4e0d\u8fc7\u4f60\u5148\u522b\u6025\uff0c\u8fd9\u4e2a\u770b\u8d77\u6765\u4e0d\u77e5\u6240\u4e91\u7684\u8d4b\u503c\u8bed\u53e5\uff0c\u5176\u5b9e\u4e0e\u524d\u8005\u5b8c\u5168\u7b49\u6548\u3002C \u6807\u51c6\u662f\u4ec1\u6148\u7684\uff0c\u5b83\u4e0d\u5fcd\u5fc3\u770b\u5230\u88ab\u51fd\u6570\u7ed5\u6655\u7684\u521d\u5b66\u8005\u9762\u5bf9\u9519\u8bef\u7684\u89e3\u5f15\u7528\u4e0d\u77e5\u6240\u63aa\uff0c\u4e8e\u662f\u89c4\u5b9a\u4e86\u51fd\u6570\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u3002

\u4efb\u4f55\u51fd\u6570\u6307\u4ee3\u5668\u8868\u8fbe\u5f0f\uff0c\u5728\u7528\u4e8e\u5f02\u4e8e\u4e0b\u5217\u8bed\u5883\u65f6

\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u8868\u8fbe\u5f0f\u6240\u6307\u4ee3\u51fd\u6570\u7684\u6307\u9488\u7684\u8f6c\u6362\u3002

\u8fd9\u91cc function \u7ecf\u8fc7\u4e00\u6b21\u9690\u5f0f\u8f6c\u6362\u53d8\u6210 &function\u3002\u8fd9\u4e00\u6b65\u8f6c\u6362\u5e76\u4e0d\u6539\u53d8\u503c\uff0c\u800c\u7c7b\u578b\u4ece int (int) \u53d8\u6210 int (*)(int) \u4e86\u3002\u4e5f\u5c31\u662f\u5b9e\u9645\u4e0a\u5728\u7f16\u8bd1\u5668\u770b\u6765\uff0c\u7b2c\u4e8c\u884c\u5c31\u662f\u7b2c\u4e00\u884c\u3002

\u73b0\u5728\u4f60\u5df2\u7ecf\u5bf9\u51fd\u6570\u548c\u51fd\u6570\u6307\u9488\u6709\u4e86\u4e00\u5b9a\u4e86\u89e3\uff0c\u8ba9\u6211\u4eec\u770b\u4e00\u770b\u4e0b\u9762\u8fd9\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u628a\u6211\u4eec\u5df2\u7ecf\u5b66\u5230\u7684\u77e5\u8bc6\u8fd0\u7528\u5230\u5b9e\u8df5\u4e2d\u5427\u3002

\u8bf7\u89e3\u91ca\u4ee5\u4e0b\u4ee3\u7801\u7684\u4f5c\u7528\uff1a

// \u8bd5\u8bd5\u770b\uff01:)\n(*(void(*)())0)();\n

\u597d\u5427\uff0c\u8fd9\u6837\u7684\u8868\u8fbe\u5f0f\u6216\u8bb8\u5bf9\u4f60\u6765\u8bf4\u4e3a\u65f6\u5c1a\u65e9\u3002\u6211\u4eec\u6362\u4e9b\u7b80\u5355\u70b9\u7684\u4f8b\u5b50\u3002

function(20);\n(function)(20);\n(*&function)(20);\n(&function)(20);\n(*function)(20);\n(***********function)(20); // \u4e0d\u7528\u6570\u4e86\uff0c11 \u4e2a\n

\u5148\u4e0d\u7ba1\u7b2c\u516d\u4e2a\u662f\u4ec0\u4e48\u4e1c\u897f\uff0c\u6211\u4eec\u770b\u770b\u524d\u4e94\u4e2a\u3002

\u7b2c\u4e00\u4e2a\u4e0d\u80fd\u518d\u719f\u6089\u4e86\uff0c\u4e00\u4e2a\u4eba\u755c\u65e0\u5bb3\u7684\u51fd\u6570\u8c03\u7528\u3002

\u7b2c\u4e8c\u4e2a\u770b\u7740\u548c\u7b2c\u4e00\u4e2a\u5dee\u4e0d\u591a\u2026\u2026\uff1f\u6ca1\u9519\uff0c\u76f8\u4fe1\u81ea\u5df1\uff0c\u5b83\u4eec\u5b8c\u5168\u4e00\u6837\u3002

\u7b2c\u4e09\u4e2a\u5462\uff1f\u6ca1\u9519\uff0c\u53d6\u5730\u5740\u518d\u89e3\u5f15\u7528\uff0c\u9664\u4e86\u51fa\u9898\u6ca1\u6709\u7528\u3002\u8fde\u7f16\u8bd1\u5668\u90fd\u4f1a\u6beb\u4e0d\u72b9\u8c6b\u5730\u4f18\u5316\u6389\u3002

\u7b2c\u56db\u4e2a\u5f00\u59cb\u5947\u602a\u4e86\u8d77\u6765\u3002\u7f3a\u5931\u7684\u89e3\u5f15\u7528\u5e76\u975e\u7c97\u5fc3\u5927\u610f\uff0c\u5b83\u8c61\u5f81\u7740\u6211\u4eec\u73a9\u8f6c\u6307\u9488\u7684\u81ea\u4fe1\u4e0e\u60ec\u610f\uff0c\u4ee5\u53ca\u634d\u536b\u6307\u9488\u5730\u4f4d\u7684\u51b3\u5fc3\u3002\u9274\u4e8e C \u6807\u51c6\u5141\u8bb8\u901a\u8fc7\u51fd\u6570\u6307\u9488\u8c03\u7528\u51fd\u6570\uff0c\u7f16\u8bd1\u5668\u5bf9\u6b64\u4e5f\u6ca1\u4ec0\u4e48\u610f\u89c1\u3002

\u7b2c\u4e94\u4e2a\u6362\u4e86\u79cd\u6298\u78e8\u65b9\u5f0f\u3002\u806a\u660e\u5982\u4f60\u65e9\u5df2\u6599\u5230\u6700\u540e\u7684\u7ed3\u679c\u3002\u4f46\u662f\u4e3a\u4ec0\u4e48\uff1f\u5f15\u8a00\u5b9a\u771f\uff0c\u9274\u5b9a\u4e3a\u9690\u5f0f\u8f6c\u6362\u60ef\u7684\u3002\u56de\u5fc6\u4e00\u4e0b\u51fd\u6570\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\uff0c*function \u7b49\u6548\u4e8e *&function\uff0c\u8fd9\u4e0b\u770b\u61c2\u4e86\u3002

\u73b0\u5728\u7b2c\u516d\u4e2a\u4f60\u5e94\u8be5\u4e5f\u80fd\u7406\u89e3\u4e86\u3002\u6bcf\u6b21\u5c1d\u8bd5\u5bf9 function \u89e3\u5f15\u7528\uff0c\u90fd\u4f1a\u8feb\u4f7f\u7f16\u8bd1\u5668\u5c06\u5b83\u8f6c\u6362\u4e3a\u51fd\u6570\u6307\u9488\uff0c\u4ee5\u6ee1\u8db3\u4f60\u5bf9\u4ee3\u7801\u98ce\u683c\u7684\u5947\u602a\u7656\u597d\u3002

\u8fd8\u662f\u770b\u770b\u8fdc\u5904\u7684 func_ptr \u5427\u5bb6\u4eba\u4eec\u3002

(*func_ptr)(20);\nfunc_ptr(20);\n(****func_ptr)(20);\n(&func_ptr)(20);\n

\u7b2c\u4e00\u4e2a\uff0c\u7b80\u5355\u6613\u61c2\u7684\u6307\u9488\u89e3\u5f15\u7528\uff0c\u76f8\u5f53\u4e8e\u4e0a\u9762\u7684\u7b2c\u4e8c\u4e2a\u3002

\u7b2c\u4e8c\u4e2a\uff0c\u4eba\u755c\u65e0\u5bb3\u7684\u51fd\u6570\u6307\u9488\u8c03\u7528\u51fd\u6570\uff0c\u76f8\u5f53\u4e8e\u4e0a\u9762\u7684\u7b2c\u56db\u4e2a\u3002

\u7b2c\u4e09\u4e2a\uff0c\u51fd\u6570\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u53d1\u751f\u4e86\u6574\u6574\u4e09\u56de\u554a\u4e09\u56de\uff0c\u7c7b\u4f3c\u4e0a\u9762\u7684\u7b2c\u516d\u4e2a\u3002

\u7b2c\u56db\u4e2a\uff0c\u7f16\u8bd1\u5668\u8ddf\u4f60\u7206\u4e86\u3002\u600e\u4e48\u4f1a\u662f\u5462\uff1f\u6211\u4eec\u4e0d\u59a8\u62c6\u5f00\u770b\u770b\uff1a

int (*func_ptr)(int) = &function;    // \u8fd9\u662f\u4e4b\u524d\u7684\nint (**second_ptr)(int) = &func_ptr; // \u8fd9\u662f\u6211\u4eec\u6b63\u5728\u505a\u7684\nsecond_ptr(20);                      // \u6211\u4eec\u60f3\u8fd9\u6837\n

\u5728\u8fd9\u91cc\uff0csecond_ptr \u5df2\u7ecf\u662f\u4e2a\u4e8c\u7ea7\u6307\u9488\u4e86\u3002\u51fd\u6570\u5230\u51fd\u6570\u6307\u9488\uff08\u5b83\u662f\u4e2a\u4e00\u7ea7\u6307\u9488\uff09\u7684\u8f6c\u6362\u8fc7\u7a0b\u4e2d\uff0c\u5730\u5740\u503c\u662f\u4e0d\u4f1a\u6539\u53d8\u7684\uff0c\u5c31\u662f\u8fd9\u4e2a\u51fd\u6570\u7684\u53ef\u6267\u884c\u4ee3\u7801\u6240\u5728\u7684\u4f4d\u7f6e\u3002\u95ee\u9898\u5728\u4e8e\uff0c\u4e8c\u7ea7\u6307\u9488\u7684\u503c\u4e0d\u662f function \u7684\u5730\u5740\uff0c\u800c\u662f func_ptr \u8fd9\u4e2a\u53d8\u91cf\u7684\u5730\u5740\u3002\u8fd9\u8fd8\u5f97\u4e86\uff0c\u9a97\u81ea\u5df1\u53ef\u4ee5\uff0c\u9a97\u5144\u5f1f\u4e5f\u5c31\u7b97\u4e86\uff0c\u7f16\u8bd1\u5668\u53ef\u4e0d\u5403\u4f60\u8fd9\u5957\u3002

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u518d\u770b\u70b9\u4e0d\u592a\u4e00\u6837\u7684\uff1a

int func_two(int a, int f(int arg))\n{\n    return 3 * f(a);\n}\n

\u8fd9\u662f\u4ec0\u4e48\uff1f\u51fd\u6570\uff0c\u8c03\u7528\u4e00\u4e0b\uff1a

// function \u5982\u4e0a\u6587\u5b9a\u4e49\nint function(int arg);\n\nint a = 1;\nint b = func_two(a, function);\n

\u76f8\u4fe1\u806a\u660e\u7684\u4f60\u5df2\u7ecf\u731c\u5230\u4e86\uff0cb \u7684\u503c\u5c31\u662f 6\u3002\u6865\u8c46\u9ebb\u888b\uff0c\u597d\u50cf\u6709\u54ea\u91cc\u4e0d\u592a\u5bf9\u52b2\u3002func_two \u7684\u4e24\u4e2a\u53c2\u6570\u7c7b\u578b\u5206\u522b\u662f int \u548c int (int)\uff0c\u4f46\u662f\u8c03\u7528\u65f6\u5374\u4f20\u5165\u4e86\u4e00\u4e2a\u51fd\u6570\u6307\u9488\uff08\u8fd8\u8bb0\u5f97\u9690\u5f0f\u8f6c\u6362\u5417\uff1f\uff09\uff0c\u8fd9\u5374\u6ca1\u6709\u4ea7\u751f\u4efb\u4f55\u95ee\u9898\u3002\u8fd9\u53c8\u662f\u4ec0\u4e48\u64cd\u4f5c\uff1f

\u53c8\u662f\u9690\u5f0f\u8f6c\u6362\uff1fBingo\uff01\u4e0d\u8fc7\u9700\u8981\u6ce8\u610f\u53d1\u751f\u9690\u5f0f\u8f6c\u6362\u7684\u4f4d\u7f6e\u3002func_two \u7684\u7b2c\u4e8c\u4e2a\u5f62\u53c2\u5b9e\u9645\u4e0a\u662f int (*)(int) \uff0c\u800c\u975e\u5b57\u9762\u4e0a\u7684 int (int)\u3002\u8fd9\u5c31\u548c void f(int a[]) \u5b9e\u9645\u4e0a\u662f void f(int *a) \u4e00\u6837\uff0c\u540c\u6837\u662f\u51fa\u4e8e\u8282\u7ea6\u8d44\u6e90\u7684\u8003\u8651\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u7f16\u8bd1\u5668\u773c\u4e2d\u7684 func_two \u662f int func_two(int a, int (*f)(int)\u3002\u641e\u6e05\u695a\u8fd9\u4e00\u70b9\uff0c\u5176\u4f59\u90e8\u5206\u4e5f\u5c31\u987a\u7406\u6210\u7ae0\u4e86\u3002

\u7ecf\u8fc7\u7ec3\u4e60\uff0c\u4f60\u5e94\u8be5\u5df2\u7ecf\u53ef\u4ee5\u770b\u51fa\uff0c\u4ece\u51fd\u6570\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u89c4\u5b9a\u51fa\u53d1\uff0c\u7406\u89e3\u4e0a\u8ff0\u60c5\u666f\u5e76\u975e\u96be\u4e8b\u3002\u5bf9\u51fd\u6570\u6307\u9488\u7684\u754f\u60e7\uff0c\u5f80\u5f80\u662f\u56e0\u4e3a\u4e0d\u719f\u6089\u8f6c\u6362\u89c4\u5219\uff0c\u6216\u53d7\u590d\u6742\u7684\u58f0\u660e\u8bed\u6cd5\u5e72\u6270\u3002\u56e0\u6b64\uff0c\u63d0\u9ad8\u8bc6\u522b\u7c7b\u578b\u7684\u719f\u7ec3\u5ea6\uff0c\u8db3\u4ee5\u8ba9\u4f60\u81ea\u4fe1\u8fd0\u7528\u51fd\u6570\u6307\u9488\u3002

"},{"location":"programming/common/notes/pointers/","title":"\u6307\u9488\u6982\u89c8","text":"

\u4f60\u53ef\u80fd\u5df2\u7ecf\u542c\u8bf4\u8fc7\uff0cC \u8bed\u8a00\u662f\u8d34\u8fd1\u5e95\u5c42\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u8fd9\u662f\u56e0\u4e3a\uff0cC \u8bed\u8a00\u672a\u5bf9\u8ba1\u7b97\u673a\u786c\u4ef6\u4f5c\u8fc7\u591a\u62bd\u8c61\uff0c\u5b83\u65b9\u4fbf\u800c\u53c8\u7075\u6d3b\u7684\u8bed\u8a00\u7279\u6027\u4e3a\u4e0e\u786c\u4ef6\u4ea4\u4e92\u63d0\u4f9b\u4e86\u6781\u5927\u4fbf\u5229\u3002

\u6307\u9488\u662f C \u8bed\u8a00\u7684\u6838\u5fc3\u7279\u6027\u4e4b\u4e00\uff0c\u5b83\u7684\u7075\u6d3b\u6027\u4e0e\u5f3a\u5927\u6027\uff0c\u4f7f\u5f97 C \u8bed\u8a00\u6210\u4e3a\u4e0e\u786c\u4ef6\u4ea4\u4e92\u7684\u9996\u9009\u8bed\u8a00\u3002\u4f46\u662f\uff0c\u6307\u9488\u4e5f\u662f C \u8bed\u8a00\u4e2d\u6700\u5bb9\u6613\u5f15\u53d1\u9519\u8bef\u7684\u7279\u6027\u4e4b\u4e00\uff0c\u5b83\u8981\u6c42\u4f7f\u7528\u8005\u6b63\u786e\u7406\u89e3\u5185\u5b58\u6a21\u578b\uff0c\u5e76\u5bf9\u6307\u9488\u7684\u4f7f\u7528\u4e25\u52a0\u7ea6\u675f\u3002

\u672c\u6587\u5c06\u5c3d\u91cf\u5168\u9762\u5730\u8bb2\u89e3\u6307\u9488\u7684\u5b9a\u4e49\u4e0e\u7279\u6027\uff0c\u5e76\u68b3\u7406\u90e8\u5206\u4f7f\u7528\u6280\u5de7\u3002\u5728\u6b64\u4e4b\u524d\uff0c\u4e3a\u4e86\u51c6\u786e\u7406\u89e3\u6307\u9488\uff0c\u6211\u4eec\u9700\u8981\u5148\u4e86\u89e3 C \u8bed\u8a00\u7684\u5185\u5b58\u6a21\u578b\u4e0e\u5bf9\u8c61\u6a21\u578b\u3002

\u9605\u8bfb\u63d0\u793a

\u7a0b\u7b97\u8bfe\u7a0b\u4e2d\u5b66\u4e60\u7684 C \u8bed\u8a00\u8bed\u6cd5\u5747\u5728 C99 \u6807\u51c6\u89c4\u5b9a\u7684\u8303\u56f4\u5185\u3002\u4e0b\u6587\u4e2d\uff0c\u5982\u679c\u672a\u4f5c\u989d\u5916\u8bf4\u660e\uff0c\u6240\u6709\u5185\u5bb9\u5747\u57fa\u4e8e C99 \u6807\u51c6\u3002

\u4e0b\u6587\u4e2d\u90e8\u5206\u63d0\u793a\u9ed8\u8ba4\u88ab\u6298\u53e0\u3002\u6b64\u7c7b\u63d0\u793a\u4e3a\u62d3\u5c55\u5185\u5bb9\uff0c\u5bf9\u77e5\u8bc6\u79ef\u7d2f\u4e0e\u7406\u89e3\u80fd\u529b\u6709\u4e00\u5b9a\u8981\u6c42\uff0c\u4f46\u6709\u52a9\u4e8e\u7406\u89e3\u4e00\u4e9b\u7ec6\u8282\u95ee\u9898\uff0c\u8bf7\u914c\u60c5\u9605\u8bfb\u3002

"},{"location":"programming/common/notes/pointers/#_2","title":"\u5e95\u5c42\u6982\u5ff5","text":""},{"location":"programming/common/notes/pointers/#_3","title":"\u5185\u5b58\u6a21\u578b","text":"

\u5185\u5b58\u6a21\u578b

\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5176\u6bcf\u4e2a\u5b57\u8282\u7684\u7d22\u5f15\u3001\u503c\u4e0e\u5185\u5b58\u5730\u5740\u3002

\uff08\u5355\u51fb\u56fe\u7247\u53ef\u653e\u5927\uff09

\u5728 C \u8bed\u8a00\u7684\u5185\u5b58\u6a21\u578b\u4e2d\uff0c\u5b57\u8282\uff08Byte\uff09\u5b9a\u4e49\u4e3a\u4e00\u7cfb\u5217\u8fde\u7eed\u7684\u4f4d\uff08bit\uff09\uff0c\u662f\u5185\u5b58\u7684\u6700\u5c0f\u53ef\u5bfb\u5740\u5355\u5143\u3002\u5728\u51e0\u4e4e\u6240\u6709\u73b0\u4ee3\u8ba1\u7b97\u673a\u4e0a\uff0c\u4e00\u4e2a\u5b57\u8282\u7684\u957f\u5ea6\u90fd\u662f 8 \u4f4d\uff0c\u6211\u4eec\u7684\u8ba8\u8bba\u4e5f\u57fa\u4e8e\u8fd9\u4e00\u6807\u51c6\u3002

\u6240\u8c13\u201c\u53ef\u5bfb\u5740\u201d\u6307\u7684\u662f\u5185\u5b58\u4e2d\u7684\u6240\u6709\u5b57\u8282\u90fd\u62e5\u6709\u4e00\u4e2a\u552f\u4e00\u7f16\u53f7\uff0c\u4e5f\u5373\u5185\u5b58\u5730\u5740\u3002\u4e60\u60ef\u4e0a\uff0c\u5185\u5b58\u5730\u5740\u7531\u957f\u5ea6\u4e00\u5b9a\u7684\u3001\u4ece 0 \u5f00\u59cb\u9012\u589e\u7684\u65e0\u7b26\u53f7\u6574\u6570\u8868\u793a\uff0c\u5176\u957f\u5ea6\u7531\u64cd\u4f5c\u7cfb\u7edf\u51b3\u5b9a\u3002

\u5e38\u89c1\u67b6\u6784\u4e2d\u5185\u5b58\u5730\u5740\u7684\u957f\u5ea6

\u6211\u4eec\u7ecf\u5e38\u63a5\u89e6\u7684\u5904\u7406\u5668\u67b6\u6784\u4e2d\uff0cx86\uff08\u53c8\u79f0 IA-32\uff09\u67b6\u6784\u4f7f\u7528 32 \u4f4d\u957f\u7684\u5185\u5b58\u5730\u5740\uff0cx86-64\uff08\u53c8\u79f0 x64\u3001AMD64\u3001Intel 64\uff09\u4e0e ARM64\uff08\u53c8\u79f0 AArch64\uff09\u67b6\u6784\u4f7f\u7528 64 \u4f4d\u957f\u7684\u5185\u5b58\u5730\u5740\u3002\u5bb9\u6613\u770b\u51fa\uff0cx86 \u67b6\u6784\u652f\u6301\u7684\u6700\u5927\u5185\u5b58\u7a7a\u95f4\u53ea\u6709 4 GB\uff0c\u800c\u540e\u4e24\u4e2a\u67b6\u6784\u652f\u6301\u7684\u6700\u5927\u5185\u5b58\u7a7a\u95f4\u5219\u8fdc\u8d85\u524d\u8005\u3002

"},{"location":"programming/common/notes/pointers/#_4","title":"\u5bf9\u8c61","text":"

C \u8bed\u8a00\u5c06\u7a0b\u5e8f\u4f7f\u7528\u7684\u6570\u636e\u62bd\u8c61\u4e3a\u5bf9\u8c61\uff0c\u5b83\u88ab\u5b9a\u4e49\u4e3a\u6267\u884c\u73af\u5883\u4e2d\u5185\u5b58\u7684\u4e00\u4e2a\u533a\u57df\uff0c\u5176\u5185\u5bb9\u53ef\u4ee5\u8868\u793a\u7279\u5b9a\u7c7b\u578b\u7684\u503c\u3002\u6839\u636e\u6570\u636e\u7c7b\u578b\u4e0e\u957f\u5ea6\u7684\u4e0d\u540c\uff0c\u4e00\u4e2a\u5bf9\u8c61\u53ef\u5360\u636e\u4e00\u4e2a\u6216\u591a\u4e2a\u5b57\u8282\uff0c\u6211\u4eec\u79f0\u8d77\u59cb\u5b57\u8282\u7684\u5185\u5b58\u5730\u5740\u4e3a\u8be5\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u3002

\u6bcf\u4e2a\u5bf9\u8c61\u53ef\u4ee5\u7528 memcpy \u590d\u5236\u5230 unsigned char[n] \u7c7b\u578b\u7684\u5bf9\u8c61\u4e2d\uff0c\u6211\u4eec\u79f0\u751f\u6210\u7684\u6570\u7ec4\u5185\u5bb9\u4e3a\u5bf9\u8c61\u8868\u793a\u3002\u65b9\u4fbf\u8d77\u89c1\uff0c\u6211\u4eec\u901a\u5e38\u4ee5\u5341\u516d\u8fdb\u5236\u6574\u6570\u5e8f\u5217\u5f62\u5f0f\u5c55\u793a\u5bf9\u8c61\u8868\u793a\uff0c\u6bcf\u4e24\u4f4d\u5341\u516d\u8fdb\u5236\u6570\u4ee3\u8868\u4e00\u4e2a\u5b57\u8282\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0cint \u7c7b\u578b\u5e38\u91cf 1 \u5728\u5c0f\u7aef\u5e8f\u8ba1\u7b97\u673a\u4e0a\u7684\u5bf9\u8c61\u8868\u793a\u4e3a 0x01 00 00 00\u3002

\u53e6\u5916\uff0c\u5bf9\u8c61\u8868\u793a\u548c\u503c\u5e76\u4e0d\u8981\u6c42\u4e00\u4e00\u5bf9\u5e94\uff0c\u4e24\u4e2a\u503c\u76f8\u7b49\u7684\u5bf9\u8c61\u53ef\u4ee5\u62e5\u6709\u4e0d\u540c\u7684\u5bf9\u8c61\u8868\u793a\u3002

\u9664\u4e86\u76f4\u63a5\u4f7f\u7528\u5b57\u9762\u91cf\uff08\u5e38\u91cf\u7684\u4e00\u79cd\uff09\u521b\u5efa\u5bf9\u8c61\u5916\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u58f0\u660e\u8bed\u53e5\u521b\u5efa\uff0c\u5e76\u4e3a\u5176\u5206\u914d\u4e00\u4e2a\u6807\u8bc6\u7b26\uff0c\u4ee5\u63a9\u76d6\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u4e0e\u8bbf\u95ee\u5185\u5b58\u5730\u5740\u7684\u7ec6\u8282\u8fc7\u7a0b\uff0c\u5e76\u589e\u5f3a\u7a0b\u5e8f\u53ef\u8bfb\u6027\u3002

\u6807\u8bc6\u7b26

C \u6807\u51c6\u5b9a\u4e49\uff0c\u6807\u8bc6\u7b26\u662f\u6570\u5b57\u3001\u4e0b\u5212\u7ebf\u3001\u5c0f\u5199\u53ca\u5927\u5199\u62c9\u4e01\u5b57\u6bcd\u7684\u4efb\u610f\u957f\u5ea6\u5e8f\u5217\uff08\u4e0d\u8ba8\u8bba Unicode \u5b57\u7b26\uff09\u3002\u5408\u6cd5\u7684\u6807\u8bc6\u7b26\u5fc5\u987b\u4ee5\u975e\u6570\u5b57\u5b57\u7b26\u5f00\u59cb\uff0c\u4ee5\u533a\u522b\u4e8e\u6574\u6570\u5e38\u91cf\u6216\u6d6e\u70b9\u5e38\u91cf\u3002

\u6807\u8bc6\u7b26\u80fd\u6307\u4ee3\u4e0b\u5217\u7c7b\u578b\u7684\u5b9e\u4f53\uff1a

\u5b8f\u540d\u6216\u5b8f\u5f62\u53c2\u540d\u4ee5\u5916\u7684\u6bcf\u4e2a\u6807\u8bc6\u7b26\u90fd\u62e5\u6709\u4f5c\u7528\u57df\uff0c\u5e76\u53ef\u4ee5\u62e5\u6709\u94fe\u63a5\u3002\u76f8\u540c\u7684\u6807\u8bc6\u7b26\u53ef\u4ee5\u5728\u7a0b\u5e8f\u7684\u76f8\u5f02\u70b9\u6307\u4ee3\u76f8\u5f02\u5b9e\u4f53\u3002

\u5173\u952e\u5b57\u4e5f\u5c5e\u4e8e\u6807\u8bc6\u7b26\uff0c\u4f46\u5b83\u4eec\u88ab\u4fdd\u7559\uff0c\u4e0d\u53ef\u5728\u7a0b\u5e8f\u4e2d\u58f0\u660e\u3002\u4ee5\u4e00\u4e2a\u6216\u591a\u4e2a\u4e0b\u5212\u7ebf\u5f00\u59cb\u7684\u6807\u8bc6\u7b26\u4e5f\u4e0d\u5e94\u5728\u7a0b\u5e8f\u4e2d\u51fa\u73b0\uff1b\u6839\u636e\u7ea6\u5b9a\uff0c\u8fd9\u4e9b\u6807\u8bc6\u7b26\u5e94\u7531\u5e93\u7684\u5185\u90e8\u5b9e\u73b0\u4f7f\u7528\u3002\u53e6\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u6807\u8bc6\u7b26\u88ab\u6307\u5b9a\u4fdd\u7559\uff0c\u6b64\u5904\u4e0d\u518d\u5c55\u5f00\u3002

\u533a\u5206\u5bf9\u8c61\u6982\u5ff5

\u5982\u679c\u4f60\u5b66\u4e60\u8fc7\u6216\u5c06\u8981\u5b66\u4e60\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\uff0c\u8bf7\u4e25\u683c\u533a\u5206\u4e0d\u540c\u8bed\u8a00\u4e2d\u7684\u5bf9\u8c61\u6982\u5ff5\uff0c\u5c24\u5176\u662f\u9762\u5411\u5bf9\u8c61\u8bed\u8a00\u4e2d\u7684\u201c\u5bf9\u8c61\u201d\u3002

\u56e0\u6b64\uff0c\u58f0\u660e\u4e00\u4e2a\u53d8\u91cf\u5b9e\u9645\u4e0a\u5305\u62ec\u4e24\u6b65\uff1a\u9996\u5148\uff0c\u4e3a\u5bf9\u8c61\u7533\u8bf7\u4e00\u5757\u5bf9\u5e94\u5927\u5c0f\u7684\u5185\u5b58\u7a7a\u95f4\uff1b\u5176\u6b21\uff0c\u5c06\u6807\u8bc6\u7b26\u4e0e\u5bf9\u8c61\u76f8\u5173\u8054\u3002

\u5f53\u7a0b\u5e8f\u5c1d\u8bd5\u8bfb\u53d6\u6216\u4fee\u6539\u5bf9\u8c61\u7684\u5185\u5bb9\u65f6\uff0c\u6211\u4eec\u79f0\u7a0b\u5e8f\u8bbf\u95ee\u4e86\u8be5\u5bf9\u8c61\u6216\u8be5\u5185\u5b58\u5730\u5740\u3002

"},{"location":"programming/common/notes/pointers/#_5","title":"\u57fa\u672c\u8bed\u6cd5","text":""},{"location":"programming/common/notes/pointers/#_6","title":"\u6307\u9488\u7c7b\u578b","text":"

\u4e00\u822c\u800c\u8a00\uff0c\u63d0\u5230\u201c\u6307\u9488\u201d\u65f6\uff0c\u6211\u4eec\u5b9e\u9645\u8ba8\u8bba\u7684\u662f\u6307\u9488\u7c7b\u578b\u5bf9\u8c61\u3002

C \u6807\u51c6\u5bf9\u6307\u9488\u7c7b\u578b\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a

A pointer type may be derived from a function type, an object type, or an incomplete type, called the referenced type. A pointer type describes an object whose value provides a reference to an entity of the referenced type. A pointer type derived from the referenced type \\(T\\) is sometimes called \"pointer to \\(T\\)\".

C \u8bed\u8a00\u4e2d\uff0c\u6307\u9488\u7c7b\u578b\u4e0e\u5176\u4ed6\u7c7b\u578b\u62e5\u6709\u76f8\u540c\u7684\u5bf9\u8c61\u6a21\u578b\uff0c\u6307\u9488\u7c7b\u578b\u7684\u5bf9\u8c61\u540c\u6837\u9700\u8981\u7533\u8bf7\u5185\u5b58\u7a7a\u95f4\u4ee5\u5b58\u50a8\u503c\u3002\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\uff0c\u6307\u9488\u7c7b\u578b\u5bf9\u8c61\u7684\u503c\u4e3a\u201c\u53e6\u4e00\u4e2a\u5bf9\u8c61\u7684\u5f15\u7528\u201d\uff0c\u4e5f\u5373\u5176\u5185\u5b58\u5730\u5740\u3002\u6211\u4eec\u79f0\u6307\u9488\u7c7b\u578b\u7684\u5bf9\u8c61\u6307\u5411\u88ab\u5f15\u7528\u5bf9\u8c61\u3002

\u6307\u9488\u7c7b\u578b\u662f\u4e00\u79cd\u6d3e\u751f\u7c7b\u578b\uff0c\u8fd9\u610f\u5473\u7740\u5b8c\u6574\u7684\u6307\u9488\u7c7b\u578b\u5305\u62ec\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u7c7b\u578b\u3002\u7531\u4e8e\u5728\u5185\u5b58\u4e2d\u6240\u6709\u6570\u636e\u5747\u4ee5\u4e00\u7cfb\u5217\u8fde\u7eed\u4f4d\u7684\u5f62\u5f0f\u5b58\u50a8\uff0c\u4e3a\u6b63\u786e\u8bfb\u53d6\u6570\u636e\uff0c\u8fd9\u79cd\u989d\u5916\u7684\u8bb0\u5f55\u663e\u7136\u662f\u5fc5\u8981\u7684\u3002

\u76f8\u5bf9\u5e94\u5730\uff0c\u4e0d\u540c\u6307\u9488\u7c7b\u578b\u95f4\u662f\u5426\u517c\u5bb9\uff0c\u53d6\u51b3\u4e8e\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u7c7b\u578b\u662f\u5426\u517c\u5bb9\u3002

"},{"location":"programming/common/notes/pointers/#_7","title":"\u58f0\u660e","text":"

\u6307\u9488\u7c7b\u578b\u5bf9\u8c61\u7684\u58f0\u660e\u8bed\u6cd5\u5982\u4e0b\uff1a

type-specifier * qualifiers declarator\n

\u5176\u4e2d\uff0ctype-specifier \u4e3a\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u7c7b\u578b\uff0cqualifiers \u4e3a\u5bf9\u6307\u9488\u7c7b\u578b\u5bf9\u8c61\u7684\u9650\u5b9a\uff0cdeclarator\u4e3a\u6307\u9488\u7c7b\u578b\u5bf9\u8c61\u7684\u6807\u8bc6\u7b26\uff08\u540d\u79f0\uff09\u3002

\u6b63\u786e\u6dfb\u52a0\u9650\u5b9a\u4e0e\u5b58\u50a8\u7c7b\u578b\u8bf4\u660e

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u53ea\u6709\u51fa\u73b0\u5728 * \u4e0e\u6807\u8bc6\u7b26\u4e4b\u95f4\u7684\u9650\u5b9a\u624d\u4f1a\u88ab\u8d4b\u4e88\u6307\u9488\u7c7b\u578b\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 char * const p; \u58f0\u660e\u4e86\u4e00\u4e2a\u7c7b\u578b\u4e3a char * \u7684\u3001\u503c\u4e0d\u53ef\u53d8\u7684\u6307\u9488 p\uff0c\u5b83\u6307\u5411\u7684\u5bf9\u8c61\u7c7b\u578b\u4e3a char\uff0c\u503c\u53ef\u901a\u8fc7\u6307\u9488 p \u6539\u53d8\uff1b\u800c\u8bed\u53e5 const char * p; \u58f0\u660e\u4e86\u4e00\u4e2a\u7c7b\u578b\u4e3a const char * \u7684\u3001\u503c\u53ef\u53d8\u7684\u6307\u9488 p\uff0c\u5b83\u6307\u5411\u7684\u5bf9\u8c61\u7c7b\u578b\u4e3a const char\uff0c\u503c\u4e0d\u53ef\u901a\u8fc7\u6307\u9488 p \u6539\u53d8\u3002

\u53e6\u5916\uff0c\u5b58\u50a8\u7c7b\u578b\u8bf4\u660e\u7b26\u5e76\u6ca1\u6709\u7c7b\u4f3c\u7684\u8bed\u4e49\uff0c\u5b83\u5fc5\u987b\u7f6e\u4e8e * \u4e4b\u524d\u3002\u4ece\u8bed\u6cd5\u4e0a\u8bf4\uff0c\u5b83\u4eec\u5c5e\u4e8e\u8bf4\u660e\u7b26\u800c\u975e\u9650\u5b9a\u7b26\uff0c\u4e0d\u5e94\u7f6e\u4e8e * \u4e0e\u6807\u8bc6\u7b26\u4e4b\u95f4\uff1b\u4ece\u8bed\u4e49\u4e0a\u6765\u8bf4\uff0c\u8bb0\u5f55\u88ab\u5f15\u7528\u5bf9\u8c61\u7c7b\u578b\u7684\u76ee\u7684\u662f\u4ece\u76ee\u6807\u5185\u5b58\u5730\u5740\u6b63\u786e\u8bfb\u53d6\u6570\u636e\uff0c\u800c\u4e86\u89e3\u6307\u5411\u5bf9\u8c61\u7684\u5b58\u50a8\u7c7b\u578b\u5bf9\u8fd9\u4e00\u76ee\u7684\u6beb\u65e0\u5e2e\u52a9\u3002

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u58f0\u660e\u4e2d * \u53ea\u5bf9\u76f4\u63a5\u7ed3\u5408\u7684\u6807\u8bc6\u7b26\u751f\u6548\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5982\u679c\u901a\u8fc7\u8bed\u53e5 int * a, b; \u58f0\u660e\u53d8\u91cf a \u4e0e b\uff0c\u90a3\u4e48\u53ea\u6709 a \u4f1a\u88ab\u8ba4\u5b9a\u4e3a\u6307\u9488\u7c7b\u578b\u3002

\u5728\u58f0\u660e\u6307\u5411\u67d0\u4e9b\u7c7b\u578b\u5bf9\u8c61\u7684\u6307\u9488\u65f6\uff0c\u53ef\u901a\u8fc7\u62ec\u53f7\u4f7f * \u4f18\u5148\u4e0e\u6807\u8bc6\u7b26\u7ed3\u5408\uff0c\u4ee5\u907f\u514d\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u5dee\u5f02\u5bfc\u81f4\u7684\u6b67\u4e49\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 int *arr[3]; \u58f0\u660e\u4e86\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int * \u4e14\u957f\u5ea6\u4e3a 3 \u7684\u6570\u7ec4 arr\uff1b\u8bed\u53e5 int (*ptr)[3]; \u5219\u58f0\u660e\u4e86\u4e00\u4e2a\u6307\u9488 ptr\uff0c\u5b83\u6307\u5411\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int \u4e14\u957f\u5ea6\u4e3a 3 \u7684\u6570\u7ec4\u3002

\u6b64\u5916\uff0c\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u7c7b\u578b\u53ef\u4ee5\u662f\u4e0d\u5b8c\u6574\u7c7b\u578b\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 int (*p)[]; \u8868\u660e\u6307\u9488 p \u6307\u5411\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int\uff0c\u4e14\u957f\u5ea6\u672a\u77e5\u7684\u6570\u7ec4\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u4e0d\u5173\u5fc3\u6570\u7ec4\u957f\u5ea6\uff0c\u6216\u8005\u6570\u7ec4\u957f\u5ea6\u9700\u8981\u5728\u4e4b\u540e\u7684\u7a0b\u5e8f\u4e2d\u901a\u8fc7\u67d0\u4e9b\u65b9\u6cd5\u786e\u5b9a\u3002\u76f8\u5bf9\u5e94\u5730\uff0c\u65e0\u6cd5\u5bf9\u89e3\u5f15\u7528 p \u7684\u7ed3\u679c\u4f7f\u7528 sizeof \u8fd0\u7b97\u7b26\u3002

\u901a\u7528\u6307\u9488\u7c7b\u578b void *

\u7531\u4e8e void \u4e5f\u5c5e\u4e8e\u4e0d\u5b8c\u6574\u7c7b\u578b\uff0cvoid * \u540c\u6837\u662f\u5408\u6cd5\u7684\u6307\u9488\u7c7b\u578b\u3002\u5b83\u7684\u5b9e\u9645\u542b\u4e49\u662f\u6307\u9488\u6307\u5411\u4e00\u4e2a\u7c7b\u578b\u672a\u77e5\u7684\u5bf9\u8c61\uff0c\u4e5f\u5373\u6307\u9488\u53ef\u4ee5\u6307\u5411\u4efb\u4f55\u7c7b\u578b\u7684\u5bf9\u8c61\u3002\u81ea\u7136\u5730\uff0c\u6211\u4eec\u65e0\u6cd5\u89e3\u5f15\u7528\u8be5\u7c7b\u578b\u7684\u6307\u9488\u5bf9\u8c61\u3002\u4e0d\u8fc7\uff0c\u5b83\u53ef\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u4efb\u610f\u5176\u4ed6\u7c7b\u578b\u7684\u6307\u9488\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002

\u867d\u7136 C \u8bed\u8a00\u5728 C11 \u6807\u51c6\u524d\u5e76\u672a\u63d0\u4f9b\u6cdb\u578b\u7279\u6027\uff0c\u4f46\u901a\u8fc7\u5f15\u5165 void * \u7c7b\u578b\u53c2\u6570\uff0c\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u8bbe\u8ba1\u901a\u7528\u63a5\u53e3\uff0c\u4f7f\u7528\u76f8\u540c\u4ee3\u7801\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002\u4e00\u4e2a\u5178\u578b\u7684\u4f8b\u5b50\u662f\uff0cstdlib.h \u4e2d\u5b9a\u4e49\u7684 qsort \u4e0e bsearch \u65b9\u6cd5\u90fd\u901a\u8fc7\u5c06\u6570\u7ec4\u6307\u9488 ptr \u7684\u7c7b\u578b\u89c4\u5b9a\u4e3a void *\uff0c\u5b9e\u73b0\u4e86\u65e0\u89c6\u6570\u7ec4\u5143\u7d20\u7c7b\u578b\u91cd\u7528\u6392\u5e8f\u4ee3\u7801\u7684\u6548\u679c\u3002

\u5f53\u7136\uff0c\u56e0\u4e3a\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u7c7b\u578b\u672a\u77e5\uff0c\u6b64\u65f6 C \u8bed\u8a00\u7f16\u8bd1\u5668\u65e0\u6cd5\u5e2e\u4f60\u68c0\u67e5\u7c7b\u578b\u517c\u5bb9\u95ee\u9898\uff0c\u6240\u4ee5\u4f7f\u7528 void * \u7c7b\u578b\u6307\u9488\u65f6\u9700\u4e07\u5206\u5c0f\u5fc3\u3002

"},{"location":"programming/common/notes/pointers/#_8","title":"\u503c\u4e0e\u8fd0\u7b97","text":"

\u901a\u8fc7\u6307\u9488\u83b7\u5f97\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u8fc7\u7a0b\u79f0\u4e3a\u89e3\u5f15\u7528\uff0c\u7531\u8fd0\u7b97\u7b26 * \u5b8c\u6210\uff1b\u901a\u8fc7\u67d0\u4e2a\u5bf9\u8c61\u83b7\u5f97\u6307\u5411\u8be5\u5bf9\u8c61\u6307\u9488\u7684\u8fc7\u7a0b\u79f0\u4e3a\u53d6\u5740\uff0c\u7531\u8fd0\u7b97\u7b26 & \u5b8c\u6210\u3002

\u7ed3\u5408\u8d4b\u503c\u64cd\u4f5c\uff0c\u53ef\u6839\u636e\u9700\u8981\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u5e76\u4fee\u6539\u6307\u5411\u7684\u5bf9\u8c61\uff0c\u6216\u4ee4\u6307\u9488\u6307\u5411\u4e0d\u540c\u7684\u5bf9\u8c61\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5bf9\u4e8e int \u7c7b\u578b\u53d8\u91cf a\uff0c\u8bed\u53e5 p = &a; \u5c06\u4f7f\u6307\u9488 p \u7684\u503c\u8bbe\u4e3a a \u7684\u5185\u5b58\u5730\u5740\uff0c\u4e5f\u5373\u4ee4 p \u6307\u5411 a\uff1b\u5728\u6b64\u57fa\u7840\u4e0a\uff0c\u8bed\u53e5 *p = 1; \u5c06\u6539\u53d8 p \u6307\u5411\u7684\u5bf9\u8c61\uff0c\u4e5f\u5373\u53d8\u91cf a \u7684\u503c\u3002

\u4e0d\u8fc7\uff0c\u5728\u7f16\u5199\u8868\u8fbe\u5f0f\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u7684\u5f71\u54cd\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8868\u8fbe\u5f0f *p++ \u5c06\u4f7f\u6307\u9488 p \u7684\u503c\u81ea\u589e 1\uff0c\u800c\u8868\u8fbe\u5f0f (*p)++ \u5c06\u4f7f\u6307\u9488 p \u6307\u5411\u5bf9\u8c61\u7684\u503c\u81ea\u589e 1\u3002

\u7406\u89e3\u521d\u59cb\u5316\u8bed\u53e5\u4e2d\u7684 * \u8fd0\u7b97\u7b26

C \u8bed\u8a00\u7684\u8bed\u6cd5\u529b\u56fe\u4f7f\u58f0\u660e\u548c\u4f7f\u7528\u76f8\u4e00\u81f4\u3002

\u5728\u9605\u8bfb\u6307\u9488\u521d\u59cb\u5316\u8bed\u53e5\u65f6\uff0c\u4f60\u53ef\u80fd\u5e38\u5e38\u6df7\u6dc6 * \u7684\u58f0\u660e\u4e0e\u89e3\u5f15\u7528\u8bed\u6cd5\u3002\u6b63\u786e\u5206\u8fa8\u7684\u8981\u70b9\u5728\u4e8e\uff0c\u521d\u59cb\u5316\u8bed\u53e5\u5206\u4e3a\u58f0\u660e\u548c\u521d\u59cb\u5316\u5668\u4e24\u90e8\u5206\uff0c\u5176\u4e2d\u8d4b\u503c\u53f7 = \u524d\u7684\u90e8\u5206\u4e3a\u58f0\u660e\uff0c\u8d4b\u503c\u53f7\u53ca\u5176\u540e\u7684\u90e8\u5206\u4e3a\u521d\u59cb\u5316\u5668\u3002

\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5728\u8bed\u53e5 int *ip = *ipp; \u4e2d\uff0cint *ip \u4e3a\u58f0\u660e\uff0c= *ipp \u4e3a\u521d\u59cb\u5316\u5668\uff0c\u8fd9\u6761\u8bed\u53e5\u7684\u542b\u4e49\u662f\uff1a\u58f0\u660e\u4e00\u4e2a\u6307\u5411 int \u7c7b\u578b\u5bf9\u8c61\u7684\u6307\u9488 ip\uff0c\u5e76\u5c06\u5b83\u7684\u521d\u59cb\u503c\u8bbe\u4e3a ipp \u6307\u5411\u5bf9\u8c61\u7684\u503c\u3002

\u91ce\u6307\u9488

\u58f0\u660e\u81ea\u52a8\u4f5c\u7528\u57df\u7684\u5bf9\u8c61\u540e\uff0cC \u8bed\u8a00\u4ec5\u4fdd\u8bc1\u53ef\u4ee5\u6b63\u5e38\u8bbf\u95ee\u5e76\u4fee\u6539\u8be5\u5bf9\u8c61\uff0c\u800c\u4e0d\u4fdd\u8bc1\u5176\u521d\u59cb\u5185\u5bb9\uff0c\u8fd9\u70b9\u5bf9\u6307\u9488\u540c\u6837\u6210\u7acb\u3002\u5982\u679c\u58f0\u660e\u4e86\u4e00\u4e2a\u6307\u9488\u5374\u6ca1\u6709\u8d4b\u503c\uff0c\u8fd9\u4e2a\u6307\u9488\u7684\u6307\u5411\u4fbf\u65e0\u6cd5\u786e\u5b9a\uff0c\u6211\u4eec\u79f0\u5b83\u4e3a\u91ce\u6307\u9488\u3002

\u56e0\u4e3a\u91ce\u6307\u9488\u53ef\u80fd\u6307\u5411\u4efb\u610f\u5185\u5b58\u6bb5\uff0c\u4e0d\u52a0\u9274\u522b\u7684\u968f\u610f\u4f7f\u7528\u53ef\u80fd\u5bfc\u81f4\u8bbf\u95ee\u975e\u6cd5\u5185\u5b58\u3001\u635f\u574f\u6b63\u5e38\u6570\u636e\uff0c\u751a\u81f3\u9020\u6210\u5176\u4ed6\u672a\u77e5\u540e\u679c\u3002\u5c1d\u8bd5\u89e3\u5f15\u7528\u91ce\u6307\u9488\u662f\u6bb5\u9519\u8bef\uff08Segmentation Fault\uff09\u7684\u4e3b\u8981\u8bf1\u56e0\u4e4b\u4e00\u3002\u56e0\u6b64\uff0c\u58f0\u660e\u6307\u9488\u65f6\u52a1\u5fc5\u5b8c\u6210\u521d\u59cb\u5316\u3002

\u6bcf\u79cd\u7c7b\u578b\u7684\u6307\u9488\u90fd\u542b\u6709\u4e00\u4e2a\u8be5\u7c7b\u578b\u7684\u7279\u6b8a\u503c\uff0c\u79f0\u4e3a\u7a7a\u6307\u9488\u503c\u3002\u503c\u4e3a\u7a7a\u7684\u6307\u9488\u4e0d\u6307\u5411\u4efb\u4f55\u5bf9\u8c61\uff0c\u4e14\u89e3\u5f15\u7528\u7a7a\u6307\u9488\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\u3002\u53ef\u4f7f\u7528\u7a7a\u6307\u9488\u7b26\u53f7\u5e38\u91cf NULL \u4e3a\u6307\u9488\u8d4b\u7a7a\u503c\uff0c\u5b83\u5728 stdio.h\u3001stdlib.h\u3001string.h\u3001stddef.h \u7b49\u5e38\u7528\u5e93\u4e2d\u5747\u6709\u5b9a\u4e49\u3002\u6839\u636e C \u8bed\u8a00\u6807\u51c6\uff0cNULL \u7684\u503c\u4e3a 0\u3002

\u7a7a\u6307\u9488\u5e38\u91cf NULL \u7684\u503c

\u6839\u636e C \u6807\u51c6\u5b9a\u4e49\uff0c\u5b8f NULL \u662f\u5b9e\u73b0\u5b9a\u4e49\u7684\u7a7a\u6307\u9488\u5e38\u91cf\uff0c\u5b83\u53ef\u4ee5\u662f\u503c\u4e3a 0 \u7684\u6574\u6570\u5e38\u91cf\u8868\u8fbe\u5f0f\uff0c\u6216\u8005\u88ab\u8f6c\u6362\u4e3a void * \u7c7b\u578b\u7684\u6b64\u7c7b\u8868\u8fbe\u5f0f\u3002

\u90a3\u4e48\uff0c\u4e3a\u4ec0\u4e48 NULL \u7684\u503c\u88ab\u89c4\u5b9a\u4e3a 0 \u5462\uff1f

\u4f60\u53ef\u80fd\u4f1a\u731c\u60f3\uff0c\u8fd9\u662f\u56e0\u4e3a\u5185\u5b58\u5730\u5740 0x0 \u88ab\u7cfb\u7edf\u9884\u7559\u3002\u5bf9\u65e9\u671f\u64cd\u4f5c\u7cfb\u7edf\u800c\u8a00\uff0c\u8fd9\u79cd\u8bf4\u6cd5\u662f\u6210\u7acb\u7684\uff1b\u4f46\u662f\u73b0\u5728\uff0c\u4e0d\u540c\u5e73\u53f0\u5bf9\u7a7a\u6307\u9488\u7684\u503c\u5df2\u7ecf\u6709\u8bb8\u591a\u4e0d\u540c\u7684\u89c4\u5b9a\u3002\u65e0\u8bba NULL \u7684\u503c\u88ab\u5982\u4f55\u5b9a\u4e49\uff0c\u94fe\u63a5\u5668\u90fd\u5e94\u5c06\u7a7a\u6307\u9488\u7684\u503c\u6539\u4e3a\u76ee\u6807\u5e73\u53f0\u6307\u5b9a\u7684\u7a7a\u6307\u9488\u503c\u3002\u4e3a\u4e86\u5f3a\u8c03\u8fd9\u4e00\u70b9\uff0cC++11 \u5f15\u5165\u4e86 nullptr \u5173\u952e\u5b57\uff0c\u4f46 C \u6807\u51c6\u5e76\u672a\u5bf9\u6b64\u4f5c\u4efb\u4f55\u4fee\u6539\u3002

\u56de\u5230\u95ee\u9898\u672c\u8eab\uff0c\u5c06 0 \u89c6\u4f5c\u7279\u6b8a\u503c\u7684\u4e60\u60ef\u662f\u4e00\u4e2a\u6bd4\u8f83\u6709\u8bf4\u670d\u529b\u7684\u7406\u7531\u3002\u6b64\u5916\uff0c\u5c06 NULL \u5b9a\u4e49\u4e3a 0 \u4e5f\u53ef\u4ee5\u7b80\u5316\u8868\u8fbe\u5f0f\uff0c\u5373\u5229\u7528 C \u8bed\u8a00\u5c06 0 \u89c6\u4e3a false \u7684\u7279\u6027\uff0c\u7b80\u5316\u5bf9\u6307\u9488\u662f\u5426\u4e3a\u7a7a\u7684\u5224\u65ad\u3002

\u4e24\u4e2a\u7c7b\u578b\u517c\u5bb9\u7684\u6307\u9488\u95f4\u7684\u8d4b\u503c\u8fd0\u7b97\u3001\u6bd4\u8f83\u8fd0\u7b97\u4e0e\u51cf\u6cd5\u8fd0\u7b97\u662f\u6709\u6548\u7684\u3002\u82e5\u6307\u9488\u7c7b\u578b\u4e0d\u517c\u5bb9\uff0c\u5219\u9700\u8981\u8fdb\u884c\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u3002\u8fd9\u79cd\u8fd0\u7b97\u4ec5\u5728\u5c11\u6570\u60c5\u5f62\u4e0b\u6709\u610f\u4e49\uff0c\u5982\u4e24\u4e2a\u6307\u9488\u4f4d\u4e8e\u540c\u4e00\u6570\u7ec4\u5185\u65f6\u3002

\u6307\u9488\u4e0e\u6574\u6570\u95f4\u7684\u52a0\u6cd5\u6216\u51cf\u6cd5\u8fd0\u7b97\u4e5f\u662f\u6709\u6548\u7684\uff0c\u5176\u542b\u4e49\u662f\u4ee4\u6307\u9488\u524d\u79fb\u6216\u540e\u79fb\u82e5\u5e72\u4e2a\u6307\u5411\u5bf9\u8c61\u7684\u957f\u5ea6\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8868\u8fbe\u5f0f p + n \u7684\u503c\uff0c\u4ee3\u8868\u6307\u9488 p \u5f53\u524d\u6307\u5411\u7684\u5bf9\u8c61\u4e4b\u540e\u7b2c n \u4e2a\u5bf9\u8c61\u7684\u5730\u5740\u3002\u8fd9\u79cd\u8fd0\u7b97\u5728\u6570\u7ec4\u4e0e\u5b57\u7b26\u4e32\u64cd\u4f5c\u4e2d\u5341\u5206\u5e38\u89c1\u3002

\u867d\u7136\u5185\u5b58\u5730\u5740\u5f80\u5f80\u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u4f46\u662f\u6307\u9488\u4e0e\u6574\u6570\u4e4b\u95f4\u4e0d\u80fd\u76f8\u4e92\u8f6c\u6362\uff0c0 \u662f\u552f\u4e00\u7684\u4f8b\u5916\uff1a\u5e38\u91cf 0 \u53ef\u4ee5\u8d4b\u503c\u7ed9\u6307\u9488\uff0c\u6307\u9488\u4e5f\u53ef\u4e0e\u5e38\u91cf 0 \u8fdb\u884c\u6bd4\u8f83\u3002\u663e\u7136\uff0c\u6b64\u65f6\u5e38\u91cf 0 \u5c06\u88ab\u89c6\u4e3a\u7a7a\u6307\u9488 NULL\u3002

\u9664\u4ee5\u4e0a\u8fd0\u7b97\u5916\uff0c\u5176\u4ed6\u5f62\u5f0f\u7684\u6307\u9488\u8fd0\u7b97\u90fd\u662f\u975e\u6cd5\u7684\u3002

"},{"location":"programming/common/notes/pointers/#_9","title":"\u7528\u6cd5\u6982\u8ff0","text":""},{"location":"programming/common/notes/pointers/#_10","title":"\u53c2\u6570\u4f20\u9012","text":"

\u5728 C \u8bed\u8a00\u4e2d\uff0c\u8c03\u7528\u51fd\u6570\u65f6\u4ee5\u503c\u4f20\u9012\u5f62\u5f0f\u4f20\u9012\u53c2\u6570\uff1b\u5177\u4f53\u800c\u8a00\uff0c\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6\u4f1a\u91cd\u65b0\u521b\u5efa\u5f62\u53c2\uff0c\u5e76\u5c06\u5b9e\u53c2\u7684\u503c\u590d\u5236\u5230\u5bf9\u5e94\u7684\u5f62\u53c2\u3002\u51fd\u6570\u53ef\u4ee5\u4fee\u6539\u81ea\u8eab\u5f62\u53c2\uff0c\u4f46\u662f\u5b9e\u53c2\u7684\u503c\u4e0d\u4f1a\u968f\u4e4b\u6539\u53d8\u3002\u8fd9\u79cd\u8bbe\u8ba1\u5c06\u51fd\u6570\u4e0e\u6570\u636e\u9694\u79bb\uff0c\u907f\u514d\u4ea7\u751f\u610f\u6599\u4e4b\u5916\u7684\u526f\u4f5c\u7528\u3002

C \u8bed\u8a00\u4e2d\u53ea\u6709\u503c\u4f20\u9012

\u5982\u679c\u4f60\u5b66\u4e60\u8fc7 C++\uff0c\u4f60\u53ef\u80fd\u4f1a\u60f3\u5230\u5c06\u5f62\u53c2\u7684\u7c7b\u578b\u58f0\u660e\u4e3a\u5f15\u7528\uff0c\u968f\u540e\u901a\u8fc7\u5f15\u7528\u6539\u53d8\u5b9e\u53c2\u7684\u503c\u3002\u7136\u800c\uff0cC \u8bed\u8a00\u4e2d\u6ca1\u6709\u5f15\u7528\u7c7b\u578b\uff0c\u5728\u5f62\u53c2\u7c7b\u578b\u4e2d\u6dfb\u52a0 & \u662f\u975e\u6cd5\u7684\u3002

\u4e0d\u8fc7\uff0c\u5982\u679c\u6211\u4eec\u671f\u671b\u51fd\u6570\u4ea7\u751f\u526f\u4f5c\u7528\uff0c\u503c\u4f20\u9012\u7684\u65b9\u5f0f\u4fbf\u65e0\u6cd5\u6ee1\u8db3\u9700\u6c42\u3002\u4e3a\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u5f15\u5165\u6307\u9488\u7c7b\u578b\u7684\u53c2\u6570\uff0c\u4ee5\u8fbe\u5230\u4fee\u6539\u5176\u4ed6\u5bf9\u8c61\u7684\u76ee\u7684\u3002

\u6848\u4f8b\uff1a\u4ea4\u6362\u51fd\u6570

\u5047\u8bbe fake_swap \u51fd\u6570\u5b9a\u4e49\u5982\u4e0b\uff1a

void fake_swap(int x, int y) {\n    int tmp = x;\n    x = y;\n    y = tmp;\n}\n

\u8c03\u7528\u90e8\u5206\u5982\u4e0b\uff1a

int a = 1, b = 2;\nfake_swap(a, b);\n

\u5728\u8c03\u7528 fake_swap \u51fd\u6570\u540e\u68c0\u67e5 a\u3001b \u7684\u503c\uff0c\u53ef\u53d1\u73b0\u5b83\u4eec\u7684\u503c\u5e76\u6ca1\u6709\u4ea4\u6362\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u8c03\u7528 fake_swap \u51fd\u6570\u65f6\uff0c\u5b9e\u53c2 a\u3001b \u7684\u503c\u88ab\u590d\u5236\u7ed9\u5f62\u53c2 x\u3001y\uff0c\u51fd\u6570\u4ec5\u4fee\u6539\u4e86\u5f62\u53c2\u7684\u503c\uff0c\u5e76\u672a\u5f71\u54cd\u51fd\u6570\u5916\u90e8\u7684\u5b9e\u53c2\u3002

\u73b0\u5728\uff0c\u6211\u4eec\u5c06 fake_swap \u51fd\u6570\u4fee\u6539\u4e3a\uff1a

void swap(int *x, int *y) {\n    int tmp = *x;\n    *x = *y;\n    *y = tmp;\n}\n

\u8c03\u7528\u90e8\u5206\u5982\u4e0b\uff1a

int a = 1, b = 2;\nswap(&a, &b);\n

\u5728\u8c03\u7528 swap \u51fd\u6570\u540e\u68c0\u67e5 a\u3001b \u7684\u503c\uff0c\u53ef\u53d1\u73b0\u5b83\u4eec\u7684\u503c\u5df2\u7ecf\u4ea4\u6362\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u8c03\u7528 swap \u51fd\u6570\u65f6\uff0c\u5b9e\u53c2 a\u3001b \u7684\u5730\u5740\u88ab\u590d\u5236\u7ed9\u5f62\u53c2 x\u3001y\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0cx\u3001y \u5206\u522b\u6307\u5411 a\u3001b\u3002\u51fd\u6570\u4fee\u6539\u4e86 x\u3001y \u6307\u5411\u5bf9\u8c61\u7684\u503c\uff0c\u4e5f\u5c31\u662f a\u3001b \u7684\u503c\uff0c\u56e0\u6b64\u867d\u7136 a\u3001b \u5728\u51fd\u6570\u5916\u90e8\uff0c\u4f46\u5b83\u4eec\u7684\u503c\u5df2\u88ab\u6210\u529f\u4fee\u6539\u3002

C \u8bed\u8a00\u4e2d\u7684\u51fd\u6570\u53ea\u6709\u4e00\u4e2a\u8fd4\u56de\u503c\u3002\u82e5\u8981\u8fd4\u56de\u591a\u4e2a\u503c\uff0c\u53ef\u5c06\u6240\u6709\u8fd4\u56de\u503c\u653e\u5165\u7ed3\u6784\u4f53\u4e2d\uff1b\u4f46\u662f\uff0c\u8fd9\u9700\u8981\u989d\u5916\u58f0\u660e\u4e00\u4e2a\u4e34\u65f6\u4f7f\u7528\u7684\u7ed3\u6784\u4f53\u7c7b\u578b\uff0c\u62c6\u89e3\u7ed3\u6784\u4f53\u7684\u8fc7\u7a0b\u4e5f\u8017\u65f6\u8017\u529b\u3002\u4e00\u4e2a\u66f4\u597d\u7684\u65b9\u6848\u662f\uff0c\u5411\u51fd\u6570\u4f20\u9012\u6307\u9488\u53c2\u6570\uff0c\u7531\u51fd\u6570\u901a\u8fc7\u6307\u9488\u5c06\u7ed3\u679c\u5199\u5165\u76ee\u6807\u5bf9\u8c61\u3002\u6211\u4eec\u7ecf\u5e38\u4f7f\u7528\u7684 scanf \u51fd\u6570\u4fbf\u662f\u4e00\u4e2a\u5178\u578b\u4f8b\u5b50\u3002

"},{"location":"programming/common/notes/pointers/#_11","title":"\u64cd\u4f5c\u6570\u7ec4","text":"

\u4e00\u822c\u800c\u8a00\uff0c\u63d0\u5230\u201c\u6570\u7ec4\u201d\u65f6\uff0c\u6211\u4eec\u8ba8\u8bba\u7684\u65e2\u53ef\u4ee5\u662f\u6570\u7ec4\u7c7b\u578b\uff0c\u4e5f\u53ef\u4ee5\u662f\u6570\u7ec4\u7c7b\u578b\u7684\u5bf9\u8c61\u3002

\u6307\u9488\u4e0e\u6570\u7ec4\u7684\u5173\u7cfb\u5341\u5206\u5bc6\u5207\uff0c\u5b83\u4eec\u4e4b\u95f4\u7684\u8f6c\u6362\u4e5f\u662f C \u8bed\u8a00\u4e2d\u6700\u5e38\u89c1\u7684\u7c7b\u578b\u8f6c\u6362\u4e4b\u4e00\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u7528\u6307\u9488\u7f16\u5199\u7684\u7a0b\u5e8f\u6bd4\u7528\u6570\u7ec4\u7f16\u5199\u7684\u7a0b\u5e8f\u6267\u884c\u901f\u5ea6\u5feb\uff0c\u4f46\u53ef\u8bfb\u6027\u76f8\u5bf9\u8f83\u5dee\u3002

\u9605\u8bfb\u5efa\u8bae

\u4e0b\u6587\u7684\u8ba8\u8bba\u4e2d\u4f1a\u8bb2\u89e3\u6570\u7ec4\u7684\u90e8\u5206\u7279\u6027\uff0c\u4e0d\u8fc7\u4ecd\u7136\u5efa\u8bae\u5728\u719f\u6089\u6570\u7ec4\u540e\u9605\u8bfb\u3002

"},{"location":"programming/common/notes/pointers/#_12","title":"\u6570\u7ec4\u9000\u5316","text":"

\u6570\u7ec4\u7684\u503c\u5c31\u662f\u8be5\u6570\u7ec4\u7b2c\u4e00\u4e2a\u5143\u7d20\u7684\u5730\u5740\uff1b\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u6570\u7ec4\u4e5f\u7ecf\u5e38\u53ef\u88ab\u770b\u4f5c\u6307\u5411\u5176\u9996\u5143\u7d20\u6307\u9488\u3002\u4e8b\u5b9e\u4e0a\uff0cC \u6807\u51c6\u5bf9\u6b64\u4f5c\u5982\u4e0b\u89c4\u5b9a\uff1a

\u4efb\u4f55\u6570\u7ec4\u7c7b\u578b\u7684\u5de6\u503c\u8868\u8fbe\u5f0f\uff0c\u5f53\u7528\u4e8e\u5f02\u4e8e

\u7684\u8bed\u5883\u65f6\uff0c\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u3002

\u4e60\u60ef\u4e0a\uff0c\u6211\u4eec\u5c06\u6570\u7ec4\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u8fc7\u7a0b\uff0c\u79f0\u4e3a\u6570\u7ec4\u9000\u5316\u4e3a\u6307\u9488\u3002

C \u6807\u51c6\u89c4\u5b9a\uff0c\u8868\u8fbe\u5f0f E1[E2] \u7b49\u4ef7\u4e8e (*((E1) + (E2)))\u3002\u8fd9\u610f\u5473\u7740\uff0c\u6570\u7ec4\u5143\u7d20\u5728\u5185\u5b58\u4e2d\u8fde\u7eed\u3002\u53e6\u5916\uff0c\u5982\u679c\u786e\u4fe1\u76f8\u5e94\u5143\u7d20\u5b58\u5728\uff0c\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u8d85\u51fa\u6570\u7ec4\u8303\u56f4\u7684\u4e0b\u6807\uff0c\u8bbf\u95ee\u6570\u7ec4\u524d\u540e\u7684\u5143\u7d20\u3002

\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c

C \u8bed\u8a00\u4e0d\u4f1a\u68c0\u67e5\u6570\u7ec4\u4e0b\u6807\u662f\u5426\u8d85\u8fc7\u6570\u7ec4\u957f\u5ea6\uff0c\u5bf9\u6307\u9488\u4e5f\u51e0\u4e4e\u6ca1\u6709\u9650\u5236\u63aa\u65bd\u3002\u5c1d\u8bd5\u8bbf\u95ee\u8d85\u51fa\u6570\u7ec4\u8fb9\u754c\u7684\u5185\u5b58\u5730\u5740\uff0c\u53ef\u80fd\u5bfc\u81f4\u4e0e\u5c1d\u8bd5\u89e3\u5f15\u7528\u91ce\u6307\u9488\u7b49\u540c\u7684\u5371\u5bb3\u3002\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c\u662f\u6bb5\u9519\u8bef\u7684\u4e3b\u8981\u8bf1\u56e0\u4e4b\u4e00\u3002\u56e0\u6b64\uff0c\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u524d\uff0c\u52a1\u5fc5\u5145\u5206\u68c0\u67e5\u6307\u5b9a\u7684\u4e0b\u6807\u4e0e\u6307\u9488\u504f\u79fb\u91cf\u662f\u5426\u5728\u6570\u7ec4\u8303\u56f4\u5185\u3002

\u7531\u4e8e\u590d\u5236\u6570\u7ec4\u7684\u5f00\u9500\u7ecf\u5e38\u5927\u5230\u4e0d\u53ef\u63a5\u53d7\uff0cC \u6807\u51c6\u89c4\u5b9a\uff0c\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u65f6\u6570\u7ec4\u4e5f\u5e94\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u5176\u9996\u5143\u7d20\u6307\u9488\u3002\u6240\u4ee5\uff0c\u5728\u8bed\u6cd5\u5c42\u9762\u4e0a\uff0c\u51fd\u6570\u58f0\u660e\u4e0e\u5b9a\u4e49\u4e2d\uff0c\u5f62\u5982 char str[] \u7684\u5f62\u53c2\u58f0\u660e\u4e0e char *str \u662f\u7b49\u4ef7\u7684\uff0c\u4e0d\u8fc7\u524d\u8005\u53ef\u4ee5\u63d0\u9192\u51fd\u6570\u7f16\u5199\u8005\u4e0e\u4f7f\u7528\u8005\u7559\u610f str \u7684\u5b9e\u9645\u542b\u4e49\u3002\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f20\u5165\u6307\u5411\u5176\u4ed6\u5143\u7d20\u7684\u6307\u9488\uff0c\u8fd9\u5728\u4f20\u53c2\u8fc7\u7a0b\u4e2d\u6ca1\u6709\u533a\u522b\u3002

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd4\u56de\u7c7b\u578b\u4e2d\u7684\u6570\u7ec4\u4e0d\u4f1a\u81ea\u52a8\u8f6c\u6362\u6210\u6307\u9488\uff0c\u56e0\u6b64\u5f62\u5982 char func() []; \u7684\u51fd\u6570\u58f0\u660e\u662f\u975e\u6cd5\u7684\u3002

\u6570\u7ec4\u7c7b\u578b\u4e0e\u6307\u9488\u7c7b\u578b\u7684\u533a\u522b

\u5c3d\u7ba1\u5728\u7a0b\u5e8f\u4e2d\u6570\u7ec4\u7ecf\u5e38\u9000\u5316\u4e3a\u6307\u9488\uff0c\u6211\u4eec\u4ecd\u5e94\u8be5\u533a\u5206\u8fd9\u4e24\u4e2a\u7c7b\u578b\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8003\u8651\u5982\u4e0b\u7684\u7a0b\u5e8f\u7247\u6bb5\uff08C \u6807\u51c6\u89c4\u5b9a sizeof \u7684\u8fd4\u56de\u503c\u7c7b\u578b\u4e3a\u65e0\u7b26\u53f7\u6574\u578b size_t\uff0c\u5e94\u4f7f\u7528 %zu \u683c\u5f0f\u6307\u793a\u7b26\u8f93\u51fa\uff09\uff1a

int a[3], *p;\nprintf(\"%zu %zu\", sizeof(a), sizeof(p));\n

\u5b83\u5c06\u4f1a\u8f93\u51fa 12 8\u3002\u8fd9\u662f\u56e0\u4e3a\uff0ca \u662f\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int \u4e14\u957f\u5ea6\u4e3a 3 \u7684\u6570\u7ec4\u5bf9\u8c61\uff0c\u5728\u591a\u6570\u7cfb\u7edf\u4e2d int \u7c7b\u578b\u957f\u5ea6\u4e3a 4 \u5b57\u8282\uff0c\u56e0\u6b64 a \u7684\u957f\u5ea6\u4e3a 12 \u5b57\u8282\uff1b\u800c p \u662f\u4e00\u4e2a\u6307\u9488\uff0c\u5728\u5e38\u7528\u7684 64 \u4f4d\u7cfb\u7edf\u4e2d\u957f\u5ea6\u4e3a 8 \u5b57\u8282\u3002

\u53e6\u5916\uff0c\u6307\u9488\u7684\u503c\u53ef\u5728\u4efb\u610f\u65f6\u523b\u901a\u8fc7\u8d4b\u503c\u4fee\u6539\uff0c\u800c\u6570\u7ec4\u4e0d\u80fd\u88ab\u8d4b\u503c\u3002

"},{"location":"programming/common/notes/pointers/#_13","title":"\u591a\u7ef4\u6570\u7ec4","text":"

\u4e0e\u6307\u9488\u7c7b\u4f3c\uff0c\u6570\u7ec4\u4e5f\u662f\u6d3e\u751f\u7c7b\u578b\u3002\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\uff0c\u4e3a\u4e86\u6b63\u786e\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff0c\u9700\u8981\u77e5\u9053\u6570\u7ec4\u5143\u7d20\u7684\u957f\u5ea6\uff0c\u5373\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u578b\u5fc5\u987b\u662f\u5b8c\u6574\u7684\u3002

\u591a\u7ef4\u6570\u7ec4

\u6211\u4eec\u79f0\u5143\u7d20\u7c7b\u578b\u4e3a\u6570\u7ec4\u7684\u6570\u7ec4\u4e3a\u591a\u7ef4\u6570\u7ec4\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c[] \u8fd0\u7b97\u7b26\u662f\u4ece\u53f3\u5f80\u5de6\u7ed3\u5408\u7684\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 int a[2][3]; \u58f0\u660e\u4e86\u4e00\u4e2a\u957f\u5ea6\u4e3a 2\u7684\u6570\u7ec4 a\uff0c\u5b83\u7684\u5143\u7d20\u7c7b\u578b\u4e3a int [3]\uff1b\u5bf9\u5e94\u5730\uff0c\u901a\u8fc7\u8868\u8fbe\u5f0f a[x][y] \u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u65f6\uff0cx \u4e0e y \u7684\u53d6\u503c\u8303\u56f4\u5206\u522b\u4e3a 0~1 \u4e0e 0~2\u3002

\u5f53\u5e94\u7528\u6570\u7ec4\u5230\u6307\u9488\u8f6c\u6362\u65f6\uff0c\u591a\u7ef4\u6570\u7ec4\u88ab\u8f6c\u6362\u6210\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u6307\u9488\u3002\u6211\u4eec\u79f0\u8fd9\u79cd\u6307\u5411\u6570\u7ec4\u7684\u6307\u9488\u4e3a\u6570\u7ec4\u6307\u9488\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0cint [2][3] \u7c7b\u578b\u7684\u4e8c\u7ef4\u6570\u7ec4\u4f1a\u88ab\u8f6c\u6362\u4e3a int (*)[3] \u7c7b\u578b\u7684\u6570\u7ec4\u6307\u9488\u3002

\u6848\u4f8b\uff1a\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u591a\u7ef4\u6570\u7ec4\u5143\u7d20

\u6839\u636e C \u6807\u51c6\u89c4\u5b9a\uff0c\u4e0d\u96be\u63a8\u65ad\u51fa\u8868\u8fbe\u5f0f a[i][j] \u4e0e\u8868\u8fbe\u5f0f *(*(a + i) + j) \u7b49\u4ef7\u3002\u4e0d\u8fc7\uff0c\u540e\u8005\u7684\u6c42\u503c\u8fc7\u7a0b\u76f8\u6bd4\u524d\u8005\u66f4\u52a0\u62bd\u8c61\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u5c06\u4ee5\u6b64\u4e3a\u4f8b\u9010\u6b65\u5206\u6790\u5176\u6c42\u503c\u8fc7\u7a0b\u3002

  1. \u5047\u8bbe a \u7684\u7c7b\u578b\u4e3a int [2][3]\u3002\u6211\u4eec\u77e5\u9053\uff0c\u6b64\u5904\u6570\u7ec4 a \u4f1a\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a int (*)[3] \u7c7b\u578b\u7684\u6307\u9488\u3002\u56de\u5fc6\u4e00\u4e0b\u6307\u9488\u4e0e\u6574\u6570\u7684\u52a0\u51cf\u6cd5\u8fd0\u7b97\uff0cp + i \u5e76\u975e\u7b80\u5355\u5730\u5c06\u6307\u9488 p \u7684\u503c\u589e\u52a0 i \u5b57\u8282\uff0c\u800c\u662f\u589e\u52a0 i \u4e2a int [3] \u7c7b\u578b\u5bf9\u8c61\u7684\u957f\u5ea6\uff0c\u5373 i * sizeof(int [3]) \u5b57\u8282\u3002

  2. \u4e0d\u59a8\u79f0\u6570\u7ec4 a \u9690\u5f0f\u8f6c\u6362\u7684\u6307\u9488\u4e3a ap\u3002\u90a3\u4e48\uff0c\u5185\u5c42\u8868\u8fbe\u5f0f\u53ef\u6539\u5199\u4e3a *(ap + i)\uff0c\u5176\u542b\u4e49\u662f\u4ece a \u5f00\u59cb\uff0c\u5411\u540e\u79fb\u52a8 i * sizeof(int [3]) \u4e2a\u5b57\u8282\uff0c\u5e76\u83b7\u5f97\u8be5\u5185\u5b58\u5730\u5740\u5b58\u50a8\u7684 int [3] \u7c7b\u578b\u7684\u6570\u7ec4\u3002\u6b64\u65f6\uff0c\u6211\u4eec\u5f97\u5230\u4e86\u6570\u7ec4 a[i]\u3002

  3. \u4e0d\u59a8\u79f0\u4e0a\u4e00\u6b65\u5f97\u5230\u7684\u6570\u7ec4\u4e3a a_i\u3002\u90a3\u4e48\uff0c\u4e0b\u4e00\u5c42\u8868\u8fbe\u5f0f\u53ef\u4ee5\u6539\u5199\u4e3a *(a_i + j)\uff0c\u5176\u542b\u4e49\u662f\u4ece a_i \u5f00\u59cb\uff0c\u5411\u540e\u79fb\u52a8 j * sizeof(int) \u4e2a\u5b57\u8282\uff0c\u5e76\u83b7\u5f97\u8be5\u5185\u5b58\u5730\u5740\u5b58\u50a8\u7684 int \u7c7b\u578b\u5bf9\u8c61\u7684\u503c\u3002\u4e0d\u96be\u770b\u51fa\uff0c\u6211\u4eec\u5f97\u5230\u7684\u7ed3\u679c\u6b63\u662f a[i][j] \u7684\u503c\u3002

\u6709\u5fc5\u8981\u8bf4\u660e\uff0c\u4ee5\u4e0a\u5206\u6790\u8fc7\u7a0b\u5bf9\u6240\u6709\u6574\u6570 i\u3001j \u5747\u6210\u7acb\u3002\u8fd9\u610f\u5473\u7740\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8868\u8fbe\u5f0f a[1][-1] \u8bbf\u95ee a[0] \u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002\u7136\u800c\uff0c\u6b64\u7c7b\u8868\u8fbe\u5f0f\u53ef\u8bfb\u6027\u4e0d\u5f3a\uff0c\u6700\u597d\u5728\u5b9e\u9645\u7a0b\u5e8f\u4e2d\u907f\u514d\u3002

\u6307\u9488\u6570\u7ec4

\u6211\u4eec\u79f0\u5143\u7d20\u7c7b\u578b\u4e3a\u6307\u9488\u7684\u6570\u7ec4\u4e3a\u6307\u9488\u6570\u7ec4\u3002\u5bb9\u6613\u60f3\u5230\uff0c\u6307\u9488\u6570\u7ec4\u5176\u5b9e\u662f\u4e2a\u4e00\u7ef4\u6570\u7ec4\uff1b\u4e0d\u8fc7\u7531\u4e8e\u5176\u5143\u7d20\u7c7b\u578b\u4e3a\u6307\u9488\uff0c\u8bbf\u95ee\u5143\u7d20\u7684\u5f62\u5f0f\u4e0e\u591a\u7ef4\u6570\u7ec4\u6709\u90e8\u5206\u76f8\u4f3c\u4e4b\u5904\u3002\u6307\u9488\u6570\u7ec4\u7684\u4e00\u4e2a\u5178\u578b\u7528\u6cd5\u662f\u5b58\u50a8\u5e76\u4f20\u9012\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u5373\u4e00\u79cd main \u51fd\u6570\u58f0\u660e int main(int argc, char *argv[]) \u4e2d\u7684 argv \u53c2\u6570\u3002

\u7c7b\u4f3c\u5730\uff0c\u6211\u4eec\u79f0\u6307\u5411\u67d0\u4e2a\u6307\u9488\u7684\u6307\u9488\u4e3a\u591a\u7ea7\u6307\u9488\u3002\u4e8c\u7ea7\u6307\u9488\u5e38\u89c1\u4e8e\u94fe\u8868\u64cd\u4f5c\u4e2d\uff0c\u66f4\u9ad8\u7ea7\u7684\u6307\u9488\u5219\u5f88\u5c11\u51fa\u73b0\u3002

\u6570\u7ec4\u9000\u5316\u7684\u9650\u5ea6

\u56de\u5fc6\u4e0a\u6587\u5f15\u7528\u7684 C \u6807\u51c6\u89c4\u5b9a\uff0c\u82e5\u8bed\u5883\u6ee1\u8db3\u6761\u4ef6\uff0c\u6570\u7ec4\u5c06\u4f1a\u9690\u5f0f\u8f6c\u6362\u4e3a\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u6307\u9488\u3002\u8fd9\u610f\u5473\u7740\uff0c\u6570\u7ec4\u9000\u5316\u7684\u9650\u5ea6\u662f\u5c06\u6307\u9488\u7ea7\u6570\u589e\u52a0\u4e00\u7ea7\u3002\u6211\u4eec\u53ef\u4ee5\u60f3\u5230\uff0c\u8fd9\u4e00\u9650\u5ea6\u662f\u4e3a\u4e86\u786e\u4fdd\u8fd0\u7b97\u7b26 [] \u7684\u6b63\u786e\u6027\uff0c\u5373\u4fdd\u8bc1\u6309\u6807\u51c6\u4e0e\u5176\u7b49\u4ef7\u7684\u6307\u9488\u8fd0\u7b97\u53ef\u4ee5\u6b63\u786e\u8ba1\u7b97\u504f\u79fb\u91cf\u3002\u56e0\u6b64\uff0c\u4e8c\u7ef4\u6570\u7ec4\u4e0d\u80fd\u9690\u5f0f\u8f6c\u6362\u4e3a\u4e8c\u7ea7\u6307\u9488\u3002\u7f16\u8bd1\u5668\u5bf9\u6b64\u5c06\u4f1a\u7ed9\u51fa\u8b66\u544a\u3002

"},{"location":"programming/common/notes/pointers/#_14","title":"\u5b57\u7b26\u4e32","text":"

\u6211\u4eec\u77e5\u9053\uff0cC \u8bed\u8a00\u4e2d\u7684\u5b57\u7b26\u4e32\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u7a7a\u5b57\u7b26\uff08\u79f0\u4e3a\u4e2d\u6b62\u5b57\u7b26\uff09\u7ed3\u5c3e\u7684\u5b57\u7b26\u6570\u7ec4\u3002\u56e0\u6b64\uff0c\u4e0a\u4e00\u5c0f\u8282\u7684\u8ba8\u8bba\u540c\u6837\u9002\u7528\u4e8e\u8fd9\u4e00\u5c0f\u8282\u3002

\u7531\u4e8e\u5b57\u7b26\u4e32\u540c\u65f6\u5177\u6709\u6570\u7ec4\u7684\u5c5e\u6027\uff0c\u8ba8\u8bba\u4e0e\u5185\u5b58\u7a7a\u95f4\u6709\u5173\u7684\u6982\u5ff5\u4e0e\u64cd\u4f5c\u65f6\uff0c\u4e3a\u907f\u514d\u6df7\u6dc6\uff0c\u6211\u4eec\u5c06\u6570\u7ec4\u5bf9\u8c61\u5360\u7528\u7684\u5b57\u8282\u6570\u79f0\u4e3a\u5176\u5927\u5c0f\uff0c\u5c06\u5b9e\u9645\u7ec4\u6210\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u6570\u79f0\u4e3a\u5176\u957f\u5ea6\u3002\u4e00\u4e2a\u76f4\u89c2\u7406\u89e3\u662f\uff0c\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u8ba1\u5165\u4e2d\u6b62\u5b57\u7b26\uff0c\u800c\u5176\u957f\u5ea6\u4e0d\u8ba1\u5165\u3002

\u5728 C \u8bed\u8a00\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u662f\u7531\u4e00\u5bf9 \" \u5305\u56f4\u7684\u4efb\u610f\u957f\u5ea6\u7684\u5b57\u7b26\u5e8f\u5217\uff0c\u5176\u4e2d\u7684\u5b57\u7b26\u53ef\u4ee5\u662f\u4e00\u822c\u5b57\u7b26\u6216\u8f6c\u4e49\u5b57\u7b26\uff0c\u5982 \"abc\"\u3001\"x y\\nz\"\u3001\"\"\u3002\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u672b\u5c3e\u9690\u5f0f\u5305\u542b\u4e2d\u6b62\u5b57\u7b26\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\"\" \u4ee3\u8868\u5927\u5c0f\u4e3a 1 \u7684\u5b57\u7b26\u6570\u7ec4\uff0c\u5b83\u7684\u552f\u4e00\u5143\u7d20\u4e3a '\\0'\u3002

\u542b\u7a7a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u5b57\u9762\u91cf

\u82e5\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5b57\u7b26\u5e8f\u5217\u5185\u5305\u542b\u7a7a\u5b57\u7b26\uff0c\u5219\u5b83\u8868\u793a\u542b\u6709\u591a\u4e8e\u4e00\u6761\u5b57\u7b26\u4e32\u7684\u6570\u7ec4\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5bf9\u4e8e\u5b57\u7b26\u4e32\u5b57\u9762\u91cf \"abc\\0\"\uff0c\u5b83\u5305\u542b \"abc\" \u548c \"\" \u4e24\u4e2a\u5b57\u7b26\u4e32\u3002

\u4f60\u53ef\u4ee5\u901a\u8fc7 sizeof \u8fd0\u7b97\u7b26\u548c strlen \u51fd\u6570\u9a8c\u8bc1\u7a0b\u5e8f\u884c\u4e3a\u3002

\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u7c7b\u578b\u4e3a char [N]\uff0c\u5176\u4e2d N \u662f\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\uff0c\u5305\u62ec\u9690\u5f0f\u7684\u4e2d\u6b62\u5b57\u7b26\u3002\u663e\u7136\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u4e5f\u9075\u5b88\u6570\u7ec4\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u89c4\u5219\u3002

\u5c1d\u8bd5\u4fee\u6539\u5b57\u7b26\u4e32\u5b57\u9762\u91cf

\u867d\u7136\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u7c7b\u578b\u6ca1\u6709\u6307\u5b9a\u4e3a const\uff0c\u4f46\u5b83\u5b9e\u9645\u4e0a\u4e5f\u662f\u5e38\u91cf\u3002\u5c1d\u8bd5\u4fee\u6539\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\u3002\u4e00\u822c\u800c\u8a00\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5185\u5bb9\u4f1a\u88ab\u653e\u5165\u53ea\u8bfb\u5185\u5b58\u4e2d\uff0c\u56e0\u6b64\u5c1d\u8bd5\u4fee\u6539\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u9519\u8bef\u3002

\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u672a\u9000\u5316\u60c5\u5f62

\u8003\u8651\u5982\u4e0b\u7a0b\u5e8f\u7247\u6bb5\uff1a

char *str = \"abc\";\nprintf(\"%zu %zu\\n\", sizeof(\"abc\"), sizeof(str));\n

\u5b83\u5c06\u4f1a\u8f93\u51fa 4 8\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u6b64\u65f6\u5b57\u7b26\u4e32\u5b57\u9762\u91cf \"abc\" \u88ab\u4f5c\u4e3a sizeof \u7684\u64cd\u4f5c\u6570\uff0c\u4e0d\u4f1a\u9000\u5316\u4e3a\u6307\u9488\uff0c\u56e0\u6b64\u8868\u8fbe\u5f0f sizeof(\"abc\") \u7684\u7ed3\u679c\u662f\u5b57\u7b26\u4e32\u6570\u7ec4\u7684\u5927\u5c0f\u3002

\u4e0d\u96be\u60f3\u5230\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5176\u6548\u679c\u76f8\u5f53\u4e8e\u4f7f\u7528\u5bf9\u5e94\u7684\u5b57\u7b26\u6570\u7ec4\u5e38\u91cf\u521d\u59cb\u5316\u3002\u4e0e\u4e00\u822c\u7684\u6570\u7ec4\u521d\u59cb\u5316\u7c7b\u4f3c\uff0c\u6570\u7ec4\u957f\u5ea6\u53ef\u7531\u521d\u59cb\u5316\u5668\u9690\u5f0f\u6307\u5b9a\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 char str[] = \"abc\"; \u7b49\u4ef7\u4e8e\u8bed\u53e5 char str[] = {'a', 'b', 'c', '\\0'};\uff0c\u5b83\u58f0\u660e\u5e76\u521d\u59cb\u5316\u4e86\u4e00\u4e2a\u957f\u5ea6\u4e3a 4 \u7684\u5b57\u7b26\u6570\u7ec4 str\u3002

\u6570\u7ec4\u7684\u5927\u5c0f\u53ef\u4ee5\u6bd4\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5927\u5c0f\u5c11 1\uff0c\u6b64\u65f6\u4e2d\u6b62\u5b57\u7b26\u5c06\u88ab\u5ffd\u7565\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 char str[3] = \"abc\"; \u7b49\u4ef7\u4e8e\u8bed\u53e5 char str[3] = {'a', 'b', 'c'};\u3002

\u6848\u4f8b\uff1a\u9519\u8bef\u7684\u5b57\u7b26\u6570\u7ec4\u521d\u59cb\u5316

\u8003\u8651\u5982\u4e0b\u7a0b\u5e8f\u7247\u6bb5\uff1a

char str[3] = \"abc\";\nchar backdoor[] = \"xyz\";\nprintf(\"%s\", str);\n

\u5b83\u5c06\u4f1a\u8f93\u51fa abcxyz\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf \"abc\" \u7684\u5927\u5c0f str \u7684\u5927\u5c0f\u5927 1\uff0c\u521d\u59cb\u5316\u65f6\u4e2d\u6b62\u5b57\u7b26\u88ab\u5ffd\u7565\uff0cstr \u6700\u7ec8\u88ab\u521d\u59cb\u5316\u4e3a {'a', 'b', 'c'}\u3002\u5c06\u5176\u89c6\u4e3a\u5b57\u7b26\u4e32\u5e76\u8f93\u51fa\u65f6\uff0c\u7531\u4e8e str \u5185\u4e0d\u542b\u4e2d\u6b62\u5b57\u7b26\uff0c\u8f93\u51fa\u51fd\u6570\u5c06\u4f1a\u7ee7\u7eed\u8bbf\u95ee str \u540e\u7684\u5185\u5b58\u5730\u5740\uff0c\u5373\u51fa\u73b0\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c\u95ee\u9898\u3002

\u7531\u4e8e C \u6807\u51c6\u5e76\u672a\u5bf9\u5b57\u9762\u91cf\u7684\u5185\u5b58\u6392\u5e03\u4f5c\u4efb\u4f55\u89c4\u5b9a\uff0c\u5728\u4e0d\u540c\u73af\u5883\u4e0b\u5b57\u7b26\u4e32\u5e38\u91cf backdoor \u7684\u5185\u5b58\u5730\u5740\u53ef\u80fd\u4f4d\u4e8e str \u7684\u5185\u5b58\u5730\u5740\u4e4b\u524d\u3002\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u6539\u53d8\u58f0\u660e\u987a\u5e8f\u4ee5\u8fbe\u5230\u7c7b\u4f3c\u7684\u8f93\u51fa\u6548\u679c\u3002

\u6839\u636e\u9690\u5f0f\u8f6c\u6362\u89c4\u5219\uff0c\u5728\u591a\u6570\u8868\u8fbe\u5f0f\u4e2d\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u5c06\u4f1a\u9690\u5f0f\u8f6c\u6362\u4e3a\u6307\u5411\u5b83\u7684\u6307\u9488\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8be5\u6307\u9488\u7684\u503c\u662f\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5185\u5b58\u5730\u5740\u3002\u7c7b\u4f3c\u5730\uff0c\u88ab\u7528\u4e8e\u5bf9\u6307\u9488\u7684\u521d\u59cb\u5316\u65f6\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u4e5f\u4f1a\u9000\u5316\u4e3a\u6307\u9488\u3002

\u5728\u51fd\u6570\u5185\u4fee\u6539\u5b57\u7b26\u4e32\u65f6\uff0c\u4f20\u5165\u7684\u5b57\u7b26\u6570\u7ec4\u5c06\u4f1a\u9000\u5316\u4e3a\u6307\u9488\uff0c\u6570\u7ec4\u7684\u5927\u5c0f\u4fe1\u606f\u56e0\u6b64\u4e22\u5931\u3002\u53ef\u4ee5\u60f3\u5230\uff0c\u5b57\u7b26\u4e32\u672b\u5c3e\u7684\u7a7a\u5b57\u7b26\u6b63\u662f\u4e3a\u8fd9\u79cd\u60c5\u5f62\u8bbe\u8ba1\u7684\u3002

\u7b80\u5316\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570

\u5173\u4e8e\u5229\u7528\u6307\u9488\u7f16\u5199\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\u7684\u6280\u5de7\uff0c\u4f60\u53ef\u4ee5\u53c2\u8003\u300aC \u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u300b\uff08\u4e5f\u5c31\u662f\u7a0b\u8bbe\u8bfe\u7a0b\u4f7f\u7528\u7684\u8bfe\u672c\uff09\u4e2d\u7ed9\u51fa\u7684 strcpy \u4e0e strcmp \u51fd\u6570\u7684\u5b9e\u73b0\u8fed\u4ee3\u3002\u672c\u6587\u5bf9\u6b64\u4e0d\u518d\u8d58\u8ff0\u3002

C \u8bed\u8a00\u6807\u51c6\u5e93\u4e2d\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\uff0c\u5b83\u4eec\u5927\u591a\u88ab\u5b9a\u4e49\u5728 string.h \u5934\u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528\u65f6\u5747\u9700\u4fdd\u8bc1\u63d0\u4f9b\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u7b26\u5408\u7ea6\u5b9a\u3002

\u4e2d\u6b62\u5b57\u7b26\u7f3a\u5931

\u6807\u51c6\u5e93\u4e2d\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\u901a\u8fc7\u68c0\u67e5\u4e2d\u6b62\u5b57\u7b26\u5224\u65ad\u662f\u5426\u5230\u8fbe\u5b57\u7b26\u4e32\u672b\u5c3e\u3002\u56e0\u6b64\uff0c\u5728\u4fee\u6539\u5b57\u7b26\u4e32\u65f6\u52a1\u5fc5\u6ce8\u610f\u4fdd\u7559\u4e2d\u6b62\u5b57\u7b26\u3002\u5982\u679c\u4e2d\u6b62\u5b57\u7b26\u7f3a\u5931\uff0c\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\u5c06\u4f1a\u5bfc\u81f4\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c\u95ee\u9898\u3002

"},{"location":"programming/common/notes/pointers/#_15","title":"\u51fd\u6570\u6307\u9488","text":"

\u6709\u65f6\uff0c\u6211\u4eec\u5e0c\u671b\u51fd\u6570\u53ef\u4ee5\u9075\u5faa\u6307\u5b9a\u7684\u89c4\u5219\uff0c\u6216\u8005\u5b8c\u6210\u6307\u5b9a\u64cd\u4f5c\uff0c\u4f46\u662f\u53c8\u4e0d\u5e0c\u671b\u6216\u65e0\u6cd5\u5b9e\u73b0\u4e00\u7cfb\u5217\u9ad8\u5ea6\u76f8\u4f3c\u7684\u51fd\u6570\uff0c\u56e0\u6b64\u6211\u4eec\u5e0c\u671b\u5728\u53c2\u6570\u4e2d\u5f15\u5165\u53e6\u4e00\u4e2a\u51fd\u6570\u3002C \u8bed\u8a00\u4e3a\u6b64\u63d0\u4f9b\u4e86\u6307\u5411\u51fd\u6570\u7684\u6307\u9488\uff0c\u79f0\u4e3a\u51fd\u6570\u6307\u9488\u3002

\u5728\u7f16\u8bd1\u5f97\u5230\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\uff0c\u7a0b\u5e8f\u4e2d\u7684\u6307\u4ee4\u4e0e\u6570\u636e\u88ab\u5206\u522b\u5b58\u50a8\uff0c\u4ee5\u4f9b CPU \u8bbf\u95ee\u5e76\u4f7f\u7528\u3002\u51fd\u6570\u6307\u9488\u7684\u503c\uff0c\u5b9e\u9645\u4e0a\u662f\u51fd\u6570\u7b2c\u4e00\u6761\u6307\u4ee4\u7684\u5730\u5740\uff0c\u4e5f\u5373\u51fd\u6570\u7684\u5165\u53e3\u5730\u5740\u3002

\u51fd\u6570\u7684\u5185\u5b58\u5e03\u5c40

\u5728\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\uff0c\u6307\u4ee4\u4e0e\u6570\u636e\u88ab\u5206\u522b\u5b58\u50a8\u5728\u4ee3\u7801\u6bb5\u4e0e\u6570\u636e\u6bb5\u4e2d\u3002\u6bcf\u4e2a\u51fd\u6570\u7684\u6307\u4ee4\u5f80\u5f80\u88ab\u5b58\u50a8\u5728\u4ee3\u7801\u6bb5\u4e2d\u7684\u4e00\u6bb5\u8fde\u7eed\u5185\u5b58\u7a7a\u95f4\u4e2d\uff0c\u6839\u636e\u8fd9\u4e00\u7279\u70b9\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u51fd\u6570\u770b\u4f5c\u4e00\u79cd\u7279\u6b8a\u7684\u5bf9\u8c61\u3002

\u4e0e\u6570\u7ec4\u7c7b\u4f3c\uff0c\u51fd\u6570\u4e5f\u4f1a\u9000\u5316\u4e3a\u6307\u9488\u3002C \u6807\u51c6\u5bf9\u6b64\u4f5c\u5982\u4e0b\u89c4\u5b9a\uff1a

\u4efb\u4f55\u51fd\u6570\u6307\u4ee3\u5668\u8868\u8fbe\u5f0f\uff0c\u5728\u7528\u4e8e\u5f02\u4e8e\u4e0b\u5217\u8bed\u5883\u65f6

\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u8868\u8fbe\u5f0f\u6240\u6307\u4ee3\u51fd\u6570\u7684\u6307\u9488\u7684\u8f6c\u6362\u3002

\u5229\u7528\u8fd9\u4e2a\u89c4\u5219\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u540d\u4e3a\u51fd\u6570\u6307\u9488\u8d4b\u503c\uff0c\u4e5f\u53ef\u4ee5\u5199\u51fa\u590d\u6742\u7684\u8868\u8fbe\u5f0f\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c() \u8fd0\u7b97\u7b26\u4e5f\u662f\u4ece\u53f3\u5f80\u5de6\u7ed3\u5408\u7684\uff0c\u4e14\u4f18\u5148\u7ea7\u9ad8\u4e8e * \u8fd0\u7b97\u7b26\u3002\u4e3e\u4f8b\u800c\u8a00\uff0c\u8bed\u53e5 int *f(void); \u58f0\u660e\u4e86\u4e00\u4e2a\u51fd\u6570 f\uff0c\u5b83\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u4e3a int *\uff1b\u800c\u8bed\u53e5 int (*fp)(void); \u58f0\u660e\u4e86\u4e00\u4e2a\u51fd\u6570\u6307\u9488 fp\uff0c\u5b83\u6307\u5411\u4e00\u4e2a\u8fd4\u56de\u503c\u7c7b\u578b\u4e3a int \u7684\u51fd\u6570\u3002

\u51fd\u6570\u6307\u9488\u8bed\u53e5\u9605\u8bfb\u7ec3\u4e60

\u53e6\u4e00\u7bc7\u7b14\u8bb0\u7ec6\u81f4\u8bb2\u89e3\u4e86\u5982\u4f55\u9605\u8bfb\u5e76\u7406\u89e3\u5305\u542b\u51fd\u6570\u6307\u9488\u7684\u8bed\u53e5\uff0c\u672c\u6587\u5bf9\u6b64\u4e0d\u518d\u8d58\u8ff0\u3002

"},{"location":"programming/common/notes/pointers/#_16","title":"\u7ed3\u6784\u4f53\u4e0e\u5185\u5b58\u7ba1\u7406","text":"

\u9605\u8bfb\u5efa\u8bae

\u4e0b\u6587\u7684\u8ba8\u8bba\u4e2d\u4f1a\u8bb2\u89e3\u7ed3\u6784\u4f53\u7684\u90e8\u5206\u7279\u6027\uff0c\u4e0d\u8fc7\u4ecd\u7136\u5efa\u8bae\u5728\u719f\u6089\u7ed3\u6784\u4f53\u540e\u9605\u8bfb\u3002

\u7ed3\u6784\u4f53\u662f\u4e00\u79cd\u805a\u5408\u7c7b\u578b\uff0c\u5b83\u5c06\u591a\u4e2a\u4e0d\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\u7ec4\u5408\u6210\u4e00\u4e2a\u5bf9\u8c61\u3002\u7ed3\u6784\u4f53\u7ecf\u5e38\u88ab\u7528\u4e8e\u7ed9\u4e00\u4e2a\u590d\u6742\u6982\u5ff5\u5efa\u7acb\u6a21\u578b\u3002

\u5728\u590d\u6742\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u7ebf\u6027\u7684\u6570\u7ec4\u5f80\u5f80\u65e0\u6cd5\u5c55\u793a\u6570\u636e\u95f4\u7684\u903b\u8f91\u5173\u7cfb\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u5f80\u5f80\u4f1a\u5927\u91cf\u4f7f\u7528\u7ed3\u6784\u4f53\u4e0e\u7ed3\u6784\u4f53\u6307\u9488\u3002\u7531\u4e8e\u901a\u8fc7\u7ed3\u6784\u4f53\u6307\u9488\u8bbf\u95ee\u5176\u6210\u5458\u7684\u60c5\u5f62\u5341\u5206\u5e38\u89c1\uff0cC \u8bed\u8a00\u63d0\u4f9b\u4e86 -> \u8fd0\u7b97\u7b26\u4ee5\u7b80\u5316\u8868\u8fbe\u5f0f\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8868\u8fbe\u5f0f p->x \u7b49\u4ef7\u4e8e (*p).x\u3002

\u7531\u4e8e\u5efa\u7acb\u8fc7\u7a0b\u6bd4\u8f83\u7e41\u7410\uff0c\u6211\u4eec\u5e0c\u671b\u4e00\u76f4\u5b58\u50a8\u5b8c\u6210\u5efa\u7acb\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4ee5\u4f9b\u7a0b\u5e8f\u4e2d\u7684\u5176\u4ed6\u90e8\u5206\u4f7f\u7528\uff1b\u53e6\u4e00\u65b9\u9762\uff0c\u5b83\u4eec\u5f80\u5f80\u4f1a\u5360\u7528\u6bd4\u8f83\u591a\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u56e0\u6b64\u6211\u4eec\u4e5f\u5e0c\u671b\u5728\u9700\u8981\u65f6\u7acb\u523b\u9500\u6bc1\u3002\u5bf9\u4e8e\u8fd9\u4e9b\u9700\u6c42\uff0c\u65e0\u8bba\u662f\u5168\u5c40\u53d8\u91cf\u8fd8\u662f\u9759\u6001\u5c40\u90e8\u53d8\u91cf\u90fd\u4ecd\u7136\u4e0d\u591f\u7075\u6d3b\u3002\u4e3a\u6b64\uff0cC \u8bed\u8a00\u5728 stdlib.h \u4e2d\u63d0\u4f9b\u4e86\u52a8\u6001\u5185\u5b58\u7ba1\u7406\u51fd\u6570\u3002

\u5e38\u7528\u7684\u52a8\u6001\u5185\u5b58\u7ba1\u7406\u51fd\u6570\u5305\u62ec malloc \u4e0e free\uff0c\u5b83\u4eec\u5206\u522b\u8d1f\u8d23\u7533\u8bf7\u4e0e\u91ca\u653e\u5185\u5b58\u7a7a\u95f4\u3002

\u5185\u5b58\u6cc4\u9732

\u901a\u8fc7\u52a8\u6001\u5185\u5b58\u7ba1\u7406\u63a5\u53e3\u7533\u8bf7\u7684\u5185\u5b58\u7a7a\u95f4\u5c06\u4f1a\u4e00\u76f4\u88ab\u5360\u7528\uff0c\u76f4\u5230\u7a0b\u5e8f\u7ed3\u675f\u6216\u624b\u52a8\u91ca\u653e\u3002\u5982\u679c\u4f60\u6ca1\u6709\u53ca\u65f6\u91ca\u653e\u5b83\u4eec\uff0c\u672a\u91ca\u653e\u5185\u5b58\u5c06\u65e0\u6cd5\u88ab\u518d\u5206\u914d\u3002\u5806\u79ef\u7684\u672a\u91ca\u653e\u5185\u5b58\u6700\u7ec8\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u8d85\u8fc7\u7cfb\u7edf\u9650\u989d\uff0c\u6211\u4eec\u79f0\u4e3a\u5185\u5b58\u6cc4\u9732\uff0c\u6b64\u65f6\u7a0b\u5e8f\u5c06\u4f1a\u88ab\u7cfb\u7edf\u5f3a\u5236\u7ec8\u6b62\u3002\u56e0\u6b64\uff0c\u52a1\u5fc5\u5728\u4e0d\u518d\u4f7f\u7528\u52a8\u6001\u5185\u5b58\u65f6\u53ca\u65f6\u91ca\u653e\u3002

\u60ac\u5782\u6307\u9488

\u91ca\u653e\u7533\u8bf7\u5f97\u5230\u7684\u5185\u5b58\u7a7a\u95f4\u540e\uff0c\u6307\u5411\u8be5\u5185\u5b58\u7a7a\u95f4\u7684\u6307\u9488\u5c06\u4f1a\u53d8\u6210\u60ac\u5782\u6307\u9488\u3002\u5c1d\u8bd5\u7ee7\u7eed\u4f7f\u7528\u60ac\u5782\u6307\u9488\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002

\u53e6\u5916\uff0c\u5c1d\u8bd5\u91ca\u653e\u60ac\u5782\u6307\u9488\uff0c\u5373\u4e8c\u6b21\u91ca\u653e\u540c\u4e00\u5757\u5185\u5b58\u5730\u5740\uff0c\u540c\u6837\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\u3002\u4e8c\u6b21\u91ca\u653e\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002

"},{"location":"programming/common/notes/pointers/#_17","title":"\u8fdb\u9636\u6280\u5de7","text":"

\u9605\u8bfb\u5efa\u8bae

\u672c\u8282\u4e3a\u62d3\u5c55\u5185\u5bb9\uff0c\u4e0d\u5728\u7a0b\u7b97\u8bfe\u7a0b\u8981\u6c42\u8303\u56f4\u5185\u3002\u5982\u679c\u4f60\u80fd\u591f\u719f\u7ec3\u4f7f\u7528\u6307\u9488\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u9605\u8bfb\u5e76\u7406\u89e3\u4ee5\u4e0b\u5185\u5bb9\u3002

\u8f93\u51fa\u4e00\u7cfb\u5217\u7a7a\u683c\u5206\u9694\u7684\u6570\u5b57\uff0c\u672b\u5c3e\u65e0\u591a\u4f59\u7a7a\u683c

\u8fd9\u79cd\u60c5\u5f62\u5e38\u89c1\u4e8e OJ \u7684\u8f93\u51fa\u8981\u6c42\u4e2d\u3002

\u5bf9\u4e8e\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 a\uff0c\u4e00\u4e2a\u5178\u578b\u7684\u5b9e\u73b0\u7a0b\u5e8f\u5982\u4e0b\u3002

printf(\"%d\", a[0]);\nfor (int i = 1; i < n; i++)\n{\n    printf(\" %d\", a[i]);\n}\n

\u4e0d\u96be\u770b\u51fa\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u4e00\u6b21\u5224\u65ad\uff0c\u5c06\u5faa\u73af\u5916\u7684\u8f93\u51fa\u8bed\u53e5\u653e\u5165\u5faa\u73af\u5185\u3002

for (int i = 0; i < n; i++)\n{\n    printf((!i) ? \"%d\" : \" %d\", a[i]);\n}\n

\u8fd9\u4e2a\u7248\u672c\u7684\u7a0b\u5e8f\u770b\u8d77\u6765\u66f4\u52a0\u6574\u6d01\u3002\u540c\u65f6\uff0c\u901a\u8fc7\u5c06\u8868\u8fbe\u5f0f (!i) \u66ff\u6362\u4e3a\u5176\u4ed6\u6807\u5fd7\uff0c\u8be5\u7a0b\u5e8f\u53ef\u5728\u9700\u8981\u65f6\u53e6\u8d77\u4e00\u884c\uff0c\u5e76\u4ee5\u76f8\u540c\u683c\u5f0f\u8f93\u51fa\u5269\u4f59\u7ed3\u679c\u3002\u8fd9\u610f\u5473\u7740\u8f93\u51fa\u7684\u7075\u6d3b\u6027\u5927\u5927\u589e\u5f3a\u3002

\u4e0d\u8fc7\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u7ed9\u51fa\u66f4\u52a0\u70ab\u6280\u7684\u5199\u6cd5\u3002

for (int i = 0; i < n; i++)\n{\n    printf(\" %d\" + !i, a[i]);\n}\n

\u8fd9\u4e2a\u7248\u672c\u7684\u7a0b\u5e8f\u901a\u8fc7\u6307\u9488\u8fd0\u7b97\uff0c\u6539\u53d8\u4e86\u5b57\u7b26\u4e32\u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u4ece\u800c\u6539\u53d8\u4e86\u8f93\u51fa\u683c\u5f0f\u3002\u5177\u4f53\u800c\u8a00\uff0ci \u4e3a 0 \u65f6\uff0cprintf \u5b9e\u9645\u63a5\u6536\u7684\u683c\u5f0f\u5b57\u7b26\u4e32\u4e3a \"%d\"\uff0c\u5373\u4e0d\u5728\u884c\u9996\u8f93\u51fa\u7a7a\u683c\u3002

\u76f8\u6bd4\u524d\u4e00\u7248\u672c\uff0c\u8fd9\u4e00\u7248\u672c\u53ea\u6709\u51cf\u5c11\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u6570\u91cf\u8fd9\u4e00\u610f\u4e49\u4e0d\u5927\u7684\u63d0\u5347\u3002\uff08\u4f46\u7528\u6765\u70ab\u6280\u518d\u597d\u4e0d\u8fc7\u4e86 :P\uff09

\u8f93\u51fa\u6d6e\u70b9\u6570\u7684\u4e8c\u8fdb\u5236\u8868\u793a

\u4e00\u4e2a\u5178\u578b\u7684\u8f93\u51fa\u6574\u6570\u4e8c\u8fdb\u5236\u8868\u793a\u7684\u7a0b\u5e8f\u5982\u4e0b\uff1a

int a = 1;\nfor (int i = 0; i < 32; i++)\n    printf(\"%d\", (a >> (31 - i)) & 1);\n

\u7531\u4e8e\u6d6e\u70b9\u6570\u4e0d\u80fd\u8fdb\u884c\u4f4d\u8fd0\u7b97\uff0c\u6211\u4eec\u65e0\u6cd5\u50cf\u4ee5\u4e0a\u7a0b\u5e8f\u4e00\u6837\u76f4\u63a5\u8f93\u51fa\u6bcf\u4e00\u4f4d\uff08bit\uff09\u3002\u5982\u679c\u5c06\u6d6e\u70b9\u6570\u5f3a\u5236\u8f6c\u6362\u6210\u6574\u6570\uff0c\u5c06\u4f1a\u76f4\u63a5\u5bf9\u6d6e\u70b9\u6570\u53d6\u6574\uff0c\u5bfc\u81f4\u7cbe\u5ea6\u4e22\u5931\u3002

\u4e3a\u4e86\u89c4\u907f\u8fd9\u4e00\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6307\u9488\u7c7b\u578b\u8f6c\u6362\uff0c\u6539\u53d8\u5bf9\u5185\u5b58\u6570\u636e\u7684\u8bfb\u53d6\u65b9\u5f0f\u3002\u5177\u4f53\u800c\u8a00\uff0c\u6211\u4eec\u6307\u5b9a\u4ee5\u6574\u6570\u5f62\u5f0f\u8bfb\u53d6\u6d6e\u70b9\u6570\u5bf9\u8c61\u6240\u5728\u7684\u5185\u5b58\u5730\u5740\uff0c\u4ee5\u907f\u514d\u4fee\u6539\u5bf9\u8c61\u8868\u793a\uff0c\u518d\u8f93\u51fa\u8f6c\u6362\u540e\u6574\u6570\u7684\u4e8c\u8fdb\u5236\u8868\u793a\uff0c\u6765\u5b9e\u73b0\u8f93\u51fa\u6d6e\u70b9\u6570\u4e8c\u8fdb\u5236\u8868\u793a\u7684\u76ee\u7684\u3002

double a = 1.0;\nunsigned long long p = *(unsigned long long *)&a;\nfor (int i = 0; i < 64; i++)\n    printf(\"%llu\", (p >> (63 - i)) & 1);\n

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u79cd\u6307\u9488\u8f6c\u6362\u4e25\u683c\u6765\u8bf4\u5c5e\u4e8e\u672a\u5b9a\u4e49\u884c\u4e3a\u3002But it just works :P

\u4f7f\u7528\u4e8c\u7ea7\u6307\u9488\u5220\u9664\u94fe\u8868\u8282\u70b9

\u6b64\u5904\u4ec5\u8ba8\u8bba\u6ca1\u6709\u5934\u8282\u70b9\u7684\u5355\u5411\u65e0\u73af\u94fe\u8868\u3002

\u94fe\u8868\u8282\u70b9\u5b9a\u4e49\u5982\u4e0b\uff1a

typedef struct node\n{\n    int val;\n    struct node *next;\n} Node;\n

\u4e00\u4e2a\u5178\u578b\u7684\u5220\u9664\u94fe\u8868\u8282\u70b9\u7684\u7a0b\u5e8f\u5982\u4e0b\uff1a

Node *remove(Node *head, int val)\n{\n    for (Node *prev = NULL, *curr = head; curr; )\n    {\n        Node *next = curr->next;\n        if (curr->val == val)\n        {\n            if (prev)\n                prev->next = next;\n            else\n                head = next;\n            free(curr);\n        }\n        else\n            prev = curr;\n        curr = next;\n    }\n    return head;\n}\n

\u4f46\u662f\uff0c\u5728 Linus \u770b\u6765\uff0c\u8fd9\u662f\u4e0d\u61c2\u6307\u9488\u7684\u4eba\u7684\u505a\u6cd5\u3002\u4ed6\u63a8\u5d07\u7684\u505a\u6cd5\u662f\u4f7f\u7528\u4e8c\u7ea7\u6307\u9488\uff0c\u907f\u514d\u5bf9\u79fb\u9664\u7b2c\u4e00\u4e2a\u8282\u70b9\u7684\u7279\u5224\u3002

void remove(Node *head, int val)\n{\n    for (Node **curr = &head; *curr; )\n    {\n        Node *entry = *curr;\n        if (entry->val == val)\n        {\n            *curr = entry->next;\n            free(entry);\n        }\n        else\n            curr = &entry->next;\n    }\n}\n

\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u8fd9\u4e2a\u7248\u672c\u7684 remove \u51fd\u6570\u4e0d\u518d\u9700\u8981\u989d\u5916\u7ef4\u62a4\u4e00\u4e2a prev \u6307\u9488\uff0c\u4e5f\u4e0d\u9700\u8981\u5224\u65ad\u9700\u8981\u79fb\u9664\u7684\u8282\u70b9\u662f\u5426\u4e3a\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002\u53e6\u5916\uff0c\u8fd9\u4e2a\u7248\u672c\u7684 remove \u51fd\u6570\u4e5f\u4e0d\u518d\u9700\u8981\u8fd4\u56de\u503c\u3002

\u8fd9\u662f\u56e0\u4e3a\uff0c\u73b0\u5728\u4e8c\u7ea7\u6307\u9488 curr \u6307\u5411\u4e0a\u4e00\u4e2a\u8282\u70b9\u7684 next \u6210\u5458\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u6307\u5411\u5f53\u524d\u8282\u70b9\u3002\u79fb\u9664\u8282\u70b9\u65f6\uff0c\u901a\u8fc7 curr \u4fee\u6539 next \u6210\u5458\u8d77\u5230\u4e86\u548c\u4fee\u6539 prev->next \u76f8\u540c\u7684\u6548\u679c\u3002\u8fd9\u5bf9\u4e8e\u7b2c\u4e00\u4e2a\u8282\u70b9\u4e5f\u662f\u6210\u7acb\u7684\uff0c\u56e0\u4e3a\u6b64\u65f6\u4e8c\u7ea7\u6307\u9488 curr \u6307\u5411 head\uff0c\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7 curr \u4fee\u6539 head \u6307\u5411\u7684\u8282\u70b9\u3002

"}]} \ No newline at end of file