diff --git a/programming/daily/2023/index.html b/programming/daily/2023/index.html index d6d2c02..da60ecc 100644 --- a/programming/daily/2023/index.html +++ b/programming/daily/2023/index.html @@ -1192,9 +1192,6 @@
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"
argv[1] = "this"
@@ -1204,6 +1201,9 @@ 「4」 Command Line Arguments
+
+
For more information about argv
and argc
, see cppreference-argc, argv.
list
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:
data
to data
.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:
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
.
\ud83d\ude09 \u4f60\u597d~
\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\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\u666e\u901a\u8f85\u5b66\u7248\u5757\u4f7f\u7528 \ud83d\udcda \u6807\u6ce8\uff0c\u7cbe\u54c1\u8bfe\u7a0b\u7248\u5757\u4f7f\u7528 \ud83c\udfeb \u6807\u6ce8\u3002
\u5fae\u79ef\u5206 I/II\uff08H\uff09
23-24\u8f85\u5b66\u7fa4\uff1a204755170
\u6570\u5b66\u5206\u6790 I/II\uff08H\uff09
23-24\u8f85\u5b66\u7fa4\uff1a618962803
\u7ebf\u6027\u4ee3\u6570 I/II\uff08H\uff09
23-24\u8f85\u5b66\u7fa4\uff1a913067714 \ud83c\udfeb\u7ebf\u6027\u4ee3\u6570\uff1a\u672a\u7adf\u4e4b\u7f8e
\u7a0b\u5e8f\u8bbe\u8ba1\uff08H\uff09
23-24\u8f85\u5b66\u7fa4\uff1a728919863 \u6bcf\u65e5\u4e00\u9898 \ud83c\udfeb\u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057 \ud83c\udfeb\u5b9e\u7528\u6280\u80fd\u62fe\u9057
\u666e\u901a\u5316\u5b66\uff08H\uff09
23-24\u8f85\u5b66\u7fa4\uff1a635023447
\u666e\u901a\u7269\u7406\u5b66 I\uff08H\uff09
22-23\u8f85\u5b66\u7fa4\uff1a727382522
\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":"\u8f85\u5b66\u7b80\u4ecb","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":"\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
\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
\u6bcf\u4e2a\u8f85\u5b66\u79d1\u76ee\u7684\u6587\u4ef6\u5939\u7ec4\u7ec7\u5982\u4e0b\uff1a
subject\n\u251c\u2500\u2500 year\n\u2502 \u251c\u2500\u2500 some_file.md\n\u2502 \u2514\u2500\u2500 some_file.pdf\n\u251c\u2500\u2500 exam\n\u2502 \u251c\u2500\u2500 some_paper.pdf\n\u2502 \u2514\u2500\u2500 some_paper_answer.pdf\n\u2514\u2500\u2500 index.md\n
index.md
\uff0c\u5305\u542b\u4e86\u8be5\u79d1\u76ee\u6587\u4ef6\u5939\u5185\u5404\u4e2a\u8d44\u6599\u7684\u94fe\u63a5\u3002\u9875\u9762\u4fa7\u8fb9\u680f\u4e0d\u9700\u8981\u6709\u4e1c\u897f\uff0c\u4e0d\u9700\u8981\u5728 mkdocs.yml
\u4e2d\u518d\u4e3a\u8fd9\u4e9b\u6587\u4ef6\u6dfb\u52a0\u7d22\u5f15\u3002lecture1_contents.pdf
\u7b49\u3002exam
\u6587\u4ef6\u5939\u4e2d\uff0c\u6587\u4ef6\u547d\u540d\u4e3a subject_year_exam.pdf
\u7b49\uff0c\u7b54\u6848\u6dfb\u52a0\u540e\u7f00 _answer
\u3002\u7cbe\u54c1\u8bfe\u7a0b\u7684\u6587\u4ef6\u5939\u7531\u8be5\u8bfe\u7a0b\u7ec4\u81ea\u884c\u7ec4\u7ec7\u548c\u7ef4\u62a4\u3002
"},{"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\u542funicode\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\u542fmhchem\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"},{"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":"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/#2023-2024","title":"2023-2024 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":""},{"location":"analysis/#_2","title":"\u6388\u8bfe","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/#_3","title":"\u5386\u5e74\u5377","text":""},{"location":"analysis/#ih","title":"\u6570\u5b66\u5206\u6790 I\uff08H\uff09","text":"\u5e74\u4efd \u8bd5\u5377 2023-2024 \u5c0f\u6d4b1 2022-2023 \u5c0f\u6d4b1/\u7b54\u6848\u5c0f\u6d4b2/\u7b54\u6848\u671f\u672b\u8bd5\u5377/\u7b54\u6848 2021-2022 \u5c0f\u6d4b/\u7b54\u6848\u671f\u672b\u8bd5\u5377/\u7b54\u6848 2020-2021 \u671f\u672b\u8bd5\u5377\uff08\u90e8\u5206\uff09"},{"location":"analysis/#iih","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/#_4","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/2024/analysis_lecture1_sequence_limits/","title":"\u7b2c\u4e00\u8bb2 \u6570\u5217\u6781\u9650","text":"\u7ed9\u51fa\u6982\u5ff5\u3001\u5b9a\u7406\u7684\u540d\u5b57\u53ef\u4ee5\u4f7f\u7528\u6570\u5b66\u8bed\u8a00\u51c6\u786e\u53d9\u8ff0\u3002
\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
\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
\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
\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} \\]\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} \\]\u786e\u754c\u539f\u7406
\u975e\u7a7a\u6709\u754c\u96c6\u5fc5\u6709\u4e0a\u4e0b\u786e\u754c
\u5355\u8c03\u6709\u754c\u5b9a\u7406
\u5355\u8c03\u6709\u754c\u6570\u5217\u5fc5\u6536\u655b
\u81f4\u5bc6\u6027\u5b9a\u7406
\u4efb\u4f55\u6709\u754c\u6570\u5217\u5fc5\u6709\u6536\u655b\u5b50\u5217
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 \\]\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} \\]\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} \\]\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\\}\\)
\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
\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) \\]\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} \\]Stolz\u5b9a\u7406
\u5e38\u7528\u4e8e\u8ba1\u7b97\u5f62\u5f0f\u9700\u8981\u6d1b\u5fc5\u8fbe\u7684\u6781\u9650
Cauchy\u6536\u655b\u51c6\u5219\u3001\u7b49\u4ef7\u5f62\u5f0f\u53ca\u5426\u5b9a
\u4e00\u4e9b\u5173\u7cfb\u94fe\uff1a
\u8bc1\u660e\u6570\u5217\u6781\u9650\u5b58\u5728\uff1a
\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)
Cauchy\u51c6\u5219\uff1a\u4e0d\u9700\u8981\u77e5\u9053\u6781\u9650\u503c
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)\\))
\u5355\u8c03\u6709\u754c\u539f\u7406\uff1a\u4e0d\u52a8\u70b9\uff0c\u9012\u63a8\u5f0f\u8003\u8651
\u6781\u9650\u7684\u8fd0\u7b97\u6027\u8d28\uff1a\u672c\u8eab\u5b58\u5728\u6781\u9650 \u6709\u9650\u9879\u8fd0\u7b97
\u8bc1\u660e\u6570\u5217\u6781\u9650\u4e0d\u5b58\u5728\uff1a
\u6c42\u6570\u5217(\u51fd\u6570)\u6781\u9650\uff1a
\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\\)
Stolz\u5b9a\u7406
\u5939\u903c\u5b9a\u7406
\u7b49\u4ef7\u4ee3\u6362\u4e0e\u521d\u7b49\u53d8\u5f62
\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
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
\u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u5b50\u5217\u7684\u547d\u9898
\u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u65e0\u7a77\u5c0f\u91cf\u7684\u547d\u9898
\u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u6570\u5217\u6781\u9650\u7684\u547d\u9898
\u91cd\u8981\u7684\u4e8c\u7ea7\u7ed3\u8bba\uff1a
\\(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)
\u6c42\u6781\u9650\\(\\lim\\limits_{n\\rightarrow\\infty}x_n\\)\uff1a
(2019(?)\u5e74\u6570\u52061\u671f\u672b)
\u9898\u76ee\u3001\u9009\u9879\u987a\u5e8f\u53c2\u8003\u5c0f\u6d4b1
\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\u5730\u5740 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 \u5f3a\u533b 2101 \u5362\u601d\u7426"},{"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":"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":"lalu/#_2","title":"\u8bfe\u7a0b\u7b80\u4ecb","text":"\u7ebf\u6027\u4ee3\u6570\u4f5c\u4e3a\u5927\u5b66\u6570\u5b66\u7684\u57fa\u7840\u8bfe\uff0c\u4e0e\u6570\u5b66\u5206\u6790\u4e0d\u540c\uff0c\u8fd9\u95e8\u8bfe\u7684\u4e00\u5f00\u59cb\u5c31\u4e0e\u4e2d\u5b66\u6570\u5b66\u7684\u98ce\u683c\u6709\u7740\u5f88\u5927\u7684\u5dee\u8ddd\uff0c\u8bb8\u591a\u540c\u5b66\u5728\u6b64\u95e8\u8bfe\u7684\u5165\u95e8\u4e0e\u8fdb\u9636\u65b9\u9762\u90fd\u9047\u89c1\u4e86\u5f88\u5927\u7684\u56f0\u96be\u3002\u4e3a\u89e3\u51b3\u6b64\u56f0\u96be\uff0c\u672c\u8bfe\u7a0b\u5e0c\u671b\u6df1\u5165\u6d45\u51fa\u5730\u5256\u6790\u6982\u5ff5\u4e0e\u5b9a\u7406\uff0c\u5e2e\u52a9\u540c\u5b66\u4eec\u4e86\u89e3\u7ebf\u6027\u4ee3\u6570\u201c\u5e72\u7684\u662f\u4ec0\u4e48\u4e8b\u201d\uff0c\u7406\u89e3\u7ebf\u6027\u4ee3\u6570\u7684\u672c\u8d28\uff0c\u4ee5\u53ca\u66f4\u597d\u638c\u63e1\u540e\u7eed\u7684\u8ba1\u7b97\u6280\u5de7\uff0c\u5b66\u597d\u7ebf\u4ee3\u8fd9\u95e8\u5927\u5b66\u7684\u5165\u95e8\u8bfe\uff01
"},{"location":"lalu/#_3","title":"\u8bfe\u9898\u7ec4\u6210\u5458","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 W1 Oct.29 \u5f15\u5165\uff1a\u7ebf\u6027\u7a7a\u95f4 \u6885\u654f\u70ab Bilibili T1 Oct.29 \u5f15\u5165\uff1a\u7ebf\u6027\u7a7a\u95f4 \u5434\u4e00\u822a Bilibili H2 Nov.18 \u7ebf\u6027\u6620\u5c04\u53ca\u5176\u77e9\u9635\u8868\u793a \u5434\u4e00\u822a Bilibili"},{"location":"lalu/#_5","title":"\u8bfe\u7a0b\u5b89\u6392","text":"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
\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":"programming/","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66","text":"\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u7a0b\u8bbe\u7248\u5757\ud83e\udd17\u3002
"},{"location":"programming/#_2","title":"\u6bcf\u65e5\u4e00\u9898","text":"\u89c1\u6bcf\u65e5\u4e00\u9898\u3002
"},{"location":"programming/#_3","title":"\u4e13\u9898\u7b14\u8bb0","text":"\u6211\u4eec\u4e3a\u7a0b\u5e8f\u8bbe\u8ba1\u4e2d\u7684\u4e00\u4e9b\u91cd\u96be\u70b9\u6574\u7406\u4e86\u4e13\u9898\u7b14\u8bb0\uff0c\u73b0\u6709\u5982\u4e0b\u4e13\u9898\u7b14\u8bb0\uff1a
\u6211\u4eec\u4e3a\u540c\u5b66\u4eec\u7ecf\u5e38\u9047\u5230\u7684\u95ee\u9898\u6574\u7406\u4e86\u4e00\u4e9b FAQ\uff0c\u53c2\u89c1 FAQ\u3002
"},{"location":"programming/#_4","title":"\u5386\u5e74\u5377","text":"\u5386\u5e74\u5377\u5178\u578b\u9898\u76ee\u7b54\u7591\u96c6\u6b63\u5728\u6574\u7406\u4e2d\u3002
"},{"location":"programming/#_5","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u4e0e\u7b97\u6cd5\u57fa\u7840","text":"\u6682\u65e0
"},{"location":"programming/#_6","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u57fa\u7840\u4e0e\u5b9e\u9a8c","text":"\u6682\u65e0
"},{"location":"programming/#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/#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/#_7","title":"\u5176\u4ed6\u8d44\u6e90","text":""},{"location":"programming/#_8","title":"\u5e38\u7528\u7f51\u7ad9","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
\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/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\uff1fAuthor\uff1a\u6731\u5b9d\u6797
\u5e03\u5c14\u7c7b\u578b\u7684\u5386\u53f2\uff1a
_Bool
\u7c7b\u578b\u548c <stdbool.h>
\u5934\u6587\u4ef6\u3002\u8be5\u5934\u6587\u4ef6\u5b9a\u4e49\u4e86 bool
\u3001true
\u548c false
\u4e09\u4e2a\u4fbf\u5229\u5b8f\u3002bool
\u5c55\u5f00\u6210 _Bool
\u3002true
\u548c false
\u5206\u522b\u5c55\u5f00\u6210 int
\u7c7b\u578b\u7684 1
\u548c 0
\u3002bool
\u4ee3\u66ff _Bool
\u4f5c\u4e3a\u7c7b\u578b\u540d\u3002true
\u548c false
\u4e5f\u76f4\u63a5\u5c55\u5f00\u4e3a bool
\u7c7b\u578b\u503c\u3002\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
bool
\u7684\u8f6c\u6362\u4e0e\u5230\u5176\u4ed6\u6574\u6570\u7c7b\u578b\u7684\u8f6c\u6362\u4e0d\u540c\uff1a (bool)0.5
\u6c42\u503c\u4e3a 1
\uff0c\u7136\u800c (int)0.5
\u6c42\u503c\u4e3a \u200b0
\u200b\u3002\u5728\u7ed9 _Bool
\u7c7b\u578b\u8d4b\u503c\u65f6\u9700\u8981\u6ce8\u610f\u8fd9\u4e00\u70b9\u3002Author\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/faq/#_3","title":"\u6570\u7ec4\u3001\u5b57\u7b26\u4e32","text":""},{"location":"programming/faq/#_4","title":"\u5faa\u73af\u3001\u5206\u652f\u548c\u8df3\u8f6c","text":""},{"location":"programming/faq/#_5","title":"\u51fd\u6570\u3001\u6807\u51c6\u5e93\u4e0e\u9884\u5904\u7406\u5668","text":""},{"location":"programming/faq/#io","title":"\u6587\u4ef6 I/O","text":""},{"location":"programming/faq/#_6","title":"\u6307\u9488\u3001\u5b58\u50a8\u7c7b\u522b\u3001\u94fe\u63a5\u548c\u5185\u5b58\u7ba1\u7406","text":""},{"location":"programming/faq/#_7","title":"\u7ed3\u6784\u548c\u5176\u4ed6\u6570\u636e\u5f62\u5f0f","text":""},{"location":"programming/temp/","title":"\u5e38\u89c1\u95ee\u9898","text":"\u65bd\u5de5\u4e2d
"},{"location":"programming/temp/#_2","title":"\u6307\u9488\u3001\u58f0\u660e","text":""},{"location":"programming/temp/#_3","title":"\u600e\u4e48\u8bfb\u58f0\u660e\uff1f","text":"Author\uff1a45gfg9\u3001Anston Sun
\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
\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\u5c31\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\u4e00\u4e2a\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\u3002\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\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\u53d8\u5316\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\u5c31\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/temp/#_5","title":"\u51fd\u6570\u5230\u6307\u9488\u8f6c\u6362","text":"\u4efb\u4f55\u51fd\u6570\u6307\u4ee3\u5668\u8868\u8fbe\u5f0f\uff0c\u5728\u7528\u4e8e\u5f02\u4e8e\u4e0b\u5217\u8bed\u5883\u65f6
sizeof
\u7684\u64cd\u4f5c\u6570\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u8868\u8fbe\u5f0f\u6240\u6307\u4ee3\u51fd\u6570\u7684\u6307\u9488\u7684\u8f6c\u6362\u3002
"},{"location":"programming/temp/#_6","title":"\u56fe\u5f62\u5e93","text":"\u7b80\u8981\u6574\u7406\u4e00\u4e0b libgraphics
\u7528\u6cd5\uff1a
\u56fe\u5f62\u4e0e\u6587\u5b57
\u503c\u5f97\u6ce8\u610f\u7684\u4e00\u70b9\u662f\uff1alibgraphics
\u7684\u5750\u6807\u7cfb\u7edf\u4e0e ACLLib
\u4e0d\u540c\u3002\u524d\u8005\u4ee5\u5de6\u4e0b\u89d2\u4e3a\u539f\u70b9\uff0c\u7b26\u5408\u6211\u4eec\u5e38\u7528\u7684\u6570\u5b66\u8868\u8fbe\uff1b\u540e\u8005\u4ee5\u5de6\u4e0a\u89d2\u4e3a\u9876\u70b9\uff0c\u4f7f\u7528\u7a97\u53e3\u5750\u6807\u7cfb\u7edf\u3002
void InitGraphics(void)
\uff1a\u4f7f\u7528\u56fe\u5f62\u5e93\u4e2d\u7684\u51fd\u6570\u524d\u8c03\u7528void MovePen(double x, double y)
\uff1a\u5c06\u7b14\u79fb\u52a8\u5230\u67d0\u70b9\uff08\u6ce8\u610f\u4e0d\u662f\u76f8\u5bf9\u79fb\u52a8\uff09void DrawLine(double dx, double dy)
\uff1a\u4ece\u5f53\u524d\u70b9 \\((x,y)\\) \u753b\u5230 \\((x+dx, y+dy)\\) \u7684\u7ebf\uff0c\u753b\u7b14\u968f\u4e4b\u79fb\u52a8void DrawArc(double r, double start, double sweep)
\uff1a\u4ee5\u5f53\u524d\u70b9\u4e3a\u5706\u5fc3\uff0c\u4ece \\(\\phi=start\\) \u89d2\u5f00\u59cb\uff0c\u753b\u534a\u5f84\u4e3a \\(r\\)\uff0c\u5706\u5fc3\u89d2\u4e3a \\(\\Delta\\phi=sweep\\) \u7684\u5706\u5f27\u3002double GetWindowWidth(void)
\uff1a\u83b7\u53d6\u7a97\u53e3\u5bbd\u5ea6double GetWindowHeight(void)
double GetCurrentX(void)
\uff1a\u83b7\u53d6\u5f53\u524d\u753b\u7b14\u7684\u4f4d\u7f6edouble GetCurrentY(void)
void DrawTextString(string text)
\uff1a\u5728\u5f53\u524d\u4f4d\u7f6e\u6253\u5370\u5b57\u7b26\u4e32double TextStringWidth(string text)
\uff1a\u83b7\u53d6\u8be5\u5b57\u7b26\u4e32\u6253\u5370\u65f6\u7684\u5bbd\u5ea6\u5173\u4e8e SetEraseMode()
\u548c GetEraseMode()
\u6211\u76f4\u63a5\u628a\u6ce8\u91ca\u8d34\u5728\u8fd9\u4e86\uff0c\u76f4\u63a5\u8bfb\u5427\uff1a
/*\n * Function: SetEraseMode\n * Usage: SetEraseMode(TRUE);\n * SetEraseMode(FALSE);\n * ---------------------------\n * The SetEraseMode function sets the value of the internal\n * erasing flag. Setting this flag is similar to setting the\n * color to \"White\" in its effect but does not affect the\n * current color setting. When erase mode is set to FALSE,\n * normal drawing is restored, using the current color.\n */\n\nvoid SetEraseMode(bool mode);\n\n/*\n * Function: GetEraseMode\n * Usage: mode = GetEraseMode();\n * -----------------------------\n * This function returns the current state of the erase mode flag.\n */\n\nbool GetEraseMode(void);\n
\u8fd8\u662f\u9644\u4e2a\u7ffb\u8bd1\u5427\uff1aSetEraseMode \u51fd\u6570\u8bbe\u7f6e\u5185\u90e8\u64e6\u9664\u6807\u5fd7\u7684\u503c\u3002\u8bbe\u7f6e\u8fd9\u4e2a\u503c\u7684\u6548\u679c\u5c31\u50cf\u628a\u989c\u8272\u8bbe\u7f6e\u4e3a\u201c\u767d\u8272\u201d\uff0c\u4f46\u4e0d\u4f1a\u5f71\u54cd\u5f53\u524d\u7684\u989c\u8272\u8bbe\u7f6e\u3002\u5f53\u64e6\u9664\u6a21\u5f0f\u8bbe\u7f6e\u4e3a FALSE \u65f6\uff0c\u6062\u590d\u5230\u6b63\u5e38\u7684\u7ed8\u753b\u72b6\u6001\uff0c\u4f7f\u7528\u5f53\u524d\u7684\u989c\u8272\u3002
\u63a7\u5236\u53f0\u4ea4\u4e92\uff1a\u8fd9\u4e9b\u6e90\u4ee3\u7801\u5728 simpio.h
\u4e2d
void InitConsole(void)
\uff1a\u6253\u5f00\u4e00\u4e2a\u65b0\u7684\u63a7\u5236\u53f0\uff0c\u8981\u4f7f\u7528 stdio.h
\u4e2d\u7684\u6807\u51c6\u8f93\u5165\u8f93\u51fa\u51fd\u6570\u524d\u8bb0\u5f97\u5199\u4e0a\u8fd9\u4e2a\u3002
int GetInteger(void)
\uff1a\u4ece\u6807\u51c6\u8f93\u5165\u4e2d\u8bfb\u5165\u4e00\u884c\uff0c\u5e76\u5c1d\u8bd5\u8bfb\u53d6\u4e00\u4e2a\u6574\u6570\u3002\u5982\u679c\u9047\u5230\u610f\u5916\u60c5\u51b5\uff0c\u4f1a\u8981\u6c42\u7528\u6237\u91cd\u65b0\u8f93\u5165\u3002\u6e90\u7801\u5982\u4e0b\uff1a
int GetInteger(void)\n{\n string line;\n int value;\n char termch;\n\n while (TRUE) {\n line = GetLine();\n if (line == NULL) Error(\"GetInteger: unexpected end of file\");\n switch (sscanf(line, \" %d %c\", &value, &termch)) {\n case 1:\n FreeBlock(line);\n return (value);\n case 2:\n printf(\"Unexpected character: '%c'\\n\", termch);\n break;\n default:\n printf(\"Please enter an integer\\n\");\n break;\n }\n FreeBlock(line);\n printf(\"Retry: \");\n }\n}\n
double GetReal(void)
\uff1a\u8bfb\u53d6\u4e00\u4e2a\u5b9e\u6570\uff0c\u5177\u4f53\u540c\u4e0a\u3002
string GetLine(void)
string ReadLine(FILE *infile)
\uff1a\u4ece\u6307\u5b9a\u7684\u6587\u4ef6\u4e2d\u8bfb\u5165\u4e00\u884c\u3002
\u8ba1\u65f6\u5668\u7528\u4e8e\u5ef6\u65f6\u6216\u91cd\u590d\u6267\u884c\u540c\u7c7b\u4efb\u52a1\u3002\u76f8\u6bd4\u949f\u8868\u7b49\u7eaf\u7cb9\u7684\u8ba1\u65f6\u5de5\u5177\uff0c\u8ba1\u65f6\u5668\u66f4\u63a5\u8fd1\u4e8e\u65e5\u7a0b\u5b89\u6392\u3002\u8ba1\u65f6\u5668\u7684\u6838\u5fc3\u529f\u80fd\u5982\u4e0b\uff1a\u6bcf\u7ecf\u8fc7\u9884\u5148\u8bbe\u5b9a\u7684\u65f6\u957f\uff0c\u8ba1\u65f6\u5668\u4fbf\u4f1a\u901a\u8fc7\u67d0\u79cd\u673a\u5236\uff0c\u6267\u884c\u7279\u5b9a\u7684\u6307\u4ee4\u3002
libgraphics
\u5e93\u901a\u8fc7\u4e8b\u4ef6\u56de\u8c03\u673a\u5236\u5b9e\u73b0\u5b9a\u65f6\u89e6\u53d1\u7684\u529f\u80fd\u3002\u56de\u8c03\u673a\u5236\u6b64\u5904\u4e0d\u518d\u8d58\u8ff0\u3002
\u4e0e\u8ba1\u65f6\u5668\u76f8\u5173\u7684\u51fd\u6570\u5982\u4e0b\uff1a
void startTimer(int timerID, int interval)
void cancelTimer(int timerID)
\u987e\u540d\u601d\u4e49\uff0c\u4e24\u4e2a\u51fd\u6570\u5206\u522b\u7528\u4e8e\u542f\u52a8\u4e0e\u7ec8\u6b62\u5b9a\u65f6\u5668\u3002interval
\u662f\u9884\u5148\u8bbe\u5b9a\u7684\u65f6\u957f\uff0c\u5373\u6bcf\u4e24\u6b21\u89e6\u53d1\u7684\u65f6\u95f4\u95f4\u9694\u3002timerID
\u4e3a\u8ba1\u65f6\u5668\u7684\u6807\u8bc6\u7b26\uff0c\u53ef\u7406\u89e3\u4e3a\u8ba1\u65f6\u5668\u7684\u4e13\u7528\u540d\u79f0\u3002
\u4e3a\u4e86\u5b8c\u6210\u591a\u9879\u5b9a\u65f6\u4efb\u52a1\uff0c\u5f80\u5f80\u9700\u8981\u5206\u522b\u542f\u52a8\u591a\u4e2a\u95f4\u9694\u4e0d\u540c\u7684\u5b9a\u65f6\u5668\u3002\u7531\u4e8e\u6240\u6709\u8ba1\u65f6\u5668\u5747\u4f1a\u89e6\u53d1 TimerEvent
\uff0c\u5728\u56de\u8c03\u51fd\u6570\u5185\u9700\u8981\u4f7f\u7528 timerID
\u533a\u5206\u4e0d\u540c\u7684\u5b9a\u65f6\u5668\u3002
void registerTimerEvent(TimerEventCallback)
\uff1a\u6ce8\u518c\u8ba1\u65f6\u5668\u4e8b\u4ef6\u3002 TimerEventCallback
\u7c7b\u578b\u89c1\u4e0b\u3002typedef void (*TimerEventCallback)(int timerID)
TimerEventCallback
\u662f\u4e00\u4e2a\u51fd\u6570\u6307\u9488\u7c7b\u578b\uff0c\u8be5\u7c7b\u578b\u53d8\u91cf\u6307\u5411\u51fd\u6570\uff08\u5047\u8bbe\u540d\u79f0\u4e3a func
\uff09\u7684\u7c7b\u578b\u4e3a void func(int timerID)
\u3002\u901a\u8fc7\u56de\u8c03\u673a\u5236\uff0c\u6bcf\u5f53\u4efb\u4e00\u8ba1\u65f6\u5668\u5230\u8fbe\u8bbe\u5b9a\u65f6\u95f4\u65f6\uff0c\u5747\u4f1a\u901a\u8fc7\u8be5\u7c7b\u578b\u51fd\u6570\u6307\u9488\u8c03\u7528 func
\u51fd\u6570\u3002\u901a\u8fc7\u4f20\u5165\u7684 timerID
\uff0c\u56de\u8c03\u51fd\u6570\u5185\u53ef\u4ee5\u533a\u5206\u4e0d\u540c\u8ba1\u65f6\u5668\u7684\u89e6\u53d1\u4e8b\u4ef6\uff0c\u5e76\u6267\u884c\u7279\u5b9a\u64cd\u4f5c\u3002
\u4ee5\u4e0a\u4ecb\u7ecd\u5747\u96c6\u4e2d\u4e8e\u91cd\u590d\u6267\u884c\uff0c\u4f46\u662f\u524d\u9762\u63d0\u5230\u8ba1\u65f6\u5668\u4e5f\u53ef\u7528\u4e8e\u5ef6\u65f6\u6267\u884c\uff0c\u5373\u5728\u9884\u5148\u8bbe\u5b9a\u7684\u65f6\u957f\u540e\u6267\u884c\u7279\u5b9a\u6b21\u6570\u7684\u7279\u5b9a\u64cd\u4f5c\u3002\u7ed3\u5408 cancelTimer
\u51fd\u6570\uff0c\u60f3\u60f3\u600e\u6837\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002
typedef void (*KeyboardEventCallback) (int key,int event);\ntypedef void (*CharEventCallback) (char c);\ntypedef void (*MouseEventCallback) (int x, int y, int button, int event);\ntypedef void (*TimerEventCallback) (int timerID);\n\nvoid registerKeyboardEvent(KeyboardEventCallback callback);\nvoid registerCharEvent(CharEventCallback callback);\nvoid registerMouseEvent(MouseEventCallback callback);\nvoid registerTimerEvent(TimerEventCallback callback);\nvoid startTimer(int id,int timeinterval);\n
\u56e0\u4e3a\u8fd9\u4e9b\u56de\u8c03\u51fd\u6570\u5728 graphics
\u5e93\u4e2d\u90fd\u6ca1\u6709\u6ce8\u91ca\uff0c\u6211\u5c31\u4e0d\u4f5c\u89e3\u91ca\u4e86\uff0c\u8bfe\u4e0a\u90fd\u8bb2\u8fc7\u56de\u8c03\u51fd\u6570\u600e\u4e48\u7528\u3002
\u8ba1\u65f6\u5668\uff1a\u4ee5 20 \u5e74\u7a0b\u5e8f\u586b\u7a7a\u7b2c 3 \u9898\u4e3a\u4f8b\uff1a
void Main()\n{\n InitGraphics();\n registerTimerEvent(TimerEventProcess);\n //...\n startTimer(TIMER_CURSOR, 500);/*start 500ms cursor blinking timer*/\n}\nvoid TimerEventProcess(int timerID)\n{\n bool erasemode;\n if(TIMER_CURSOR == timerID)\n {\n //...\n }\n}\n
\u4ece\u8fd9\u6bb5\u4f8b\u7a0b\u4e2d\u53ef\u4ee5\u4e86\u89e3\u5230\u51e0\u4e2a\u91cd\u8981\u7684\u70b9\uff1a
void registerTimerEvent(TimerEventCallback callback)
\u6ce8\u518c\u56de\u8c03\u51fd\u6570 callback
\u540e\uff0c\u8fd8\u9700\u8981\u7528 void startTimer(int id,int timeinterval)
\u8bbe\u5b9a\u5e76\u542f\u52a8\u4e00\u4e2a\u8ba1\u65f6\u5668\uff0c\u8bbe\u5b9a\u8fd9\u4e2a\u8ba1\u65f6\u5668\u7684 id
\u548c timeinterval
\u3002id
\u5e76\u68c0\u67e5\u662f\u4e0d\u662f\u81ea\u5df1\u9700\u8981\u8fdb\u884c\u52a8\u4f5c\u7684\u90a3\u4e2a\u8ba1\u65f6\u5668\u3002\u8fd9\u5c31\u662f TimerEventProcess
\u51fd\u6570\u4e2d if
\u8bed\u53e5\u7684\u4f5c\u7528\u3002void Main()
\u522b\u5199\u9519\u4e86#include <stdio.h>\n#include \"graphics.h\"\n\nvoid Main(void)\n{\n InitGraphics();\n MovePen(1.5, 1.0);\n DrawArc(0.5, 0, 360);\n}\n
"},{"location":"programming/temp/#new","title":"New()
\u51fd\u6570","text":"\u5411\u4e0b\u7ffb\uff0c\u627e\u5230 2019 \u5e74\u7a0b\u5e8f\u586b\u7a7a\u7b2c 3 \u9898\uff0c\u4f7f\u7528\u65b9\u6cd5\u5728\u90a3\u91cc\u3002
"},{"location":"programming/temp/#_15","title":"\u7b97\u6cd5\u590d\u6742\u5ea6\u5206\u6790","text":"\u8bb0\u4f4f\uff1a\u6392\u5e8f\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e0e\u4e24\u9879\u64cd\u4f5c\u7684\u6b21\u6570\u6709\u5173\uff1a\u6bd4\u8f83\u548c\u4ea4\u6362\u3002
\u4f60\u53ef\u4ee5\u8fd9\u6837\u60f3\uff1a\u521b\u5efa\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\u4f5c\u4e3a\u8ba1\u6570\u5668\uff0c\u5728\u6240\u6709\u6d89\u53ca\u6bd4\u8f83\u548c\u4ea4\u6362\u7684\u5730\u65b9\u8ba9\u5b83 ++
\uff0c\u8fd0\u884c\u5b8c\u7684\u7ed3\u679c\u5c31\u662f\u5176\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u6bd4\u5982\uff1a
int count = 0;\nfor (int i = 0; i < n; ++i) {\n for (int j = 0; j < n; ++j) {\n for (int k = 0; k < m; ++k) {\n count++;\n }\n }\n}\n
\u8fd0\u884c\u5b8c\u8fd9\u6bb5\u4ee3\u7801\uff0ccount = n*n*m
\uff0c\u5219\u5176\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2m)\\)\u3002
\u8bb0\u4f4f\u5e76\u7406\u89e3\u4e00\u4e9b\u5e38\u89c1\u7684\u7b97\u6cd5\u7684\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u3001\u6700\u4f18\u3001\u6700\u5dee\u60c5\u51b5\u590d\u6742\u5ea6\uff1a
\u6765\u6e90\uff1a\u5e38\u7528\u6392\u5e8f\u7b97\u6cd5\u603b\u7ed3\u5bf9\u6bd4 | \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5 \u7cfb\u5217\u6559\u7a0b\uff08\u7b14\u8bb0\uff09 (zq99299.github.io)
\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
\u9875\u9762\u6b63\u5728\u65bd\u5de5\u4e2d
"},{"location":"programming/temp2/#2020-2021","title":"2020-2021 \u5e74\u5377","text":"typedef
\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
char *
&(t->name[0])
\uff0c\u5373 char *
\u7c7b\u578b\u3002char *
*(t.name)
\u662f\u4e00\u4e2a\u9519\u8bef\u7684\u7528\u6cd5\uff0c\u4e0d\u80fd\u76f4\u63a5\u5bf9\u7ed3\u6784\u7684\u6307\u9488\u4f7f\u7528 .
\u8fd0\u7b97\u7b26\u8bbf\u95ee\u5176\u6210\u5458\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
p
\u662f\u51fd\u6570\u540dp
\u662f\u51fd\u6570\u540dp
\u662f\u6307\u5411 int[5]
\u7684\u6307\u9488p
\u662f\u4e00\u4e2a\u6570\u7ec4C \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
auto
\uff1a\u9ed8\u8ba4\u7684\u5b58\u50a8\u7c7b\u522b\u9650\u5b9a\u7b26\uff0c\u7528\u4e8e\u5c40\u90e8\u53d8\u91cf\uff0c\u8868\u793a\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u4e0e\u51fd\u6570\u8c03\u7528\u76f8\u540c\u3002register
\uff1a\u7528\u4e8e\u5c40\u90e8\u53d8\u91cf\uff0c\u8868\u793a\u53d8\u91cf\u53ef\u80fd\u5b58\u50a8\u5728 CPU \u5bc4\u5b58\u5668\u4e2d\uff0c\u4ee5\u52a0\u5feb\u8bbf\u95ee\u901f\u5ea6\u3002extern
\uff1a\u7528\u4e8e\u5168\u5c40\u53d8\u91cf\uff0c\u8868\u793a\u53d8\u91cf\u5728\u5176\u4ed6\u6587\u4ef6\u4e2d\u5b9a\u4e49\u3002static
\uff1a
_Thread_local
\uff1a\u4e0d\u4f5c\u8981\u6c42\u3002
\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
InitGraphics()
\u4e00\u5b9a\u8981\u8bb0\u5f97void registerTimerEvent(TimerEventCallback callback)
\u4e0e void startTimer(int id,int timeinterval)
\u914d\u5bf9\u4f7f\u7528\uff0c\u5b83\u4eec\u5404\u81ea\u7684\u53c2\u6570\u610f\u4e49\u3002timerID
\u662f\u7528\u6765\u505a\u4ec0\u4e48\u7684\uff1f\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
\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. [...]
(*pf)
\u7684\u5f62\u5f0f\u662f\u6700\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u5982 void ToUpper(char *)
\u6539\u4e3a\u51fd\u6570\u6307\u9488 void (*pf)(char *)
\u3002\u58f0\u660e\u51fd\u6570\u6307\u9488\u540e\uff0c\u53ef\u4ee5\u5c06\u51fd\u6570\u7684\u5730\u5740\u8d4b\u7ed9\u5b83\uff0c\u8fd9\u79cd\u8bed\u5883\u4e0b\u51fd\u6570\u540d\u53ef\u4ee5\u8868\u793a\u51fd\u6570\u7684\u5730\u5740\u3002\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u5199\uff1apf = ToUpper
\uff0c\u6ce8\u610f\u4e0d\u662f pf = ToUpper()
\u3002
\u4f7f\u7528\u51fd\u6570\u6307\u9488\u8c03\u7528\u51fd\u6570\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a(*pf)(mis)
\u548c pf(mis)
\uff0c\u5b83\u4eec\u770b\u8d77\u6765\u77db\u76fe\u3002\u4e8b\u5b9e\u4e0a\uff0cK&R C \u4e0d\u5141\u8bb8\u7b2c\u4e8c\u79cd\u5f62\u5f0f\uff0c\u6211\u4e5f\u63a8\u8350\u5927\u5bb6\u59cb\u7ec8\u5c06\u51fd\u6570\u8c03\u7528\u7406\u89e3\u4e3a\u7b2c\u4e00\u79cd\u5f62\u5f0f\u3002
\u53d6\u51fd\u6570\u7684\u5730\u5740\u4e5f\u6709\u4e24\u79cd\u65b9\u6cd5\uff1af
\u548c &f
\u3002
C \u9879 \u6216\u8bb8\u901a\u8fc7\u4e0a\u9762\u7684\u8bb2\u89e3\uff0c\u4f60\u80fd\u7406\u89e3 (*cmd)
\u4e0e cmd
\u7684\u7b49\u4ef7\u4e4b\u5904\u3002\u4e0b\u9762\u662f StackOverflow \u4e2d\u7684\u8ba8\u8bba\uff1ac++ - What does void f(void())
mean? - Stack Overflow\u3002
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
F
\u5b9a\u4e49\u4e3a int (int)
\u7c7b\u578b\u7684\u51fd\u6570\u3002F
\u7684\u51fd\u6570 g
\u548c h
\u3002\u5176\u5b9e\u5c31\u662f int g(int a)
\u548c int h(int a)
\u3002p
\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f int (*)(int)
\u7c7b\u578b\uff08\u4e0e F
\u7b49\u4ef7\uff09\u3002\u5e76\u7528 g
\u548c h
\u6765\u521d\u59cb\u5316\u8fd9\u4e2a\u6570\u7ec4\u3002p
\u662f\u6807\u8bc6\u7b26\u7684\u540d\u79f0\uff0c\u5411\u53f3 []
\u8868\u660e\u8fd9\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u5411\u5de6 *
\u8868\u793a\u5176\u5143\u7d20\u662f\u6307\u9488\uff0c\u518d\u5411\u53f3 (int)
\u8868\u793a\u5176\u6240\u6307\u7c7b\u578b\u662f\u51fd\u6570\uff0c\u8fd9\u79cd\u51fd\u6570\u63a5\u53d7 int
\u7c7b\u578b\u53c2\u6570\uff0c\u518d\u5411\u5de6 int
\u8bf4\u660e\u8fd9\u79cd\u51fd\u6570\u8fd4\u56de int
\u7c7b\u578b\u3002g
\u548c h
\u521d\u59cb\u5316\u8fd9\u4e2a\u6570\u7ec4\u65f6\uff0cg
\u548c h
\u88ab\u8f6c\u6362\u4e3a\u51fd\u6570\u6307\u9488\uff08\u56de\u987e\u4e0a\u9762\u7684\u8ba8\u8bba\uff09\u3002\u7b2c\u56db\u884c\uff1a\u58f0\u660e\u4e00\u4e2a\u51fd\u6570 q
\u8fd9\u4e2a\u51fd\u6570\u8fd4\u56de int
\uff0c\u63a5\u53d7\u4e00\u79cd\u6570\u7ec4\uff0c\u8fd9\u79cd\u6570\u7ec4\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f F*
\u7c7b\u578b\uff0c\u5373 int (*)(int)
\u3002\u6545\u51fd\u6570 q
\u7684\u53c2\u6570\u7c7b\u578b\u4e3a int (**)(int)
\u3002
A \u9879\uff1a\u6570\u7ec4\u540d\u5c31\u662f\u9996\u5143\u7d20\u6307\u9488\uff0c\u4e3a int (**)(int)
\uff0c\u5339\u914d\u3002
int (*)(int)
\uff0c\u4e0e int (**)(int)
\u7c7b\u578b\u4e0d\u5339\u914d\u3002\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
((H)\u5185\u5c42\u8868\u8fbe\u5f0f )(100);
\uff0c\u5b83\u4f1a\u5c06\u5185\u5c42\u8868\u8fbe\u5f0f\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u4e3a H
\u7c7b\u578b\u7684\u51fd\u6570\uff0c\u7136\u540e\u5bf9\u8be5\u51fd\u6570\u6267\u884c\u51fd\u6570\u8c03\u7528\u3002h(0)
\u3002\u8c03\u7528\u540e\u8fd4\u56de\u4e86 h
\uff0c\u5373\u51fd\u6570\u81ea\u5df1\uff0c\u4e5f\u5c31\u662f\u51fd\u6570\u81ea\u5df1\u7684\u6307\u9488\u3002\u4f5c\u4e3a void *
\u7c7b\u578b\u8fd4\u56de\uff0c\u8868\u660e\u5b83\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u4f46\u4e0d\u77e5\u9053\u6240\u6307\u5411\u7684\u7c7b\u578b\u3002h(100)
\u4e86\uff0c\u56e0\u4e3a h
\u672c\u6765\u5c31\u662f H
\u7c7b\u578b\u7684\u51fd\u6570\u3002geblib.h
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
New()
\u5b8f\u51fd\u6570\uff1a
Usage: p = New(pointer-type);
The New pseudofunction allocates enough space to hold an object of the type to which pointer-type points and returns a pointer to the newly allocated pointer. Note that \"New\" is different from the \"new\" operator used in C++; the former takes a pointer type and the latter takes the target type.
\u6e90\u7801\uff1a
void *GetBlock(size_t nbytes);\n#define New(type) ((type) GetBlock(sizeof *((type) NULL)))\n
\u4e3e\u4e2a\u4f8b\u5b50\uff1a\u8c03\u7528 New(char*)
((char*) GetBlock(sizeof *((char*) NULL)))
GetBlock()
\u51fd\u6570\u63a5\u6536\u9700\u8981\u5206\u914d\u7684\u5b57\u8282\u6570\uff0c\u8fd4\u56de\u5206\u914d\u6210\u529f\u7684\u6307\u9488\u3002\u5bf9\u4e8e\u4e0a\u9762\u7684\u5b8f\u5c55\u5f00\u540e\u7684\u8c03\u7528\u53c2\u6570\uff0cNULL
\u88ab\u8f6c\u6362\u4e3a char*
\u968f\u540e\u89e3\u5f15\u7528\u4ecd\u4e3a char
\u7c7b\u578b\u7684\u5927\u5c0f\u3002char*
\u7684\u6307\u9488\u3002FreeBlock()
\u51fd\u6570\uff1a
void FreeBlock(void *ptr)
free()
\u529f\u80fd\u7c7b\u4f3c\uff0c\u4e0d\u52a0\u89e3\u91ca\u3002\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
\u9012\u5f52\u60c5\u5f62\uff1a\u753b\u4e00\u6839\uff0c\u968f\u540e\u4e24\u6b21\u9012\u5f52\u8c03\u7528\uff0c\u7ed8\u5236\u4e0b\u4e00\u652f\u7684 length
\u548c order
\u3002\u6bcf\u6b21\u9012\u5f52\u8c03\u7528\u540e\uff0c\u90fd\u5e94\u5f53\u8fd4\u56de\u539f\u4f4d\u3002
#include <stdio.h>\n#include <math.h>\n#include <stdlib.h>\n#include \"graphics.h\"\n#define MIN_LEN .1\n\ndouble toRadius(double deg)\n{\n return deg * 3.1415926 / 180;\n}\n\nvoid DrawBranch(double len, double deg)\n{\n DrawLine(len * cos(toRadius(deg)), len * sin(toRadius(deg)));\n if (len * 0.75 < MIN_LEN)\n return;\n DrawBranch(len * 0.75, deg - 15);\n MovePen(GetCurrentX() - len * 0.75 * cos(toRadius(deg - 15)),\n GetCurrentY() - len * 0.75 * sin(toRadius(deg - 15)));\n //\u4e5f\u53ef\u4ee5\u7528 DrawLine \u5b9e\u73b0\n DrawBranch(len * 0.75, deg + 15);\n MovePen(GetCurrentX() - len * 0.75 * cos(toRadius(deg + 15)),\n GetCurrentY() - len * 0.75 * sin(toRadius(deg + 15)));\n}\n\nint main(void)\n{\n double length;\n char order;\n printf(\"Please enter initial length: \");\n scanf(\"%lf\", &length);\n getchar();\n printf(\"Please enter order (u)pper, (d)own, (r)ight, (l)eft: \");\n scanf(\"%c\", &order);\n double deg;\n switch(order)\n {\n case 'u': deg = 90; break;\n case 'd': deg = -90; break;\n case 'r': deg = 0; break;\n case 'l': deg = 180; break;\n default: printf(\"error.\\n\"); return 1;\n }\n InitGraphics();\n MovePen(GetWindowWidth()/2, GetWindowHeight()/2);\n DrawBranch(length, deg);\n return 0;\n}\n
\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/temp2/#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
StudentInfo
\uff1a\u4e24\u4e2a char
\u6570\u7ec4 + \u4e00\u4e2a\u6307\u9488 = \\(12 + 20 + 4 = 36\\)PtrStudentInfo
\uff1a\\(4\\)pStudent->name
\uff1a\u4e00\u4e2a char
\u6570\u7ec4 \\(=20\\)pStudent->photo
\uff1a\u4e00\u4e2a void*
\u6307\u9488 \\(=4\\)\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
main()
\u4e2d\u7684 Push()
\uff0c\u8fd9\u600e\u4e48\u6bd4\u5e73\u5e38\u7684 Push()
\u591a\u4e00\u4e2a\u53c2\u6570\u5462\uff1fTop
\uff1f\u56de\u60f3 main()
\u4e2d\u4e00\u4e2a\u4ee4\u4e3a -1
\u4e00\u4e2a\u4ee4\u4e3a MaxSize
\u4fbf\u77e5\u9053\u8fd9\u662f\u4e00\u4e2a\u53cc\u5411\u6808\u4e86\u3002Push()
\u548c Pop()
\u7684\u4ee3\u7801\u5c31\u4e0d\u7528\u770b\u4e86\uff0c\u60f3\u8c61\u5f97\u5230\u662f\u600e\u4e48\u64cd\u4f5c\u7684\u3002\u6700\u591a\u518d\u591a\u770b\u4e00\u773c if(Tag == 1)
\u77e5\u9053\u54ea\u4e2a\u503c\u5bf9\u5e94\u54ea\u4e00\u5934\uff0c\u5c31\u53ef\u4ee5\u5b8c\u6210\u8fd9\u9053\u9898\u4e86\u3002\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
\u753b\u4e2a\u5750\u6807\u8f74\uff0c\u4e00\u5207\u90fd\u6e05\u6670\u8d77\u6765\u4e86\u3002\u7136\u540e Main()
\u91cc\u6700\u5f00\u59cb\u5bf9\u5927\u4e09\u89d2\u5f62\u4e09\u4e2a\u9876\u70b9\u7684\u6c42\u503c\u53ef\u80fd\u4f1a\u5f15\u8d77\u56f0\u60d1\uff0c\u5176\u5b9e\u53ef\u4ee5\u4e0d\u7528\u7ba1\u5b83\uff0c\u5b83\u4e0d\u5f71\u54cd\u4f60\u5206\u6790\u9012\u5f52\u8c03\u7528\u8fc7\u7a0b\u3002\u5b83\u53ea\u662f\u5728\u7528\u4e09\u89d2\u51fd\u6570\u8ba1\u7b97\u4f4d\u7f6e\u4f7f\u8fd9\u4e2a\u5927\u4e09\u89d2\u5f62\u7684\u4e2d\u5fc3\u5728\u5c4f\u5e55\u4e2d\u592e\u7f62\u4e86\u3002\u7ed9\u4e2a\u5f88\u8349\u7684\u8349\u7a3f\u793a\u610f\u56fe\uff1a
\u753b\u8fd9\u4e2a\u5206\u5f62\u7684\u6b65\u9aa4\u5c31\u662f\uff1a\u5148\u753b\u5927\u4e09\u89d2\uff0c\u7136\u540e\u5404\u8fb9\u53d6\u4e2d\u70b9\u3002\u5927\u4e09\u89d2\u7684\u6bcf\u4e2a\u9876\u70b9\u548c\u76f8\u90bb\u4e24\u8fb9\u4e2d\u70b9\u6784\u6210\u4e24\u4e2a\u5c0f\u4e09\u89d2\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
strcpy()
\u53ea\u80fd\u7528\u4e8e\u5b57\u7b26\u4e32\u3002\u8fdb\u4e00\u6b65\u8bf4\uff0c\u5b83\u4f9d\u636e\u5b57\u7b26\u4e32\u672b\u5c3e\u7684 \\0
\u6765\u51b3\u5b9a\u662f\u5426\u505c\u6b62\u590d\u5236\uff0c\u56e0\u6b64\u4e0d\u5b9c\u7528\u4e8e\u6b64\u60c5\u5883\u3002*pc2++ = *pc1++
\uff0c\u90fd\u4f1a\u5c06 pc1
\u7684\u4e00\u4e2a\u5b57\u8282\u62f7\u8d1d\u5230 pc2
\u6307\u5411\u7684\u4f4d\u7f6e\uff0c\u5e76\u8ba9\u8fd9\u4e24\u4e2a\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4e2a char
\u7684\u4f4d\u7f6e\u3002\u7531\u4e8e p1
\u548c p2
\u4e24\u4e2a\u7ed3\u6784\u53d8\u91cf\u5927\u5c0f\u90fd\u662f \\(8+8=16\\) \u5b57\u8282\uff0c\u56e0\u6b64\u8be5\u9009\u9879\u6b63\u786e\u5730\u6267\u884c\u4e86\u62f7\u8d1d\u3002\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
static
\u6b64\u5904\u4fee\u9970\u7684\u662f\u6307\u9488 p
\u3002\u4e8b\u5b9e\u4e0a\uff0c\u4e5f\u4e0d\u5b58\u5728\u6307\u9488\u6307\u5411 static int
\u8fd9\u79cd\u8bf4\u6cd5\u3002static
\u4f5c\u4e3a\u5b58\u50a8\u7c7b\u522b\u9650\u5b9a\u7b26\uff0c\u5728\u53d8\u91cf\u7684\u58f0\u660e\u4e2d\u8868\u793a\u8be5\u53d8\u91cf\u5177\u6709\u9759\u6001\u5b58\u50a8\u671f\u3002\u4e00\u4e2a\u6307\u9488\uff0c\u53ea\u9700\u8981\u7ba1\u5b83\u6307\u5411\u7684\u662f\u4ec0\u4e48\u7c7b\u578b\uff0c\u4e0d\u9700\u8981\u77e5\u9053\u8fd9\u4e2a\u5bf9\u8c61\u7684\u5b58\u50a8\u671f\u3002\u5148\u60f3\u60f3\u81ea\u5df1\u4f1a\u600e\u4e48\u8c03\u7528\u8fd9\u4e2a fun
\u51fd\u6570\u624d\u80fd\u5f97\u5230 void
\u7c7b\u578b\uff1a
fun(int)
\u3002(*fun(int))(int)
\u3002\u6ce8\u610f\uff0c\u51fd\u6570\u6307\u9488\u5e94\u5f53\u4f7f\u7528 (*fp)()
\u5f62\u5f0f\u8c03\u7528\u3002\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
\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
count
\u6570\u7ec4\uff1a\u5148\u7528\u4e8e\u7edf\u8ba1\u51fa\u73b0\u6b21\u6570\uff0c\u540e\u7528\u6765\u6807\u8bb0\u5f00\u59cb\u4f4d\u7f6e\u3002output_array[count[input_array[i]]] = input_array[i]
\u6211\u4eec\u6765\u62c6\u89e3\u4e00\u4e0b\uff1aintput_array[i]
\u5c31\u662f\u7b2c i
\u4e2a\u5143\u7d20count[]
\u5c31\u80fd\u67e5\u5230\u8fd9\u4e2a\u6570\u5e94\u8be5\u653e\u7f6e\u7684\u8d77\u59cb\u4f4d\u7f6e\u3002\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/temp2/#2015-2016","title":"2015-2016 \u5e74\u5377","text":"\u5b8f\u5c55\u5f00\u53ea\u662f\u7b80\u5355\u7684\u6587\u672c\u66ff\u6362\u3002
DD
\u5f97\u5230 SQ(2*3) - SQ(2+3)
\uff0c\u5f97\u5230 2 * 3 * 2 * 3 - 2 + 3 * 2 + 3
SQ
\u5f97\u5230 DD(x, y) = x * x - y * y
\uff0c\u5f97\u5230 2 * 3 * 2 * 3 - 2 + 3 * 2 + 3
\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/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/daily/2023/#december","title":"December","text":""},{"location":"programming/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:
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/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/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
.
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/daily/2023/#3-sizeof-struct","title":"\u300c3\u300dsizeof
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)
?
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/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:
printf
series of formatting output functions.2
, and if the hexadecimal number is less than 2 digits, pad it with leading zeros. For example, 0x0a
.Sample Input\uff1a
Hello\nWorld!\n
Sample Output\uff1a
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/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.
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/daily/2023/#november","title":"November","text":""},{"location":"programming/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 list
list->next
node
node
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:
data
to data
.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/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/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/daily/2023/#27-i-love-scanf","title":"\u300c27\u300d I Lovescanf
!","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/daily/2023/#26-broken-strcpy","title":"\u300c26\u300d Brokenstrcpy()
","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:
*t
is 'H'
, and is assigned to *s
.s
and t
increment.*t
, now being 'e'
, is used to evaluate the while
condition.t
points to 'o'
and is assigned to *s
.s
and t
increment.*t
, now being '\\0'
, is used to evaluate the while
condition. The loop ends.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 = \"\"
?
'\\0'
is assigned to *s
.s
and t
increment. t
gets past its end.*t
is undefined behavior.'\\0'
, or it goes too far and causes a segmentation fault.\u4f9b\u9898\u4eba\uff1a\u674e\u82f1\u7426
"},{"location":"programming/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
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/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/daily/2023/#23-typedef-and-string","title":"\u300c23\u300dtypedef
and String","text":"The preprocessing of this program is as follows\uff1a
#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/daily/2023/#october","title":"October","text":""},{"location":"programming/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:
a++
!
--a
-
<<
<
, >
||
a ? b : c
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
evaluates to 0, and y << 0
has the value 2.2 > 2
is false, thus the value of the Logical OR depends on the right part.x++
assigns the value of x
(1) to the expression and then increments x
by 1, making x
equal to 2.--y
decreases the value of y
(2) by 1, so y
becomes 1.x++ > --y
is equivalent to 1 > 1, which is false, so this part equals 0.!(x++ > --y)
negates false, so this part equals 1, making the condition of the Ternary conditional true.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/daily/2023/#27-or-in-switch","title":"\u300c27\u300d Or inswitch
","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.
AnswerD
.
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/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];
A
.
B
will always be 0
when x==y
. C
and D
is not logically correct.\u4f9b\u9898\u4eba\uff1a\u7a0b\u6615\u5b87
"},{"location":"programming/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/daily/2023/#24-nested-switch-confusing-default-and-break","title":"\u300c24\u300d Nestedswitch
, 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/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
The result of the increment and decrement operators
Increment and decrement operators have postfix form x++
(or x--
), and prefix form ++x
(or --x
).
x
.x + 1
for ++x
(or x - 1
for --x
).For more information, see cppreference-Increment/decrement operators
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/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.
strcmp
function in <string.h>
header file. Learn how to use the function by yourself.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/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/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/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/daily/2023/#18-bad-if-else","title":"\u300c18\u300d Badif
-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/daily/2023/#17-character","title":"\u300c17\u300d Character","text":"Given: char c = '@';
, the value of expression 'A' <= c <= 'Z'
is __.
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/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?
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/topic/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
sizeof
\u7684\u64cd\u4f5c\u6570\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/topic/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/topic/pointers/#_2","title":"\u5e95\u5c42\u6982\u5ff5","text":""},{"location":"programming/topic/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/topic/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\u7b26C \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/topic/pointers/#_5","title":"\u57fa\u672c\u8bed\u6cd5","text":""},{"location":"programming/topic/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/topic/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
\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
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
\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
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/topic/pointers/#_9","title":"\u7528\u6cd5\u6982\u8ff0","text":""},{"location":"programming/topic/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\u8bed\u6cd5\u9519\u8bef\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
\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/topic/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
\u6839\u636e\u6807\u51c6\u89c4\u5b9a\uff0c\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u65f6\uff0c\u6570\u7ec4\u5e94\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u5176\u9996\u5143\u7d20\u6307\u9488\uff0c\u8fd9\u662f\u56e0\u4e3a\u590d\u5236\u6570\u7ec4\u7684\u5f00\u9500\u7ecf\u5e38\u5927\u5230\u4e0d\u53ef\u63a5\u53d7\u3002\u6240\u4ee5\uff0c\u5728\u8bed\u6cd5\u5c42\u9762\u4e0a\uff0c\u51fd\u6570\u5b9a\u4e49\u4e2d\uff08\u5373\u53c2\u6570\u7c7b\u578b\u4e0e\u8fd4\u56de\u503c\u7c7b\u578b\u5904\uff09char []
\u7c7b\u578b\u58f0\u660e\u4e0e char *
\u7c7b\u578b\u58f0\u660e\u662f\u7b49\u4ef7\u7684\uff0c\u4e0d\u8fc7\u524d\u8005\u53ef\u4ee5\u63d0\u9192\u51fd\u6570\u7f16\u5199\u8005\u4e0e\u4f7f\u7528\u8005\u7559\u610f s
\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\u5bf9\u51fd\u6570\u800c\u8a00\u6ca1\u6709\u8bed\u4e49\u533a\u522b\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/topic/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
\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
\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
\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
\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
\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
\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
\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
\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/topic/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
sizeof
\u7684\u64cd\u4f5c\u6570\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/topic/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/topic/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
\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_lecture/#_2","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
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_lecture/lecture1/lecture1/","title":"\u8bb2\u4e49\uff1a\u7a0b\u5e8f\u7f16\u8bd1\u8fc7\u7a0b\u4e0e\u8c03\u8bd5\u6280\u672f","text":"\u76f4\u64ad\u56de\u653eBilibili
\u5185\u5bb9\u63d0\u8981gcc
\u3001clang
\u548c llvm
\u7a76\u7adf\u662f\u4ec0\u4e48\uff1fgdb
\u6216 lldb
\u8bbe\u7f6e\u65ad\u70b9\u3001\u627e\u5230\u6bb5\u9519\u8bef\u7684\u6839\u6e90\uff1f\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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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\u5b50c = 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 \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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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
(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(a--) - b
a - (--b)
y = x
\u3002/*
\u88ab\u8d2a\u5fc3\u6cd5\u89e3\u91ca\u4e3a\u6ce8\u91ca\u7684\u5f00\u5934\u3002y = x / (*p)
(n--) > 0
(n--) > 0
(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((a++)++) + b
\u3002\u8bf7\u601d\u8003\u4e00\u4e0b\uff0c\u8fd9\u4e2a\u8bed\u53e5\u6709\u6548\u5417\uff1f\u4e3a\u4e86\u4fbf\u4e8e\u521d\u5b66\u8005\u7406\u89e3\uff0c\u6211\u4eec\u91c7\u7528\u4e00\u5957\u7b80\u5316\u7684\u8bed\u6cd5\u89c4\u5219\uff1a
\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
+-*/%
\u7b49\u7b49\uff09\u548c\u64cd\u4f5c\u6570\uff08\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u51fd\u6570\u8fd4\u56de\u503c......\uff09\u7ec4\u6210\u7684\u5f0f\u5b50\uff0c\u53ef\u4ee5\u8ba1\u7b97\u51fa\u4e00\u4e2a\u503c\u3002\u8bed\u53e5\uff08Statement\uff09\uff1aC \u6807\u51c6\u786e\u5b9a\u4e86\u4e94\u79cd\u8bed\u53e5\u7c7b\u578b\u3002\u9664\u4e86\u590d\u5408\u8bed\u53e5\uff0c\u5176\u5b83\u8bed\u53e5\u90fd\u4ee5\u5206\u53f7 ;
\u7ed3\u5c3e\u3002\u4e0b\u9762\u662f\u8bed\u53e5\u7684\u5b9a\u4e49\uff0c\u4f60\u53ef\u4ee5\u53d1\u73b0\u8bed\u53e5\u662f\u9012\u5f52\u5b9a\u4e49\u7684\u3002
\u590d\u5408\u8bed\u53e5\uff1a\u7531\u82b1\u62ec\u53f7\u5305\u56f4\u7684\u4e00\u7ec4\u8bed\u53e5\u3002
{ \u8bed\u53e5\u6216\u58f0\u660e }\n
\u8868\u8fbe\u5f0f\u8bed\u53e5\uff1a\u8868\u8fbe\u5f0f\u52a0\u4e0a\u5206\u53f7\u5c31\u662f\u8868\u8fbe\u5f0f\u8bed\u53e5\u3002C \u7a0b\u5e8f\u4e2d\u5927\u90e8\u5206\u8bed\u53e5\u90fd\u662f\u8868\u8fbe\u5f0f\u8bed\u53e5\u3002\u7a7a\u8bed\u53e5\u4e5f\u7b97\u4f5c\u8868\u8fbe\u5f0f\u8bed\u53e5\u3002
\u8868\u8fbe\u5f0f;\n
\u4f8b\u5b50\uff1a
puts(\"hello\"); // \u8868\u8fbe\u5f0f\u8bed\u53e5\nchar *s;\nwhile (*s++ != '\\0')\n ; // \u7a7a\u8bed\u53e5\n
\u9009\u62e9\u8bed\u53e5\uff1a
if(\u8868\u8fbe\u5f0f) \u8bed\u53e5\nif(\u8868\u8fbe\u5f0f) \u8bed\u53e5 else \u8bed\u53e5\nswitch(\u8868\u8fbe\u5f0f) \u8bed\u53e5\n
\u5faa\u73af\u8bed\u53e5\uff1a
while(\u8868\u8fbe\u5f0f) \u8bed\u53e5\ndo \u8bed\u53e5 while(\u8868\u8fbe\u5f0f);\nfor(\u521d\u59cb\u5316\u5b50\u53e5;\u8868\u8fbe\u5f0f;\u8868\u8fbe\u5f0f) \u8bed\u53e5\n
\u8df3\u8f6c\u8bed\u53e5\uff1a
goto \u6807\u8bc6\u7b26;\ncontinue;\nbreak;\nreturn \u8868\u8fbe\u5f0f;\n
\u5b8c\u6574\u7684C\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_lecture/lecture1/lecture1/#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
void
Q\uff1avoid
\u5230\u5e95\u6709\u54ea\u4e9b\u542b\u4e49\uff1f
A: \u4e0b\u9762\u662f void
\u7684\u4e00\u822c\u7528\u6cd5
void
\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\uff0c\u8868\u793a\u51fd\u6570\u4e0d\u63a5\u53d7\u53c2\u6570\u3002void
\u4f5c\u4e3a\u51fd\u6570\u8fd4\u56de\u503c\uff0c\u8868\u793a\u51fd\u6570\u4e0d\u8fd4\u56de\u503c\u3002void*
\u662f\u4e00\u79cd\u6307\u9488\u7c7b\u578b\uff0c\u8868\u793a\u4e0d\u77e5\u9053\u6307\u5411\u7684\u7c7b\u578b\u662f\u4ec0\u4e48\u3002\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\u7528int 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
\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
\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
\u51fd\u6570\u4e0d\u8981\u5199\u5f97\u592a\u957f\uff0c\u5efa\u8bae\u572824\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
\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
\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
\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
\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_lecture/lecture1/lecture1/#_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\u6811printf(\"%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_lecture/lecture1/lecture1/#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
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\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\u9898In the following notations, _____ can express a character constant( \u5b57\u7b26\u5e38\u91cf ) correctly.
A. '\\x100'
B. 125
C. '\\08'
D. '\\'
B
"},{"location":"programming_lecture/lecture1/lecture1/#_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
.i
\u4e3a\u540e\u7f00\u3002.s
\u4e3a\u540e\u7f00\u3002.o
\u4e3a\u540e\u7f00\u3002.exe
\u4e3a\u540e\u7f00\u3002gcc
\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
\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
gcc
\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u5305\u62ec\u5b83\u8fd0\u884c\u7684\u5e73\u53f0\u3001\u914d\u7f6e\u7684\u9009\u9879\u7b49\u3002cc1
\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
\u3002as
\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
\u3002sum.c
\u91cd\u590d\u9884\u5904\u7406\u3001\u7f16\u8bd1\u548c\u6c47\u7f16\u7684\u8fc7\u7a0b\uff0c\u5f97\u5230\u4e86 /tmp/ccgMFTqK.o
\u3002collect2
\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\u3002cpp
\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_lecture/lecture1/lecture1/#_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
#include \"...\"
\u5305\u542b\u7684\u5934\u6587\u4ef6\uff0c\u7f16\u8bd1\u5668\u4f1a\u5148\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u67e5\u627e\uff0c\u518d\u5728\u7cfb\u7edf\u76ee\u5f55\u4e0b\u67e5\u627e\u3002#include <...>
\u5305\u542b\u7684\u5934\u6587\u4ef6\uff0c\u7f16\u8bd1\u5668\u53ea\u4f1a\u5728\u7cfb\u7edf\u76ee\u5f55\u4e0b\u67e5\u627e\u3002\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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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\u63a5hello.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
main
\u51fd\u6570\uff0c\u800c\u662f\u4e00\u4e9b\u542f\u52a8\u4ee3\u7801\u3002\u542f\u52a8\u4ee3\u7801\u5728\u6267\u884c main
\u524d\u8fdb\u884c\u4e00\u4e9b\u521d\u59cb\u5316\u5de5\u4f5c\uff0c\u5e76\u5728\u9000\u51fa main
\u540e\u505a\u4e00\u4e9b\u626b\u5c3e\u5de5\u4f5c\u3002Linux \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
crt1.o
\uff1a\u8d1f\u8d23\u542f\u52a8\uff0c\u5305\u542b _start
\u548c\u672a\u5b9a\u4e49\u7684 __libc_start_main
\u548c main
\u3002crti.o
\uff1a\u521d\u59cb\u5316crtbegin.o
\uff1a\u6784\u9020\uff08C++\u4f9d\u8d56\uff09crtend.o
\uff1a\u6790\u6784\uff08C++\u4f9d\u8d56\uff09crtn.o
\uff1a\u7ed3\u675fLinux \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
printf
\u3002\u6807\u51c6\u5e93\u4e2d\u7684\u4ee3\u7801\u5df2\u7ecf\u88ab\u9884\u7f16\u8bd1\u6210\u76ee\u6807\u6587\u4ef6\uff0c\u9644\u5728\u7f16\u8bd1\u5668\u7684\u5b89\u88c5\u76ee\u5f55\u4e0b\u3002\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_lecture/lecture1/lecture1/#_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
\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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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
-Wall
\u548c -Werror
\uff0c\u7f16\u8bd1\u51fa\u6765\u7684\u7a0b\u5e8f\u4e2d\u6709\u5f88\u591a\u5751\uff0c\u6bd4\u5982\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u3002fprintf(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_lecture/lecture1/lecture1/#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
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_lecture/lecture1/lecture1/#_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\u8bc1gdb\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_lecture/lecture1/lecture1/#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
file <filename>
\uff1a\u52a0\u8f7d\u53ef\u6267\u884c\u6587\u4ef6\u3002r
\u6216 run [args]
\uff1a\u8fd0\u884c\u7a0b\u5e8f\u3002[args]
\u662f\u53ef\u9009\u7684\u547d\u4ee4\u884c\u53c2\u6570\u3002b
\u6216 break <line>
\uff1a\u5728\u6307\u5b9a\u884c\u8bbe\u7f6e\u65ad\u70b9\u3002b
\u6216 break <function>
\uff1a\u5728\u6307\u5b9a\u51fd\u6570\u8bbe\u7f6e\u65ad\u70b9\u3002b
\u6216 break *<address>
\uff1a\u5728\u6307\u5b9a\u5730\u5740\u8bbe\u7f6e\u65ad\u70b9\u3002info breakpoints
\uff1a\u67e5\u770b\u65ad\u70b9\u4fe1\u606f\u3002delete breakpoints <number>
\uff1a\u5220\u9664\u6307\u5b9a\u7f16\u53f7\u7684\u65ad\u70b9\u3002continue
\uff1a\u7ee7\u7eed\u6267\u884c\u7a0b\u5e8f\u3002next
\uff1a\u6267\u884c\u4e0b\u4e00\u884c\u3002step
\uff1a\u6267\u884c\u4e0b\u4e00\u884c\uff0c\u5982\u679c\u9047\u5230\u51fd\u6570\u8c03\u7528\uff0c\u8fdb\u5165\u51fd\u6570\u5185\u90e8\u3002print <variable>
\uff1a\u6253\u5370\u53d8\u91cf\u7684\u503c\u3002print <expression>
\uff1a\u6253\u5370\u8868\u8fbe\u5f0f\u7684\u503c\u3002watch <expression>
\uff1a\u76d1\u89c6\u8868\u8fbe\u5f0f\u7684\u503c\uff0c\u5f53\u503c\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u7a0b\u5e8f\u4f1a\u505c\u4e0b\u6765\u3002backtrace
\uff1a\u67e5\u770b\u51fd\u6570\u8c03\u7528\u6808\u3002finish
\uff1a\u6267\u884c\u5b8c\u5f53\u524d\u51fd\u6570\u540e\u505c\u4e0b\u6765\u3002q
\u6216 quit
\uff1a\u9000\u51fa gdb
\u3002help
\uff1a\u67e5\u770b\u5e2e\u52a9\u4fe1\u606f\u3002Linux \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
\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_lecture/lecture1/lecture1/#_24","title":"\u53c2\u8003\u8d44\u6599","text":"\u53c2\u8003\u8d44\u6599Info
\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
Run
\u3002\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
\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
$
\u3002\u4e0b\u9762\u7684\u56fe\u4e2d\uff0cbowling
\u90a3\u4e00\u5757\u5c31\u662f\u63d0\u793a\u7b26\uff08\u6211\u505a\u4e86\u4e00\u4e9b\u7f8e\u5316\uff09\u3002\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_lecture/lecture1/pre_class/#_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
\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_lecture/lecture1/pre_class/#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_lecture/lecture1/pre_class/#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_lecture/lecture1/pre_class/#gcc","title":"\u5c31\u51b3\u5b9a\u662f\u4f60\u4e86\uff0cgcc\uff01","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_lecture/lecture1/pre_class/#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_lecture/lecture1/pre_class/#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_lecture/lecture1/pre_class/#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
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_lecture/lecture1/pre_class/#_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
WindowsMacWindows \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
\u901a\u8fc7 Code \u6253\u5f00
\u7684\u9009\u9879code
\u547d\u4ee4\u6253\u5f00 VSCodeMac \u7684\u5305\u4e0b\u8f7d\u4e0b\u6765\u4e4b\u540e\u62d6\u5165 Application
\u6587\u4ef6\u5939\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c
code
\u547d\u4ee4\u6253\u5f00 VSCode\uff0c\u90a3\u4e48\u9700\u8981\u5982\u4e0b\u64cd\u4f5cshell command
\uff0c\u9009\u62e9 Shell Command: Install \u2018code\u2019 command in PATH
\u56de\u8f66\u6267\u884c\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_lecture/lecture1/pre_class/#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
auto
\u53ef\u4ee5\u627e\u5230\u5982\u56fe\u6240\u793a\u7684 Auto Save
\u8bbe\u7f6e\u9879\uff0c\u8bbe\u7f6e\u4e3a afterDelay \u5373\u53ef\u4f5c\u4e1a.c
\u7f16\u7a0b
Coding
\uff0c\u4f46\u662f\u7edd\u5bf9\u8def\u5f84\u662f D:/\u5b66\u4e60\u8d44\u6599/Coding
hello.exe
\uff0c\u5c31\u53ef\u4ee5\u6267\u884c gcc test.c -o hello.exe\n
\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_lecture/lecture1/pre_class/#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
WSL: Connect to WSL in New Window
\uff08\u6216 WSL: \u5728\u65b0\u7a97\u53e3\u4e2d\u8fde\u63a5\u5230 WSL
\uff09\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_lecture/lecture1/pre_class/#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
\u65bd\u5de5\u4e2d
\u672c\u9875\u9762\u6b63\u5728\u65bd\u5de5\u4e2d\uff0c\u5185\u5bb9\u53ef\u80fd\u4e0d\u5b8c\u6574\u3002
\u5185\u5bb9\u6458\u8981
\u672c\u8282\u5185\u5bb9\u5bf9\u5e94 CSAPP \u7b2c 6 \u7ae0\u300c\u5b58\u50a8\u5668\u5c42\u6b21\u7ed3\u6784\u300d\u4e0e\u7b2c 9 \u7ae0\u300c\u865a\u62df\u5185\u5b58\u300d\u3002
"},{"location":"programming_lecture/lecture2/after_class/#_2","title":"\u5b58\u50a8\u5668\u5c42\u6b21\u7ed3\u6784","text":"\u5f85\u5b8c\u5584
"},{"location":"programming_lecture/lecture2/after_class/#_3","title":"\u865a\u62df\u5185\u5b58","text":"\u7cfb\u7edf\u4e2d\u7684\u8fdb\u7a0b\u95f4\u5171\u4eab CPU \u548c\u4e3b\u5b58\u8d44\u6e90\u3002\u7136\u800c\uff0c\u5171\u4eab\u4e3b\u5b58\u4f1a\u9020\u6210\u8bb8\u591a\u95ee\u9898\uff0c\u6bd4\u5982\u4e00\u4e2a\u8fdb\u7a0b\u4e0d\u5c0f\u5fc3\u5199\u5165\u4e86\u53e6\u4e00\u4e2a\u8fdb\u7a0b\u4f7f\u7528\u7684\u5185\u5b58\u3002
Linux \u8fdb\u7a0b\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4
\u4e3a\u4e86\u66f4\u52a0\u6709\u6548\u5730\u7ba1\u7406\u5185\u5b58\u5e76\u51cf\u5c11\u51fa\u9519\uff0c\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u5c06\u4e3b\u5b58\u62bd\u8c61\u4e3a\u865a\u62df\u5185\u5b58\uff08Vitrual Memory\uff09\u3002\u53f3\u56fe\u5c55\u793a\u4e86 Linux \u7cfb\u7edf\u4e2d\u8fdb\u7a0b\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\u8bbe\u8ba1\u3002
\u865a\u62df\u5185\u5b58\u9700\u8981\u786c\u4ef6\u5f02\u5e38\u3001\u786c\u4ef6\u5730\u5740\u7ffb\u8bd1\u3001\u4e3b\u5b58\u3001\u78c1\u76d8\u6587\u4ef6\u548c\u5185\u6838\u8f6f\u4ef6\u5171\u540c\u4ea4\u4e92\u5b9e\u73b0\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u4e00\u6b65\u6b65\u4e86\u89e3\u865a\u62df\u5185\u5b58\u7684\u7ec6\u8282\u3002
"},{"location":"programming_lecture/lecture2/after_class/#_4","title":"\u865a\u62df\u5185\u5b58\u7684\u57fa\u672c\u601d\u60f3","text":"\u4e00\u4e2a\u8fdb\u7a0b\u865a\u62df\u5185\u5b58\u7684\u5185\u5bb9\u5b58\u50a8\u5728\u78c1\u76d8\u4e0a\uff0c\u7136\u540e\u7528\u4e3b\u5b58\u4f5c\u4e3a\u78c1\u76d8\u7684\u9ad8\u901f\u7f13\u5b58\u3002
\u78c1\u76d8\u4e0a\u7684\u6570\u636e\u88ab\u5206\u5272\u6210\u865a\u62df\u9875\uff08Virtual Page\uff09\uff0c\u4e3b\u5b58\u88ab\u5206\u5272\u6210\u7269\u7406\u9875\uff08Physical Page\uff09\u3002\u865a\u62df\u9875\u548c\u7269\u7406\u9875\u7684\u5927\u5c0f\u76f8\u540c\uff0c\u901a\u5e38\u4e3a 4KB\u3002\u8fd9\u4e9b\u9875\u662f\u78c1\u76d8\u548c\u4e3b\u5b58\u4e4b\u95f4\u7684\u4f20\u8f93\u5355\u5143\u3002
\u4efb\u610f\u65f6\u523b\uff0c\u865a\u62df\u9875\u9762\u53ef\u80fd\u5904\u4e8e\u4ee5\u4e0b\u4e09\u79cd\u72b6\u6001\u4e4b\u4e2d\uff1a
\u4e0b\u9762\u4ecb\u7ecd\u7684\u662f Linux \u7cfb\u7edf\u4e2d\u8fdb\u7a0b\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\u7ed3\u6784\u3002\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u53ef\u80fd\u6709\u4e0d\u540c\u7684\u8bbe\u8ba1\u3002\u4ece\u6700\u4f4e\u7684\u5730\u5740\u5f00\u59cb\u5411\u4e0a\uff0c\u4f9d\u6b21\u662f\uff1a
malloc
\u548c free
\u7b49\u6807\u51c6\u5e93\u51fd\u6570\u65f6\uff0c\u5806\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u5730\u6269\u5c55\u548c\u6536\u7f29\u3002\u865a\u62df\u5730\u5740\u7a7a\u95f4\u7684\u5927\u5c0f\u7531\u8868\u793a\u6700\u5927\u5730\u5740\u6240\u9700\u8981\u7684\u4f4d\u6570\u51b3\u5b9a\u3002\u73b0\u4ee3\u7cfb\u7edf\u901a\u5e38\u652f\u6301 32 \u6216 64 \u4f4d\u3002\u6bd4\u5982 32 \u4f4d\u64cd\u4f5c\u7cfb\u7edf\u652f\u6301\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\u5927\u5c0f\u4e3a 2^32 = 4GB\u3002
"},{"location":"programming_lecture/lecture2/after_class/#_6","title":"\u865a\u62df\u5185\u5b58\u7684\u5de5\u4f5c\u539f\u7406","text":""},{"location":"programming_lecture/lecture2/after_class/#_7","title":"\u865a\u62df\u5bfb\u5740","text":"CPU \u4e0d\u4f1a\u76f4\u63a5\u4f7f\u7528\u7269\u7406\u5730\u5740\uff08Physical Address\uff09\u8bbf\u95ee\u4e3b\u5b58\uff0c\u800c\u662f\u4f7f\u7528\u865a\u62df\u5730\u5740\uff08Virtual Address\uff09\u3002
\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_lecture/lecture2/lecture2/#_1","title":"\u524d\u7f6e\uff1a\u6570\u3001\u8fdb\u5236\u4e0e\u6570\u636e","text":"20231029
[0b] 1001101001011001101110101
[0o] 115131565
[0x] 134b375
\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_lecture/lecture2/lecture2/#_2","title":"\u5982\u4f55\u9605\u8bfb\u5b83\u4eec\uff1f","text":"\u8fd9\u4e9b\u90fd\u662f\u201c\u5341\u201d\uff1a0b1010
\uff0c0o12
\uff0c0xa
\uff0c10
\u3002
0x18
0o23
0b1010
0x10000
\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
\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_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#_6","title":"\u5148\u6765\u7ec3\u7ec3\u624b\uff01","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
int
\uff0c\u6545\u5360\u7528 4 \u5b57\u8282\u3002\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
\u6216\u8bb8\u4f60\u4f1a\u548c\u6211\u540c\u6837\u5bf9\u4ee5\u4e0b\u51e0\u4e2a\u95ee\u9898\u611f\u5230\u56f0\u60d1\uff1a
int
\u4e14\u957f\u5ea6\u662f 4 \u4e2a\u5b57\u8282\uff1fgetchar()
\u7b49\u51fd\u6570\u8fd4\u56de int
\u800c\u4e0d\u662f char
\uff1f\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
int
\uff1f\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
getchar()
\u4e3a\u4ec0\u4e48\u8981\u8fd4\u56de int
\u7c7b\u578b\uff1f\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
int c = getchar()
? Why int
? : C_Programming (reddit.com)\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
\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
\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
\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_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#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
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
\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_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#_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 - \u4e3a\u5bf9\u8c61\u5206\u914d\u5185\u5b58 - \u5c06\u6807\u8bc6\u7b26\u4e0e\u5bf9\u8c61\u5173\u8054
\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
psi
\u53d8\u91cf\u7684\u503c\u5c31\u662f i
\u5173\u8054\u7684\u5bf9\u8c61\u7684\u5730\u5740\uff080x16fdbae4c
\uff09psi
\u53ef\u4ee5\u8bbf\u95ee i
\u5173\u8054\u7684\u5bf9\u8c61\uff08*psi
\uff09psi
\u672c\u8eab\u4f5c\u4e3a\u4e00\u4e2a\u53d8\u91cf\uff0c\u4e5f\u6709\u81ea\u5df1\u7684\u5730\u5740\uff080x16fdbae08
\uff09\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
i
\u662f\u6807\u8bc6\u7b26\uff0c\u662f\u53ef\u4fee\u6539\u7684\u5de6\u503c*psi
\u6216 arr[3]
\u662f\u8868\u8fbe\u5f0f\uff0c\u662f\u53ef\u4fee\u6539\u7684\u5de6\u503c2 * i
\u6216 &i
\u6216 &psi
\uff0c\u4e0d\u662f\u6807\u8bc6\u7b26\uff0c\u662f\u53f3\u503cconst char *pc = \"Good morning my neighbors\";\n
pc
\u662f\u53ef\u4fee\u6539\u7684\u5de6\u503c*pc
\u662f\u4e0d\u53ef\u4fee\u6539\u7684\u5de6\u503c\u53c2\u8003\uff1a\u503c\u7c7b\u522b - cppreference.com
"},{"location":"programming_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#_16","title":"\u5b58\u50a8\u671f","text":"malloc()
\u5206\u914d\u7684\u5185\u5b58\u3002#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_lecture/lecture2/lecture2/#_17","title":"\u4f5c\u7528\u57df","text":"\u4f5c\u7528\u57df - cppreference.com
"},{"location":"programming_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#_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
\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_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#_22","title":"\u94fe\u63a5","text":""},{"location":"programming_lecture/lecture2/lecture2/#_23","title":"\u9605\u8bfb\u548c\u64b0\u5199\u7c7b\u578b\u58f0\u660e","text":""},{"location":"programming_lecture/lecture2/pre_class/","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_lecture/lecture3/lecture3/","title":"\u8bb2\u4e49\uff1aI/O \u4e0e\u6587\u4ef6","text":"\u5185\u5bb9\u63d0\u8981
\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\u7b49I/O\u64cd\u4f5c\u7684\u4e00\u4e9b\u6570\u636e\uff0c\u8fd9\u4e9b\u9884\u7559\u7684\u7a7a\u95f4\u5c31\u53eb\u505a\u7f13\u51b2\u533a\uff1b\u800cbuffer\u7f13\u51b2\u533a\u548cCache\u7f13\u5b58\u533a\u90fd\u5c5e\u4e8e\u7f13\u51b2\u533a\u7684\u4e00\u79cd\u3002
buffer\u7f13\u51b2\u533a\u548ccache\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
\u7cfb\u7edf\u5c42\u9762\uff0c\u51cf\u5c11CPU\u5bf9\u78c1\u76d8\u7684\u8bfb\u5199\u6b21\u6570\uff1aCPU\u8bfb\u53d6\u78c1\u76d8\u4e2d\u7684\u6570\u636e\u5e76\u4e0d\u662f\u76f4\u63a5\u8bfb\u53d6\u78c1\u76d8\uff0c\u800c\u662f\u5148\u5c06\u78c1\u76d8\u7684\u5185\u5bb9\u8bfb\u5165\u5230\u5185\u5b58\uff0c\u4e5f\u5c31\u662fCache\uff0c\u7136\u540eCPU\u5bf9Cache\u8fdb\u884c\u8bfb\u53d6\uff0c\u8fdb\u800c\u64cd\u4f5c\u6570\u636e\uff1b\u8ba1\u7b97\u673a\u5bf9Cache\u7684\u64cd\u4f5c\u65f6\u95f4\u8fdc\u8fdc\u5c0f\u4e8e\u5bf9\u78c1\u76d8\u7684\u64cd\u4f5c\u65f6\u95f4\uff0c\u5927\u5927\u7684\u52a0\u5feb\u4e86\u8fd0\u884c\u901f\u5ea6\uff0c\u63d0\u9ad8CPU\u7684\u4f7f\u7528\u6548\u7387\u3002
\u5728C\u8bed\u8a00\u8f93\u5165\u4e2d\uff0c\u628a\u82e5\u5e72\u5b57\u7b26\u4f5c\u4e3a\u4e00\u4e2a\u5757\u8fdb\u884c\u4f20\u8f93\u6bd4\u9010\u4e2a\u53d1\u9001\u8fd9\u4e9b\u5b57\u7b26\u8282\u7701\u65f6\u95f4\uff0c\u6253\u9519\u5b57\u7b26\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u952e\u76d8\u4fee\u6b63\u9519\u8bef\u3002
\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\u4e48C \u6807\u51c6\u8981\u89c4\u5b9a\u8f93\u5165\u662f\u7f13\u51b2\u7684\u5417\uff1f
\u4e3a\u4ec0\u4e48C\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
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
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\u4e2dI/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\u5728C\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_lecture/lecture3/lecture3/#_3","title":"\u6807\u51c6\u6d41","text":"\u5728\u6807\u51c6\u5934\u6587\u4ef6<stidio.h>
\u4e2d\uff0c\u5b9a\u4e49\u4e86\u4e09\u4e2a\u6587\u672c\u6d41.
#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
\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_lecture/lecture3/lecture3/#_4","title":"\u5b57\u7b26\u8f93\u5165\u8f93\u51fa","text":""},{"location":"programming_lecture/lecture3/lecture3/#_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\u5728UNIX\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
\u5728\u5b57\u7b26I/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
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
\u4ee5\u4e0a\u51fd\u6570\u90fd\u5c06\u5b57\u7b26\u4ece\u7f13\u51b2\u533a\u4e2d\u7684 unsigned char
\u7c7b\u578b\u8f6c\u6362\u4e3a int
\u7c7b\u578b\u3002
getchar()
\u5b83\u7684\u8fd4\u56de\u503c\u662f int
\u7c7b\u578b\u800c\u975e char
\u7c7b\u578b\uff0c\u503c\u5f97\u6ce8\u610f\u3002\u6240\u4ee5\u4e3a\u4ec0\u4e48\u53ef\u4ee5\u4f7f\u7528char c = getchar()
?
#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
wchar_t
\u4e3a16\u4f4d\uff0c\u5373unsigned short
\u7c7b\u578b\u3002wchar_t
\u4e3a32\u4f4d\uff0c\u5373unsigned int
\u7c7b\u578b\u3002\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
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_lecture/lecture3/lecture3/#_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
\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
*
\u3002\u82e5\u6709\u8981\u6c42\uff0c\u5219\u7ed3\u679c\u4f1a\u4ee5\u7a7a\u683c\u5b57\u7b26\uff08\u9ed8\u8ba4\u60c5\u51b5\uff09\u586b\u5145\uff0c\u5728\u53f3\u6821\u6b63\u65f6\u4e8e\u5de6\uff0c\u5de6\u6821\u6b63\u65f6\u4e8e\u53f3\u3002\u4f7f\u7528 *
\u7684\u60c5\u51b5\u4e0b\uff0c\u4ee5\u4e00\u4e2a\u989d\u5916\u7684int
\u7c7b\u578b\u53c2\u6570\u6307\u5b9a\u5bbd\u5ea6\u3002\u82e5\u53c2\u6570\u503c\u4e3a\u8d1f\u6570\uff0c\u5219\u5b83\u5bfc\u81f4\u6307\u5b9a - \u6807\u7b7e\u548c\u6b63\u57df\u5bbd\u3002\uff08\u6ce8\u610f\uff1a\u8fd9\u662f\u6700\u5c0f\u5bbd\u5ea6\uff1a\u51b3\u4e0d\u88ab\u622a\u65ad\u503c\uff09\u3002*
\u6216\u4e24\u8005\u7686\u65e0\u7684 .
\u6307\u793a\u8f6c\u6362\u7684\u7cbe\u5ea6\u3002\u5728\u4f7f\u7528 *
\u7684\u60c5\u51b5\u4e0b\uff0c\u7cbe\u5ea6\u7531\u989d\u5916\u7684 int \u7c7b\u578b\u53c2\u6570\u6307\u5b9a\u3002\u82e5\u6b64\u53c2\u6570\u7684\u503c\u4e3a\u8d1f\u6570\uff0c\u5219\u5b83\u88ab\u5ffd\u7565\u3002\u82e5\u65e2\u4e0d\u4f7f\u7528\u6570\u5b57\u4ea6\u4e0d\u4f7f\u7528 *
\uff0c\u5219\u7cbe\u5ea6\u91c7\u7528\u96f6\u3002\u7cbe\u5ea6\u7684\u51c6\u786e\u6548\u679c\u89c1\u4e0b\u8868\u3002printf()
\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
\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\u51falong\u7c7b\u578b\u7684\u503c\u65f6\uff0c\u4e5f\u4f1a\u51fa\u73b0\u9519\u8bef\u5417\uff1f 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
\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
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
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
#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
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
scanf()
\u4e2d\u7684\u8f93\u5165\u8fc7\u7a0b
\u5047\u8bbescanf()
\u6839\u636e%d
\u8f6c\u6362\u8bfb\u53d6\u4e00\u4e2a\u6574\u6570,scanf()
\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\u7b2c1\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
\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
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\u56de0\u3002\u5f53scanf()
\u8bfb\u53d6\u5230\u6587\u4ef6\u672b\u5c3e\u5219\u8fd4\u56deEOF
\u3002
\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
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_lecture/lecture3/lecture3/#_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
\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\n$ file c_file.o\n$ file c_file\n$ objdump -h -s -d c_file.o\n$ objdump -h -s c_file\n
\u5bf9\u4e8eC\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\u4e0eUNIX\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_lecture/lecture3/lecture3/#_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\u4ee5UTF-16(Windows API\u5927\u91cf\u504f\u597dUTF-16 LE\u7f16\u7801\u7684\u5b57\u7b26\u4e32\u4f5c\u4e3a\u53c2\u6570)\u6765\u50a8\u5b58\uff0c\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\u66ff\u6362\u4e3aUTF-8\u7b49\u683c\u5f0f\uff0c\u53ef\u4ee5\u538b\u7f29\u7a7a\u95f4\u3002
"},{"location":"programming_lecture/lecture3/lecture3/#_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\u5982ASCII\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\u6210C\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
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_lecture/lecture3/lecture3/#_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
\u5728 <stdio.h>
\u4e2d\u6709\u5982\u4e0b\u4e0e\u6587\u4ef6\u76f8\u5173\u7684\u7c7b\u578b\u548c\u5b8f\uff1a
FILE
\u5bf9\u8c61\u7c7b\u578b\uff0c\u8bb0\u5f55\u63a7\u5236\u6d41\u6240\u9700\u8981\u7684\u6240\u6709\u4fe1\u606f\uff0c\u5305\u62ec\uff1a\u6587\u4ef6\u5b9a\u4f4d\u7b26\u3001\u6307\u5411\u76f8\u5173\u7f13\u51b2\u7684\u6307\u9488\u3001\u9519\u8bef\u6307\u793a\u7b26\u548c\u6587\u4ef6\u7ed3\u675f\u7b26\u3002FILE *
\u6570\u636e\u5bf9\u8c61\u7684\u5185\u90e8\uff0c\u5373\u4f7f\u5b9e\u73b0\u7ed9\u51fa\u4e86\u67d0\u4e9b\u53ef\u89c1\u57df\u3002\u4e0d\u8981\u4fee\u6539\u5bf9\u8c61\u3001\u4e0d\u8981\u62f7\u8d1d\u5bf9\u8c61\u5e76\u4ee3\u66ff\u4f7f\u7528\uff0c\u56e0\u4e3a\u5b9e\u73b0\u5047\u5b9a\u77e5\u9053\u6d41\u6570\u636e\u5bf9\u8c61\u7684\u6240\u6709\u5730\u5740\u3002fpos_t
\u5bf9\u8c61\u7c7b\u578b\uff0c\u542b\u6709\u552f\u4e00\u6307\u5b9a\u6587\u4ef6\u4e2d\u6bcf\u4e2a\u4f4d\u7f6e\u6240\u9700\u7684\u6240\u6709\u4fe1\u606f\u3002stderr
, stdin
, stdout
\u90fd\u662f FILE*
\u7c7b\u578b\u7684\u8868\u8fbe\u5f0f\u3002EOF
\u5c55\u5f00\u4e3a\u4e00\u4e2a\u8d1f\u7684\u6574\u503c\u5e38\u91cf\u3002NULL
SEEK_CUR
\u6587\u4ef6\u5f53\u524d\u4f4d\u7f6eSEEK_END
\u6587\u4ef6\u7ed3\u675f\u4f4d\u7f6eSEEK_SET
\u6587\u4ef6\u5f00\u59cb\u4f4d\u7f6eint remove (const char *filename)
int rename (const char *old, const char *new)
FILE *tmpfile(void)
char * tmpnam(char *s)
int fclose(FILE *stream)
int fflush(FILE *stream)
FILE *fopen(const char *filename, const char *mode)
FILE *freopen(const char *filename, const char *mode, FILE *stream)
void setbuf(FILE *stream, char *buf)
int setvbuf(FILE *stream, char *buf, int mode, size_t size)
\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
fprintf
,fscanf
,vfprintf
,vprintf
,vsprintf
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
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
int fseek(FILE *stream, long int offset, int whence)
whence
\u53ef\u4ee5\u662f SEEK_SET
\u3001SEEK_CUR
\u3001SEEK_END
long int ftell(FILE *stream)
void rewind(FILE *stream)
\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
int fgetpos(FILE *stream, fpos_t *pos)
int fsetpos(FILE *stream, const fpos_t *pos)
\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
\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\n$ echo_eof < echo_eof.c > echo_eof.txt\n$ echo_eof < echo_eof.c | cat\n
\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,\u5de6\u8fb9\u8865\u7a7a\u683c\n printf(\"%-5d\\n\", 1000); // \u5de6\u5bf9\u9f50,\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\u51fa0x\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\u76840\n printf(\"%05d\\n\", 1000); // \u524d\u9762\u88650\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\u5bfc0\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\u7f6e0\n printf(\"%.8g\\n\", 1000.123456); // \u6700\u5927\u6709\u6548\u6570\u5b57\u4e3a8\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\u53f7char\n printf(\"%hhu\\n\", 'A' + 128); // \u8f93\u51fa\u65e0\u7b26\u53f7char\n printf(\"%hd\\n\", 32767); // \u8f93\u51fa\u6709\u7b26\u53f7\u77ed\u6574\u578bshort int\n printf(\"%hu\\n\", 65535); // \u8f93\u51fa\u65e0\u7b26\u53f7\u77ed\u6574\u578bunsigned short int\n printf(\"%ld\\n\", 0x7fffffffffffffff); // \u8f93\u51fa\u6709\u7b26\u53f7\u957f\u6574\u578blong int\n printf(\"%lu\\n\", 0xffffffffffffffff); // \u8f93\u51fa\u6709\u7b26\u53f7\u957f\u6574\u578bunsigned long int\n}\n
\u5173\u4e8eprintf()
#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
\u5173\u4e8escanf()
#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
\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\n$ file c_file.o\n$ file c_file\n$ objdump -h -s -d c_file.o\n$ objdump -h -s c_file\n
\u65bd\u5de5\u4e2d
\u672c\u9875\u9762\u6b63\u5728\u7f16\u8f91\u4e2d\u3002
"},{"location":"programming_lecture/lecture4/after_class/#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
<ctype.h> <stdio.h> <stdlib.h> <string.h>\n
<assert.h> <limits.h> <stddef.h> <time.h>\n
<float.h> <math.h> <error.h> <locale.h> <setjmp.h> <signal.h> <stdarg.h>\n
\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_lecture/lecture4/after_class/#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
#undef
\u9884\u5904\u7406\u6307\u4ee4\u7684\u4f7f\u7528\u4e5f\u53ef\u4ee5\u4fdd\u8bc1\u5b9e\u9645\u51fd\u6570\u7684\u5f15\u7528\u3002atoi()
\u7684\u4f7f\u7528\u65b9\u5f0f
#include <stdlib.h>\nconst char *str;\ni = atoi(str);\n
#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
<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\u548cioctl
\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.
\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_lecture/lecture4/lecture4/","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
ctype.h
stdio.h
string.h
stdlib.h
math.h
\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_lecture/lecture4/lecture4/#_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
NULL
\u3001EOF
printf
\u3001scanf
FILE
\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_lecture/lecture4/lecture4/#_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
int main(void);\n
\u6307\u9488 \u7684\u6982\u5ff5
\u6307\u9488\u5177\u6709\u7c7b\u578b\u4fe1\u606f\uff0c\u51b3\u5b9a\u4e86\u6307\u9488\u7684\u8fd0\u7b97\u65b9\u5f0f
\u4f8b\u5b50
int p[10];\nchar q[10];\nint *p1 = p, *p2 = &p[1];\nchar *q1 = q, *q2 = &q[1];\n
\u8bf7\u95ee\uff0cp1 + 1
\u3001p2 - p1
\u3001q1 + 1
\u3001q2 - q1
\u7684\u503c\u662f\u591a\u5c11\uff1f\u7c7b\u578b\u662f\u4ec0\u4e48\uff1f
\u5982\u679c\u76f4\u63a5\u5bf9\u4ed6\u4eec\u7684\u503c\u8fdb\u884c\u52a0\u51cf\uff0c\u7ed3\u679c\u5e94\u5f53\u662f\u591a\u5c11\uff1f
\u6570\u7ec4\u4e0e\u6307\u9488
\u4f8b\u5b50
int a[10];\nint *p;\n
\u8bf7\u95ee\uff1aa
\u3001a[0]
\u3001&a[0]
\u3001&a
\u3001*a
\u3001p
\u3001*p
\u3001&p
\u7684\u7c7b\u578b\u662f\u4ec0\u4e48\uff1f
\u8bf7\u95ee\uff0c\u6267\u884c p = &a
\u62a5\u544a
warning: initialization of `int *` from incompatible pointer type `int (*)[10]`\n
\u662f\u4ec0\u4e48\u539f\u56e0\uff1f
\u591a\u7ef4\u6570\u7ec4\u6bd4\u8f83\u590d\u6742\uff0c\u7b49\u6b63\u6587\u8bb2\u5b8c\u8fd8\u6709\u65f6\u95f4\u518d\u56de\u6765\u8bb2
<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
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
0x20
~ 0x7E
0x00
~ 0x1F
\u548c 0x7F
\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
\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
int isalnum(int c);\nint isalpha(int c);\n// int iscntrl(int c);\nint isdigit(int c);\n// int isgraph(int c);\nint islower(int c);\n// int isprint(int c);\n// int ispunct(int c);\nint isspace(int c);\nint isupper(int c);\n// int isxdigit(int c);\n
int tolower(int c);\nint toupper(int c);\n
<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
isblank
\u4ec5\u5224\u65ad\u7a7a\u683c
\u548c\u6c34\u5e73\u5236\u8868\u7b26 \\t
\u3002isspace
\u5224\u65ad\u7a7a\u683c
\u3001\u6c34\u5e73\u5236\u8868\u7b26 \\t
\u3001\u6362\u884c\u7b26 \\n
\u3001\u56de\u8f66\u7b26 \\r
\u3001\u6362\u9875\u7b26 \\f
\u3001\u5782\u76f4\u5236\u8868\u7b26 \\v
\u3002<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
\u5b8f\u7684\u53c2\u6570\u53ef\u80fd\u4f1a\u88ab\u6c42\u503c\u591a\u6b21\uff0c\u5177\u6709\u526f\u4f5c\u7528\u7684\u5b8f\u53c2\u6570\u4f1a\u5bfc\u81f4\u610f\u5916\u3002
\u4e3e\u4e2a\u4f8b\u5b50
#define SQUARE(X) ((X) * (X))\nSQUARE(x++); // x++ * x++\n
\u4f7f\u7528\u8005\u4ee5\u4e3a\u5b83\u53ea\u4f1a\u8ba9 x
\u81ea\u589e\u4e00\u6b21\uff0c\u4f46\u662f\u5b9e\u9645\u4e0a\u5b83\u4f1a\u8ba9 x
\u81ea\u589e\u4e24\u6b21\u3002
\u4f1a\u4ea7\u751f\u4e0d\u5b89\u5168\u884c\u4e3a\u7684\u5b8f
\u6807\u51c6\u5e93\u4e2d\uff0c\u53ea\u6709 getc
\u548c putc
\u53ef\u80fd\u4f1a\u4ea7\u751f\u8fd9\u79cd\u4e0d\u5b89\u5168\u884c\u4e3a\u3002
<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
#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
<math.h>
","text":""},{"location":"programming_lecture/lecture4/lecture4/#_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
asin
\u8f93\u5165\u4e86\u4e0d\u5728 \\([-1, 1]\\) \u7684\u503c\uff09\uff0c\u4f1a\u53d1\u751f\u5b9a\u4e49\u57df\u9519\u8bef\u3002double
\u503c\uff0c\u53d1\u751f\u503c\u57df\u9519\u8bef\u3002\u4e0a\u6ea2\u8fd4\u56de HUGE_VAL
\uff0c\u4e0b\u6ea2\u8fd4\u56de 0
\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
\u5b8f
HUGE_VAL\n
GCC \u5b9a\u4e49\u7684\u5b8f
INFINITY\nNAN\n
\u4e0a\u9762\u8fd9\u4e24\u4e2a\u5b8f\u8d77\u521d\u4e0d\u5728\u6807\u51c6\u5e93\u4e2d\uff0c\u7531 GCC \u5b9a\u4e49\u3002
\u636e\u8bf4\u5728 C99 \u4ee5\u540e\uff0cINFINITY
\u88ab\u6807\u51c6\u5e93\u7eb3\u5165\uff0c\u6211\u6ca1\u6709\u67e5\u8bc1\u3002
\u51fd\u6570\uff08\u4ec5\u4e3e\u4e00\u4e9b\u5e38\u7528\u7684
double acos(double x);\ndouble asin(double x);\ndouble atan(double x);\ndouble cos(double x);\ndouble sin(double x);\ndouble tan(double x);\ndouble exp(double x);\ndouble log(double x);\ndouble log10(double x);\ndouble pow(double x, double y);\ndouble sqrt(double x);\ndouble ceil(double x);\ndouble fabs(double x);\ndouble floor(double x);\n
double
\u7c7b\u578b\uff08\u6ce8\u610f\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u5e26\u6765\u7684\u5f71\u54cd\uff09\u3002PI
\u8fd9\u4e2a\u5b8f\u3002atan(1)*4
\u4ee3\u66ff\u3002M_
\u5f00\u5934\uff0c\u6bd4\u5982 M_PI
\u3002\u5b83\u4eec\u9ed8\u8ba4\u4e3a double
\u7c7b\u578b\u3002\u5982\u679c\u4f60\u9700\u8981\u5176\u4ed6\u7cbe\u5ea6\uff0c\u53ef\u4ee5\u6dfb\u52a0 l
\u540e\u7f00\uff0c\u6bd4\u5982 M_PIl
\u3002<string.h>
","text":""},{"location":"programming_lecture/lecture4/lecture4/#_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
scanf
\u4f7f\u7528 %s
\u8bfb\u53d6\u7684\u5b57\u7b26\u5e8f\u5217\u662f\u5b57\u7b26\u4e32\u3002scanf
\u4f1a\u81ea\u52a8\u6dfb\u52a0\u7a7a\u5b57\u7b26\u3002size_t\n
NULL\n
void *memcpy(void *dest, const void *src, size_t n);\nvoid *memmove(void *dest, const void *src, size_t n);\nchar *strcpy(char *dest, const char *src);\nchar *strncpy(char *dest, const char *src, size_t n);\n
char *strcat(char *dest, const char *src);\nchar *strncat(char *dest, const char *src, size_t n);\n
int memcmp(const void *s1, const void *s2, size_t n);\nint strcmp(const char *s1, const char *s2);\nint strncmp(const char *s1, const char *s2, size_t n);\n
void *memchr(const void *s, int c, size_t n);\nchar *strchr(const char *s, int c);\n// size_t strcspn(const char *s1, const char *s2);\n// char *strpbrk(const char *s1, const char *s2);\n// char *strrchr(const char *s, int c);\n// size_t strspn(const char *s1, const char *s2);\nchar *strstr(const char *s1, const char *s2);\n// char *strtok(char *s1, const char *s2);\n
void *memset(void *s, int c, size_t n);\n// char *strerror(int errnum);\nsize_t strlen(const char *s);\n
\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
<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
\u8bf7\u770b\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_lecture/lecture4/lecture4/#_13","title":"\u5185\u5bb9","text":"RAND_MAX\nEXIT_FAILURE\nEXIT_SUCCESS\n
\u51fd\u6570
int rand(void);\nvoid srand(unsigned int seed);\n
int abs(int n);\ndiv_t div(int numer, int denom);\nlong labs(long n);\nldiv_t ldiv(long numer, long denom);\n
void *bsearch(const void *key, const void *base, size_t n, size_t size, int (*compar)(const void *, const void *));\nvoid qsort(void *base, size_t n, size_t size, int (*compar)(const void *, const void *));\n
double atof(const char *str);\nint atoi(const char *str);\nlong atol(const char *str);\ndouble strtod(const char *str, char **endptr);\nlong strtol(const char *str, char **endptr, int base);\nunsigned long strtoul(const char *str, char **endptr, int base);\n
// void abort(void);\n// int atexit(void (*func)(void));\n// void exit(int status);\n// char *getenv(const char *name);\n// int system(const char *string);\n
\u5185\u5b58\u7ba1\u7406\uff08\u91cd\u96be\u70b9\uff09
void *calloc(size_t nobj, size_t size);\nvoid free(void *ptr);\nvoid *malloc(size_t size);\nvoid *realloc(void *ptr, size_t size);\n
\u6ce8\u610f\uff0c\u5185\u5b58\u62f7\u8d1d\u51fd\u6570\u5374\u5728 <string.h>
\u4e2d\u3002
\u7c7b\u578b
div_t // int quot, rem;\nldiv_t // long quot, rem;\n
rand
\u548c srand
\u7528\u4e8e\u4ea7\u751f\u4f2a\u968f\u673a\u6570\u3002srand
\u7528\u4e8e\u8bbe\u7f6e\u968f\u673a\u6570\u79cd\u5b50\uff0crand
\u7528\u4e8e\u4ea7\u751f\u968f\u673a\u6570\u3002rand
\u4ea7\u751f\u7684\u968f\u673a\u6570\u8303\u56f4\u662f \\([0, RAND\\_MAX]\\)\u3002abs
\u548c labs
\u7528\u4e8e\u6c42\u7edd\u5bf9\u503c\u3002div
\u548c ldiv
\u7528\u4e8e\u6c42\u5546\u548c\u4f59\u6570\u3002qsort
\u7684\u7528\u4f8b\uff1a int cmpfunc (const void * a, const void * b) {\n return ( *(int*)a - *(int*)b );\n}\nqsort(values, 5, sizeof(int), cmpfunc);\n
atoi
\u51fd\u6570\u7684\u5177\u4f53\u5b9e\u73b0\u8981\u6bd4\u8fd9\u590d\u6742\u5f97\u591a\uff09\uff1a int atoi(char *str) {\n int res = 0;\n for (int i = 0; str[i] != '\\0'; ++i)\n res = res * 10 + str[i] - '0';\n return res;\n}\n
malloc
\u8bb0\u5f97\u53c2\u6570\u662f\u5b57\u8282\u6570\uff0c\u5343\u4e07\u8bb0\u5f97\u4e58\u4e0a sizeof
\u3002\u4e3a\u4e86\u9632\u6b62\u81ea\u5df1\u5fd8\u8bb0\uff0c\u4e5f\u53ef\u4ee5\u575a\u6301\u4f7f\u7528 calloc
\u3002\u4e14\u5b83\u4f1a\u81ea\u52a8\u521d\u59cb\u5316\u5185\u5b58\u4e3a 0\u3002realloc
\u76f8\u5f53\u4e8e\u7ed3\u5408\u4e86 malloc
\u3001memcpy
\u548c free
\u7684\u529f\u80fd\u3002<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_lecture/lecture4/lecture4/#_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
\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_lecture/lecture4/lecture4/#_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 ^D
Ctrl+D ^Z
Ctrl+Z ^D
Ctrl+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
C \u8bed\u8a00\u63d0\u4f9b\u4e24\u79cd\u6d41\uff1a\u6587\u672c\u6d41\u548c\u4e8c\u8fdb\u5236\u6d41\u3002
\\n
\u548c EOF
\u3002char
\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_lecture/lecture4/lecture4/#_19","title":"\u5185\u5bb9","text":"size_t\nFILE\nfpos_t\n
stderr\nstdin\nstdout\nNULL\nEOF\nSEEK_CUR\nSEEK_END\nSEEK_SET\n// BUFSIZ\n// FOPEN_MAX\n// FILENAME_MAX\n
// int remove(const char *filename);\n// int rename(const char *old, const char *new);\n// FILE *tmpfile(void);\n
int fclose(FILE *stream);\n// int fflush(FILE *stream);\nFILE *fopen(const char *filename, const char *mode);\nFILE *freopen(const char *filename, const char *mode, FILE *stream);\n// void setbuf(FILE *stream, char *buf);\n// int setvbuf(FILE *stream, char *buf, int mode, size_t size);\n
int fprintf(FILE *stream, const char *format, ...);\nint fscanf(FILE *stream, const char *format, ...);\nint printf(const char *format, ...);\nint scanf(const char *format, ...);\nint sprintf(char *str, const char *format, ...);\nint sscanf(const char *str, const char *format, ...);\n// int vfprintf(FILE *stream, const char *format, va_list arg);\n
// int fgetc(FILE *stream);\n// char *fgets(char *str, int n, FILE *stream);\n// int fputc(int c, FILE *stream);\nint fputs(const char *str, FILE *stream);\n// int getc(FILE *stream);\nint getchar(void);\n// char *gets(char *str);\n// int putc(int c, FILE *stream);\nint putchar(int c);\nint puts(const char *str);\n// int ungetc(int c, FILE *stream);\n
size_t fread(void *ptr, size_t size, size_t nobj, FILE *stream);\nsize_t fwrite(const void *ptr, size_t size, size_t nobj, FILE *stream);\n
//int fgetpos(FILE *stream, fpos_t *pos);\nint fseek(FILE *stream, long offset, int origin);\n//int fsetpos(FILE *stream, const fpos_t *pos);\nlong ftell(FILE *stream);\nvoid rewind(FILE *stream);\n
// void clearerr(FILE *stream);\n// int feof(FILE *stream);\n// int ferror(FILE *stream);\n// void perror(const char *str);\n
\u4ee5\u4e0b\u662f\u8bfe\u5185\u5185\u5bb9\uff0c\u4ec5\u5217\u51fa\uff0c\u4e0d\u505a\u8be6\u7ec6\u4ecb\u7ecd\uff1a
printf
/scanf
\u8fd9\u51e0\u4e2a\u683c\u5f0f\u5316\u8f93\u5165/\u8f93\u51fa\u51fd\u6570\u7684\u4f7f\u7528\u3002%d
\u3001%p
\u7b49\u8f6c\u6362\u8bf4\u660e\u7684\u4f7f\u7528\u3002\\n
\u3001\\r
\u7b49\u5e38\u89c1\u8f6c\u4e49\u5e8f\u5217\u7684\u4f7f\u7528\u3002fopen
\u3001fclose
\u7684\u4f7f\u7528\u3002r
\u3001w
\u3001a
\u3001b
\u7b49\u6a21\u5f0f\u7684\u4f7f\u7528\u3002FILE
\u4e2d\u7528 fscanf
\u3001fprintf
\u8bfb\u5199\u6570\u636e\u3002fread
\u548c fwrite
\u8bfe\u4e0a\u5e94\u8be5\u4f1a\u8bb2\uff0c\u4f46\u662f\u7f16\u7a0b\u4e5f\u4e0d\u4f1a\u8981\u6c42\u7684\u3002\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
scanf
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
\u96f6\u6216\u66f4\u591a\u4e2a\u6807\u5fd7\uff0c\u8bf4\u660e\u8f6c\u6362\u4e2d\u7684\u53d8\u5316\u3002
char meaning-
\u5de6\u5bf9\u9f50\uff08\u53f3\u4fa7\u586b\u5145\u7a7a\u767d\uff09 +
\u603b\u662f\u6253\u5370\u7b26\u53f7\uff08\u5305\u62ec\u6b63\u53f7\uff09
\u5982\u679c\u65e0\u7b26\u53f7\uff0c\u6253\u5370\u7a7a\u683c 0
\u7528 0 \u586b\u5145 \u4e00\u4e2a\u53ef\u9009\u7684\u6700\u5c0f\u5b57\u6bb5\u5bbd\u5ea6\uff1a\u4e00\u4e2a\u661f\u53f7\u6216\u8005\u4e00\u4e2a\u5341\u8fdb\u5236\u6574\u6570\u3002
\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
scanf
%s
\u53ea\u8bfb\u53d6\u975e\u7a7a\u767d\u5b57\u7b26\uff0c\u9047\u5230\u7a7a\u767d\u5b57\u7b26\u5c31\u7ed3\u675f\u3002%c
\u53ea\u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26\uff0c\u9047\u5230\u7a7a\u767d\u5b57\u7b26\u4e5f\u4f1a\u8bfb\u53d6\u3002\u8fd8\u8bb0\u5f97\u4e0a\u9762 <ctype.h>
\u521a\u521a\u8bb2\u7684\u7a7a\u767d\u5b57\u7b26\u5417\uff1f
&
\uff1f\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
printf
\u3001fprintf
\u3001sprintf
\u3001snprintf
scanf
\u3001fscanf
\u3001sscanf
EOF
ungetc
\u5c06\u5b57\u7b26\u9000\u56de\u6d41\u4e2d\uff08\u4e0d\u8981\u5728 PTA \u7b49 OJ \u7cfb\u7edf\u4e0a\u4f7f\u7528\uff01\u4e0d\u8981\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u4f7f\u7528\uff01\uff09\u3002\u603b\u4e4b\uff0c\u5c31\u662f\u4e0d\u5efa\u8bae\u78b0\u8fd9\u4e2a\u4e1c\u897f\u3002fseek
\u3001ftell
\u3001rewind
\uff1a\u8f83\u8001\u7684\u4f20\u7edf\u7684\u6587\u4ef6\u5b9a\u4f4d\u51fd\u6570fgetpos
\u3001fsetpos
\u3001rewind
\uff1a\u4efb\u610f\u5927\u5c0f\u3001\u7ed3\u6784\u7684\u6587\u4ef6\uff0c\u4f7f\u7528 fpos_t
\u7c7b\u578b\uff0c\u5b83\u4e0d\u80fd\u8fdb\u884c\u4efb\u4f55\u8ba1\u7b97\u3002\u65bd\u5de5\u4e2d
\u672c\u9875\u9762\u6b63\u5728\u7f16\u8f91\u4e2d\u3002
"}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u8ba1\u5212\u7f51\u7ad9","text":"\ud83d\ude09 \u4f60\u597d~
\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\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\u666e\u901a\u8f85\u5b66\u7248\u5757\u4f7f\u7528 \ud83d\udcda \u6807\u6ce8\uff0c\u7cbe\u54c1\u8bfe\u7a0b\u7248\u5757\u4f7f\u7528 \ud83c\udfeb \u6807\u6ce8\u3002
\u5fae\u79ef\u5206 I/II\uff08H\uff09
23-24\u8f85\u5b66\u7fa4\uff1a204755170
\u6570\u5b66\u5206\u6790 I/II\uff08H\uff09
23-24\u8f85\u5b66\u7fa4\uff1a618962803
\u7ebf\u6027\u4ee3\u6570 I/II\uff08H\uff09
23-24\u8f85\u5b66\u7fa4\uff1a913067714 \ud83c\udfeb\u7ebf\u6027\u4ee3\u6570\uff1a\u672a\u7adf\u4e4b\u7f8e
\u7a0b\u5e8f\u8bbe\u8ba1\uff08H\uff09
23-24\u8f85\u5b66\u7fa4\uff1a728919863 \u6bcf\u65e5\u4e00\u9898 \ud83c\udfeb\u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057 \ud83c\udfeb\u5b9e\u7528\u6280\u80fd\u62fe\u9057
\u666e\u901a\u5316\u5b66\uff08H\uff09
23-24\u8f85\u5b66\u7fa4\uff1a635023447
\u666e\u901a\u7269\u7406\u5b66 I\uff08H\uff09
22-23\u8f85\u5b66\u7fa4\uff1a727382522
\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":"\u8f85\u5b66\u7b80\u4ecb","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":"\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
\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
\u6bcf\u4e2a\u8f85\u5b66\u79d1\u76ee\u7684\u6587\u4ef6\u5939\u7ec4\u7ec7\u5982\u4e0b\uff1a
subject\n\u251c\u2500\u2500 year\n\u2502 \u251c\u2500\u2500 some_file.md\n\u2502 \u2514\u2500\u2500 some_file.pdf\n\u251c\u2500\u2500 exam\n\u2502 \u251c\u2500\u2500 some_paper.pdf\n\u2502 \u2514\u2500\u2500 some_paper_answer.pdf\n\u2514\u2500\u2500 index.md\n
index.md
\uff0c\u5305\u542b\u4e86\u8be5\u79d1\u76ee\u6587\u4ef6\u5939\u5185\u5404\u4e2a\u8d44\u6599\u7684\u94fe\u63a5\u3002\u9875\u9762\u4fa7\u8fb9\u680f\u4e0d\u9700\u8981\u6709\u4e1c\u897f\uff0c\u4e0d\u9700\u8981\u5728 mkdocs.yml
\u4e2d\u518d\u4e3a\u8fd9\u4e9b\u6587\u4ef6\u6dfb\u52a0\u7d22\u5f15\u3002lecture1_contents.pdf
\u7b49\u3002exam
\u6587\u4ef6\u5939\u4e2d\uff0c\u6587\u4ef6\u547d\u540d\u4e3a subject_year_exam.pdf
\u7b49\uff0c\u7b54\u6848\u6dfb\u52a0\u540e\u7f00 _answer
\u3002\u7cbe\u54c1\u8bfe\u7a0b\u7684\u6587\u4ef6\u5939\u7531\u8be5\u8bfe\u7a0b\u7ec4\u81ea\u884c\u7ec4\u7ec7\u548c\u7ef4\u62a4\u3002
"},{"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\u542funicode\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\u542fmhchem\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"},{"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":"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/#2023-2024","title":"2023-2024 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":""},{"location":"analysis/#_2","title":"\u6388\u8bfe","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/#_3","title":"\u5386\u5e74\u5377","text":""},{"location":"analysis/#ih","title":"\u6570\u5b66\u5206\u6790 I\uff08H\uff09","text":"\u5e74\u4efd \u8bd5\u5377 2023-2024 \u5c0f\u6d4b1 2022-2023 \u5c0f\u6d4b1/\u7b54\u6848\u5c0f\u6d4b2/\u7b54\u6848\u671f\u672b\u8bd5\u5377/\u7b54\u6848 2021-2022 \u5c0f\u6d4b/\u7b54\u6848\u671f\u672b\u8bd5\u5377/\u7b54\u6848 2020-2021 \u671f\u672b\u8bd5\u5377\uff08\u90e8\u5206\uff09"},{"location":"analysis/#iih","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/#_4","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/2024/analysis_lecture1_sequence_limits/","title":"\u7b2c\u4e00\u8bb2 \u6570\u5217\u6781\u9650","text":"\u7ed9\u51fa\u6982\u5ff5\u3001\u5b9a\u7406\u7684\u540d\u5b57\u53ef\u4ee5\u4f7f\u7528\u6570\u5b66\u8bed\u8a00\u51c6\u786e\u53d9\u8ff0\u3002
\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
\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
\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
\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} \\]\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} \\]\u786e\u754c\u539f\u7406
\u975e\u7a7a\u6709\u754c\u96c6\u5fc5\u6709\u4e0a\u4e0b\u786e\u754c
\u5355\u8c03\u6709\u754c\u5b9a\u7406
\u5355\u8c03\u6709\u754c\u6570\u5217\u5fc5\u6536\u655b
\u81f4\u5bc6\u6027\u5b9a\u7406
\u4efb\u4f55\u6709\u754c\u6570\u5217\u5fc5\u6709\u6536\u655b\u5b50\u5217
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 \\]\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} \\]\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} \\]\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\\}\\)
\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
\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) \\]\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} \\]Stolz\u5b9a\u7406
\u5e38\u7528\u4e8e\u8ba1\u7b97\u5f62\u5f0f\u9700\u8981\u6d1b\u5fc5\u8fbe\u7684\u6781\u9650
Cauchy\u6536\u655b\u51c6\u5219\u3001\u7b49\u4ef7\u5f62\u5f0f\u53ca\u5426\u5b9a
\u4e00\u4e9b\u5173\u7cfb\u94fe\uff1a
\u8bc1\u660e\u6570\u5217\u6781\u9650\u5b58\u5728\uff1a
\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)
Cauchy\u51c6\u5219\uff1a\u4e0d\u9700\u8981\u77e5\u9053\u6781\u9650\u503c
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)\\))
\u5355\u8c03\u6709\u754c\u539f\u7406\uff1a\u4e0d\u52a8\u70b9\uff0c\u9012\u63a8\u5f0f\u8003\u8651
\u6781\u9650\u7684\u8fd0\u7b97\u6027\u8d28\uff1a\u672c\u8eab\u5b58\u5728\u6781\u9650 \u6709\u9650\u9879\u8fd0\u7b97
\u8bc1\u660e\u6570\u5217\u6781\u9650\u4e0d\u5b58\u5728\uff1a
\u6c42\u6570\u5217(\u51fd\u6570)\u6781\u9650\uff1a
\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\\)
Stolz\u5b9a\u7406
\u5939\u903c\u5b9a\u7406
\u7b49\u4ef7\u4ee3\u6362\u4e0e\u521d\u7b49\u53d8\u5f62
\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
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
\u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u5b50\u5217\u7684\u547d\u9898
\u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u65e0\u7a77\u5c0f\u91cf\u7684\u547d\u9898
\u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u6570\u5217\u6781\u9650\u7684\u547d\u9898
\u91cd\u8981\u7684\u4e8c\u7ea7\u7ed3\u8bba\uff1a
\\(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)
\u6c42\u6781\u9650\\(\\lim\\limits_{n\\rightarrow\\infty}x_n\\)\uff1a
(2019(?)\u5e74\u6570\u52061\u671f\u672b)
\u9898\u76ee\u3001\u9009\u9879\u987a\u5e8f\u53c2\u8003\u5c0f\u6d4b1
\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\u5730\u5740 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 \u5f3a\u533b 2101 \u5362\u601d\u7426"},{"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":"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":"lalu/#_2","title":"\u8bfe\u7a0b\u7b80\u4ecb","text":"\u7ebf\u6027\u4ee3\u6570\u4f5c\u4e3a\u5927\u5b66\u6570\u5b66\u7684\u57fa\u7840\u8bfe\uff0c\u4e0e\u6570\u5b66\u5206\u6790\u4e0d\u540c\uff0c\u8fd9\u95e8\u8bfe\u7684\u4e00\u5f00\u59cb\u5c31\u4e0e\u4e2d\u5b66\u6570\u5b66\u7684\u98ce\u683c\u6709\u7740\u5f88\u5927\u7684\u5dee\u8ddd\uff0c\u8bb8\u591a\u540c\u5b66\u5728\u6b64\u95e8\u8bfe\u7684\u5165\u95e8\u4e0e\u8fdb\u9636\u65b9\u9762\u90fd\u9047\u89c1\u4e86\u5f88\u5927\u7684\u56f0\u96be\u3002\u4e3a\u89e3\u51b3\u6b64\u56f0\u96be\uff0c\u672c\u8bfe\u7a0b\u5e0c\u671b\u6df1\u5165\u6d45\u51fa\u5730\u5256\u6790\u6982\u5ff5\u4e0e\u5b9a\u7406\uff0c\u5e2e\u52a9\u540c\u5b66\u4eec\u4e86\u89e3\u7ebf\u6027\u4ee3\u6570\u201c\u5e72\u7684\u662f\u4ec0\u4e48\u4e8b\u201d\uff0c\u7406\u89e3\u7ebf\u6027\u4ee3\u6570\u7684\u672c\u8d28\uff0c\u4ee5\u53ca\u66f4\u597d\u638c\u63e1\u540e\u7eed\u7684\u8ba1\u7b97\u6280\u5de7\uff0c\u5b66\u597d\u7ebf\u4ee3\u8fd9\u95e8\u5927\u5b66\u7684\u5165\u95e8\u8bfe\uff01
"},{"location":"lalu/#_3","title":"\u8bfe\u9898\u7ec4\u6210\u5458","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 W1 Oct.29 \u5f15\u5165\uff1a\u7ebf\u6027\u7a7a\u95f4 \u6885\u654f\u70ab Bilibili T1 Oct.29 \u5f15\u5165\uff1a\u7ebf\u6027\u7a7a\u95f4 \u5434\u4e00\u822a Bilibili H2 Nov.18 \u7ebf\u6027\u6620\u5c04\u53ca\u5176\u77e9\u9635\u8868\u793a \u5434\u4e00\u822a Bilibili"},{"location":"lalu/#_5","title":"\u8bfe\u7a0b\u5b89\u6392","text":"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
\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":"programming/","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66","text":"\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u7a0b\u8bbe\u7248\u5757\ud83e\udd17\u3002
"},{"location":"programming/#_2","title":"\u6bcf\u65e5\u4e00\u9898","text":"\u89c1\u6bcf\u65e5\u4e00\u9898\u3002
"},{"location":"programming/#_3","title":"\u4e13\u9898\u7b14\u8bb0","text":"\u6211\u4eec\u4e3a\u7a0b\u5e8f\u8bbe\u8ba1\u4e2d\u7684\u4e00\u4e9b\u91cd\u96be\u70b9\u6574\u7406\u4e86\u4e13\u9898\u7b14\u8bb0\uff0c\u73b0\u6709\u5982\u4e0b\u4e13\u9898\u7b14\u8bb0\uff1a
\u6211\u4eec\u4e3a\u540c\u5b66\u4eec\u7ecf\u5e38\u9047\u5230\u7684\u95ee\u9898\u6574\u7406\u4e86\u4e00\u4e9b FAQ\uff0c\u53c2\u89c1 FAQ\u3002
"},{"location":"programming/#_4","title":"\u5386\u5e74\u5377","text":"\u5386\u5e74\u5377\u5178\u578b\u9898\u76ee\u7b54\u7591\u96c6\u6b63\u5728\u6574\u7406\u4e2d\u3002
"},{"location":"programming/#_5","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u4e0e\u7b97\u6cd5\u57fa\u7840","text":"\u6682\u65e0
"},{"location":"programming/#_6","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u57fa\u7840\u4e0e\u5b9e\u9a8c","text":"\u6682\u65e0
"},{"location":"programming/#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/#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/#_7","title":"\u5176\u4ed6\u8d44\u6e90","text":""},{"location":"programming/#_8","title":"\u5e38\u7528\u7f51\u7ad9","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
\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/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\uff1fAuthor\uff1a\u6731\u5b9d\u6797
\u5e03\u5c14\u7c7b\u578b\u7684\u5386\u53f2\uff1a
_Bool
\u7c7b\u578b\u548c <stdbool.h>
\u5934\u6587\u4ef6\u3002\u8be5\u5934\u6587\u4ef6\u5b9a\u4e49\u4e86 bool
\u3001true
\u548c false
\u4e09\u4e2a\u4fbf\u5229\u5b8f\u3002bool
\u5c55\u5f00\u6210 _Bool
\u3002true
\u548c false
\u5206\u522b\u5c55\u5f00\u6210 int
\u7c7b\u578b\u7684 1
\u548c 0
\u3002bool
\u4ee3\u66ff _Bool
\u4f5c\u4e3a\u7c7b\u578b\u540d\u3002true
\u548c false
\u4e5f\u76f4\u63a5\u5c55\u5f00\u4e3a bool
\u7c7b\u578b\u503c\u3002\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
bool
\u7684\u8f6c\u6362\u4e0e\u5230\u5176\u4ed6\u6574\u6570\u7c7b\u578b\u7684\u8f6c\u6362\u4e0d\u540c\uff1a (bool)0.5
\u6c42\u503c\u4e3a 1
\uff0c\u7136\u800c (int)0.5
\u6c42\u503c\u4e3a \u200b0
\u200b\u3002\u5728\u7ed9 _Bool
\u7c7b\u578b\u8d4b\u503c\u65f6\u9700\u8981\u6ce8\u610f\u8fd9\u4e00\u70b9\u3002Author\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/faq/#_3","title":"\u6570\u7ec4\u3001\u5b57\u7b26\u4e32","text":""},{"location":"programming/faq/#_4","title":"\u5faa\u73af\u3001\u5206\u652f\u548c\u8df3\u8f6c","text":""},{"location":"programming/faq/#_5","title":"\u51fd\u6570\u3001\u6807\u51c6\u5e93\u4e0e\u9884\u5904\u7406\u5668","text":""},{"location":"programming/faq/#io","title":"\u6587\u4ef6 I/O","text":""},{"location":"programming/faq/#_6","title":"\u6307\u9488\u3001\u5b58\u50a8\u7c7b\u522b\u3001\u94fe\u63a5\u548c\u5185\u5b58\u7ba1\u7406","text":""},{"location":"programming/faq/#_7","title":"\u7ed3\u6784\u548c\u5176\u4ed6\u6570\u636e\u5f62\u5f0f","text":""},{"location":"programming/temp/","title":"\u5e38\u89c1\u95ee\u9898","text":"\u65bd\u5de5\u4e2d
"},{"location":"programming/temp/#_2","title":"\u6307\u9488\u3001\u58f0\u660e","text":""},{"location":"programming/temp/#_3","title":"\u600e\u4e48\u8bfb\u58f0\u660e\uff1f","text":"Author\uff1a45gfg9\u3001Anston Sun
\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
\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\u5c31\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\u4e00\u4e2a\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\u3002\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\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\u53d8\u5316\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\u5c31\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/temp/#_5","title":"\u51fd\u6570\u5230\u6307\u9488\u8f6c\u6362","text":"\u4efb\u4f55\u51fd\u6570\u6307\u4ee3\u5668\u8868\u8fbe\u5f0f\uff0c\u5728\u7528\u4e8e\u5f02\u4e8e\u4e0b\u5217\u8bed\u5883\u65f6
sizeof
\u7684\u64cd\u4f5c\u6570\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u8868\u8fbe\u5f0f\u6240\u6307\u4ee3\u51fd\u6570\u7684\u6307\u9488\u7684\u8f6c\u6362\u3002
"},{"location":"programming/temp/#_6","title":"\u56fe\u5f62\u5e93","text":"\u7b80\u8981\u6574\u7406\u4e00\u4e0b libgraphics
\u7528\u6cd5\uff1a
\u56fe\u5f62\u4e0e\u6587\u5b57
\u503c\u5f97\u6ce8\u610f\u7684\u4e00\u70b9\u662f\uff1alibgraphics
\u7684\u5750\u6807\u7cfb\u7edf\u4e0e ACLLib
\u4e0d\u540c\u3002\u524d\u8005\u4ee5\u5de6\u4e0b\u89d2\u4e3a\u539f\u70b9\uff0c\u7b26\u5408\u6211\u4eec\u5e38\u7528\u7684\u6570\u5b66\u8868\u8fbe\uff1b\u540e\u8005\u4ee5\u5de6\u4e0a\u89d2\u4e3a\u9876\u70b9\uff0c\u4f7f\u7528\u7a97\u53e3\u5750\u6807\u7cfb\u7edf\u3002
void InitGraphics(void)
\uff1a\u4f7f\u7528\u56fe\u5f62\u5e93\u4e2d\u7684\u51fd\u6570\u524d\u8c03\u7528void MovePen(double x, double y)
\uff1a\u5c06\u7b14\u79fb\u52a8\u5230\u67d0\u70b9\uff08\u6ce8\u610f\u4e0d\u662f\u76f8\u5bf9\u79fb\u52a8\uff09void DrawLine(double dx, double dy)
\uff1a\u4ece\u5f53\u524d\u70b9 \\((x,y)\\) \u753b\u5230 \\((x+dx, y+dy)\\) \u7684\u7ebf\uff0c\u753b\u7b14\u968f\u4e4b\u79fb\u52a8void DrawArc(double r, double start, double sweep)
\uff1a\u4ee5\u5f53\u524d\u70b9\u4e3a\u5706\u5fc3\uff0c\u4ece \\(\\phi=start\\) \u89d2\u5f00\u59cb\uff0c\u753b\u534a\u5f84\u4e3a \\(r\\)\uff0c\u5706\u5fc3\u89d2\u4e3a \\(\\Delta\\phi=sweep\\) \u7684\u5706\u5f27\u3002double GetWindowWidth(void)
\uff1a\u83b7\u53d6\u7a97\u53e3\u5bbd\u5ea6double GetWindowHeight(void)
double GetCurrentX(void)
\uff1a\u83b7\u53d6\u5f53\u524d\u753b\u7b14\u7684\u4f4d\u7f6edouble GetCurrentY(void)
void DrawTextString(string text)
\uff1a\u5728\u5f53\u524d\u4f4d\u7f6e\u6253\u5370\u5b57\u7b26\u4e32double TextStringWidth(string text)
\uff1a\u83b7\u53d6\u8be5\u5b57\u7b26\u4e32\u6253\u5370\u65f6\u7684\u5bbd\u5ea6\u5173\u4e8e SetEraseMode()
\u548c GetEraseMode()
\u6211\u76f4\u63a5\u628a\u6ce8\u91ca\u8d34\u5728\u8fd9\u4e86\uff0c\u76f4\u63a5\u8bfb\u5427\uff1a
/*\n * Function: SetEraseMode\n * Usage: SetEraseMode(TRUE);\n * SetEraseMode(FALSE);\n * ---------------------------\n * The SetEraseMode function sets the value of the internal\n * erasing flag. Setting this flag is similar to setting the\n * color to \"White\" in its effect but does not affect the\n * current color setting. When erase mode is set to FALSE,\n * normal drawing is restored, using the current color.\n */\n\nvoid SetEraseMode(bool mode);\n\n/*\n * Function: GetEraseMode\n * Usage: mode = GetEraseMode();\n * -----------------------------\n * This function returns the current state of the erase mode flag.\n */\n\nbool GetEraseMode(void);\n
\u8fd8\u662f\u9644\u4e2a\u7ffb\u8bd1\u5427\uff1aSetEraseMode \u51fd\u6570\u8bbe\u7f6e\u5185\u90e8\u64e6\u9664\u6807\u5fd7\u7684\u503c\u3002\u8bbe\u7f6e\u8fd9\u4e2a\u503c\u7684\u6548\u679c\u5c31\u50cf\u628a\u989c\u8272\u8bbe\u7f6e\u4e3a\u201c\u767d\u8272\u201d\uff0c\u4f46\u4e0d\u4f1a\u5f71\u54cd\u5f53\u524d\u7684\u989c\u8272\u8bbe\u7f6e\u3002\u5f53\u64e6\u9664\u6a21\u5f0f\u8bbe\u7f6e\u4e3a FALSE \u65f6\uff0c\u6062\u590d\u5230\u6b63\u5e38\u7684\u7ed8\u753b\u72b6\u6001\uff0c\u4f7f\u7528\u5f53\u524d\u7684\u989c\u8272\u3002
\u63a7\u5236\u53f0\u4ea4\u4e92\uff1a\u8fd9\u4e9b\u6e90\u4ee3\u7801\u5728 simpio.h
\u4e2d
void InitConsole(void)
\uff1a\u6253\u5f00\u4e00\u4e2a\u65b0\u7684\u63a7\u5236\u53f0\uff0c\u8981\u4f7f\u7528 stdio.h
\u4e2d\u7684\u6807\u51c6\u8f93\u5165\u8f93\u51fa\u51fd\u6570\u524d\u8bb0\u5f97\u5199\u4e0a\u8fd9\u4e2a\u3002
int GetInteger(void)
\uff1a\u4ece\u6807\u51c6\u8f93\u5165\u4e2d\u8bfb\u5165\u4e00\u884c\uff0c\u5e76\u5c1d\u8bd5\u8bfb\u53d6\u4e00\u4e2a\u6574\u6570\u3002\u5982\u679c\u9047\u5230\u610f\u5916\u60c5\u51b5\uff0c\u4f1a\u8981\u6c42\u7528\u6237\u91cd\u65b0\u8f93\u5165\u3002\u6e90\u7801\u5982\u4e0b\uff1a
int GetInteger(void)\n{\n string line;\n int value;\n char termch;\n\n while (TRUE) {\n line = GetLine();\n if (line == NULL) Error(\"GetInteger: unexpected end of file\");\n switch (sscanf(line, \" %d %c\", &value, &termch)) {\n case 1:\n FreeBlock(line);\n return (value);\n case 2:\n printf(\"Unexpected character: '%c'\\n\", termch);\n break;\n default:\n printf(\"Please enter an integer\\n\");\n break;\n }\n FreeBlock(line);\n printf(\"Retry: \");\n }\n}\n
double GetReal(void)
\uff1a\u8bfb\u53d6\u4e00\u4e2a\u5b9e\u6570\uff0c\u5177\u4f53\u540c\u4e0a\u3002
string GetLine(void)
string ReadLine(FILE *infile)
\uff1a\u4ece\u6307\u5b9a\u7684\u6587\u4ef6\u4e2d\u8bfb\u5165\u4e00\u884c\u3002
\u8ba1\u65f6\u5668\u7528\u4e8e\u5ef6\u65f6\u6216\u91cd\u590d\u6267\u884c\u540c\u7c7b\u4efb\u52a1\u3002\u76f8\u6bd4\u949f\u8868\u7b49\u7eaf\u7cb9\u7684\u8ba1\u65f6\u5de5\u5177\uff0c\u8ba1\u65f6\u5668\u66f4\u63a5\u8fd1\u4e8e\u65e5\u7a0b\u5b89\u6392\u3002\u8ba1\u65f6\u5668\u7684\u6838\u5fc3\u529f\u80fd\u5982\u4e0b\uff1a\u6bcf\u7ecf\u8fc7\u9884\u5148\u8bbe\u5b9a\u7684\u65f6\u957f\uff0c\u8ba1\u65f6\u5668\u4fbf\u4f1a\u901a\u8fc7\u67d0\u79cd\u673a\u5236\uff0c\u6267\u884c\u7279\u5b9a\u7684\u6307\u4ee4\u3002
libgraphics
\u5e93\u901a\u8fc7\u4e8b\u4ef6\u56de\u8c03\u673a\u5236\u5b9e\u73b0\u5b9a\u65f6\u89e6\u53d1\u7684\u529f\u80fd\u3002\u56de\u8c03\u673a\u5236\u6b64\u5904\u4e0d\u518d\u8d58\u8ff0\u3002
\u4e0e\u8ba1\u65f6\u5668\u76f8\u5173\u7684\u51fd\u6570\u5982\u4e0b\uff1a
void startTimer(int timerID, int interval)
void cancelTimer(int timerID)
\u987e\u540d\u601d\u4e49\uff0c\u4e24\u4e2a\u51fd\u6570\u5206\u522b\u7528\u4e8e\u542f\u52a8\u4e0e\u7ec8\u6b62\u5b9a\u65f6\u5668\u3002interval
\u662f\u9884\u5148\u8bbe\u5b9a\u7684\u65f6\u957f\uff0c\u5373\u6bcf\u4e24\u6b21\u89e6\u53d1\u7684\u65f6\u95f4\u95f4\u9694\u3002timerID
\u4e3a\u8ba1\u65f6\u5668\u7684\u6807\u8bc6\u7b26\uff0c\u53ef\u7406\u89e3\u4e3a\u8ba1\u65f6\u5668\u7684\u4e13\u7528\u540d\u79f0\u3002
\u4e3a\u4e86\u5b8c\u6210\u591a\u9879\u5b9a\u65f6\u4efb\u52a1\uff0c\u5f80\u5f80\u9700\u8981\u5206\u522b\u542f\u52a8\u591a\u4e2a\u95f4\u9694\u4e0d\u540c\u7684\u5b9a\u65f6\u5668\u3002\u7531\u4e8e\u6240\u6709\u8ba1\u65f6\u5668\u5747\u4f1a\u89e6\u53d1 TimerEvent
\uff0c\u5728\u56de\u8c03\u51fd\u6570\u5185\u9700\u8981\u4f7f\u7528 timerID
\u533a\u5206\u4e0d\u540c\u7684\u5b9a\u65f6\u5668\u3002
void registerTimerEvent(TimerEventCallback)
\uff1a\u6ce8\u518c\u8ba1\u65f6\u5668\u4e8b\u4ef6\u3002 TimerEventCallback
\u7c7b\u578b\u89c1\u4e0b\u3002typedef void (*TimerEventCallback)(int timerID)
TimerEventCallback
\u662f\u4e00\u4e2a\u51fd\u6570\u6307\u9488\u7c7b\u578b\uff0c\u8be5\u7c7b\u578b\u53d8\u91cf\u6307\u5411\u51fd\u6570\uff08\u5047\u8bbe\u540d\u79f0\u4e3a func
\uff09\u7684\u7c7b\u578b\u4e3a void func(int timerID)
\u3002\u901a\u8fc7\u56de\u8c03\u673a\u5236\uff0c\u6bcf\u5f53\u4efb\u4e00\u8ba1\u65f6\u5668\u5230\u8fbe\u8bbe\u5b9a\u65f6\u95f4\u65f6\uff0c\u5747\u4f1a\u901a\u8fc7\u8be5\u7c7b\u578b\u51fd\u6570\u6307\u9488\u8c03\u7528 func
\u51fd\u6570\u3002\u901a\u8fc7\u4f20\u5165\u7684 timerID
\uff0c\u56de\u8c03\u51fd\u6570\u5185\u53ef\u4ee5\u533a\u5206\u4e0d\u540c\u8ba1\u65f6\u5668\u7684\u89e6\u53d1\u4e8b\u4ef6\uff0c\u5e76\u6267\u884c\u7279\u5b9a\u64cd\u4f5c\u3002
\u4ee5\u4e0a\u4ecb\u7ecd\u5747\u96c6\u4e2d\u4e8e\u91cd\u590d\u6267\u884c\uff0c\u4f46\u662f\u524d\u9762\u63d0\u5230\u8ba1\u65f6\u5668\u4e5f\u53ef\u7528\u4e8e\u5ef6\u65f6\u6267\u884c\uff0c\u5373\u5728\u9884\u5148\u8bbe\u5b9a\u7684\u65f6\u957f\u540e\u6267\u884c\u7279\u5b9a\u6b21\u6570\u7684\u7279\u5b9a\u64cd\u4f5c\u3002\u7ed3\u5408 cancelTimer
\u51fd\u6570\uff0c\u60f3\u60f3\u600e\u6837\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002
typedef void (*KeyboardEventCallback) (int key,int event);\ntypedef void (*CharEventCallback) (char c);\ntypedef void (*MouseEventCallback) (int x, int y, int button, int event);\ntypedef void (*TimerEventCallback) (int timerID);\n\nvoid registerKeyboardEvent(KeyboardEventCallback callback);\nvoid registerCharEvent(CharEventCallback callback);\nvoid registerMouseEvent(MouseEventCallback callback);\nvoid registerTimerEvent(TimerEventCallback callback);\nvoid startTimer(int id,int timeinterval);\n
\u56e0\u4e3a\u8fd9\u4e9b\u56de\u8c03\u51fd\u6570\u5728 graphics
\u5e93\u4e2d\u90fd\u6ca1\u6709\u6ce8\u91ca\uff0c\u6211\u5c31\u4e0d\u4f5c\u89e3\u91ca\u4e86\uff0c\u8bfe\u4e0a\u90fd\u8bb2\u8fc7\u56de\u8c03\u51fd\u6570\u600e\u4e48\u7528\u3002
\u8ba1\u65f6\u5668\uff1a\u4ee5 20 \u5e74\u7a0b\u5e8f\u586b\u7a7a\u7b2c 3 \u9898\u4e3a\u4f8b\uff1a
void Main()\n{\n InitGraphics();\n registerTimerEvent(TimerEventProcess);\n //...\n startTimer(TIMER_CURSOR, 500);/*start 500ms cursor blinking timer*/\n}\nvoid TimerEventProcess(int timerID)\n{\n bool erasemode;\n if(TIMER_CURSOR == timerID)\n {\n //...\n }\n}\n
\u4ece\u8fd9\u6bb5\u4f8b\u7a0b\u4e2d\u53ef\u4ee5\u4e86\u89e3\u5230\u51e0\u4e2a\u91cd\u8981\u7684\u70b9\uff1a
void registerTimerEvent(TimerEventCallback callback)
\u6ce8\u518c\u56de\u8c03\u51fd\u6570 callback
\u540e\uff0c\u8fd8\u9700\u8981\u7528 void startTimer(int id,int timeinterval)
\u8bbe\u5b9a\u5e76\u542f\u52a8\u4e00\u4e2a\u8ba1\u65f6\u5668\uff0c\u8bbe\u5b9a\u8fd9\u4e2a\u8ba1\u65f6\u5668\u7684 id
\u548c timeinterval
\u3002id
\u5e76\u68c0\u67e5\u662f\u4e0d\u662f\u81ea\u5df1\u9700\u8981\u8fdb\u884c\u52a8\u4f5c\u7684\u90a3\u4e2a\u8ba1\u65f6\u5668\u3002\u8fd9\u5c31\u662f TimerEventProcess
\u51fd\u6570\u4e2d if
\u8bed\u53e5\u7684\u4f5c\u7528\u3002void Main()
\u522b\u5199\u9519\u4e86#include <stdio.h>\n#include \"graphics.h\"\n\nvoid Main(void)\n{\n InitGraphics();\n MovePen(1.5, 1.0);\n DrawArc(0.5, 0, 360);\n}\n
"},{"location":"programming/temp/#new","title":"New()
\u51fd\u6570","text":"\u5411\u4e0b\u7ffb\uff0c\u627e\u5230 2019 \u5e74\u7a0b\u5e8f\u586b\u7a7a\u7b2c 3 \u9898\uff0c\u4f7f\u7528\u65b9\u6cd5\u5728\u90a3\u91cc\u3002
"},{"location":"programming/temp/#_15","title":"\u7b97\u6cd5\u590d\u6742\u5ea6\u5206\u6790","text":"\u8bb0\u4f4f\uff1a\u6392\u5e8f\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e0e\u4e24\u9879\u64cd\u4f5c\u7684\u6b21\u6570\u6709\u5173\uff1a\u6bd4\u8f83\u548c\u4ea4\u6362\u3002
\u4f60\u53ef\u4ee5\u8fd9\u6837\u60f3\uff1a\u521b\u5efa\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\u4f5c\u4e3a\u8ba1\u6570\u5668\uff0c\u5728\u6240\u6709\u6d89\u53ca\u6bd4\u8f83\u548c\u4ea4\u6362\u7684\u5730\u65b9\u8ba9\u5b83 ++
\uff0c\u8fd0\u884c\u5b8c\u7684\u7ed3\u679c\u5c31\u662f\u5176\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u6bd4\u5982\uff1a
int count = 0;\nfor (int i = 0; i < n; ++i) {\n for (int j = 0; j < n; ++j) {\n for (int k = 0; k < m; ++k) {\n count++;\n }\n }\n}\n
\u8fd0\u884c\u5b8c\u8fd9\u6bb5\u4ee3\u7801\uff0ccount = n*n*m
\uff0c\u5219\u5176\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2m)\\)\u3002
\u8bb0\u4f4f\u5e76\u7406\u89e3\u4e00\u4e9b\u5e38\u89c1\u7684\u7b97\u6cd5\u7684\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u3001\u6700\u4f18\u3001\u6700\u5dee\u60c5\u51b5\u590d\u6742\u5ea6\uff1a
\u6765\u6e90\uff1a\u5e38\u7528\u6392\u5e8f\u7b97\u6cd5\u603b\u7ed3\u5bf9\u6bd4 | \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5 \u7cfb\u5217\u6559\u7a0b\uff08\u7b14\u8bb0\uff09 (zq99299.github.io)
\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
\u9875\u9762\u6b63\u5728\u65bd\u5de5\u4e2d
"},{"location":"programming/temp2/#2020-2021","title":"2020-2021 \u5e74\u5377","text":"typedef
\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
char *
&(t->name[0])
\uff0c\u5373 char *
\u7c7b\u578b\u3002char *
*(t.name)
\u662f\u4e00\u4e2a\u9519\u8bef\u7684\u7528\u6cd5\uff0c\u4e0d\u80fd\u76f4\u63a5\u5bf9\u7ed3\u6784\u7684\u6307\u9488\u4f7f\u7528 .
\u8fd0\u7b97\u7b26\u8bbf\u95ee\u5176\u6210\u5458\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
p
\u662f\u51fd\u6570\u540dp
\u662f\u51fd\u6570\u540dp
\u662f\u6307\u5411 int[5]
\u7684\u6307\u9488p
\u662f\u4e00\u4e2a\u6570\u7ec4C \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
auto
\uff1a\u9ed8\u8ba4\u7684\u5b58\u50a8\u7c7b\u522b\u9650\u5b9a\u7b26\uff0c\u7528\u4e8e\u5c40\u90e8\u53d8\u91cf\uff0c\u8868\u793a\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u4e0e\u51fd\u6570\u8c03\u7528\u76f8\u540c\u3002register
\uff1a\u7528\u4e8e\u5c40\u90e8\u53d8\u91cf\uff0c\u8868\u793a\u53d8\u91cf\u53ef\u80fd\u5b58\u50a8\u5728 CPU \u5bc4\u5b58\u5668\u4e2d\uff0c\u4ee5\u52a0\u5feb\u8bbf\u95ee\u901f\u5ea6\u3002extern
\uff1a\u7528\u4e8e\u5168\u5c40\u53d8\u91cf\uff0c\u8868\u793a\u53d8\u91cf\u5728\u5176\u4ed6\u6587\u4ef6\u4e2d\u5b9a\u4e49\u3002static
\uff1a
_Thread_local
\uff1a\u4e0d\u4f5c\u8981\u6c42\u3002
\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
InitGraphics()
\u4e00\u5b9a\u8981\u8bb0\u5f97void registerTimerEvent(TimerEventCallback callback)
\u4e0e void startTimer(int id,int timeinterval)
\u914d\u5bf9\u4f7f\u7528\uff0c\u5b83\u4eec\u5404\u81ea\u7684\u53c2\u6570\u610f\u4e49\u3002timerID
\u662f\u7528\u6765\u505a\u4ec0\u4e48\u7684\uff1f\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
\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. [...]
(*pf)
\u7684\u5f62\u5f0f\u662f\u6700\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u5982 void ToUpper(char *)
\u6539\u4e3a\u51fd\u6570\u6307\u9488 void (*pf)(char *)
\u3002\u58f0\u660e\u51fd\u6570\u6307\u9488\u540e\uff0c\u53ef\u4ee5\u5c06\u51fd\u6570\u7684\u5730\u5740\u8d4b\u7ed9\u5b83\uff0c\u8fd9\u79cd\u8bed\u5883\u4e0b\u51fd\u6570\u540d\u53ef\u4ee5\u8868\u793a\u51fd\u6570\u7684\u5730\u5740\u3002\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u5199\uff1apf = ToUpper
\uff0c\u6ce8\u610f\u4e0d\u662f pf = ToUpper()
\u3002
\u4f7f\u7528\u51fd\u6570\u6307\u9488\u8c03\u7528\u51fd\u6570\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a(*pf)(mis)
\u548c pf(mis)
\uff0c\u5b83\u4eec\u770b\u8d77\u6765\u77db\u76fe\u3002\u4e8b\u5b9e\u4e0a\uff0cK&R C \u4e0d\u5141\u8bb8\u7b2c\u4e8c\u79cd\u5f62\u5f0f\uff0c\u6211\u4e5f\u63a8\u8350\u5927\u5bb6\u59cb\u7ec8\u5c06\u51fd\u6570\u8c03\u7528\u7406\u89e3\u4e3a\u7b2c\u4e00\u79cd\u5f62\u5f0f\u3002
\u53d6\u51fd\u6570\u7684\u5730\u5740\u4e5f\u6709\u4e24\u79cd\u65b9\u6cd5\uff1af
\u548c &f
\u3002
C \u9879 \u6216\u8bb8\u901a\u8fc7\u4e0a\u9762\u7684\u8bb2\u89e3\uff0c\u4f60\u80fd\u7406\u89e3 (*cmd)
\u4e0e cmd
\u7684\u7b49\u4ef7\u4e4b\u5904\u3002\u4e0b\u9762\u662f StackOverflow \u4e2d\u7684\u8ba8\u8bba\uff1ac++ - What does void f(void())
mean? - Stack Overflow\u3002
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
F
\u5b9a\u4e49\u4e3a int (int)
\u7c7b\u578b\u7684\u51fd\u6570\u3002F
\u7684\u51fd\u6570 g
\u548c h
\u3002\u5176\u5b9e\u5c31\u662f int g(int a)
\u548c int h(int a)
\u3002p
\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f int (*)(int)
\u7c7b\u578b\uff08\u4e0e F
\u7b49\u4ef7\uff09\u3002\u5e76\u7528 g
\u548c h
\u6765\u521d\u59cb\u5316\u8fd9\u4e2a\u6570\u7ec4\u3002p
\u662f\u6807\u8bc6\u7b26\u7684\u540d\u79f0\uff0c\u5411\u53f3 []
\u8868\u660e\u8fd9\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u5411\u5de6 *
\u8868\u793a\u5176\u5143\u7d20\u662f\u6307\u9488\uff0c\u518d\u5411\u53f3 (int)
\u8868\u793a\u5176\u6240\u6307\u7c7b\u578b\u662f\u51fd\u6570\uff0c\u8fd9\u79cd\u51fd\u6570\u63a5\u53d7 int
\u7c7b\u578b\u53c2\u6570\uff0c\u518d\u5411\u5de6 int
\u8bf4\u660e\u8fd9\u79cd\u51fd\u6570\u8fd4\u56de int
\u7c7b\u578b\u3002g
\u548c h
\u521d\u59cb\u5316\u8fd9\u4e2a\u6570\u7ec4\u65f6\uff0cg
\u548c h
\u88ab\u8f6c\u6362\u4e3a\u51fd\u6570\u6307\u9488\uff08\u56de\u987e\u4e0a\u9762\u7684\u8ba8\u8bba\uff09\u3002\u7b2c\u56db\u884c\uff1a\u58f0\u660e\u4e00\u4e2a\u51fd\u6570 q
\u8fd9\u4e2a\u51fd\u6570\u8fd4\u56de int
\uff0c\u63a5\u53d7\u4e00\u79cd\u6570\u7ec4\uff0c\u8fd9\u79cd\u6570\u7ec4\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f F*
\u7c7b\u578b\uff0c\u5373 int (*)(int)
\u3002\u6545\u51fd\u6570 q
\u7684\u53c2\u6570\u7c7b\u578b\u4e3a int (**)(int)
\u3002
A \u9879\uff1a\u6570\u7ec4\u540d\u5c31\u662f\u9996\u5143\u7d20\u6307\u9488\uff0c\u4e3a int (**)(int)
\uff0c\u5339\u914d\u3002
int (*)(int)
\uff0c\u4e0e int (**)(int)
\u7c7b\u578b\u4e0d\u5339\u914d\u3002\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
((H)\u5185\u5c42\u8868\u8fbe\u5f0f )(100);
\uff0c\u5b83\u4f1a\u5c06\u5185\u5c42\u8868\u8fbe\u5f0f\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u4e3a H
\u7c7b\u578b\u7684\u51fd\u6570\uff0c\u7136\u540e\u5bf9\u8be5\u51fd\u6570\u6267\u884c\u51fd\u6570\u8c03\u7528\u3002h(0)
\u3002\u8c03\u7528\u540e\u8fd4\u56de\u4e86 h
\uff0c\u5373\u51fd\u6570\u81ea\u5df1\uff0c\u4e5f\u5c31\u662f\u51fd\u6570\u81ea\u5df1\u7684\u6307\u9488\u3002\u4f5c\u4e3a void *
\u7c7b\u578b\u8fd4\u56de\uff0c\u8868\u660e\u5b83\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u4f46\u4e0d\u77e5\u9053\u6240\u6307\u5411\u7684\u7c7b\u578b\u3002h(100)
\u4e86\uff0c\u56e0\u4e3a h
\u672c\u6765\u5c31\u662f H
\u7c7b\u578b\u7684\u51fd\u6570\u3002geblib.h
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
New()
\u5b8f\u51fd\u6570\uff1a
Usage: p = New(pointer-type);
The New pseudofunction allocates enough space to hold an object of the type to which pointer-type points and returns a pointer to the newly allocated pointer. Note that \"New\" is different from the \"new\" operator used in C++; the former takes a pointer type and the latter takes the target type.
\u6e90\u7801\uff1a
void *GetBlock(size_t nbytes);\n#define New(type) ((type) GetBlock(sizeof *((type) NULL)))\n
\u4e3e\u4e2a\u4f8b\u5b50\uff1a\u8c03\u7528 New(char*)
((char*) GetBlock(sizeof *((char*) NULL)))
GetBlock()
\u51fd\u6570\u63a5\u6536\u9700\u8981\u5206\u914d\u7684\u5b57\u8282\u6570\uff0c\u8fd4\u56de\u5206\u914d\u6210\u529f\u7684\u6307\u9488\u3002\u5bf9\u4e8e\u4e0a\u9762\u7684\u5b8f\u5c55\u5f00\u540e\u7684\u8c03\u7528\u53c2\u6570\uff0cNULL
\u88ab\u8f6c\u6362\u4e3a char*
\u968f\u540e\u89e3\u5f15\u7528\u4ecd\u4e3a char
\u7c7b\u578b\u7684\u5927\u5c0f\u3002char*
\u7684\u6307\u9488\u3002FreeBlock()
\u51fd\u6570\uff1a
void FreeBlock(void *ptr)
free()
\u529f\u80fd\u7c7b\u4f3c\uff0c\u4e0d\u52a0\u89e3\u91ca\u3002\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
\u9012\u5f52\u60c5\u5f62\uff1a\u753b\u4e00\u6839\uff0c\u968f\u540e\u4e24\u6b21\u9012\u5f52\u8c03\u7528\uff0c\u7ed8\u5236\u4e0b\u4e00\u652f\u7684 length
\u548c order
\u3002\u6bcf\u6b21\u9012\u5f52\u8c03\u7528\u540e\uff0c\u90fd\u5e94\u5f53\u8fd4\u56de\u539f\u4f4d\u3002
#include <stdio.h>\n#include <math.h>\n#include <stdlib.h>\n#include \"graphics.h\"\n#define MIN_LEN .1\n\ndouble toRadius(double deg)\n{\n return deg * 3.1415926 / 180;\n}\n\nvoid DrawBranch(double len, double deg)\n{\n DrawLine(len * cos(toRadius(deg)), len * sin(toRadius(deg)));\n if (len * 0.75 < MIN_LEN)\n return;\n DrawBranch(len * 0.75, deg - 15);\n MovePen(GetCurrentX() - len * 0.75 * cos(toRadius(deg - 15)),\n GetCurrentY() - len * 0.75 * sin(toRadius(deg - 15)));\n //\u4e5f\u53ef\u4ee5\u7528 DrawLine \u5b9e\u73b0\n DrawBranch(len * 0.75, deg + 15);\n MovePen(GetCurrentX() - len * 0.75 * cos(toRadius(deg + 15)),\n GetCurrentY() - len * 0.75 * sin(toRadius(deg + 15)));\n}\n\nint main(void)\n{\n double length;\n char order;\n printf(\"Please enter initial length: \");\n scanf(\"%lf\", &length);\n getchar();\n printf(\"Please enter order (u)pper, (d)own, (r)ight, (l)eft: \");\n scanf(\"%c\", &order);\n double deg;\n switch(order)\n {\n case 'u': deg = 90; break;\n case 'd': deg = -90; break;\n case 'r': deg = 0; break;\n case 'l': deg = 180; break;\n default: printf(\"error.\\n\"); return 1;\n }\n InitGraphics();\n MovePen(GetWindowWidth()/2, GetWindowHeight()/2);\n DrawBranch(length, deg);\n return 0;\n}\n
\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/temp2/#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
StudentInfo
\uff1a\u4e24\u4e2a char
\u6570\u7ec4 + \u4e00\u4e2a\u6307\u9488 = \\(12 + 20 + 4 = 36\\)PtrStudentInfo
\uff1a\\(4\\)pStudent->name
\uff1a\u4e00\u4e2a char
\u6570\u7ec4 \\(=20\\)pStudent->photo
\uff1a\u4e00\u4e2a void*
\u6307\u9488 \\(=4\\)\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
main()
\u4e2d\u7684 Push()
\uff0c\u8fd9\u600e\u4e48\u6bd4\u5e73\u5e38\u7684 Push()
\u591a\u4e00\u4e2a\u53c2\u6570\u5462\uff1fTop
\uff1f\u56de\u60f3 main()
\u4e2d\u4e00\u4e2a\u4ee4\u4e3a -1
\u4e00\u4e2a\u4ee4\u4e3a MaxSize
\u4fbf\u77e5\u9053\u8fd9\u662f\u4e00\u4e2a\u53cc\u5411\u6808\u4e86\u3002Push()
\u548c Pop()
\u7684\u4ee3\u7801\u5c31\u4e0d\u7528\u770b\u4e86\uff0c\u60f3\u8c61\u5f97\u5230\u662f\u600e\u4e48\u64cd\u4f5c\u7684\u3002\u6700\u591a\u518d\u591a\u770b\u4e00\u773c if(Tag == 1)
\u77e5\u9053\u54ea\u4e2a\u503c\u5bf9\u5e94\u54ea\u4e00\u5934\uff0c\u5c31\u53ef\u4ee5\u5b8c\u6210\u8fd9\u9053\u9898\u4e86\u3002\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
\u753b\u4e2a\u5750\u6807\u8f74\uff0c\u4e00\u5207\u90fd\u6e05\u6670\u8d77\u6765\u4e86\u3002\u7136\u540e Main()
\u91cc\u6700\u5f00\u59cb\u5bf9\u5927\u4e09\u89d2\u5f62\u4e09\u4e2a\u9876\u70b9\u7684\u6c42\u503c\u53ef\u80fd\u4f1a\u5f15\u8d77\u56f0\u60d1\uff0c\u5176\u5b9e\u53ef\u4ee5\u4e0d\u7528\u7ba1\u5b83\uff0c\u5b83\u4e0d\u5f71\u54cd\u4f60\u5206\u6790\u9012\u5f52\u8c03\u7528\u8fc7\u7a0b\u3002\u5b83\u53ea\u662f\u5728\u7528\u4e09\u89d2\u51fd\u6570\u8ba1\u7b97\u4f4d\u7f6e\u4f7f\u8fd9\u4e2a\u5927\u4e09\u89d2\u5f62\u7684\u4e2d\u5fc3\u5728\u5c4f\u5e55\u4e2d\u592e\u7f62\u4e86\u3002\u7ed9\u4e2a\u5f88\u8349\u7684\u8349\u7a3f\u793a\u610f\u56fe\uff1a
\u753b\u8fd9\u4e2a\u5206\u5f62\u7684\u6b65\u9aa4\u5c31\u662f\uff1a\u5148\u753b\u5927\u4e09\u89d2\uff0c\u7136\u540e\u5404\u8fb9\u53d6\u4e2d\u70b9\u3002\u5927\u4e09\u89d2\u7684\u6bcf\u4e2a\u9876\u70b9\u548c\u76f8\u90bb\u4e24\u8fb9\u4e2d\u70b9\u6784\u6210\u4e24\u4e2a\u5c0f\u4e09\u89d2\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
strcpy()
\u53ea\u80fd\u7528\u4e8e\u5b57\u7b26\u4e32\u3002\u8fdb\u4e00\u6b65\u8bf4\uff0c\u5b83\u4f9d\u636e\u5b57\u7b26\u4e32\u672b\u5c3e\u7684 \\0
\u6765\u51b3\u5b9a\u662f\u5426\u505c\u6b62\u590d\u5236\uff0c\u56e0\u6b64\u4e0d\u5b9c\u7528\u4e8e\u6b64\u60c5\u5883\u3002*pc2++ = *pc1++
\uff0c\u90fd\u4f1a\u5c06 pc1
\u7684\u4e00\u4e2a\u5b57\u8282\u62f7\u8d1d\u5230 pc2
\u6307\u5411\u7684\u4f4d\u7f6e\uff0c\u5e76\u8ba9\u8fd9\u4e24\u4e2a\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4e2a char
\u7684\u4f4d\u7f6e\u3002\u7531\u4e8e p1
\u548c p2
\u4e24\u4e2a\u7ed3\u6784\u53d8\u91cf\u5927\u5c0f\u90fd\u662f \\(8+8=16\\) \u5b57\u8282\uff0c\u56e0\u6b64\u8be5\u9009\u9879\u6b63\u786e\u5730\u6267\u884c\u4e86\u62f7\u8d1d\u3002\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
static
\u6b64\u5904\u4fee\u9970\u7684\u662f\u6307\u9488 p
\u3002\u4e8b\u5b9e\u4e0a\uff0c\u4e5f\u4e0d\u5b58\u5728\u6307\u9488\u6307\u5411 static int
\u8fd9\u79cd\u8bf4\u6cd5\u3002static
\u4f5c\u4e3a\u5b58\u50a8\u7c7b\u522b\u9650\u5b9a\u7b26\uff0c\u5728\u53d8\u91cf\u7684\u58f0\u660e\u4e2d\u8868\u793a\u8be5\u53d8\u91cf\u5177\u6709\u9759\u6001\u5b58\u50a8\u671f\u3002\u4e00\u4e2a\u6307\u9488\uff0c\u53ea\u9700\u8981\u7ba1\u5b83\u6307\u5411\u7684\u662f\u4ec0\u4e48\u7c7b\u578b\uff0c\u4e0d\u9700\u8981\u77e5\u9053\u8fd9\u4e2a\u5bf9\u8c61\u7684\u5b58\u50a8\u671f\u3002\u5148\u60f3\u60f3\u81ea\u5df1\u4f1a\u600e\u4e48\u8c03\u7528\u8fd9\u4e2a fun
\u51fd\u6570\u624d\u80fd\u5f97\u5230 void
\u7c7b\u578b\uff1a
fun(int)
\u3002(*fun(int))(int)
\u3002\u6ce8\u610f\uff0c\u51fd\u6570\u6307\u9488\u5e94\u5f53\u4f7f\u7528 (*fp)()
\u5f62\u5f0f\u8c03\u7528\u3002\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
\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
count
\u6570\u7ec4\uff1a\u5148\u7528\u4e8e\u7edf\u8ba1\u51fa\u73b0\u6b21\u6570\uff0c\u540e\u7528\u6765\u6807\u8bb0\u5f00\u59cb\u4f4d\u7f6e\u3002output_array[count[input_array[i]]] = input_array[i]
\u6211\u4eec\u6765\u62c6\u89e3\u4e00\u4e0b\uff1aintput_array[i]
\u5c31\u662f\u7b2c i
\u4e2a\u5143\u7d20count[]
\u5c31\u80fd\u67e5\u5230\u8fd9\u4e2a\u6570\u5e94\u8be5\u653e\u7f6e\u7684\u8d77\u59cb\u4f4d\u7f6e\u3002\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/temp2/#2015-2016","title":"2015-2016 \u5e74\u5377","text":"\u5b8f\u5c55\u5f00\u53ea\u662f\u7b80\u5355\u7684\u6587\u672c\u66ff\u6362\u3002
DD
\u5f97\u5230 SQ(2*3) - SQ(2+3)
\uff0c\u5f97\u5230 2 * 3 * 2 * 3 - 2 + 3 * 2 + 3
SQ
\u5f97\u5230 DD(x, y) = x * x - y * y
\uff0c\u5f97\u5230 2 * 3 * 2 * 3 - 2 + 3 * 2 + 3
\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/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/daily/2023/#december","title":"December","text":""},{"location":"programming/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:
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/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/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
.
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/daily/2023/#3-sizeof-struct","title":"\u300c3\u300dsizeof
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)
?
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/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:
printf
series of formatting output functions.2
, and if the hexadecimal number is less than 2 digits, pad it with leading zeros. For example, 0x0a
.Sample Input\uff1a
Hello\nWorld!\n
Sample Output\uff1a
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/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.
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/daily/2023/#november","title":"November","text":""},{"location":"programming/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 list
list->next
node
node
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:
data
to data
.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/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/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/daily/2023/#27-i-love-scanf","title":"\u300c27\u300d I Lovescanf
!","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/daily/2023/#26-broken-strcpy","title":"\u300c26\u300d Brokenstrcpy()
","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:
*t
is 'H'
, and is assigned to *s
.s
and t
increment.*t
, now being 'e'
, is used to evaluate the while
condition.t
points to 'o'
and is assigned to *s
.s
and t
increment.*t
, now being '\\0'
, is used to evaluate the while
condition. The loop ends.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 = \"\"
?
'\\0'
is assigned to *s
.s
and t
increment. t
gets past its end.*t
is undefined behavior.'\\0'
, or it goes too far and causes a segmentation fault.\u4f9b\u9898\u4eba\uff1a\u674e\u82f1\u7426
"},{"location":"programming/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
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/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/daily/2023/#23-typedef-and-string","title":"\u300c23\u300dtypedef
and String","text":"The preprocessing of this program is as follows\uff1a
#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/daily/2023/#october","title":"October","text":""},{"location":"programming/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:
a++
!
--a
-
<<
<
, >
||
a ? b : c
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
evaluates to 0, and y << 0
has the value 2.2 > 2
is false, thus the value of the Logical OR depends on the right part.x++
assigns the value of x
(1) to the expression and then increments x
by 1, making x
equal to 2.--y
decreases the value of y
(2) by 1, so y
becomes 1.x++ > --y
is equivalent to 1 > 1, which is false, so this part equals 0.!(x++ > --y)
negates false, so this part equals 1, making the condition of the Ternary conditional true.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/daily/2023/#27-or-in-switch","title":"\u300c27\u300d Or inswitch
","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.
AnswerD
.
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/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];
A
.
B
will always be 0
when x==y
. C
and D
is not logically correct.\u4f9b\u9898\u4eba\uff1a\u7a0b\u6615\u5b87
"},{"location":"programming/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/daily/2023/#24-nested-switch-confusing-default-and-break","title":"\u300c24\u300d Nestedswitch
, 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/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
The result of the increment and decrement operators
Increment and decrement operators have postfix form x++
(or x--
), and prefix form ++x
(or --x
).
x
.x + 1
for ++x
(or x - 1
for --x
).For more information, see cppreference-Increment/decrement operators
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/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.
strcmp
function in <string.h>
header file. Learn how to use the function by yourself.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/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/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/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/daily/2023/#18-bad-if-else","title":"\u300c18\u300d Badif
-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/daily/2023/#17-character","title":"\u300c17\u300d Character","text":"Given: char c = '@';
, the value of expression 'A' <= c <= 'Z'
is __.
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/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?
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/topic/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
sizeof
\u7684\u64cd\u4f5c\u6570\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/topic/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/topic/pointers/#_2","title":"\u5e95\u5c42\u6982\u5ff5","text":""},{"location":"programming/topic/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/topic/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\u7b26C \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/topic/pointers/#_5","title":"\u57fa\u672c\u8bed\u6cd5","text":""},{"location":"programming/topic/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/topic/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
\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
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
\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
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/topic/pointers/#_9","title":"\u7528\u6cd5\u6982\u8ff0","text":""},{"location":"programming/topic/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\u8bed\u6cd5\u9519\u8bef\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
\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/topic/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
\u6839\u636e\u6807\u51c6\u89c4\u5b9a\uff0c\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u65f6\uff0c\u6570\u7ec4\u5e94\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u5176\u9996\u5143\u7d20\u6307\u9488\uff0c\u8fd9\u662f\u56e0\u4e3a\u590d\u5236\u6570\u7ec4\u7684\u5f00\u9500\u7ecf\u5e38\u5927\u5230\u4e0d\u53ef\u63a5\u53d7\u3002\u6240\u4ee5\uff0c\u5728\u8bed\u6cd5\u5c42\u9762\u4e0a\uff0c\u51fd\u6570\u5b9a\u4e49\u4e2d\uff08\u5373\u53c2\u6570\u7c7b\u578b\u4e0e\u8fd4\u56de\u503c\u7c7b\u578b\u5904\uff09char []
\u7c7b\u578b\u58f0\u660e\u4e0e char *
\u7c7b\u578b\u58f0\u660e\u662f\u7b49\u4ef7\u7684\uff0c\u4e0d\u8fc7\u524d\u8005\u53ef\u4ee5\u63d0\u9192\u51fd\u6570\u7f16\u5199\u8005\u4e0e\u4f7f\u7528\u8005\u7559\u610f s
\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\u5bf9\u51fd\u6570\u800c\u8a00\u6ca1\u6709\u8bed\u4e49\u533a\u522b\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/topic/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
\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
\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
\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
\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
\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
\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
\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
\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/topic/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
sizeof
\u7684\u64cd\u4f5c\u6570\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/topic/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/topic/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
\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_lecture/#_2","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
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_lecture/lecture1/lecture1/","title":"\u8bb2\u4e49\uff1a\u7a0b\u5e8f\u7f16\u8bd1\u8fc7\u7a0b\u4e0e\u8c03\u8bd5\u6280\u672f","text":"\u76f4\u64ad\u56de\u653eBilibili
\u5185\u5bb9\u63d0\u8981gcc
\u3001clang
\u548c llvm
\u7a76\u7adf\u662f\u4ec0\u4e48\uff1fgdb
\u6216 lldb
\u8bbe\u7f6e\u65ad\u70b9\u3001\u627e\u5230\u6bb5\u9519\u8bef\u7684\u6839\u6e90\uff1f\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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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\u5b50c = 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 \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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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
(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(a--) - b
a - (--b)
y = x
\u3002/*
\u88ab\u8d2a\u5fc3\u6cd5\u89e3\u91ca\u4e3a\u6ce8\u91ca\u7684\u5f00\u5934\u3002y = x / (*p)
(n--) > 0
(n--) > 0
(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((a++)++) + b
\u3002\u8bf7\u601d\u8003\u4e00\u4e0b\uff0c\u8fd9\u4e2a\u8bed\u53e5\u6709\u6548\u5417\uff1f\u4e3a\u4e86\u4fbf\u4e8e\u521d\u5b66\u8005\u7406\u89e3\uff0c\u6211\u4eec\u91c7\u7528\u4e00\u5957\u7b80\u5316\u7684\u8bed\u6cd5\u89c4\u5219\uff1a
\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
+-*/%
\u7b49\u7b49\uff09\u548c\u64cd\u4f5c\u6570\uff08\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u51fd\u6570\u8fd4\u56de\u503c......\uff09\u7ec4\u6210\u7684\u5f0f\u5b50\uff0c\u53ef\u4ee5\u8ba1\u7b97\u51fa\u4e00\u4e2a\u503c\u3002\u8bed\u53e5\uff08Statement\uff09\uff1aC \u6807\u51c6\u786e\u5b9a\u4e86\u4e94\u79cd\u8bed\u53e5\u7c7b\u578b\u3002\u9664\u4e86\u590d\u5408\u8bed\u53e5\uff0c\u5176\u5b83\u8bed\u53e5\u90fd\u4ee5\u5206\u53f7 ;
\u7ed3\u5c3e\u3002\u4e0b\u9762\u662f\u8bed\u53e5\u7684\u5b9a\u4e49\uff0c\u4f60\u53ef\u4ee5\u53d1\u73b0\u8bed\u53e5\u662f\u9012\u5f52\u5b9a\u4e49\u7684\u3002
\u590d\u5408\u8bed\u53e5\uff1a\u7531\u82b1\u62ec\u53f7\u5305\u56f4\u7684\u4e00\u7ec4\u8bed\u53e5\u3002
{ \u8bed\u53e5\u6216\u58f0\u660e }\n
\u8868\u8fbe\u5f0f\u8bed\u53e5\uff1a\u8868\u8fbe\u5f0f\u52a0\u4e0a\u5206\u53f7\u5c31\u662f\u8868\u8fbe\u5f0f\u8bed\u53e5\u3002C \u7a0b\u5e8f\u4e2d\u5927\u90e8\u5206\u8bed\u53e5\u90fd\u662f\u8868\u8fbe\u5f0f\u8bed\u53e5\u3002\u7a7a\u8bed\u53e5\u4e5f\u7b97\u4f5c\u8868\u8fbe\u5f0f\u8bed\u53e5\u3002
\u8868\u8fbe\u5f0f;\n
\u4f8b\u5b50\uff1a
puts(\"hello\"); // \u8868\u8fbe\u5f0f\u8bed\u53e5\nchar *s;\nwhile (*s++ != '\\0')\n ; // \u7a7a\u8bed\u53e5\n
\u9009\u62e9\u8bed\u53e5\uff1a
if(\u8868\u8fbe\u5f0f) \u8bed\u53e5\nif(\u8868\u8fbe\u5f0f) \u8bed\u53e5 else \u8bed\u53e5\nswitch(\u8868\u8fbe\u5f0f) \u8bed\u53e5\n
\u5faa\u73af\u8bed\u53e5\uff1a
while(\u8868\u8fbe\u5f0f) \u8bed\u53e5\ndo \u8bed\u53e5 while(\u8868\u8fbe\u5f0f);\nfor(\u521d\u59cb\u5316\u5b50\u53e5;\u8868\u8fbe\u5f0f;\u8868\u8fbe\u5f0f) \u8bed\u53e5\n
\u8df3\u8f6c\u8bed\u53e5\uff1a
goto \u6807\u8bc6\u7b26;\ncontinue;\nbreak;\nreturn \u8868\u8fbe\u5f0f;\n
\u5b8c\u6574\u7684C\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_lecture/lecture1/lecture1/#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
void
Q\uff1avoid
\u5230\u5e95\u6709\u54ea\u4e9b\u542b\u4e49\uff1f
A: \u4e0b\u9762\u662f void
\u7684\u4e00\u822c\u7528\u6cd5
void
\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\uff0c\u8868\u793a\u51fd\u6570\u4e0d\u63a5\u53d7\u53c2\u6570\u3002void
\u4f5c\u4e3a\u51fd\u6570\u8fd4\u56de\u503c\uff0c\u8868\u793a\u51fd\u6570\u4e0d\u8fd4\u56de\u503c\u3002void*
\u662f\u4e00\u79cd\u6307\u9488\u7c7b\u578b\uff0c\u8868\u793a\u4e0d\u77e5\u9053\u6307\u5411\u7684\u7c7b\u578b\u662f\u4ec0\u4e48\u3002\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\u7528int 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
\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
\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
\u51fd\u6570\u4e0d\u8981\u5199\u5f97\u592a\u957f\uff0c\u5efa\u8bae\u572824\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
\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
\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
\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
\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_lecture/lecture1/lecture1/#_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\u6811printf(\"%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_lecture/lecture1/lecture1/#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
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\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\u9898In the following notations, _____ can express a character constant( \u5b57\u7b26\u5e38\u91cf ) correctly.
A. '\\x100'
B. 125
C. '\\08'
D. '\\'
B
"},{"location":"programming_lecture/lecture1/lecture1/#_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
.i
\u4e3a\u540e\u7f00\u3002.s
\u4e3a\u540e\u7f00\u3002.o
\u4e3a\u540e\u7f00\u3002.exe
\u4e3a\u540e\u7f00\u3002gcc
\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
\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
gcc
\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u5305\u62ec\u5b83\u8fd0\u884c\u7684\u5e73\u53f0\u3001\u914d\u7f6e\u7684\u9009\u9879\u7b49\u3002cc1
\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
\u3002as
\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
\u3002sum.c
\u91cd\u590d\u9884\u5904\u7406\u3001\u7f16\u8bd1\u548c\u6c47\u7f16\u7684\u8fc7\u7a0b\uff0c\u5f97\u5230\u4e86 /tmp/ccgMFTqK.o
\u3002collect2
\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\u3002cpp
\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_lecture/lecture1/lecture1/#_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
#include \"...\"
\u5305\u542b\u7684\u5934\u6587\u4ef6\uff0c\u7f16\u8bd1\u5668\u4f1a\u5148\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u67e5\u627e\uff0c\u518d\u5728\u7cfb\u7edf\u76ee\u5f55\u4e0b\u67e5\u627e\u3002#include <...>
\u5305\u542b\u7684\u5934\u6587\u4ef6\uff0c\u7f16\u8bd1\u5668\u53ea\u4f1a\u5728\u7cfb\u7edf\u76ee\u5f55\u4e0b\u67e5\u627e\u3002\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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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\u63a5hello.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
main
\u51fd\u6570\uff0c\u800c\u662f\u4e00\u4e9b\u542f\u52a8\u4ee3\u7801\u3002\u542f\u52a8\u4ee3\u7801\u5728\u6267\u884c main
\u524d\u8fdb\u884c\u4e00\u4e9b\u521d\u59cb\u5316\u5de5\u4f5c\uff0c\u5e76\u5728\u9000\u51fa main
\u540e\u505a\u4e00\u4e9b\u626b\u5c3e\u5de5\u4f5c\u3002Linux \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
crt1.o
\uff1a\u8d1f\u8d23\u542f\u52a8\uff0c\u5305\u542b _start
\u548c\u672a\u5b9a\u4e49\u7684 __libc_start_main
\u548c main
\u3002crti.o
\uff1a\u521d\u59cb\u5316crtbegin.o
\uff1a\u6784\u9020\uff08C++\u4f9d\u8d56\uff09crtend.o
\uff1a\u6790\u6784\uff08C++\u4f9d\u8d56\uff09crtn.o
\uff1a\u7ed3\u675fLinux \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
printf
\u3002\u6807\u51c6\u5e93\u4e2d\u7684\u4ee3\u7801\u5df2\u7ecf\u88ab\u9884\u7f16\u8bd1\u6210\u76ee\u6807\u6587\u4ef6\uff0c\u9644\u5728\u7f16\u8bd1\u5668\u7684\u5b89\u88c5\u76ee\u5f55\u4e0b\u3002\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_lecture/lecture1/lecture1/#_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
\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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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_lecture/lecture1/lecture1/#_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
-Wall
\u548c -Werror
\uff0c\u7f16\u8bd1\u51fa\u6765\u7684\u7a0b\u5e8f\u4e2d\u6709\u5f88\u591a\u5751\uff0c\u6bd4\u5982\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u3002fprintf(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_lecture/lecture1/lecture1/#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
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_lecture/lecture1/lecture1/#_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\u8bc1gdb\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_lecture/lecture1/lecture1/#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
file <filename>
\uff1a\u52a0\u8f7d\u53ef\u6267\u884c\u6587\u4ef6\u3002r
\u6216 run [args]
\uff1a\u8fd0\u884c\u7a0b\u5e8f\u3002[args]
\u662f\u53ef\u9009\u7684\u547d\u4ee4\u884c\u53c2\u6570\u3002b
\u6216 break <line>
\uff1a\u5728\u6307\u5b9a\u884c\u8bbe\u7f6e\u65ad\u70b9\u3002b
\u6216 break <function>
\uff1a\u5728\u6307\u5b9a\u51fd\u6570\u8bbe\u7f6e\u65ad\u70b9\u3002b
\u6216 break *<address>
\uff1a\u5728\u6307\u5b9a\u5730\u5740\u8bbe\u7f6e\u65ad\u70b9\u3002info breakpoints
\uff1a\u67e5\u770b\u65ad\u70b9\u4fe1\u606f\u3002delete breakpoints <number>
\uff1a\u5220\u9664\u6307\u5b9a\u7f16\u53f7\u7684\u65ad\u70b9\u3002continue
\uff1a\u7ee7\u7eed\u6267\u884c\u7a0b\u5e8f\u3002next
\uff1a\u6267\u884c\u4e0b\u4e00\u884c\u3002step
\uff1a\u6267\u884c\u4e0b\u4e00\u884c\uff0c\u5982\u679c\u9047\u5230\u51fd\u6570\u8c03\u7528\uff0c\u8fdb\u5165\u51fd\u6570\u5185\u90e8\u3002print <variable>
\uff1a\u6253\u5370\u53d8\u91cf\u7684\u503c\u3002print <expression>
\uff1a\u6253\u5370\u8868\u8fbe\u5f0f\u7684\u503c\u3002watch <expression>
\uff1a\u76d1\u89c6\u8868\u8fbe\u5f0f\u7684\u503c\uff0c\u5f53\u503c\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u7a0b\u5e8f\u4f1a\u505c\u4e0b\u6765\u3002backtrace
\uff1a\u67e5\u770b\u51fd\u6570\u8c03\u7528\u6808\u3002finish
\uff1a\u6267\u884c\u5b8c\u5f53\u524d\u51fd\u6570\u540e\u505c\u4e0b\u6765\u3002q
\u6216 quit
\uff1a\u9000\u51fa gdb
\u3002help
\uff1a\u67e5\u770b\u5e2e\u52a9\u4fe1\u606f\u3002Linux \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
\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_lecture/lecture1/lecture1/#_24","title":"\u53c2\u8003\u8d44\u6599","text":"\u53c2\u8003\u8d44\u6599Info
\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
Run
\u3002\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
\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
$
\u3002\u4e0b\u9762\u7684\u56fe\u4e2d\uff0cbowling
\u90a3\u4e00\u5757\u5c31\u662f\u63d0\u793a\u7b26\uff08\u6211\u505a\u4e86\u4e00\u4e9b\u7f8e\u5316\uff09\u3002\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_lecture/lecture1/pre_class/#_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
\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_lecture/lecture1/pre_class/#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_lecture/lecture1/pre_class/#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_lecture/lecture1/pre_class/#gcc","title":"\u5c31\u51b3\u5b9a\u662f\u4f60\u4e86\uff0cgcc\uff01","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_lecture/lecture1/pre_class/#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_lecture/lecture1/pre_class/#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_lecture/lecture1/pre_class/#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
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_lecture/lecture1/pre_class/#_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
WindowsMacWindows \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
\u901a\u8fc7 Code \u6253\u5f00
\u7684\u9009\u9879code
\u547d\u4ee4\u6253\u5f00 VSCodeMac \u7684\u5305\u4e0b\u8f7d\u4e0b\u6765\u4e4b\u540e\u62d6\u5165 Application
\u6587\u4ef6\u5939\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c
code
\u547d\u4ee4\u6253\u5f00 VSCode\uff0c\u90a3\u4e48\u9700\u8981\u5982\u4e0b\u64cd\u4f5cshell command
\uff0c\u9009\u62e9 Shell Command: Install \u2018code\u2019 command in PATH
\u56de\u8f66\u6267\u884c\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_lecture/lecture1/pre_class/#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
auto
\u53ef\u4ee5\u627e\u5230\u5982\u56fe\u6240\u793a\u7684 Auto Save
\u8bbe\u7f6e\u9879\uff0c\u8bbe\u7f6e\u4e3a afterDelay \u5373\u53ef\u4f5c\u4e1a.c
\u7f16\u7a0b
Coding
\uff0c\u4f46\u662f\u7edd\u5bf9\u8def\u5f84\u662f D:/\u5b66\u4e60\u8d44\u6599/Coding
hello.exe
\uff0c\u5c31\u53ef\u4ee5\u6267\u884c gcc test.c -o hello.exe\n
\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_lecture/lecture1/pre_class/#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
WSL: Connect to WSL in New Window
\uff08\u6216 WSL: \u5728\u65b0\u7a97\u53e3\u4e2d\u8fde\u63a5\u5230 WSL
\uff09\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_lecture/lecture1/pre_class/#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
\u65bd\u5de5\u4e2d
\u672c\u9875\u9762\u6b63\u5728\u65bd\u5de5\u4e2d\uff0c\u5185\u5bb9\u53ef\u80fd\u4e0d\u5b8c\u6574\u3002
\u5185\u5bb9\u6458\u8981
\u672c\u8282\u5185\u5bb9\u5bf9\u5e94 CSAPP \u7b2c 6 \u7ae0\u300c\u5b58\u50a8\u5668\u5c42\u6b21\u7ed3\u6784\u300d\u4e0e\u7b2c 9 \u7ae0\u300c\u865a\u62df\u5185\u5b58\u300d\u3002
"},{"location":"programming_lecture/lecture2/after_class/#_2","title":"\u5b58\u50a8\u5668\u5c42\u6b21\u7ed3\u6784","text":"\u5f85\u5b8c\u5584
"},{"location":"programming_lecture/lecture2/after_class/#_3","title":"\u865a\u62df\u5185\u5b58","text":"\u7cfb\u7edf\u4e2d\u7684\u8fdb\u7a0b\u95f4\u5171\u4eab CPU \u548c\u4e3b\u5b58\u8d44\u6e90\u3002\u7136\u800c\uff0c\u5171\u4eab\u4e3b\u5b58\u4f1a\u9020\u6210\u8bb8\u591a\u95ee\u9898\uff0c\u6bd4\u5982\u4e00\u4e2a\u8fdb\u7a0b\u4e0d\u5c0f\u5fc3\u5199\u5165\u4e86\u53e6\u4e00\u4e2a\u8fdb\u7a0b\u4f7f\u7528\u7684\u5185\u5b58\u3002
Linux \u8fdb\u7a0b\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4
\u4e3a\u4e86\u66f4\u52a0\u6709\u6548\u5730\u7ba1\u7406\u5185\u5b58\u5e76\u51cf\u5c11\u51fa\u9519\uff0c\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u5c06\u4e3b\u5b58\u62bd\u8c61\u4e3a\u865a\u62df\u5185\u5b58\uff08Vitrual Memory\uff09\u3002\u53f3\u56fe\u5c55\u793a\u4e86 Linux \u7cfb\u7edf\u4e2d\u8fdb\u7a0b\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\u8bbe\u8ba1\u3002
\u865a\u62df\u5185\u5b58\u9700\u8981\u786c\u4ef6\u5f02\u5e38\u3001\u786c\u4ef6\u5730\u5740\u7ffb\u8bd1\u3001\u4e3b\u5b58\u3001\u78c1\u76d8\u6587\u4ef6\u548c\u5185\u6838\u8f6f\u4ef6\u5171\u540c\u4ea4\u4e92\u5b9e\u73b0\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u4e00\u6b65\u6b65\u4e86\u89e3\u865a\u62df\u5185\u5b58\u7684\u7ec6\u8282\u3002
"},{"location":"programming_lecture/lecture2/after_class/#_4","title":"\u865a\u62df\u5185\u5b58\u7684\u57fa\u672c\u601d\u60f3","text":"\u4e00\u4e2a\u8fdb\u7a0b\u865a\u62df\u5185\u5b58\u7684\u5185\u5bb9\u5b58\u50a8\u5728\u78c1\u76d8\u4e0a\uff0c\u7136\u540e\u7528\u4e3b\u5b58\u4f5c\u4e3a\u78c1\u76d8\u7684\u9ad8\u901f\u7f13\u5b58\u3002
\u78c1\u76d8\u4e0a\u7684\u6570\u636e\u88ab\u5206\u5272\u6210\u865a\u62df\u9875\uff08Virtual Page\uff09\uff0c\u4e3b\u5b58\u88ab\u5206\u5272\u6210\u7269\u7406\u9875\uff08Physical Page\uff09\u3002\u865a\u62df\u9875\u548c\u7269\u7406\u9875\u7684\u5927\u5c0f\u76f8\u540c\uff0c\u901a\u5e38\u4e3a 4KB\u3002\u8fd9\u4e9b\u9875\u662f\u78c1\u76d8\u548c\u4e3b\u5b58\u4e4b\u95f4\u7684\u4f20\u8f93\u5355\u5143\u3002
\u4efb\u610f\u65f6\u523b\uff0c\u865a\u62df\u9875\u9762\u53ef\u80fd\u5904\u4e8e\u4ee5\u4e0b\u4e09\u79cd\u72b6\u6001\u4e4b\u4e2d\uff1a
\u4e0b\u9762\u4ecb\u7ecd\u7684\u662f Linux \u7cfb\u7edf\u4e2d\u8fdb\u7a0b\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\u7ed3\u6784\u3002\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u53ef\u80fd\u6709\u4e0d\u540c\u7684\u8bbe\u8ba1\u3002\u4ece\u6700\u4f4e\u7684\u5730\u5740\u5f00\u59cb\u5411\u4e0a\uff0c\u4f9d\u6b21\u662f\uff1a
malloc
\u548c free
\u7b49\u6807\u51c6\u5e93\u51fd\u6570\u65f6\uff0c\u5806\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u5730\u6269\u5c55\u548c\u6536\u7f29\u3002\u865a\u62df\u5730\u5740\u7a7a\u95f4\u7684\u5927\u5c0f\u7531\u8868\u793a\u6700\u5927\u5730\u5740\u6240\u9700\u8981\u7684\u4f4d\u6570\u51b3\u5b9a\u3002\u73b0\u4ee3\u7cfb\u7edf\u901a\u5e38\u652f\u6301 32 \u6216 64 \u4f4d\u3002\u6bd4\u5982 32 \u4f4d\u64cd\u4f5c\u7cfb\u7edf\u652f\u6301\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\u5927\u5c0f\u4e3a 2^32 = 4GB\u3002
"},{"location":"programming_lecture/lecture2/after_class/#_6","title":"\u865a\u62df\u5185\u5b58\u7684\u5de5\u4f5c\u539f\u7406","text":""},{"location":"programming_lecture/lecture2/after_class/#_7","title":"\u865a\u62df\u5bfb\u5740","text":"CPU \u4e0d\u4f1a\u76f4\u63a5\u4f7f\u7528\u7269\u7406\u5730\u5740\uff08Physical Address\uff09\u8bbf\u95ee\u4e3b\u5b58\uff0c\u800c\u662f\u4f7f\u7528\u865a\u62df\u5730\u5740\uff08Virtual Address\uff09\u3002
\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_lecture/lecture2/lecture2/#_1","title":"\u524d\u7f6e\uff1a\u6570\u3001\u8fdb\u5236\u4e0e\u6570\u636e","text":"20231029
[0b] 1001101001011001101110101
[0o] 115131565
[0x] 134b375
\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_lecture/lecture2/lecture2/#_2","title":"\u5982\u4f55\u9605\u8bfb\u5b83\u4eec\uff1f","text":"\u8fd9\u4e9b\u90fd\u662f\u201c\u5341\u201d\uff1a0b1010
\uff0c0o12
\uff0c0xa
\uff0c10
\u3002
0x18
0o23
0b1010
0x10000
\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
\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_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#_6","title":"\u5148\u6765\u7ec3\u7ec3\u624b\uff01","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
int
\uff0c\u6545\u5360\u7528 4 \u5b57\u8282\u3002\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
\u6216\u8bb8\u4f60\u4f1a\u548c\u6211\u540c\u6837\u5bf9\u4ee5\u4e0b\u51e0\u4e2a\u95ee\u9898\u611f\u5230\u56f0\u60d1\uff1a
int
\u4e14\u957f\u5ea6\u662f 4 \u4e2a\u5b57\u8282\uff1fgetchar()
\u7b49\u51fd\u6570\u8fd4\u56de int
\u800c\u4e0d\u662f char
\uff1f\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
int
\uff1f\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
getchar()
\u4e3a\u4ec0\u4e48\u8981\u8fd4\u56de int
\u7c7b\u578b\uff1f\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
int c = getchar()
? Why int
? : C_Programming (reddit.com)\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
\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
\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
\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_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#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
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
\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_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#_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 - \u4e3a\u5bf9\u8c61\u5206\u914d\u5185\u5b58 - \u5c06\u6807\u8bc6\u7b26\u4e0e\u5bf9\u8c61\u5173\u8054
\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
psi
\u53d8\u91cf\u7684\u503c\u5c31\u662f i
\u5173\u8054\u7684\u5bf9\u8c61\u7684\u5730\u5740\uff080x16fdbae4c
\uff09psi
\u53ef\u4ee5\u8bbf\u95ee i
\u5173\u8054\u7684\u5bf9\u8c61\uff08*psi
\uff09psi
\u672c\u8eab\u4f5c\u4e3a\u4e00\u4e2a\u53d8\u91cf\uff0c\u4e5f\u6709\u81ea\u5df1\u7684\u5730\u5740\uff080x16fdbae08
\uff09\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
i
\u662f\u6807\u8bc6\u7b26\uff0c\u662f\u53ef\u4fee\u6539\u7684\u5de6\u503c*psi
\u6216 arr[3]
\u662f\u8868\u8fbe\u5f0f\uff0c\u662f\u53ef\u4fee\u6539\u7684\u5de6\u503c2 * i
\u6216 &i
\u6216 &psi
\uff0c\u4e0d\u662f\u6807\u8bc6\u7b26\uff0c\u662f\u53f3\u503cconst char *pc = \"Good morning my neighbors\";\n
pc
\u662f\u53ef\u4fee\u6539\u7684\u5de6\u503c*pc
\u662f\u4e0d\u53ef\u4fee\u6539\u7684\u5de6\u503c\u53c2\u8003\uff1a\u503c\u7c7b\u522b - cppreference.com
"},{"location":"programming_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#_16","title":"\u5b58\u50a8\u671f","text":"malloc()
\u5206\u914d\u7684\u5185\u5b58\u3002#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_lecture/lecture2/lecture2/#_17","title":"\u4f5c\u7528\u57df","text":"\u4f5c\u7528\u57df - cppreference.com
"},{"location":"programming_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#_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
\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_lecture/lecture2/lecture2/#_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_lecture/lecture2/lecture2/#_22","title":"\u94fe\u63a5","text":""},{"location":"programming_lecture/lecture2/lecture2/#_23","title":"\u9605\u8bfb\u548c\u64b0\u5199\u7c7b\u578b\u58f0\u660e","text":""},{"location":"programming_lecture/lecture2/pre_class/","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_lecture/lecture3/lecture3/","title":"\u8bb2\u4e49\uff1aI/O \u4e0e\u6587\u4ef6","text":"\u5185\u5bb9\u63d0\u8981
\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\u7b49I/O\u64cd\u4f5c\u7684\u4e00\u4e9b\u6570\u636e\uff0c\u8fd9\u4e9b\u9884\u7559\u7684\u7a7a\u95f4\u5c31\u53eb\u505a\u7f13\u51b2\u533a\uff1b\u800cbuffer\u7f13\u51b2\u533a\u548cCache\u7f13\u5b58\u533a\u90fd\u5c5e\u4e8e\u7f13\u51b2\u533a\u7684\u4e00\u79cd\u3002
buffer\u7f13\u51b2\u533a\u548ccache\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
\u7cfb\u7edf\u5c42\u9762\uff0c\u51cf\u5c11CPU\u5bf9\u78c1\u76d8\u7684\u8bfb\u5199\u6b21\u6570\uff1aCPU\u8bfb\u53d6\u78c1\u76d8\u4e2d\u7684\u6570\u636e\u5e76\u4e0d\u662f\u76f4\u63a5\u8bfb\u53d6\u78c1\u76d8\uff0c\u800c\u662f\u5148\u5c06\u78c1\u76d8\u7684\u5185\u5bb9\u8bfb\u5165\u5230\u5185\u5b58\uff0c\u4e5f\u5c31\u662fCache\uff0c\u7136\u540eCPU\u5bf9Cache\u8fdb\u884c\u8bfb\u53d6\uff0c\u8fdb\u800c\u64cd\u4f5c\u6570\u636e\uff1b\u8ba1\u7b97\u673a\u5bf9Cache\u7684\u64cd\u4f5c\u65f6\u95f4\u8fdc\u8fdc\u5c0f\u4e8e\u5bf9\u78c1\u76d8\u7684\u64cd\u4f5c\u65f6\u95f4\uff0c\u5927\u5927\u7684\u52a0\u5feb\u4e86\u8fd0\u884c\u901f\u5ea6\uff0c\u63d0\u9ad8CPU\u7684\u4f7f\u7528\u6548\u7387\u3002
\u5728C\u8bed\u8a00\u8f93\u5165\u4e2d\uff0c\u628a\u82e5\u5e72\u5b57\u7b26\u4f5c\u4e3a\u4e00\u4e2a\u5757\u8fdb\u884c\u4f20\u8f93\u6bd4\u9010\u4e2a\u53d1\u9001\u8fd9\u4e9b\u5b57\u7b26\u8282\u7701\u65f6\u95f4\uff0c\u6253\u9519\u5b57\u7b26\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u952e\u76d8\u4fee\u6b63\u9519\u8bef\u3002
\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\u4e48C \u6807\u51c6\u8981\u89c4\u5b9a\u8f93\u5165\u662f\u7f13\u51b2\u7684\u5417\uff1f
\u4e3a\u4ec0\u4e48C\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
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
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\u4e2dI/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\u5728C\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_lecture/lecture3/lecture3/#_3","title":"\u6807\u51c6\u6d41","text":"\u5728\u6807\u51c6\u5934\u6587\u4ef6<stidio.h>
\u4e2d\uff0c\u5b9a\u4e49\u4e86\u4e09\u4e2a\u6587\u672c\u6d41.
#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
\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_lecture/lecture3/lecture3/#_4","title":"\u5b57\u7b26\u8f93\u5165\u8f93\u51fa","text":""},{"location":"programming_lecture/lecture3/lecture3/#_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\u5728UNIX\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
\u5728\u5b57\u7b26I/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
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
\u4ee5\u4e0a\u51fd\u6570\u90fd\u5c06\u5b57\u7b26\u4ece\u7f13\u51b2\u533a\u4e2d\u7684 unsigned char
\u7c7b\u578b\u8f6c\u6362\u4e3a int
\u7c7b\u578b\u3002
getchar()
\u5b83\u7684\u8fd4\u56de\u503c\u662f int
\u7c7b\u578b\u800c\u975e char
\u7c7b\u578b\uff0c\u503c\u5f97\u6ce8\u610f\u3002\u6240\u4ee5\u4e3a\u4ec0\u4e48\u53ef\u4ee5\u4f7f\u7528char c = getchar()
?
#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
wchar_t
\u4e3a16\u4f4d\uff0c\u5373unsigned short
\u7c7b\u578b\u3002wchar_t
\u4e3a32\u4f4d\uff0c\u5373unsigned int
\u7c7b\u578b\u3002\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
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_lecture/lecture3/lecture3/#_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
\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
*
\u3002\u82e5\u6709\u8981\u6c42\uff0c\u5219\u7ed3\u679c\u4f1a\u4ee5\u7a7a\u683c\u5b57\u7b26\uff08\u9ed8\u8ba4\u60c5\u51b5\uff09\u586b\u5145\uff0c\u5728\u53f3\u6821\u6b63\u65f6\u4e8e\u5de6\uff0c\u5de6\u6821\u6b63\u65f6\u4e8e\u53f3\u3002\u4f7f\u7528 *
\u7684\u60c5\u51b5\u4e0b\uff0c\u4ee5\u4e00\u4e2a\u989d\u5916\u7684int
\u7c7b\u578b\u53c2\u6570\u6307\u5b9a\u5bbd\u5ea6\u3002\u82e5\u53c2\u6570\u503c\u4e3a\u8d1f\u6570\uff0c\u5219\u5b83\u5bfc\u81f4\u6307\u5b9a - \u6807\u7b7e\u548c\u6b63\u57df\u5bbd\u3002\uff08\u6ce8\u610f\uff1a\u8fd9\u662f\u6700\u5c0f\u5bbd\u5ea6\uff1a\u51b3\u4e0d\u88ab\u622a\u65ad\u503c\uff09\u3002*
\u6216\u4e24\u8005\u7686\u65e0\u7684 .
\u6307\u793a\u8f6c\u6362\u7684\u7cbe\u5ea6\u3002\u5728\u4f7f\u7528 *
\u7684\u60c5\u51b5\u4e0b\uff0c\u7cbe\u5ea6\u7531\u989d\u5916\u7684 int \u7c7b\u578b\u53c2\u6570\u6307\u5b9a\u3002\u82e5\u6b64\u53c2\u6570\u7684\u503c\u4e3a\u8d1f\u6570\uff0c\u5219\u5b83\u88ab\u5ffd\u7565\u3002\u82e5\u65e2\u4e0d\u4f7f\u7528\u6570\u5b57\u4ea6\u4e0d\u4f7f\u7528 *
\uff0c\u5219\u7cbe\u5ea6\u91c7\u7528\u96f6\u3002\u7cbe\u5ea6\u7684\u51c6\u786e\u6548\u679c\u89c1\u4e0b\u8868\u3002printf()
\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
\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\u51falong\u7c7b\u578b\u7684\u503c\u65f6\uff0c\u4e5f\u4f1a\u51fa\u73b0\u9519\u8bef\u5417\uff1f 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
\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
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
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
#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
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
scanf()
\u4e2d\u7684\u8f93\u5165\u8fc7\u7a0b
\u5047\u8bbescanf()
\u6839\u636e%d
\u8f6c\u6362\u8bfb\u53d6\u4e00\u4e2a\u6574\u6570,scanf()
\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\u7b2c1\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
\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
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\u56de0\u3002\u5f53scanf()
\u8bfb\u53d6\u5230\u6587\u4ef6\u672b\u5c3e\u5219\u8fd4\u56deEOF
\u3002
\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
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_lecture/lecture3/lecture3/#_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
\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\n$ file c_file.o\n$ file c_file\n$ objdump -h -s -d c_file.o\n$ objdump -h -s c_file\n
\u5bf9\u4e8eC\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\u4e0eUNIX\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_lecture/lecture3/lecture3/#_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\u4ee5UTF-16(Windows API\u5927\u91cf\u504f\u597dUTF-16 LE\u7f16\u7801\u7684\u5b57\u7b26\u4e32\u4f5c\u4e3a\u53c2\u6570)\u6765\u50a8\u5b58\uff0c\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\u66ff\u6362\u4e3aUTF-8\u7b49\u683c\u5f0f\uff0c\u53ef\u4ee5\u538b\u7f29\u7a7a\u95f4\u3002
"},{"location":"programming_lecture/lecture3/lecture3/#_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\u5982ASCII\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\u6210C\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
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_lecture/lecture3/lecture3/#_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
\u5728 <stdio.h>
\u4e2d\u6709\u5982\u4e0b\u4e0e\u6587\u4ef6\u76f8\u5173\u7684\u7c7b\u578b\u548c\u5b8f\uff1a
FILE
\u5bf9\u8c61\u7c7b\u578b\uff0c\u8bb0\u5f55\u63a7\u5236\u6d41\u6240\u9700\u8981\u7684\u6240\u6709\u4fe1\u606f\uff0c\u5305\u62ec\uff1a\u6587\u4ef6\u5b9a\u4f4d\u7b26\u3001\u6307\u5411\u76f8\u5173\u7f13\u51b2\u7684\u6307\u9488\u3001\u9519\u8bef\u6307\u793a\u7b26\u548c\u6587\u4ef6\u7ed3\u675f\u7b26\u3002FILE *
\u6570\u636e\u5bf9\u8c61\u7684\u5185\u90e8\uff0c\u5373\u4f7f\u5b9e\u73b0\u7ed9\u51fa\u4e86\u67d0\u4e9b\u53ef\u89c1\u57df\u3002\u4e0d\u8981\u4fee\u6539\u5bf9\u8c61\u3001\u4e0d\u8981\u62f7\u8d1d\u5bf9\u8c61\u5e76\u4ee3\u66ff\u4f7f\u7528\uff0c\u56e0\u4e3a\u5b9e\u73b0\u5047\u5b9a\u77e5\u9053\u6d41\u6570\u636e\u5bf9\u8c61\u7684\u6240\u6709\u5730\u5740\u3002fpos_t
\u5bf9\u8c61\u7c7b\u578b\uff0c\u542b\u6709\u552f\u4e00\u6307\u5b9a\u6587\u4ef6\u4e2d\u6bcf\u4e2a\u4f4d\u7f6e\u6240\u9700\u7684\u6240\u6709\u4fe1\u606f\u3002stderr
, stdin
, stdout
\u90fd\u662f FILE*
\u7c7b\u578b\u7684\u8868\u8fbe\u5f0f\u3002EOF
\u5c55\u5f00\u4e3a\u4e00\u4e2a\u8d1f\u7684\u6574\u503c\u5e38\u91cf\u3002NULL
SEEK_CUR
\u6587\u4ef6\u5f53\u524d\u4f4d\u7f6eSEEK_END
\u6587\u4ef6\u7ed3\u675f\u4f4d\u7f6eSEEK_SET
\u6587\u4ef6\u5f00\u59cb\u4f4d\u7f6eint remove (const char *filename)
int rename (const char *old, const char *new)
FILE *tmpfile(void)
char * tmpnam(char *s)
int fclose(FILE *stream)
int fflush(FILE *stream)
FILE *fopen(const char *filename, const char *mode)
FILE *freopen(const char *filename, const char *mode, FILE *stream)
void setbuf(FILE *stream, char *buf)
int setvbuf(FILE *stream, char *buf, int mode, size_t size)
\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
fprintf
,fscanf
,vfprintf
,vprintf
,vsprintf
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
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
int fseek(FILE *stream, long int offset, int whence)
whence
\u53ef\u4ee5\u662f SEEK_SET
\u3001SEEK_CUR
\u3001SEEK_END
long int ftell(FILE *stream)
void rewind(FILE *stream)
\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
int fgetpos(FILE *stream, fpos_t *pos)
int fsetpos(FILE *stream, const fpos_t *pos)
\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
\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\n$ echo_eof < echo_eof.c > echo_eof.txt\n$ echo_eof < echo_eof.c | cat\n
\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,\u5de6\u8fb9\u8865\u7a7a\u683c\n printf(\"%-5d\\n\", 1000); // \u5de6\u5bf9\u9f50,\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\u51fa0x\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\u76840\n printf(\"%05d\\n\", 1000); // \u524d\u9762\u88650\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\u5bfc0\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\u7f6e0\n printf(\"%.8g\\n\", 1000.123456); // \u6700\u5927\u6709\u6548\u6570\u5b57\u4e3a8\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\u53f7char\n printf(\"%hhu\\n\", 'A' + 128); // \u8f93\u51fa\u65e0\u7b26\u53f7char\n printf(\"%hd\\n\", 32767); // \u8f93\u51fa\u6709\u7b26\u53f7\u77ed\u6574\u578bshort int\n printf(\"%hu\\n\", 65535); // \u8f93\u51fa\u65e0\u7b26\u53f7\u77ed\u6574\u578bunsigned short int\n printf(\"%ld\\n\", 0x7fffffffffffffff); // \u8f93\u51fa\u6709\u7b26\u53f7\u957f\u6574\u578blong int\n printf(\"%lu\\n\", 0xffffffffffffffff); // \u8f93\u51fa\u6709\u7b26\u53f7\u957f\u6574\u578bunsigned long int\n}\n
\u5173\u4e8eprintf()
#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
\u5173\u4e8escanf()
#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
\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\n$ file c_file.o\n$ file c_file\n$ objdump -h -s -d c_file.o\n$ objdump -h -s c_file\n
\u65bd\u5de5\u4e2d
\u672c\u9875\u9762\u6b63\u5728\u7f16\u8f91\u4e2d\u3002
"},{"location":"programming_lecture/lecture4/after_class/#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
<ctype.h> <stdio.h> <stdlib.h> <string.h>\n
<assert.h> <limits.h> <stddef.h> <time.h>\n
<float.h> <math.h> <error.h> <locale.h> <setjmp.h> <signal.h> <stdarg.h>\n
\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_lecture/lecture4/after_class/#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
#undef
\u9884\u5904\u7406\u6307\u4ee4\u7684\u4f7f\u7528\u4e5f\u53ef\u4ee5\u4fdd\u8bc1\u5b9e\u9645\u51fd\u6570\u7684\u5f15\u7528\u3002atoi()
\u7684\u4f7f\u7528\u65b9\u5f0f
#include <stdlib.h>\nconst char *str;\ni = atoi(str);\n
#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
<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\u548cioctl
\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.
\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_lecture/lecture4/lecture4/","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
ctype.h
stdio.h
string.h
stdlib.h
math.h
\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_lecture/lecture4/lecture4/#_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
NULL
\u3001EOF
printf
\u3001scanf
FILE
\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_lecture/lecture4/lecture4/#_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
int main(void);\n
\u6307\u9488 \u7684\u6982\u5ff5
\u6307\u9488\u5177\u6709\u7c7b\u578b\u4fe1\u606f\uff0c\u51b3\u5b9a\u4e86\u6307\u9488\u7684\u8fd0\u7b97\u65b9\u5f0f
\u4f8b\u5b50
int p[10];\nchar q[10];\nint *p1 = p, *p2 = &p[1];\nchar *q1 = q, *q2 = &q[1];\n
\u8bf7\u95ee\uff0cp1 + 1
\u3001p2 - p1
\u3001q1 + 1
\u3001q2 - q1
\u7684\u503c\u662f\u591a\u5c11\uff1f\u7c7b\u578b\u662f\u4ec0\u4e48\uff1f
\u5982\u679c\u76f4\u63a5\u5bf9\u4ed6\u4eec\u7684\u503c\u8fdb\u884c\u52a0\u51cf\uff0c\u7ed3\u679c\u5e94\u5f53\u662f\u591a\u5c11\uff1f
\u6570\u7ec4\u4e0e\u6307\u9488
\u4f8b\u5b50
int a[10];\nint *p;\n
\u8bf7\u95ee\uff1aa
\u3001a[0]
\u3001&a[0]
\u3001&a
\u3001*a
\u3001p
\u3001*p
\u3001&p
\u7684\u7c7b\u578b\u662f\u4ec0\u4e48\uff1f
\u8bf7\u95ee\uff0c\u6267\u884c p = &a
\u62a5\u544a
warning: initialization of `int *` from incompatible pointer type `int (*)[10]`\n
\u662f\u4ec0\u4e48\u539f\u56e0\uff1f
\u591a\u7ef4\u6570\u7ec4\u6bd4\u8f83\u590d\u6742\uff0c\u7b49\u6b63\u6587\u8bb2\u5b8c\u8fd8\u6709\u65f6\u95f4\u518d\u56de\u6765\u8bb2
<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
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
0x20
~ 0x7E
0x00
~ 0x1F
\u548c 0x7F
\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
\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
int isalnum(int c);\nint isalpha(int c);\n// int iscntrl(int c);\nint isdigit(int c);\n// int isgraph(int c);\nint islower(int c);\n// int isprint(int c);\n// int ispunct(int c);\nint isspace(int c);\nint isupper(int c);\n// int isxdigit(int c);\n
int tolower(int c);\nint toupper(int c);\n
<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
isblank
\u4ec5\u5224\u65ad\u7a7a\u683c
\u548c\u6c34\u5e73\u5236\u8868\u7b26 \\t
\u3002isspace
\u5224\u65ad\u7a7a\u683c
\u3001\u6c34\u5e73\u5236\u8868\u7b26 \\t
\u3001\u6362\u884c\u7b26 \\n
\u3001\u56de\u8f66\u7b26 \\r
\u3001\u6362\u9875\u7b26 \\f
\u3001\u5782\u76f4\u5236\u8868\u7b26 \\v
\u3002<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
\u5b8f\u7684\u53c2\u6570\u53ef\u80fd\u4f1a\u88ab\u6c42\u503c\u591a\u6b21\uff0c\u5177\u6709\u526f\u4f5c\u7528\u7684\u5b8f\u53c2\u6570\u4f1a\u5bfc\u81f4\u610f\u5916\u3002
\u4e3e\u4e2a\u4f8b\u5b50
#define SQUARE(X) ((X) * (X))\nSQUARE(x++); // x++ * x++\n
\u4f7f\u7528\u8005\u4ee5\u4e3a\u5b83\u53ea\u4f1a\u8ba9 x
\u81ea\u589e\u4e00\u6b21\uff0c\u4f46\u662f\u5b9e\u9645\u4e0a\u5b83\u4f1a\u8ba9 x
\u81ea\u589e\u4e24\u6b21\u3002
\u4f1a\u4ea7\u751f\u4e0d\u5b89\u5168\u884c\u4e3a\u7684\u5b8f
\u6807\u51c6\u5e93\u4e2d\uff0c\u53ea\u6709 getc
\u548c putc
\u53ef\u80fd\u4f1a\u4ea7\u751f\u8fd9\u79cd\u4e0d\u5b89\u5168\u884c\u4e3a\u3002
<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
#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
<math.h>
","text":""},{"location":"programming_lecture/lecture4/lecture4/#_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
asin
\u8f93\u5165\u4e86\u4e0d\u5728 \\([-1, 1]\\) \u7684\u503c\uff09\uff0c\u4f1a\u53d1\u751f\u5b9a\u4e49\u57df\u9519\u8bef\u3002double
\u503c\uff0c\u53d1\u751f\u503c\u57df\u9519\u8bef\u3002\u4e0a\u6ea2\u8fd4\u56de HUGE_VAL
\uff0c\u4e0b\u6ea2\u8fd4\u56de 0
\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
\u5b8f
HUGE_VAL\n
GCC \u5b9a\u4e49\u7684\u5b8f
INFINITY\nNAN\n
\u4e0a\u9762\u8fd9\u4e24\u4e2a\u5b8f\u8d77\u521d\u4e0d\u5728\u6807\u51c6\u5e93\u4e2d\uff0c\u7531 GCC \u5b9a\u4e49\u3002
\u636e\u8bf4\u5728 C99 \u4ee5\u540e\uff0cINFINITY
\u88ab\u6807\u51c6\u5e93\u7eb3\u5165\uff0c\u6211\u6ca1\u6709\u67e5\u8bc1\u3002
\u51fd\u6570\uff08\u4ec5\u4e3e\u4e00\u4e9b\u5e38\u7528\u7684
double acos(double x);\ndouble asin(double x);\ndouble atan(double x);\ndouble cos(double x);\ndouble sin(double x);\ndouble tan(double x);\ndouble exp(double x);\ndouble log(double x);\ndouble log10(double x);\ndouble pow(double x, double y);\ndouble sqrt(double x);\ndouble ceil(double x);\ndouble fabs(double x);\ndouble floor(double x);\n
double
\u7c7b\u578b\uff08\u6ce8\u610f\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u5e26\u6765\u7684\u5f71\u54cd\uff09\u3002PI
\u8fd9\u4e2a\u5b8f\u3002atan(1)*4
\u4ee3\u66ff\u3002M_
\u5f00\u5934\uff0c\u6bd4\u5982 M_PI
\u3002\u5b83\u4eec\u9ed8\u8ba4\u4e3a double
\u7c7b\u578b\u3002\u5982\u679c\u4f60\u9700\u8981\u5176\u4ed6\u7cbe\u5ea6\uff0c\u53ef\u4ee5\u6dfb\u52a0 l
\u540e\u7f00\uff0c\u6bd4\u5982 M_PIl
\u3002<string.h>
","text":""},{"location":"programming_lecture/lecture4/lecture4/#_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
scanf
\u4f7f\u7528 %s
\u8bfb\u53d6\u7684\u5b57\u7b26\u5e8f\u5217\u662f\u5b57\u7b26\u4e32\u3002scanf
\u4f1a\u81ea\u52a8\u6dfb\u52a0\u7a7a\u5b57\u7b26\u3002size_t\n
NULL\n
void *memcpy(void *dest, const void *src, size_t n);\nvoid *memmove(void *dest, const void *src, size_t n);\nchar *strcpy(char *dest, const char *src);\nchar *strncpy(char *dest, const char *src, size_t n);\n
char *strcat(char *dest, const char *src);\nchar *strncat(char *dest, const char *src, size_t n);\n
int memcmp(const void *s1, const void *s2, size_t n);\nint strcmp(const char *s1, const char *s2);\nint strncmp(const char *s1, const char *s2, size_t n);\n
void *memchr(const void *s, int c, size_t n);\nchar *strchr(const char *s, int c);\n// size_t strcspn(const char *s1, const char *s2);\n// char *strpbrk(const char *s1, const char *s2);\n// char *strrchr(const char *s, int c);\n// size_t strspn(const char *s1, const char *s2);\nchar *strstr(const char *s1, const char *s2);\n// char *strtok(char *s1, const char *s2);\n
void *memset(void *s, int c, size_t n);\n// char *strerror(int errnum);\nsize_t strlen(const char *s);\n
\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
<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
\u8bf7\u770b\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_lecture/lecture4/lecture4/#_13","title":"\u5185\u5bb9","text":"RAND_MAX\nEXIT_FAILURE\nEXIT_SUCCESS\n
\u51fd\u6570
int rand(void);\nvoid srand(unsigned int seed);\n
int abs(int n);\ndiv_t div(int numer, int denom);\nlong labs(long n);\nldiv_t ldiv(long numer, long denom);\n
void *bsearch(const void *key, const void *base, size_t n, size_t size, int (*compar)(const void *, const void *));\nvoid qsort(void *base, size_t n, size_t size, int (*compar)(const void *, const void *));\n
double atof(const char *str);\nint atoi(const char *str);\nlong atol(const char *str);\ndouble strtod(const char *str, char **endptr);\nlong strtol(const char *str, char **endptr, int base);\nunsigned long strtoul(const char *str, char **endptr, int base);\n
// void abort(void);\n// int atexit(void (*func)(void));\n// void exit(int status);\n// char *getenv(const char *name);\n// int system(const char *string);\n
\u5185\u5b58\u7ba1\u7406\uff08\u91cd\u96be\u70b9\uff09
void *calloc(size_t nobj, size_t size);\nvoid free(void *ptr);\nvoid *malloc(size_t size);\nvoid *realloc(void *ptr, size_t size);\n
\u6ce8\u610f\uff0c\u5185\u5b58\u62f7\u8d1d\u51fd\u6570\u5374\u5728 <string.h>
\u4e2d\u3002
\u7c7b\u578b
div_t // int quot, rem;\nldiv_t // long quot, rem;\n
rand
\u548c srand
\u7528\u4e8e\u4ea7\u751f\u4f2a\u968f\u673a\u6570\u3002srand
\u7528\u4e8e\u8bbe\u7f6e\u968f\u673a\u6570\u79cd\u5b50\uff0crand
\u7528\u4e8e\u4ea7\u751f\u968f\u673a\u6570\u3002rand
\u4ea7\u751f\u7684\u968f\u673a\u6570\u8303\u56f4\u662f \\([0, RAND\\_MAX]\\)\u3002abs
\u548c labs
\u7528\u4e8e\u6c42\u7edd\u5bf9\u503c\u3002div
\u548c ldiv
\u7528\u4e8e\u6c42\u5546\u548c\u4f59\u6570\u3002qsort
\u7684\u7528\u4f8b\uff1a int cmpfunc (const void * a, const void * b) {\n return ( *(int*)a - *(int*)b );\n}\nqsort(values, 5, sizeof(int), cmpfunc);\n
atoi
\u51fd\u6570\u7684\u5177\u4f53\u5b9e\u73b0\u8981\u6bd4\u8fd9\u590d\u6742\u5f97\u591a\uff09\uff1a int atoi(char *str) {\n int res = 0;\n for (int i = 0; str[i] != '\\0'; ++i)\n res = res * 10 + str[i] - '0';\n return res;\n}\n
malloc
\u8bb0\u5f97\u53c2\u6570\u662f\u5b57\u8282\u6570\uff0c\u5343\u4e07\u8bb0\u5f97\u4e58\u4e0a sizeof
\u3002\u4e3a\u4e86\u9632\u6b62\u81ea\u5df1\u5fd8\u8bb0\uff0c\u4e5f\u53ef\u4ee5\u575a\u6301\u4f7f\u7528 calloc
\u3002\u4e14\u5b83\u4f1a\u81ea\u52a8\u521d\u59cb\u5316\u5185\u5b58\u4e3a 0\u3002realloc
\u76f8\u5f53\u4e8e\u7ed3\u5408\u4e86 malloc
\u3001memcpy
\u548c free
\u7684\u529f\u80fd\u3002<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_lecture/lecture4/lecture4/#_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
\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_lecture/lecture4/lecture4/#_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 ^D
Ctrl+D ^Z
Ctrl+Z ^D
Ctrl+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
C \u8bed\u8a00\u63d0\u4f9b\u4e24\u79cd\u6d41\uff1a\u6587\u672c\u6d41\u548c\u4e8c\u8fdb\u5236\u6d41\u3002
\\n
\u548c EOF
\u3002char
\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_lecture/lecture4/lecture4/#_19","title":"\u5185\u5bb9","text":"size_t\nFILE\nfpos_t\n
stderr\nstdin\nstdout\nNULL\nEOF\nSEEK_CUR\nSEEK_END\nSEEK_SET\n// BUFSIZ\n// FOPEN_MAX\n// FILENAME_MAX\n
// int remove(const char *filename);\n// int rename(const char *old, const char *new);\n// FILE *tmpfile(void);\n
int fclose(FILE *stream);\n// int fflush(FILE *stream);\nFILE *fopen(const char *filename, const char *mode);\nFILE *freopen(const char *filename, const char *mode, FILE *stream);\n// void setbuf(FILE *stream, char *buf);\n// int setvbuf(FILE *stream, char *buf, int mode, size_t size);\n
int fprintf(FILE *stream, const char *format, ...);\nint fscanf(FILE *stream, const char *format, ...);\nint printf(const char *format, ...);\nint scanf(const char *format, ...);\nint sprintf(char *str, const char *format, ...);\nint sscanf(const char *str, const char *format, ...);\n// int vfprintf(FILE *stream, const char *format, va_list arg);\n
// int fgetc(FILE *stream);\n// char *fgets(char *str, int n, FILE *stream);\n// int fputc(int c, FILE *stream);\nint fputs(const char *str, FILE *stream);\n// int getc(FILE *stream);\nint getchar(void);\n// char *gets(char *str);\n// int putc(int c, FILE *stream);\nint putchar(int c);\nint puts(const char *str);\n// int ungetc(int c, FILE *stream);\n
size_t fread(void *ptr, size_t size, size_t nobj, FILE *stream);\nsize_t fwrite(const void *ptr, size_t size, size_t nobj, FILE *stream);\n
//int fgetpos(FILE *stream, fpos_t *pos);\nint fseek(FILE *stream, long offset, int origin);\n//int fsetpos(FILE *stream, const fpos_t *pos);\nlong ftell(FILE *stream);\nvoid rewind(FILE *stream);\n
// void clearerr(FILE *stream);\n// int feof(FILE *stream);\n// int ferror(FILE *stream);\n// void perror(const char *str);\n
\u4ee5\u4e0b\u662f\u8bfe\u5185\u5185\u5bb9\uff0c\u4ec5\u5217\u51fa\uff0c\u4e0d\u505a\u8be6\u7ec6\u4ecb\u7ecd\uff1a
printf
/scanf
\u8fd9\u51e0\u4e2a\u683c\u5f0f\u5316\u8f93\u5165/\u8f93\u51fa\u51fd\u6570\u7684\u4f7f\u7528\u3002%d
\u3001%p
\u7b49\u8f6c\u6362\u8bf4\u660e\u7684\u4f7f\u7528\u3002\\n
\u3001\\r
\u7b49\u5e38\u89c1\u8f6c\u4e49\u5e8f\u5217\u7684\u4f7f\u7528\u3002fopen
\u3001fclose
\u7684\u4f7f\u7528\u3002r
\u3001w
\u3001a
\u3001b
\u7b49\u6a21\u5f0f\u7684\u4f7f\u7528\u3002FILE
\u4e2d\u7528 fscanf
\u3001fprintf
\u8bfb\u5199\u6570\u636e\u3002fread
\u548c fwrite
\u8bfe\u4e0a\u5e94\u8be5\u4f1a\u8bb2\uff0c\u4f46\u662f\u7f16\u7a0b\u4e5f\u4e0d\u4f1a\u8981\u6c42\u7684\u3002\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
scanf
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
\u96f6\u6216\u66f4\u591a\u4e2a\u6807\u5fd7\uff0c\u8bf4\u660e\u8f6c\u6362\u4e2d\u7684\u53d8\u5316\u3002
char meaning-
\u5de6\u5bf9\u9f50\uff08\u53f3\u4fa7\u586b\u5145\u7a7a\u767d\uff09 +
\u603b\u662f\u6253\u5370\u7b26\u53f7\uff08\u5305\u62ec\u6b63\u53f7\uff09
\u5982\u679c\u65e0\u7b26\u53f7\uff0c\u6253\u5370\u7a7a\u683c 0
\u7528 0 \u586b\u5145 \u4e00\u4e2a\u53ef\u9009\u7684\u6700\u5c0f\u5b57\u6bb5\u5bbd\u5ea6\uff1a\u4e00\u4e2a\u661f\u53f7\u6216\u8005\u4e00\u4e2a\u5341\u8fdb\u5236\u6574\u6570\u3002
\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
scanf
%s
\u53ea\u8bfb\u53d6\u975e\u7a7a\u767d\u5b57\u7b26\uff0c\u9047\u5230\u7a7a\u767d\u5b57\u7b26\u5c31\u7ed3\u675f\u3002%c
\u53ea\u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26\uff0c\u9047\u5230\u7a7a\u767d\u5b57\u7b26\u4e5f\u4f1a\u8bfb\u53d6\u3002\u8fd8\u8bb0\u5f97\u4e0a\u9762 <ctype.h>
\u521a\u521a\u8bb2\u7684\u7a7a\u767d\u5b57\u7b26\u5417\uff1f
&
\uff1f\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
printf
\u3001fprintf
\u3001sprintf
\u3001snprintf
scanf
\u3001fscanf
\u3001sscanf
EOF
ungetc
\u5c06\u5b57\u7b26\u9000\u56de\u6d41\u4e2d\uff08\u4e0d\u8981\u5728 PTA \u7b49 OJ \u7cfb\u7edf\u4e0a\u4f7f\u7528\uff01\u4e0d\u8981\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u4f7f\u7528\uff01\uff09\u3002\u603b\u4e4b\uff0c\u5c31\u662f\u4e0d\u5efa\u8bae\u78b0\u8fd9\u4e2a\u4e1c\u897f\u3002fseek
\u3001ftell
\u3001rewind
\uff1a\u8f83\u8001\u7684\u4f20\u7edf\u7684\u6587\u4ef6\u5b9a\u4f4d\u51fd\u6570fgetpos
\u3001fsetpos
\u3001rewind
\uff1a\u4efb\u610f\u5927\u5c0f\u3001\u7ed3\u6784\u7684\u6587\u4ef6\uff0c\u4f7f\u7528 fpos_t
\u7c7b\u578b\uff0c\u5b83\u4e0d\u80fd\u8fdb\u884c\u4efb\u4f55\u8ba1\u7b97\u3002\u65bd\u5de5\u4e2d
\u672c\u9875\u9762\u6b63\u5728\u7f16\u8f91\u4e2d\u3002
"}]} \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index 2972048..3d13647 100644 Binary files a/sitemap.xml.gz and b/sitemap.xml.gz differ