From c393121f054c6c4ac02148b55cd4664d07e0727a Mon Sep 17 00:00:00 2001 From: <> Date: Mon, 1 Jan 2024 08:35:51 +0000 Subject: [PATCH] Deployed ffa5913 with MkDocs version: 1.5.3 --- index.html | 16 ++--- lalu/index.html | 10 +-- programming/daily/2023/index.html | 8 +-- programming/exam/exam/index.html | 4 +- programming/faq/index.html | 2 +- programming/topic/pointers/index.html | 6 +- .../lecture1/lecture1/index.html | 22 +++--- .../lecture1/pre_class/index.html | 64 +++++++++--------- .../lecture2/after_class/index.html | 6 +- .../lecture3/lecture3/index.html | 6 +- .../lecture4/after_class/index.html | 2 +- .../lecture4/lecture4/index.html | 10 +-- .../lecture5/lecture5/index.html | 4 +- search/search_index.json | 2 +- sitemap.xml | 58 ++++++++-------- sitemap.xml.gz | Bin 427 -> 425 bytes test/index.html | 6 +- 17 files changed, 113 insertions(+), 113 deletions(-) diff --git a/index.html b/index.html index 6736276..d47e736 100644 --- a/index.html +++ b/index.html @@ -601,8 +601,8 @@
😉 你好 ~
@@ -614,7 +614,7 @@23-24 辅学群:204755170
@@ -625,7 +625,7 @@23-24 辅学群:618962803
@@ -636,7 +636,7 @@23-24 辅学群:913067714
🏫线性代数:未竟之美
23-24 辅学群:728919863
历年卷题解
每日一题
🏫系统知识拾遗
🏫实用技能拾遗
23-24 辅学群:635023447
@@ -669,7 +669,7 @@22-23 辅学群:727382522
diff --git a/lalu/index.html b/lalu/index.html index 74fdcdf..48aa4b1 100644 --- a/lalu/index.html +++ b/lalu/index.html @@ -604,7 +604,7 @@线性代数作为大学数学的基础课,与数学分析不同,这门课的一开始就与中学数学的风格有着很大的差距,许多同学在此门课的入门与进阶方面都遇见了很大的困难。为解决此困难,本课程希望深入浅出地剖析概念与定理,帮助同学们了解线性代数“干的是什么事”,理解线性代数的本质,以及更好掌握后续的计算技巧,学好线代这门大学的入门课!
For more information about argv
and argc
, see cppreference-argc, argv.
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.
@@ -1672,7 +1672,7 @@「30」 Basic Doubly Linked List - +
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:
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
.
记住并理解一些常见的算法的平均时间复杂度、最优、最差情况复杂度:
来源:常用排序算法总结对比 | 数据结构与算法 系列教程(笔记) (zq99299.github.io)
@@ -1579,7 +1579,7 @@在前缀、中缀、后缀表达式之间进行转换的最好方法是将其想象成一个树状结构。
- +如果你读完了上面的内容,你应该能理解浮点数存储不精确的原因:
多维数组
- +我们称元素类型为数组的数组为多维数组。需要注意的是,[]
运算符是从右往左结合的。举例来说,语句 int a[2][3];
声明了一个长度为 2 的数组 a
,它的元素类型为 int [3]
;对应地,通过表达式 a[x][y]
访问数组元素时,x
与 y
的取值范围分别为 0~1 与 0~2。
指针数组
- +我们称元素类型为指针的数组为指针数组。容易想到,指针数组其实是个一维数组;不过由于其元素类型为指针,访问元素的形式与多维数组有部分相似之处。指针数组的一个典型用法是存储并传递命令行参数,即一种 main
函数声明 int main(int argc, char *argv[])
中的 argv
参数。
RISC CPU
这是一个非常简单的 CPU 的电路,它能够执行你用 0 和 1 编写的机器指令。
@@ -983,7 +983,7 @@CPU 基本结构
CPU 主要由控制单元、算术逻辑单元和寄存器组成。控制单元中有程序计数器和指令寄存器。
@@ -1011,7 +1011,7 @@机器语言
Machine Code
这是第一代编程语言,也是计算机唯一能识别的语言。上图展示了世界上第一个计算机程序,它用来找出一个数最大的因数。
@@ -1022,7 +1022,7 @@汇编语言
Assembly Language
这是第二代编程语言,其实就是机器语言的助记符。它使得程序员不用再直接与 0 和 1 打交道,程序的可读性也更强了。上图显示了将两个整数相加的汇编代码。
@@ -1033,7 +1033,7 @@高级语言
High-level Language
这是第三代编程语言,它让程序员们不用再关注计算机结构上的细节,而是将注意力转移到要解决的问题上来。
@@ -1362,7 +1362,7 @@printf("%d:%d is %d minutes after 00:00\n", hour, minute, hour * 60 + minute);
编译器在翻译这条语句时,首先根据上述语法规则把这个语句解析成下图所示的语法树,然后再根据语法树生成相应的指令。语法树的末端的是一个个 Token,每一步展开利用一条语法规则。
- +理解组合(Composition)规则是理解语法规则的关键所在,正因为可以根据语法规则任意组合,我们才可以用简单的常量、变量、表达式、语句搭建出任意复杂的程序,以后我们学习新的语法规则时会进一步体会到这一点。从上面的例子可以看出,表达式不宜过度组合,否则会给阅读和调试带来困难。
.i
为后缀。.s
为后缀。hello.o
中包含了 hello.c
中的 C 语言代码翻译成的二进制代码以及一些数据,比如字符串 Hello, world.\n
。如果使用文本编辑器打开 hello.o
,你会看见一堆乱码,其中夹杂着一些字符。因为字符在源文件和内存中都是用 ASCII 编码的,所以 ASCII 字符仍能被文本编辑器识别,但其他的机器指令和数据只会被解读为乱码。
如果运行 ./hello.o
,终端会告诉你这个文件不能被操作系统执行。
exec: Failed to execute process: './hello.o' the file could not be run by the operating system.
未定义的引用
当同学们开始使用其他库构建大型项目时,这或许会成为最头疼的问题。首先应当阅读库的使用说明,接下来搜索缺失的符号可能位于哪些库文件中。
@@ -1713,7 +1713,7 @@缺失 .dll
常用 Windows 的同学多多少少见过这个报错,可以去网上搜索相应 .dll
文件放置到正确的目录。
缺失 .so
Linux 上的动态库一般通过 apt
管理,搜索相应的包并安装即可。
真正意义上的 Terminal
在计算机发展的早期阶段,还没有像现在的 Windows 这样的图形用户界面。那时人们使用终端与计算机交互。
@@ -886,7 +886,7 @@Terminal 和 Shell 的例子
这张图展示了 Windows Terminal 和 Powershell。
@@ -897,7 +897,7 @@Terminal 和 Shell 的关系
可以将 Terminal 理解成显示器,将 Shell 理解成电脑主机。
@@ -927,7 +927,7 @@运行窗口
使用 Win + R 组合键,将会出现图中的窗口。可以在其中输入命令运行,即使是 Windows XP 都可以使用。
@@ -938,7 +938,7 @@命令提示符 CMD
在运行窗口中输入 cmd
后回车,就会出现命令提示符。命令提示符是 Windows 最基本的 Shell(与 Linux 的 bash 同等地位
Powershell
Powershell 简称 pwsh
,是 Windows 的新一代命令解释器。它的功能强大,但语法和我们将要学习且最常用的 Linux Shell 大不相同。我们在 Windows 上经常使用 pwsh
,但不用花时间去学习它。
Windows Terminal
这是 Windows 上最好的 Terminal,对各种 Shell 的显示效果都支持的很好。在 Microsoft Store 中搜索 Terminal,出现图中的选项,然后选择安装即可。它对应于 macOS 上的 iTerm。今后学习 ssh
时,你还可能会接触到 Termius。
中途可能会弹出两个窗口,显示正在修改什么东西,统统选择“是”。安装完成后,将出现如下界面
- +使用终端的一大好处是方便打开 WSL。如下图所示,点击 Ubuntu 22.04.2 LTS 或者使用 Ctrl + Shift + 5 组合键就可以方便地打开 Ubuntu 22.04。当然这是因为我安装的是 Ubuntu 22.04
的缘故,在你们的电脑中显示的应该就是 Ubuntu
。
其他 WSL 的使用方法留待你们慢慢探索了,在此不再赘述。
64 位系统直接下载 tdm64-gcc-10.3.0-2.exe 安装即可,32 位则选择 tdm-gcc-10.3.0.exe。
准备安装。对于零基础的同学,电脑里应该还没装过 tdm-gcc,选择 create 即可。
接下来就是根据 64/32 位系统选择对应的版本
选择安装路径,推荐零基础同学选择默认路径(如 64 位的 C:\TDM-GCC-64
)
接下来是要认真考虑的页面。
如果希望用更新版本的 gcc 可以使用 winlibs 编译的 mingw-gcc,或者你可以自己选择。
@@ -1157,7 +1157,7 @@Windows 修改
检查一下环境变量,Win + R 键输入 sysdm.cpl
后回车,会出现 “系统属性” 界面,选择 “高级”,如下图所示:
打开环境变量,在 “系统变量” 或者 “用户变量” 中找到 PATH 变量,在其中增加一项 tdm-gcc 的路径。例如你如果默认安装 tdm-gcc,那么路径可能就是 C:\TDM-GCC-64\bin
。
打开 VSCode 后,在左侧竖栏寻找下面这个图标:
点击这个图标就进入了插件管理。建议可以安装下面两个插件:
安装汉化插件后可能需要你手动切换显示语言。Ctrl + Shift + P,出现的搜索框中输入 Configure,选择 Configure Display Language。
随后再选择“中文 ( 简体 )”就可以完成界面汉化了。
英语基础不太好的同学有困难可以使用,英语基础比较好以及想要在日常实践中学习英语的同学建议跳过这一步。
@@ -1246,17 +1246,17 @@插件安装
这里为想要尽快上手的同学提供一个简单的使用示例。打开 VSCode(打开时没有指定工作目录
工作目录,指某个专门存放你用于某个目的的文件的文件夹。例如你可能会建立一个文件夹,专门存放所有与第一次作业相关的代码、文档、配置文件等,在你为完成第一次作业而工作时,这个文件夹就是你的工作目录
点击左侧的 Open Folder
,选择一个目录作为你的工作目录,一般会把你这个窗口所要处理的所有文件放置在这里。顶栏 Terminal > New Terminal(或终端 > 新建终端)打开 VSCode 的内部终端,功能大致与命令提示符 / 终端相同。
下图就是打开了工作目录并新建了终端的界面状态。
- +鼠标移动到工作区,按 New File
键可以新建文件,旁边有新建文件夹按键。当然,直接在左侧工作目录右键也可以新建文件 / 文件夹。
创建 test.c
,输入 Hello World 的代码并保存文件。然后在终端输入以下命令并执行:
gcc test.c
@@ -1277,7 +1277,7 @@ VSCode 使用
以下展示在 macOS 上的执行结果:
- +这里有几个注意点:
作业.c
安装 WSL 插件,如下图所示:
或者你也可以像官方文档那样,直接安装整个 Remote Development 扩展包:
其中不仅有 WSL,还包括另外三个非常有用的远程开发插件。
- +WSL: Connect to WSL in New Window
(或 WSL: 在新窗口中连接到 WSL
)如果需要在本窗口连接到 WSL,或连接到非默认的 WSL 所安装的其他 Linux 发行版,可以选择其他 WSL 的命令
- +注意上图左下角所显示的状态,表明已经连接到 WSL 所安装的 Ubuntu-22.04,接下来的开发操作和上一节就区别不大了。
确保你已经将 VSCode 添加到 PATH 环境变量中。如果已经添加,那么直接在 WSL 的命令行中你所希望作为工作目录的位置执行 diff --git a/programming_lecture/lecture2/after_class/index.html b/programming_lecture/lecture2/after_class/index.html index 71fa5ac..b94a25e 100644 --- a/programming_lecture/lecture2/after_class/index.html +++ b/programming_lecture/lecture2/after_class/index.html @@ -709,7 +709,7 @@
为了更加有效地管理内存并减少出错,现代操作系统将主存抽象为虚拟内存(Vitrual Memory)。右图展示了 Linux 系统中进程的虚拟地址空间设计。
@@ -724,7 +724,7 @@一个进程虚拟内存的内容存储在磁盘上,然后用主存作为磁盘的高速缓存。
磁盘上的数据被分割成虚拟页(Virtual Page),主存被分割成物理页(Physical Page)。虚拟页和物理页的大小相同,通常为 4KB。这些页是磁盘和主存之间的传输单元。
- +任意时刻,虚拟页面可能处于以下三种状态之中:
CPU 不会直接使用物理地址(Physical Address)访问主存,而是使用虚拟地址(Virtual Address
printf()
中转换说明的意义 ¶转换说明实际上是在将以二进制存存储在计算机中的值转换成一些列字符便于显示。转换实际上是一种翻译说明。
@@ -1348,13 +1348,13 @@等 ): Unicode Transformation Format,可变长度编码,通常使用1~4字节为每个字符编码,兼容ASCII编码,这是一种Unicode的一种转换格式。文件编码
现在在内存中通常以 UTF-16(Windows API 大量偏好 UTF-16 LE 编码的字符串作为参数 ) 来储存,保存到文件中替换为 UTF-8 等格式,可以压缩空间。
所有文件的内容都以二进制形式存储。但是,如果文件最初使用二进制编码的字符 ( 例如 ASCII 码 ) 表示文本,该文件就是文本文件,其中包含文本内容。如果文件中的二进制值代表及其语言代码或数值数据,该文件是二进制文件,其中包含二进制内容。
Unix 使用同一种文件格式处理文本文件和二进制文件的内容。Unix 目录中有一个统计文件大小的计数,程序可以根据该计数确定是否读到文件尾。
C 语言提供两种访问文件的途径:二进制模式和文本模式。在二进制模式中,程序可以访问文件的每个字节,而在文本模式中,程序所见的内容和文件的实际内容不同。程序以文本模式读取文件时,把本地环境表示的行末尾或文件结尾映射成 C 模式。
- +这告诉我们文本和二进制模式不能随意混用,否则可能会出现正确性上的问题。
学习 C 标准库时,我们会接触到很多 C 标准中的规范性的严谨地语句,初读时可能让你觉得非常拗口和难以理解,让我们来读几条。
diff --git a/programming_lecture/lecture4/lecture4/index.html b/programming_lecture/lecture4/lecture4/index.html index 6d593e8..7a1d9f8 100644 --- a/programming_lecture/lecture4/lecture4/index.html +++ b/programming_lecture/lecture4/lecture4/index.html @@ -1134,7 +1134,7 @@0x20
~ 0x7E
0x00
~ 0x1F
和 0x7F
小提示
@@ -1168,7 +1168,7 @@<ctype.h>
中的函数对 ASCII 字符大致作了如下划分:
控制字符那些不用管,不要求的函数不用管。只要记得 isspace
和 isblank
的区别就行了。
<ctype.h>
的实现:宏与位运算
_Ctype
<ctype.h>
的实现:宏与位运算
_Toupper
还记得 double
表示的范围吗?
从上图你可以看到,浮点数所能表示的数值,实际上是数轴上的一个个点。毕竟只有 64 个 bit 嘛,只能编码有限个点。
double
类型(8 字节 IEEE 浮点数)所能表示的极限值为:
所以,链表其实就是以下的东西的结合:
head
,告诉我们从哪里开始遍历整个链表。剩下情况 \(3\) 还要特殊判断。我们先找到要删除的位置。回忆一下删除的过程,我们需要记录当前需要被删除的节点的指针 prev
:
Node *deleteNode(Node* head, int key) {
if (!head) return NULL;
if (head->data == key){
diff --git a/search/search_index.json b/search/search_index.json
index 14dbcdf..9955f40 100644
--- a/search/search_index.json
+++ b/search/search_index.json
@@ -1 +1 @@
-{"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 \u5386\u5e74\u5377\u9898\u89e3 \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":" - \u6bcf\u4e2a\u957f\u5b66\u671f\u521d\uff0c\u6211\u4eec\u4f1a\u62db\u52df\u4f18\u79c0\u7684\u5b66\u957f\u5b66\u59d0\u4f5c\u4e3a\u8f85\u5b66\u5b66\u957f\u3002\u6240\u6709\u8f85\u5b66\u5b66\u957f\u90fd\u4f1a\u5728\u8f85\u5b66\u7fa4\u5185\u8fdb\u884c\u7b54\u7591\uff0c\u90e8\u5206\u8f85\u5b66\u5b66\u957f\u4f1a\u8fdb\u884c\u6388\u8bfe\u3002
- \u6388\u8bfe\u4e00\u822c\u4f9d\u7167\u8bfe\u7a0b\u8fdb\u5ea6\u8fdb\u884c\uff0c\u5bf9\u4e13\u9898\u7684\u77e5\u8bc6\u8fdb\u884c\u603b\u7ed3\u590d\u4e60\uff0c\u6216\u662f\u5728\u671f\u4e2d\u671f\u672b\u8003\u524d\u8fdb\u884c\u590d\u4e60\u548c\u4e60\u9898\u8bb2\u89e3\u3002\u5f00\u5c55\u6388\u8bfe\u524d\u4e00\u5468\uff0c\u8f85\u5b66\u7fa4\u5185\u4f1a\u53d1\u5e03\u6388\u8bfe\u4fe1\u606f\u548c\u62a5\u540d\u95ee\u5377\uff0c\u540c\u5b66\u4eec\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u9009\u62e9\u53c2\u52a0\u3002
- \u8f85\u5b66\u6388\u8bfe\u7684\u5f62\u5f0f\u81ea\u7531\uff0c\u4e0d\u8bba\u4f60\u662f\u5426\u586b\u5199\u95ee\u5377\uff0c\u90fd\u53ef\u4ee5\u53c2\u52a0\u6388\u8bfe\u3002\u4f60\u53ef\u4ee5\u968f\u65f6\u6765\u5230\u8bfe\u5802\uff0c\u4e5f\u53ef\u4ee5\u968f\u65f6\u79bb\u5f00\uff0c\u4f46\u8bf7\u4e0d\u8981\u6253\u6270\u5230\u5176\u4ed6\u540c\u5b66\uff0c\u5e76\u6ce8\u610f\u7ef4\u62a4\u6559\u5ba4\u73af\u5883\u536b\u751f\u3002\u53c2\u4e0e\u8f85\u5b66\u7684\u540c\u5b66\u6bcf\u6b21\u80fd\u591f\u83b7\u5f97\u53c2\u4e0e\u5ea6\u7eaa\u5b9e\u5206\u6570 0.5 \u5206\uff0c\u6bcf\u4e2a\u957f\u5b66\u671f\u6700\u591a\u901a\u8fc7\u8f85\u5b66\u7cfb\u5217\u6d3b\u52a8\u83b7\u5f97 1 \u5206\u3002
- \u6b64\u5916\uff0c\u90e8\u5206\u8bfe\u7a0b\u5f00\u8bbe\u4e86\u8f85\u5b66\u7cbe\u54c1\u8bfe\u7a0b\u3002\u6388\u8bfe\u5b66\u957f\u5b66\u59d0\u4ee5\u8bfe\u7a0b\u7ec4\u7684\u5f62\u5f0f\u7ec4\u7ec7\u8d77\u6765\uff0c\u7f16\u5199\u7cfb\u7edf\u7684\u914d\u5957\u7684\u8bb2\u4e49\uff0c\u8fdb\u884c\u8fde\u8d2f\u7684\u6388\u8bfe\uff0c\u6df1\u5ea6\u5951\u5408\u7afa\u9662\u8363\u8a89\u8bfe\u7a0b\u7684\u5185\u5bb9\u3002\u6211\u4eec\u5e0c\u671b\u80fd\u643a\u624b\u4f18\u79c0\u7684\u5b66\u957f\u5b66\u59d0\uff0c\u4e3a\u7afa\u9662\u5b66\u5b50\u6253\u9020\u9ad8\u8d28\u91cf\u7684\u8f85\u5b66\u8bfe\u7a0b\u3002
"},{"location":"#_3","title":"\u5f55\u64ad/\u56de\u653e","text":"\u81f4\u8c22\uff1a\u7afa\u53ef\u6862\u5b66\u9662\u5168\u5a92\u4f53\u5de5\u4f5c\u5ba4
\u5728\u7afa\u9662\u5168\u5a92\u4f53\u7684\u4eba\u5458\u548c\u8bbe\u5907\u652f\u6301\u4e0b\uff0c\u5927\u90e8\u5206\u8f85\u5b66\u6388\u8bfe\u90fd\u6709\u4e86\u4f18\u8d28\u7684\u5f55\u64ad\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\u5f55\u64ad\u90fd\u5c06\u4e0a\u4f20\u5230\u7afa\u9662\u5b66\u6307\u7684 Bilibili \u8d26\u53f7\u4e2d\uff0c\u70b9\u51fb\u5361\u7247\u5373\u53ef\u8df3\u8f6c\u5230 Bilibili \u9875\u9762\u3002
"},{"location":"#_4","title":"\u8d21\u732e","text":"\u5982\u679c\u60a8\u613f\u610f\u53c2\u4e0e\u8be5\u7f51\u7ad9\u7684\u5efa\u8bbe\uff0c\u8bf7\u5230 GitHub \u4e2d\u672c\u9879\u76ee\u7684\u4ed3\u5e93\u8fdb\u884c\u8d21\u732e\u3002\u5411\u4ed3\u5e93\u63d0\u4ea4\u524d\uff0c\u8bf7\u67e5\u770b\u8d21\u732e\u9875\u9762\u3002
"},{"location":"#_5","title":"\u5927\u6587\u4ef6\u5b58\u653e\u5904","text":"\u8d85\u8fc7 20MB \u7684\u5927\u6587\u4ef6\u90fd\u653e\u7f6e\u5728\u5b66\u4e1a\u6307\u5bfc\u4e2d\u5fc3\u516c\u5171\u7f51\u76d8\u7684\u5206\u4eab\u94fe\u63a5\u4e2d\uff0c\u540c\u5b66\u4eec\u53ef\u4ee5\u70b9\u51fb\u4e0b\u9762\u7684\u94fe\u63a5\u67e5\u770b\u3002\u5982\u679c\u6709\u9700\u8981\u653e\u7f6e\u7684\u5927\u6587\u4ef6\uff0c\u8bf7\u8054\u7cfb\u5b66\u4e1a\u6307\u5bfc\u4e2d\u5fc3\u7684\u540c\u5b66\u4e0a\u4f20\u3002
- \u767e\u5ea6\u7f51\u76d8-\u7afa\u9662\u8f85\u5b66\u8d44\u6599
"},{"location":"#_6","title":"\u76f8\u5173\u7f51\u7ad9","text":" - \u6d59\u6c5f\u5927\u5b66\u56fe\u7075\u73ed\u8bfe\u7a0b\u5b66\u4e60\u6307\u5357
- \u6d59\u6c5f\u5927\u5b66\u8bfe\u7a0b\u653b\u7565\u5171\u4eab\u8ba1\u5212
"},{"location":"contribute/","title":"\u8d21\u732e","text":"\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
- \u6bcf\u4e2a\u8f85\u5b66\u79d1\u76ee\u7684\u4e3b\u9875\u653e\u7f6e\u662f
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\u3002 - \u6bcf\u5e74\u7684\u8f85\u5b66\u8d44\u6599\u653e\u7f6e\u5728\u540c\u4e00\u4e2a\u6587\u4ef6\u5939\u4e2d\uff0c\u4f9d\u6b21\u547d\u540d\u4e3a
lecture1_contents.pdf
\u7b49\u3002 - \u6240\u6709\u5386\u5e74\u5377\u53ca\u5176\u7b54\u6848\u653e\u7f6e\u5728
exam
\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/2023-2024/analysis_lecture1_sequence_limits/","title":"\u7b2c\u4e00\u8bb2 \u6570\u5217\u6781\u9650","text":" - PDF \u7248
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_2","title":"\u5b9e\u6570\u5b8c\u5907\u6027\u5b9a\u7406","text":""},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_3","title":"\u8981\u6c42","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
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_4","title":"\u6982\u5ff5\u53d9\u8ff0","text":" -
\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} \\]
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_5","title":"\u5b9a\u7406\u53d9\u8ff0","text":" -
\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} \\]
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_6","title":"\u5e38\u7528\u6280\u5de7","text":" -
\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
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_7","title":"\u4f8b\u9898&\u4e60\u9898","text":" - \u7528\u786e\u754c\u539f\u7406\u8bc1\u660e\u5355\u8c03\u6709\u754c\u539f\u7406\u3001\u81f4\u5bc6\u6027\u5b9a\u7406\u3001Cauchy\u51c6\u5219\u3001\u95ed\u533a\u95f4\u5957\u5b9a\u7406\u3001\u6709\u9650\u8986\u76d6\u5b9a\u7406\u3002
- \u7528\u5355\u8c03\u6709\u754c\u5b9a\u7406\u8bc1\u660e\u95ed\u533a\u95f4\u5957\u5b9a\u7406\uff0c\u7528\u95ed\u533a\u95f4\u5957\u5b9a\u7406\u8bc1\u660e\u6709\u9650\u8986\u76d6\u5b9a\u7406\uff1b\u7528\u81f4\u5bc6\u6027\u5b9a\u7406\u8bc1\u660eCauchy\u6536\u655b\u51c6\u5219\u3002
- \\(f,g\u4e3aD\u4e0a\u6709\u754c\u51fd\u6570,\\text{pf:}\\inf\\{f(x)+g(x)\\}\\le\\inf{f(x)}+\\sup{g(x)}\\)
- \u8bbe\\(f(x)\u5728[0,1]\u4e0a\u9012\u589e,f(0)>0,f(1)<1,\u6c42\u8bc1:\\exists x_0\\in(0,1),\u4f7f\u5f97f(x_0)=x_0^2\\) (Hint:\u786e\u754c\u539f\u7406or\u533a\u95f4\u5957\u5b9a\u7406)
- \u8bbe\\(f(x)\\)\u5728\\([a,b]\\)\u4e0a\u6709\u5b9a\u4e49\u4e14\u5728\u6bcf\u4e00\u70b9\u5904\u51fd\u6570\u7684\u6781\u9650\u5b58\u5728\uff0c\u6c42\u8bc1\\(f(x)\\)\u5728\\([a,b]\\)\u4e0a\u6709\u754c (Hint:\u6709\u9650\u8986\u76d6)
- \\(\u8bbef(x)\u5728(a,b)\u5185\u6709\u5b9a\u4e49\uff0c\\forall\\xi\\in(a,b),\\exists\\delta>0,\u5f53x\\in(\\xi-\\delta,\\xi+\\delta)\\cap(a,b)\u65f6,\\)\u6709\u5f53\\(x<\\xi\\)\u65f6,\\(f(x)<f(\\xi), \u5f53x>\\xi\\)\u65f6,\\(f(x)>f(\\xi)\\).\u8bf7\u8bc1\u660e:\\(f(x)\u5728(a,b)\\)\u5185\u4e25\u683c\u9012\u589e (Hint:\u6709\u9650\u8986\u76d6)
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_8","title":"\u6570\u5217\u6781\u9650","text":""},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_9","title":"\u8981\u6c42","text":" - \u4ece\u5c0f\u6d4b\u7684\u89d2\u5ea6\u6765\u8bf4\uff0c\u6982\u5ff5\uff0c\u5b9a\u7406\u4ee5\u53ca\u5224\u65ad\u9898\u662f\u6bd4\u8f83\u91cd\u8981\uff08\u641e\u8111\u5b50\uff09\u7684\uff0c\u5f53\u7136\u4e5f\u4f1a\u6709\u8ba1\u7b97\u9898
- \u671f\u672b\u8003\u8bd5\u53ef\u80fd\u4f1a\u51fa1-2\u9053\u6c42\u6781\u9650\uff0c1\u9053\u975e\u5e38\u7b80\u5355\u7684\u6781\u9650\u8bc1\u660e\u9898\uff08\u9644\u5728\u5b9a\u7406\u53d9\u8ff0\u4e0a\uff09
- \u8ba1\u7b97\u4e5f\u9700\u8981\u638c\u63e1\uff0c\u4f46\u662f\u6280\u5de7\u6027\u5f3a\u7684\u53ef\u4ee5\u4e0d\u638c\u63e1
- \u5b66\u597d\u6570\u5217\u6781\u9650\u5bf9\u51fd\u6570\u6781\u9650\u548c\u7ea7\u6570\u90fd\u5f88\u6709\u5e2e\u52a9\uff0c\u800c\u5b66\u597d\u4e86\u51fd\u6570\u6781\u9650\u5c31\u53ef\u4ee5\u5b66\u597d\u5bfc\u6570\u548c\u79ef\u5206\uff0c\u7136\u540e\u4f60\u5c31\u5b66\u4f1a\u4e86\u6570\u52061
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_10","title":"\u6982\u5ff5\u53d9\u8ff0","text":" - \u6570\u5217\u6781\u9650\uff08\\(\\epsilon-N\\)\u8bed\u8a00\uff09
\\[ \\forall\\epsilon>0,\\exists N>0,\\forall n>N,|x_n-A|<\\epsilon\u79f0\\lim_{x\\rightarrow\\infty}x_n=A\\\\ *:|x_n-A|<f(\\epsilon),f(x)\u6ee1\u8db3\\lim _{x\\rightarrow0}f(x)=0\u5373\u53ef \\] - \u6570\u5217\u53d1\u6563
\\[ \\forall A\\in R,\\exists\\epsilon_0>0,\\forall N>0,\\exists n_N>N,|x_n-A|\\ge\\epsilon_0 \\] -
\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} \\]
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_11","title":"\u5b9a\u7406\u53d9\u8ff0","text":" -
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
\\[ \\begin{align} a_n\u6536\u655b& \\iff\\forall \\epsilon>0,\\exists N>0,\\forall m,n>N,\u5747\u6709|a_m-a_n|<\\epsilon \\\\ & \\iff \\forall \\epsilon>0,\\exists N>0,\\forall n>N,p>0,\u5747\u6709|a_{n+p}-a_n|<\\epsilon \\\\ \u5426\u5b9a\u5f62\u5f0f:a_n\u53d1\u6563& \\iff\\exists\\epsilon_0>0,\\forall N,\\exists n_0>N,p>0,|x_{n_0+p}-x_{n_0}|\\ge\\epsilon_0 \\end{align} \\]"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_12","title":"\u5e38\u7528\u6280\u5de7","text":" -
\u4e00\u4e9b\u5173\u7cfb\u94fe\uff1a
- \\(n\\rightarrow\\infty\u65f6\\)
\\[ \\log\\log n\\ll \\log n \\ll n^a\\ll b^n\\ll n!\\ll n^n\\quad(a,b>0) \\] - \\(x\\rightarrow0\u65f6\\)
\\[ \\begin{align} x \\sim &\\sin x\\sim \\tan x \\sim \\arcsin x\\sim \\arctan x \\\\ \\sim &\\ln{(1+x)} \\sim \\text{e}^x-1 \\sim \\frac{a^x-1}{\\ln a}\\sim \\frac{(1+x)^b-1}b \\quad(a>0,b\\neq0)\\\\ & 1-\\cos x \\sim \\frac12 x^2 \\end{align} \\] -
\u8bc1\u660e\u6570\u5217\u6781\u9650\u5b58\u5728\uff1a
- \u5b9a\u4e49\uff08\\(\\epsilon-N\\)\u65b9\u6cd5\uff09
\u6280\u5de7\uff1a\u653e\u5927\u6cd5(\u5e38\u7528)/\u5206\u6b65\u6cd5/\u6784\u9020\u5f62\u5f0f\u7c7b\u4f3c\u7684\u9879/\u62df\u5408\u6cd5(\u6280\u5de7\u6027\u8f83\u5f3a)
-
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
- Cauchy\u547d\u9898\u7684\u5426\u5b9a\u5f62\u5f0f
- \u5b50\u5217\u4e0d\u6536\u655b\u6216\u6536\u655b\u4e8e\u4e0d\u540c\u7684\u6570
-
\u6c42\u6570\u5217(\u51fd\u6570)\u6781\u9650\uff1a
- \u6781\u9650\u7684\u8fd0\u7b97\u6027\u8d28
\u4e00\u4e9b\u91cd\u8981\u6781\u9650\uff1a\\(\\lim\\limits_{n\\rightarrow\\infty}n^\\frac1n=1\\)\uff0c\\(\\lim\\limits_{n\\rightarrow\\infty}(1+\\frac1n)^n=e\\)
-
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
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_13","title":"\u4f8b\u9898&\u4e60\u9898","text":" -
\u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u5b50\u5217\u7684\u547d\u9898
- \u8bbe\\(\\{a_n\\}\\)\u662f\u4e00\u4e2a\u6570\u5217\uff0c\u82e5\u5728\u4efb\u4e00\u5b50\u5217\\(\\{a_{n_k}\\}\\)\u4e2d\u5747\u5b58\u5728\u6536\u655b\u5b50\u5217\\(\\(\\{a_{n_{k_r}}\\}\\)\\),\u5219\\(\\(\\{a_n\\}\\)\\)\u5fc5\u6536\u655b
- \\(\\{a_n\\}\u5355\u8c03\u9012\u589e\uff0c\\{a_{n_k}\\}\u4e3a\u5176\u4e2d\u4e00\u4e2a\u5b50\u5217\uff0c\\lim\\limits_{k\\rightarrow\\infty}a_{n_k}=a,\u5219\\lim\\limits_{n\\rightarrow\\infty}{a_n}=a\\)
- \\(\\{a_{2k}\\}\\{a_{2p+1}\\}\\{a_{2023t+2024}\\}\u5747\u6536\u655b\uff0c\u5219\\{a_n\\}\u6536\u655b\\)
- \\(\\{a_{2k}\\}\\{a_{2t+1}\\}\\{a_{6p+5}\\}\u5747\u6536\u655b\uff0c\u5219\\{a_n\\}\u6536\u655b\\)
-
\u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u65e0\u7a77\u5c0f\u91cf\u7684\u547d\u9898
- \u65e0\u7a77\u591a\u4e2a\u65e0\u7a77\u5c0f\u91cf\u4e4b\u548c\u662f\u65e0\u7a77\u5c0f\u91cf
- \u65e0\u7a77\u591a\u4e2a\u65e0\u7a77\u5c0f\u91cf\u4e4b\u79ef\u662f\u65e0\u7a77\u5c0f\u91cf
- \u65e0\u7a77\u5c0f\u91cf\u4e0e\u6709\u754c\u91cf\u4e4b\u79ef\u4e3a\u65e0\u7a77\u5c0f\u91cf
-
\u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u6570\u5217\u6781\u9650\u7684\u547d\u9898
- \u6570\u5217\\(a_n\\)\u6536\u655b\\(\\iff \\forall p\\in N,\\lim\\limits_{n\\rightarrow+\\infty}{|a_{n+p}-a_n|=0}\\)
- \\(\\lim\\limits_{n\\rightarrow\\infty}x_n=A\\iff\\forall k\\in \\text{N},\\exists N>0,\\forall n>N,|x_n-A|<\\frac1k\\)
- \\(a_n\u6536\u655b \\iff \\exists N>0,\\forall \\epsilon>0,\\forall m,n>N,\u5747\u6709|a_m-a_n|<\\epsilon\\)
-
\u91cd\u8981\u7684\u4e8c\u7ea7\u7ed3\u8bba\uff1a
\\[ Cauchy\u5b9a\u7406:\\lim_{n\\rightarrow\\infty}x_n=A,\u5219\\lim_{n\\rightarrow\\infty}\\frac{x_1+x_2+...+x_n}{n}=A \\] -
\\(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
- \\(x_n=\\cos\\frac x2\\cos\\frac x{2^2}\\cdots\\cos\\frac x{2^n}\\)
- \\(x_n=(\\frac{\\sqrt[n]a+\\sqrt[n]b}{2})^n\\)
- \\(x_n=\\frac 1{\\sqrt[n]{n!}}\\)
- \\(x_n={(n!)}^{\\frac1{n^2}}\\)
- \\(x_n=\\sqrt[6]{x^6+x^5}-\\sqrt[6]{x^6-x^5}\\)
-
(2019(?)\u5e74\u6570\u52061\u671f\u672b)
\\[ \\begin{align} & \u5bf9\u4e8e\u6570\u5217x_0=a,0<a<\\frac\\pi2,x_n=\\sin x_{n-1}(n=1,2,\\cdots). \\\\ &\\text{pf:}(1)\\lim\\limits_{n\\rightarrow\\infty}x_n=0;(2)\\lim\\limits_{n\\rightarrow\\infty}{\\sqrt\\frac n3}x_n=1 \\end{align} \\]"},{"location":"analysis/analysis1_paper/22test1_answer/","title":"22\u6570\u5206\u5c0f\u6d4b\u7b54\u6848","text":"\u9898\u76ee\u3001\u9009\u9879\u987a\u5e8f\u53c2\u8003\u5c0f\u6d4b1
- D
- AC
- B
- A
- BCD
- ABD
- B
- B
- A (\u805a\u70b9\u5e94\u8be5\u4e0d\u8981\u6c42\uff0c\u53ef\u4ee5\u5ffd\u7565)
- C
"},{"location":"calculus/","title":"\u5fae\u79ef\u5206\u8f85\u5b66","text":"\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u5fae\u79ef\u5206\u7248\u5757 \ud83e\udd17\u3002
"},{"location":"calculus/#2023-2024","title":"2023-2024 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad 1 Oct.22 \u6781\u9650\u4e0e\u51fd\u6570\u7684\u8fde\u7eed\u6027 \u6df7\u5408 2106 \u5f20\u5fd7\u5fc3 \u8bb2\u4e49 \u7b54\u6848 Bilibili 2 Nov.5 \u671f\u4e2d\u590d\u4e60 \u6c42\u5316 2201 \u5218\u5b50\u6db5 \u8bb2\u4e49\u7b54\u6848 Bilibili 3 Dec.3 \u5fae\u5206\u4e2d\u503c\u5b9a\u7406\u548c\u4e0d\u5b9a\u79ef\u5206 \u5f3a\u533b 2101 \u5362\u601d\u7426 \u8bb2\u4e49 Bilibili"},{"location":"chemistry/","title":"\u666e\u901a\u5316\u5b66\u8f85\u5b66","text":"\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u666e\u901a\u5316\u5b66\u7248\u5757\ud83e\udd17\u3002
"},{"location":"chemistry/#_2","title":"\u8f85\u5b66\u8d44\u6599\u5f52\u6863","text":""},{"location":"chemistry/#2023-2024","title":"2023-2024 \u5b66\u5e74 \u79cb\u51ac\u5b66\u671f","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad 3 Dec.12 \u7535\u5316\u5b66\u4e0e\u7269\u8d28\u7ed3\u6784 \u6df7\u5408 2102 \u674e\u822a\u5947 \u8bb2\u4e49 Bilibili"},{"location":"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":" - \u5434\u4e00\u822a \u56fe\u70752001
- \u6885\u654f\u70ab \u56fe\u70752201
- \u6f58\u90b9\u7eac \u5f3a\u72692101
- \u859b\u8fb0\u7acb \u56fe\u70752203
"},{"location":"lalu/#_4","title":"\u8bfe\u7a0b\u5f55\u64ad","text":"W \u4ee3\u8868\u9002\u914d\u5434\u5fd7\u7965\u73ed\uff0cT \u4ee3\u8868\u9002\u914d\u8c08\u4e4b\u5955\u73ed\uff0cH \u4ee3\u8868\u5408\u73ed\u4e0a\u8bfe\u3002
\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2\u4eba \u5f55\u64ad\u5730\u5740 \u8bb2\u4e49 W1 Oct.29 \u5f15\u5165\uff1a\u7ebf\u6027\u7a7a\u95f4 \u6885\u654f\u70ab Bilibili LALU T1 Oct.29 \u5f15\u5165\uff1a\u7ebf\u6027\u7a7a\u95f4 \u5434\u4e00\u822a Bilibili LALU H2 Nov.18 \u7ebf\u6027\u6620\u5c04\u53ca\u5176\u77e9\u9635\u8868\u793a \u5434\u4e00\u822a Bilibili LALU H3 Dec.3 \u77e9\u9635\u7684\u79e9\u4e0e\u5206\u5757\u77e9\u9635 \u6f58\u90b9\u7eac Bilibili \u8bb2\u4e49 H4 Dec.16 \u884c\u5217\u5f0f\u548c\u7ebf\u6027\u65b9\u7a0b\u7ec4 \u859b\u8fb0\u7acb Bilibili LALU h5 Dec.30 \u671f\u672b\u590d\u4e60 \u5434\u4e00\u822a Bilibili (\u5f85\u4e0a\u4f20) PPT"},{"location":"lalu/#_5","title":"\u8bfe\u7a0b\u5b89\u6392","text":" - \u7b2c\u4e00\u8bb2 \u5f15\u5165 \u7ebf\u6027\u7a7a\u95f4
- \u9884\u8ba1\u7b2c 6 \u5468\uff0c\u5206\u4e24\u4e2a\u6559\u5b66\u73ed\u5f00\u8bfe\uff0c\u5434\u5fd7\u7965\u73ed\u4e0a\u5b8c\u5185\u79ef\uff0c\u8c08\u4e4b\u5955\u73ed\u4e0d\u4e0a\u5185\u79ef\uff08\u6216\u5434\u5fd7\u7965\u7b2c 5 \u5468\uff0c\u8c08\u4e4b\u5955\u7b2c 6 \u5468\uff09
- \u8bb2\u4e49 1-2 \u8bb2\u91cd\u70b9\u5728\u4e8e\u4f20\u8fbe\u4e00\u4e9b\u57fa\u672c\u601d\u60f3\uff0c\u4f4e\u8d77\u70b9\u5f15\u5165\u4f46\u9ad8\u843d\u70b9
- \u8bb2\u4e49\u7b2c 3 \u8bb2\u300a\u6709\u9650\u7ef4\u7ebf\u6027\u7a7a\u95f4\u300b\u4e00\u8bb2\u5efa\u8bae\u6309\u7167\u601d\u7ef4\u5bfc\u56fe\u8fdb\u884c\u5b8c\u6574\u4ecb\u7ecd
- \u7b2c\u4e8c\u8bb2 \u7ebf\u6027\u6620\u5c04 \u671f\u4e2d\u590d\u4e60
- \u9884\u8ba1\u7b2c 8 \u5468\uff0c\u5206\u4e24\u4e2a\u6559\u5b66\u73ed\u5f00\u8bfe\uff0c\u5434\u5fd7\u7965\u73ed\u4e0a\u5b8c\u77e9\u9635\u4e58\u6cd5\uff08\u77e9\u9635\u90e8\u5206\u53ef\u4ee5\u7565\u8bb2\uff0c\u4e4b\u540e\u6709\u4e13\u9898\uff09\uff0c\u8c08\u4e4b\u5955\u73ed\u4e0a\u5230\u7ebf\u6027\u6620\u5c04\u7ed3\u675f
- \u5efa\u7acb\u5bf9\u7ebf\u6027\u7a7a\u95f4\u4e0e\u7ebf\u6027\u6620\u5c04\u7684\u6574\u4f53\u8ba4\u8bc6\uff0c\u7406\u89e3\u4e24\u4e2a\u7ef4\u6570\u516c\u5f0f\uff0c\u7406\u89e3\u540c\u6784
- \u590d\u4e60\u90e8\u5206\u5bf9\u7279\u5b9a\u7684\u9898\u578b\u8fdb\u884c\u8bb2\u89e3\uff1a\u65b9\u7a0b\u7ec4\uff08\u542b\u53c2\uff09\uff0c\u6781\u5927\u7ebf\u6027\u65e0\u5173\u7ec4\uff0c\u76f4\u548c\u8bc1\u660e\uff0c\u50cf\u7a7a\u95f4\u6838\u7a7a\u95f4\u8bc1\u660e\u7b49\uff08\u7ed3\u5408\u5386\u5e74\u5377\u548c\u8bb2\u4e49\uff09
- \u7b2c\u4e09\u8bb2 \u77e9\u9635
- \u9884\u8ba1\u7b2c 11 \u5468\uff0c\u53ef\u4ee5\u5408\u73ed\u6559\u5b66\uff08\u6216\u5434\u5fd7\u7965\u7b2c 10 \u5468\uff0c\u8c08\u4e4b\u5955\u7b2c 11 \u5468\uff09
- \u91cd\u70b9\u5728\u4e09\u4e2a\u5185\u5bb9\uff1a\u4e00\u4e2a\u662f\u7ebf\u6027\u6620\u5c04\u77e9\u9635\u8868\u793a\uff0c\u4e00\u4e2a\u662f\u77e9\u9635\u7684\u79e9\u7684\u6574\u4f53\u8ba4\u8bc6\uff0c\u6700\u540e\u662f\u4e00\u4e9b\u4e0a\u8bfe\u4e0d\u592a\u8bb2\u7684\u6280\u5de7
- \u7b2c\u56db\u8bb2 \u884c\u5217\u5f0f \u7ebf\u6027\u65b9\u7a0b\u7ec4
- \u9884\u8ba1\u7b2c 13 \u5468\uff0c\u53ef\u4ee5\u5408\u73ed\u6559\u5b66
- \u884c\u5217\u5f0f\u91cd\u70b9\u5728\u7075\u6d3b\u8fd0\u7528\u4e00\u4e9b\u6027\u8d28\uff0c\u884c\u5217\u5f0f\u8ba1\u7b97\u89c6\u60c5\u51b5\u7ebf\u4e0b\u6388\u8bfe\u53ef\u4ee5\u629b\u5f03\uff08\u51c6\u5907\u7ebf\u4e0a\u8d44\u6599\u66ff\u4ee3\uff09\uff0c\u7ebf\u6027\u65b9\u7a0b\u7ec4\u91cd\u70b9\u5728\u4f53\u73b0\u300a\u671d\u82b1\u5915\u62fe\u300b\u7684\u6838\u5fc3\u601d\u60f3\uff0c\u7ebf\u6027\u65b9\u7a0b\u7ec4\u7406\u8bba\u610f\u5c3d
- \u7b2c\u4e94\u8bb2 \u7279\u5f81\u503c\u4e0e\u77e9\u9635\u6807\u51c6\u5f62 \u671f\u672b\u590d\u4e60
- \u9884\u8ba1\u7b2c 15 \u5468\uff0c\u53ef\u4ee5\u5408\u73ed\u6559\u5b66\uff0c\u4e5f\u53ef\u4ee5\u6309\u96be\u5ea6\u5206\u5c42\u6559\u5b66
- \u7279\u5f81\u503c\u4e0e\u77e9\u9635\u6807\u51c6\u5f62\u90e8\u5206\u6839\u636e\u73ed\u7ea7\u6388\u8bfe\u8fdb\u5ea6\u786e\u5b9a\u5185\u5bb9\uff0c\u5982\u679c\u65f6\u95f4\u6709\u9650\u6216\u6559\u5b66\u73ed\u6ca1\u6709\u4e0a\u5b8c\u6b63\u8bfe\uff0c\u90e8\u5206\u5185\u5bb9\u79fb\u81f3\u7ebf\u4e0a\u51c6\u5907\u89c6\u9891
- \u671f\u672b\u590d\u4e60\u90e8\u5206\u6574\u7406\u672c\u5b66\u671f\u5b8c\u6574\u601d\u8def\uff0c\u7ed3\u5408\u5386\u5e74\u5377\u548c\u8bb2\u4e49\u8bb2\u89e3\u6700\u6838\u5fc3\u7684\u9898\u578b
"},{"location":"lalu/#_6","title":"\u8bfe\u7a0b\u8bb2\u4e49","text":"\u8bb2\u4e49\uff08v0.3\uff09\u7b54\u6848\uff08v0.3\uff09 LALU \u8bfe\u7a0b\u7684\u8bb2\u4e49\u5b58\u653e\u5728\u4e0b\u9762\u7684\u4ed3\u5e93\u4e2d\uff0c\u4f60\u53ef\u4ee5\u70b9\u51fb\u56fe\u7247\u8df3\u8f6c\u5230\u4ed3\u5e93\u9875\u9762\u3002\u6b22\u8fce\u63d0\u51fa issue \u548c pull request\u3002
\u70b9\u51fb\u4e0b\u9762\u7684\u94fe\u63a5\u53ef\u4ee5\u4e0b\u8f7d\u8bb2\u4e49\u7684\u6700\u65b0 Release \u7248\u672c\uff1a
- \u70b9\u51fb\u4e0b\u8f7d\u8bb2\u4e49
- \u70b9\u51fb\u4e0b\u8f7d\u8bb2\u4e49\u7b54\u6848
"},{"location":"other/","title":"\u5176\u4ed6\u8d44\u6e90","text":""},{"location":"other/#_2","title":"\u6982\u7387\u8bba\u4e0e\u6570\u7406\u7edf\u8ba1","text":""},{"location":"other/#_3","title":"\u5c0f\u6d4b\u9898\u5e93","text":"\u5b66\u671f \u8bd5\u5377 23\u79cb\u51ac \u5c0f\u6d4b\u4e00(1)\u5c0f\u6d4b\u4e8c(1)/\u5c0f\u6d4b\u4e8c(2)/\u5c0f\u6d4b\u4e8c(3)\u5c0f\u6d4b\u4e09(1)/\u5c0f\u6d4b\u4e09(2) 23\u6625\u590f \u5c0f\u6d4b\u4e00(1)"},{"location":"physics/","title":"\u666e\u7269\u8f85\u5b66","text":"\u6b22\u8fce\u6765\u5230\u7afa\u9662\u666e\u7269\u8f85\u5b66\u7248\u5757\ud83e\udd17\u3002\u4f60\u53ef\u4ee5\u5728\u5de6\u4fa7\u5bfc\u822a\u680f\u4e2d\u8be6\u7ec6\u6d4f\u89c8\u672c\u6a21\u5757\u7684\u5185\u5bb9\u3002
"},{"location":"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
- \u6307\u9488\u6982\u89c8
- \u51fd\u6570\u6307\u9488\u8ba4\u8bfb
"},{"location":"programming/#faq","title":"FAQ","text":"\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":" - CPPReference\uff1aC/C++ \u53c2\u8003\u624b\u518c\uff0c\u53ef\u4ee5\u67e5\u627e C/C++ \u8bed\u6cd5\u548c\u6807\u51c6\u5e93\u7684\u7528\u6cd5\u7b49\u3002
"},{"location":"programming/#_9","title":"\u5b66\u957f\u5b66\u59d0\u7684\u7b14\u8bb0\u672c","text":"\u5f88\u591a\u5b66\u957f\u5b66\u59d0\u90fd\u5728\u81ea\u5df1\u7684\u535a\u5ba2/\u7b14\u8bb0\u672c\u4e2d\u5199\u4e86\u4e00\u4e9b\u5173\u4e8e\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u5185\u5bb9\uff0c\u8fd9\u91cc\u5217\u51fa\u4e00\u4e9b\u94fe\u63a5\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\u3002
- \u56fe\u7075\u73ed\u5b66\u4e60\u6307\u5357\uff1a\u7a0b\u5e8f\u8bbe\u8ba1\u4e0e\u7b97\u6cd5\u57fa\u7840
- TimeMachine\uff1aC-review
- \u9e64\u7fd4\u4e07\u91cc\uff1aC \u8bed\u8a00\u6742\u9879
- Isshiki\u4fee\uff1aC\u5c0f\u7a0b \u7410\u788e\u77e5\u8bc6\u70b9\u6574\u7406
- \u6e90\u8679\u7ffc\uff1aZJU\u79cb\u7a0b\u8bbe\u5b66\u4e60\u7b14\u8bb0
"},{"location":"programming/faq/","title":"\u5e38\u89c1\u95ee\u9898","text":"\u8fd9\u91cc\u5206\u6a21\u5757\u6c47\u603b\u4e86\u7a0b\u8bbe\u8f85\u5b66\u7fa4\u4e2d\u7684\u5e38\u89c1\u95ee\u9898\u53ca\u5176\u89e3\u7b54\u3002
"},{"location":"programming/faq/#_2","title":"\u57fa\u672c\u6570\u636e\u7c7b\u578b\u3001\u8fd0\u7b97\u7b26\u3001\u8868\u8fbe\u5f0f\u548c\u8bed\u53e5","text":"\u6709\u5e03\u5c14\u7c7b\u578b\u5417\uff1f Author\uff1a\u6731\u5b9d\u6797
\u5e03\u5c14\u7c7b\u578b\u7684\u5386\u53f2\uff1a
- \u6700\u65e9\u7684 C \u8bed\u8a00\u89c4\u8303\u4e2d\u6ca1\u6709\u5e03\u5c14\u7c7b\u578b\u3002
- C99 \u5f15\u5165\u4e86
_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\u3002 bool
\u5c55\u5f00\u6210 _Bool
\u3002 true
\u548c false
\u5206\u522b\u5c55\u5f00\u6210 int
\u7c7b\u578b\u7684 1
\u548c 0
\u3002
- C23 \u6b63\u5f0f\u4f7f\u7528
bool
\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
- \u5230
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\u3002
\u6d6e\u70b9\u6570\u662f\u5982\u4f55\u5b58\u50a8\u7684\uff1f\u4e3a\u4ec0\u4e48\u5b83\u4e0d\u7cbe\u786e\uff1f Author\uff1a\u6731\u5b9d\u6797
\u4e0b\u9762\u7684\u5185\u5bb9\u6765\u81ea\u300a\u8ba1\u7b97\u673a\u79d1\u5b66\u5bfc\u8bba\u300b\uff0c\u8bf7\u5b8c\u6574\u9605\u8bfb\u4ee5\u4e86\u89e3\u6d6e\u70b9\u6570\u7684\u5b58\u50a8\u65b9\u5f0f\u3002
\u5982\u679c\u4f60\u8bfb\u5b8c\u4e86\u4e0a\u9762\u7684\u5185\u5bb9\uff0c\u4f60\u5e94\u8be5\u80fd\u7406\u89e3\u6d6e\u70b9\u6570\u5b58\u50a8\u4e0d\u7cbe\u786e\u7684\u539f\u56e0\uff1a
- \u6d6e\u70b9\u6570\u7684\u5c3e\u6570\u90e8\u5206\u957f\u5ea6\u6709\u9650\uff0c\u65e0\u6cd5\u5b58\u50a8\u65e0\u9650\u7684\u5c0f\u6570\u3002
\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/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/#10-i-love-pointer","title":"\u300c10\u300d I Love pointer","text":"What is the output of the following program on a 64-bit system?
char str[3][10]={\"\",\"ILoveCKC\",\"ILoveZJU\"};\n printf(\"%lu#%lu\\n\",strlen(str[0]),sizeof(str[0]));\n printf(\"%lu#%lu\\n\",strlen(str),sizeof(str));\n printf(\"%d#%c\\n\",str[1][-10],str[1][10]); // Don't write this in your own code.\n printf(\"%s\\n\",(**str == (*(str + 1) + 8)[1] ? \"True\" : \"False\"));\n printf(\"%s\",&str[1][9] == &((*(str + 1) + 8)[1]) ? \"True\" : \"False\");\n
Answer 0#10\n 0#30\n 0#I\n True\n True\n
strlen(str[0])
returns the length of the string pointed to by str[0]
, which is 0. sizeof(str[0])
returns the size of the array str[0]
, which is 10. strlen(str)
returns the length of the string pointed to by str
, which is 0. sizeof(str)
returns the size of the array str
, which is 30. In fact, str[0]
's value is same as str
's value. str[1][-10]
is equivalent to *(str[1] - 10)
which is equivalent to **(str + 1 * 10 - 10)
which is equivalent to ** str
. So str[1][-10]
's value is '\\0'
. str[1][10]
is equivalent to *(str[1] + 10)
which is equivalent to **(str + 1 * 10 + 10)
which is equivalent to ** (str + 20)
So str[1][10]
's value is 'I'
. (*(str + 1) + 8)[1]
is the same as str[1][9]
. So **str == (*(str + 1) + 8)[1]
is true.
\u4f9b\u9898\u4eba\uff1a\u80e1\u80b2\u73ae
"},{"location":"programming/daily/2023/#9-sizeof-all-in-one","title":"\u300c9\u300d sizeof
All in One","text":"What is the output of the following program on a 64-bit system?
char str[][3] = {'L', 'o', 'v', 'e', 'C', 'K', 'C'};\nprintf(\"%d \", (int)sizeof(str));\nprintf(\"%d \", (int)sizeof(&str));\nprintf(\"%d \", (int)sizeof(*str));\nprintf(\"%d \", (int)sizeof(str + 1));\nprintf(\"%d \", (int)sizeof(*str + 1));\nprintf(\"%d \", (int)sizeof(*(str + 1)));\nprintf(\"%d\", (int)sizeof(*(*(str + 1) + 1)));\n
Answer 9 8 3 8 8 3 1
.
This is a comprehensive problem combining sizeof
and pointer.
- When the object is an array name, the return value is the total size of the whole array. At initialization, the third row of the array will be filled to a 1-D array of length 3 automatically:
char str[][3] = {{'L', 'o', 'v'}, {'e', 'C', 'K'}, {'C', '\\0', '\\0'}};
. Therefore the value of sizeof(str)
equals to 3 * 3 * 1 = 9 since sizeof(char) = 3
. - In the expression
&str
, &
represents the address-of operator and the return value is the address of the entire array. That, of course, can be regarded as a pointer and hence sizeof(&str)
equals 8 (Bytes), the size of a pointer on a 64-bit system. - Now let's focus on
str
. We know that str
is an array of char [3]
. In the view of pointer, str
is also a pointer to the first element (Note that the element here is an array of length 3). Hence *str
is equivalent to str[0]
which is an 1D array of length 3. So the output of sizeof(*str)
is 3 * 1 = 3. - In the previous discussion we know that
str
is a pointer to array of length 3 (char (*)[3]
actually), so str + 1
is also a pointer and the output is 8. *str
(equivalent to str[0]
), will be converted to int *
when added by 1. Therefore *str + 1
is a pointer to str[0][1]
and 8 will be output again. - From discussion 3 and 4 it's not difficult to find
*(str + 1)
an array of length 3 (str[1]
), so 3 is the answer. *(*(str + 1) + 1)
is classical equivalence of str[1][1]
. Therefore sizeof(*(*(str + 1) + 1))
equals to sizeof(char)
, namely 1.
\u4f9b\u9898\u4eba\uff1a\u5f90\u82e5\u79ba
"},{"location":"programming/daily/2023/#8-j-lost","title":"\u300c8\u300d J lost","text":"Given the following program:
void xqc(char c[], int i);\n\nint main(void) {\n char c[] = \"I am a Man of Fortune\";\n char d[] = \"and I must seek my Fortune\";\n\n xqc(c + 1, ~1694);\n xqc(d - ~3, -65);\n printf(\"%s, %s\\n\", c, d);\n}\n\nvoid xqc(char c[], int i) {\n c = c - 1;\n c[0] = ' ';\n c[1] = (i & 1) + 'I';\n}\n
Which of the following is correct?
A. This program fails to compile, because you cannot assign to an array in line 13.
B. Because of the call-by-value, function xqc
cannot modify the character arrays in function main
.
C. Change 1694
in line 7 to 1994
, and the result of the program is the same.
D. This program outputs I am a Man of Fortune, and J must seek my Fortune
.
Answer C.
A: Inside function xqc
, c
is a pointer type char *
rather than an array type, because when an array type is used in a function parameter list, it actually is the corresponding pointer type. Therefore, the assignment in line 13 is valid, and it means \"to move the pointer c
one position backward\".
B: The function xqc
can modify the character arrays in function main
, because it takes the address of the character arrays as parameters. The function xqc
can modify the contents of the character arrays through the pointers.
C: The ~
operator is the bitwise NOT operator. The ~1694
is equivalent to -1695
. The ~3
is equivalent to -4
. Therefore, the calls to function xqc
are equivalent to:
xqc(c + 1, -1695);\nxqc(d - -4, -65);\n
And i & 1
gets the last bit of i
. Both -1695
and -65
are odd numbers, so i & 1
is 1
, and the character 1 + 'I'
, which is 'J'
, is assigned. Changing 1694
to 1994
does not change the result of the program, because ~1994
is -1995
, and -1995
is also an odd number.
D: This program outputs \u00a0Jam a Man of Fortune, and J must seek my Fortune
.
Tip
You don't need to calculate the exact value of ~1694
. All you need to know is that the last bit of 1694
is 0 (since it is an even number), and the bitwise NOT operator will reverse that last bit. Therefore, ~1694
is an odd number, and i & 1
is 1
. Ditto for ~1994
.
\u4f9b\u9898\u4eba\uff1a\u674e\u82f1\u7426
"},{"location":"programming/daily/2023/#7-the-difference-between-strlen-and-sizeof","title":"\u300c7\u300d The difference between strlen
and sizeof
.","text":"#include <stdio.h>\n#include <string.h>\nint main()\n{\n char arr1[] = \"abcd\";\n char arr2[] = {'a', 'b', 'c', 'd'};\n printf(\"%d\\n\", sizeof(arr1));\n printf(\"%d\\n\", sizeof(arr2));\n printf(\"%d\\n\", strlen(arr1));\n printf(\"%d\\n\", strlen(arr2));\n return 0;\n}\n
What are the results?
A. 4, 4, 4, 4 B. 5, 4, 4, 4 C. 4, 4, 4, indeterminable D. 5, 4, 4, indeterminable Answer D.
arr1
has \\0
at the end, but arr2
doesn't.
The sizeof
operator returns the size of its operand in bytes. In this case, the size of arr1
is 5, because it contains 4 characters and a null character \\0
. The size of arr2
is 4, because it contains just 4 characters. The \\0
is absent in arr2
.
The strlen
function returns the length of the string, that is, the number of characters in the string before the null character \\0
. In this case, the length of arr1
is 4, because it contains 4 characters before the null character \\0
. But the length of arr2
is indeterminable, because it does not contain a null character \\0
. The strlen
function will continue to read memory until it finds a null character \\0
, resulting totally random result. If there is no null character \\0
in the memory, the behavior is undefined.
\u4f9b\u9898\u4eba\uff1a\u534e\u5c55\u8f89\uff0c\u674e\u82f1\u7426
"},{"location":"programming/daily/2023/#6-stack-and-queue-adapted-from-fds-mid-term-exam","title":"\u300c6\u300d Stack and Queue (adapted from FDS mid-term exam)","text":"Given an empty stack S
and an empty queue Q
. Push elements {1, 2, 3, 4, 5, 6, 7}
one by one onto S
. If each element that is popped from S
is enqueued onto Q
immediately, and if the dequeue sequence is {3, 2, 4, 6, 7, 5, 1}
, then the minimum size of S
should be:
A. 5 B. 4 C. 3 D. 7 Answer C.
Stack is LIFO (Last In, First Out), queue is FIFO (First In, First Out). So dequeue sequence of queue is also the enqueue sequence. If enqueue sequence of Q is {3, 2, 4, 6, 7, 5, 1}, all operation of stack S must be the following:
- Push 1 and 2 and 3 into stack sequentially. Stack S now contains 3 nodes.
- Pop 3, stack contains 2 nodes
- Pop 2, stack contains 1 node
- Push 4, stack contains 2 nodes
- Pop 4, stack contains 1 node
- Push 5, stack contains 2 nodes
- Push 6, stack contains 3 nodes
- Pop 6, stack contains 2 nodes
- Push 7, stack contains 3 nodes
- Pop 7, stack contains 2 nodes
- Pop 5, stack contains 1 node
- Pop 1, stack is empty
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
.
Answer argv
is an array of pointers to strings, and argc
is the number of strings in argv
. The argv
array contains the following strings:
argv[0] = \"./a.out\"\nargv[1] = \"this\"\nargv[2] = \"is\"\nargv[3] = \"a\"\nargv[4] = \"test\"\n
The argc
is 5, because there are 5 strings in argv
.
The argv
array is terminated by a null pointer, so argv[5]
is a null pointer.
For more information about argv
and argc
, see cppreference-argc, argv.
\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797
"},{"location":"programming/daily/2023/#3-sizeof-struct","title":"\u300c3\u300d sizeof
struct
","text":"Consider the following code fragment:
struct A {\n char a[10];\n int b;\n\n};\ntypedef struct A A;\n\nstruct B {\n char *a;\n int b;\n};\ntypedef struct B* B;\n
What is the value of sizeof(A)
and sizeof(B)
?
Answer sizeof(A)
is 16, and sizeof(B)
is 8 (on a 64-bit modern system).
The sizeof
operator returns the size of its operand in bytes. The size of a structure type is as large as the sum of the sizes of its members.
You may think the size of A
is 14, because the size of char[10]
is 10, and the size of int
is 4. However, to improve performance of memory access, C standard allows the compiler to add padding bytes after each member of a structure, and the padding strategy is implementation specific. A common strategy is to align each member to the size of its type, that is to say, make their memory address to be a multiple of the size of the member. For example, on a 64-bit system, the address of a 4-byte integer must be a multiple of 4.
Therefore, The size of A
is 16. The compiler will add 2 padding bytes after char[10]
, to make the address of int
a multiple of 4 in struct A
.
The size of B
is 8, because B
is a pointer and the size of pointer is 8. The size of type to which B
points does not affect the size of B
. Notice that type B
is not equivalent to type struct B
.
For more information about sizeof
operator, see cppreference-sizeof.
\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797\u3001\u5b59\u5146\u6c5f
"},{"location":"programming/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:
- Do not use the
printf
series of formatting output functions. - The minimum field width for output is
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.
Answer C
.
The strcat
function appends a copy of the string pointed to by s4
to the end of the string pointed to by s3
. The s3
and s4
pointers point to the third character of s1
and the fourth character of s2
, respectively. Therefore, the strcat
function appends the string \"ld\"
to the end of the string \"Hellold\"
, resulting in \"Helloldld\"
, and the printf
function prints \"Hellold, world; llold, ld.\"
.
When the strcat
function appends the string \"ld\"
after \"Hello\", it overwrites the null character '\\0'
at the end of the string \"Hello\"
and write a new null character '\\0'
at the end of the string \"Helloldld\"
. Therefore, the character w
and <
after the null character '\\0'
in s1
are not printed.
\u4f9b\u9898\u4eba\uff1a\u90d1\u4fca\u8fbe
"},{"location":"programming/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:
- Create a new node and set its
data
to data
. - Insert the new node between the dummy node and the first node of the list.
If you want to iterate over the list, you should start from the first node of the list, which is list->next
.
\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797
"},{"location":"programming/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 Love scanf
!","text":"After entering the following inputs, does the program operate normally? If it does, what should be the output?
int a;\nchar c1, c2;\nchar s[7];\nscanf(\"%d%c %c%s\\n\", &a, &c1, &c2, s);\nprintf(\"%d#%c#%c#%s\", a, c1, c2, s);\n
#input: there is no space after the last character\n20231127\n ckc-agc\ndaily_problem\n
Answer The program operates normally and the output is:
20231127#\n#c#kc-agc\n
The scanf
function reads input from the standard input stream, which is usually the keyboard. The format string of scanf
is \"%d%c %c%s\\n\"
. The first %d
matches the integer 20231127
, the second %c
matches the character '\\n'
because %c
won't miss any character including ' '
and '\\n'
. The space in formatting string will ignore every blank character, so the third %c
matches the character 'c'
, and the fourth %s
matches the string \"kc-agc\"
, whose length is 7. When you print \\n
after line2, scanf
will not stop, because '\\n'
in formatting string will ignore every blank character. So until you enter a non-blank character and use enter to send it to the program from buffer, scanf
will stop.
\u4f9b\u9898\u4eba\uff1a\u80e1\u80b2\u73ae
"},{"location":"programming/daily/2023/#26-broken-strcpy","title":"\u300c26\u300d Broken strcpy()
","text":"Does this strcpy()
implementation do its job?
void my_strcpy(char *s, const char *t) {\n do {\n *s++ = *t++;\n } while (*t);\n}\n
Answer No, it's broken. This implementation does not terminate the string pointed to by s
. To correctly copy a string, the character used in assignment must be the same character used in loop condition.
What does that mean? Suppose t = \"Hello\"
, then:
*t
is 'H'
, and is assigned to *s
. s
and t
increment. *t
, now being 'e'
, is used to evaluate the while
condition. - ... this process repeats until
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. - Now we have a memory out-of-bounds. Accessing
*t
is undefined behavior. - And it keeps copying garbage values until some arbitrary
'\\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
Answer A
.
The function my_strcat
is supposed to concatenate s1
and s2
and store the result in s3
. However, the function does not work as expected. The problem lies in the line s3 = malloc(len1 + len2 + 1);
. The function my_strcat
takes s3
as a parameter, which is a pointer to a char
array. When the function is called, the value of s3
is copied to the function's local variable s3
. Therefore, the malloc
function allocates memory for the local variable s3
, not the original s3
in main
. The memory allocated for the local variable s3
is not used after the function returns, so it is a memory leak. The original s3
in main
is not modified, so it is still an empty string.
You may think that the problem can be solved by simply deleting the line s3 = malloc(len1 + len2 + 1);
. However, this will cause another problem. s3
is initialized as an empty string, which means that it is a pointer to a char
array with only one element, the null character \\0
. The memory allocated for s3
is not enough to store the concatenated string. Therefore, this will cause a buffer overflow.
\u4f9b\u9898\u4eba\uff1a\u6885\u654f\u70ab
"},{"location":"programming/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\u300d typedef
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:
- Suffix increacement and decreacement:
a++
- Logical NOT:
!
- Prefix increacement and decreacement:
--a
- Subtraction:
-
- Bitwise left shift:
<<
- Comparison:
<
, >
- Logical OR:
||
- Ternary conditional:
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. - Since
x
has the value of 2 and y
has the value of 1, the output will be 2.
\u4f9b\u9898\u4eba\uff1a\u5f90\u82e5\u79ba
"},{"location":"programming/daily/2023/#27-or-in-switch","title":"\u300c27\u300d Or in switch
","text":"What will happen when compiling and executing the following code fragment with input 5
?
char ch;\nscanf(\"%c\", &ch);\nswitch (ch) {\n case 0 || 2 || 4 || 6 || 8:\n printf(\"even digit \");\n case 1 || 3 || 5 || 7 || 9:\n printf(\"odd digit \");\n default:\n printf(\"not a digit \");\n}\n
A. It will print odd digit
.
B. It will print odd digit not a digit
.
C. It will print not a digit
.
D. It cannot be compiled.
Answer D
.
The compiler will tell you that case label value has already appeared in this switch
. There are many problems in this code fragment, and the most important one is that 0 || 2 || 4 || 6 || 8
will not behave as expected in case
statement. It will be evaluated as 1
because 0 || 2 || 4 || 6 || 8
is equivalent to ((((0 || 2) || 4) || 6) || 8)
. The result of 0 || 2
is 1
, so the result of 0 || 2 || 4
is 1
, and so on. Therefore, the case
statement will be evaluated as case 1
. The same problem exists in case 1 || 3 || 5 || 7 || 9
, which will also be evaluated as case 1
. The correct way to write this code fragment is:
char ch;\nscanf(\"%c\", &ch);\nswitch (ch) {\n case '0': case '2': case '4': case '6': case '8':\n printf(\"even digit \"); break;\n case '1': case '3': case '5': case '7': case '9':\n printf(\"odd digit \"); break;\n default:\n printf(\"not a digit \");\n}\n
For more information about switch
statement, see cppreference-Switch statement.
\u4f9b\u9898\u4eba\uff1a\u90d1\u4fca\u8fbe
"},{"location":"programming/daily/2023/#26-bitwize-operator","title":"\u300c26\u300d Bitwize Operator","text":"Which of the following options can achieve a swapping effect for pair(*,*)
? Note that ^
represents XOR
operation. For binary numbers, 0 XOR 0 = 0
, 0 XOR 1 = 1
, 1 XOR 0 = 1
, 1 XOR 1 = 0
.
A. (x, y)
: x ^= y ^= x ^= y;
B. (a[x], a[y])
: a[x] ^= a[y] ^= a[x] ^= a[y];
C. (x, y)
: x -= y += x -= y;
D. (a[x], a[y])
: a[x] -= a[y] += a[x] -= a[y];
Answer A
.
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 Nested switch
, Confusing default
and break
","text":"After executing the following code fragment, the output should be __.
int x = 1, y = 1;\nswitch (x) {\n case 1:\n switch (y) {\n default:\n printf(\"three \");\n case 1:\n printf(\"one \");\n case 2:\n printf(\"two \");\n break;\n }\n case 2: case 3:\n printf(\"four \");\n break;\n default:\n printf(\"five \");\n}\n
Answer one two four
The syntax of switch
statement is:
switch (expression) {\n case constant-expression:\n statements\n case constant-expression:\n statements\n default:\n statements\n}\n
The expression
must have an integral or enumerated type, or be of a class type in which the class has a single conversion function to an integral or enumerated type. The constant-expression
for each case
must be a constant expression of the same type as the expression, and no two of the constant expressions associated with the same switch
statement shall have the same value after conversion.
The switch
statement evaluates expression
, then looks for the case
constant-expression whose value is equal to the value of expression
(after conversion). If such a case
is found, the statements following that case
are executed until a break
statement is encountered. If no case
is found whose value is equal to the value of the expression, and if there is a default
label, the statements following the default
label are executed. Otherwise, the statements of the switch
statement are skipped.
If some case
labels are not followed by break
statements, the execution of the switch
statement falls through to the next case
label. You can use this behavior to execute multiple statements for a particular case
label or to execute statements for more than one case
label.
\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797
"},{"location":"programming/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
).
- The result of the postfix forms is the value of
x
. - The result of the prefix forms is the value of
x + 1
for ++x
(or x - 1
for --x
).
For more information, see cppreference-Increment/decrement operators
-
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.
- To compare two strings, you should use
strcmp
function in <string.h>
header file. Learn how to use the function by yourself. - In the code snippet above,
a
, b
and c
are all arrays of char
, so a > b
and a > c
are actually comparing the addresses of these arrays. You may think that the array declared later has a larger address, but this is not always true. It depends on the design of the architecture that the stack grows towards higher memory addresses or towards lower memory addresses. So the output of this program is unpredictable. For more information on this, see StackOverflow: Is the order of memory addresses of successively declared variables always descending?
\u4f9b\u9898\u4eba\uff1a\u6768\u7433\u73a5
"},{"location":"programming/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 Bad if
-else
","text":"After executing the following code fragment, the output is __.
int x = 0;\nint y = -2;\nif(x > 0) y = 1;\nelse if(x < 0) y = -1;\nelse if(x = 0) y = 0;\nprintf(\"%d\", y);\n
A. 1 B. 0 C. -1 D. -2 Answer D
.
Notice that the condition of if
in line 5 is x = 0
, not x == 0
. The former means \"0 is assigned to x\", and then the if sentence won't be executed since it is equivalent to if(0)
. Thus the value of y
is its initial value, -2.
\u4f9b\u9898\u4eba\uff1a\u6885\u654f\u70ab
"},{"location":"programming/daily/2023/#17-character","title":"\u300c17\u300d Character","text":"Given: char c = '@';
, the value of expression 'A' <= c <= 'Z'
is __.
Answer 1
.
To solve this problem you do not need to remember ASCII code. This problem is about operator precedence. The expression 'A' <= c <= 'Z'
is equivalent to (('A' <= c) <= 'Z')
. No matter what the value of c
is, the expression ('A' <= c)
will be evaluated to 1
or 0
, which is less than 'Z'
. Therefore, the value of the expression 'A' <= c <= 'Z'
is 1
.
But in other problems you may need to remember some key ASCII codes:
Character ASCII Code '0'
48
'A'
65
'a'
97
Upper case is prior to lower case. The difference between 'A'
and 'a'
is 32
. So if you want to convert a lowercase letter to uppercase, you can use c - 32
. Or an easier way: c - 'a' + 'A'
.
\u6765\u81ea\uff1aC \u5927 13 \u5e74\u671f\u672b
"},{"location":"programming/daily/2023/#16-overflow","title":"\u300c16\u300d Overflow","text":"For code below:
unsigned short sht = 0;\nsht--;\n
What will be the value of sht
after the execution?
A. -1 B. 65535 C. 32767 D. 65536 Answer B.
Remember that unsigned short
is an unsigned integer type, so it will not be negative. Instead, it will be the largest value of unsigned short
type. The largest value of unsigned short
type is 65535
, because unsigned short
is 16-bit long.
\u6765\u81ea\uff1aC \u5927 13 \u5e74\u671f\u672b
"},{"location":"programming/exam/exam/","title":"\u5386\u5e74\u5377\u7ecf\u5178\u9898\u76ee\u89e3\u6790","text":""},{"location":"programming/exam/exam/#_2","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u57fa\u7840\u5e38\u95ee\u9898\u76ee\u96c6\u53ca\u89e3\u6790","text":"Info
\u672c\u7bc7\u7b14\u8bb0\u6765\u81ea []
\u8fd9\u91cc\u662f\u4f5c\u4e3a 2022 \u5e74\u7afa\u9662\u56e2\u59d4\u5b66\u7814\u90e8\u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66\u7b54\u7591\u5b66\u957f\u65f6\u6574\u5408\u7684\u7fa4\u91cc\u7ecf\u5e38\u95ee\u5230\u7684\u4e00\u4e9b\u95ee\u9898\uff0c\u5305\u62ec\u89e3\u6790\uff0c\u4e5f\u6709\u4e00\u4e9b\u76f8\u5173\u77e5\u8bc6\u70b9\u7684\u6574\u7406\u3002\u5927\u90e8\u5206\u9898\u76ee\u662f 13-18 \u7684\u671f\u672b\u771f\u9898\uff0c\u5c0f\u90e8\u5206\u4e2d\u6587\u9898\u76ee\u662f\u7fa4\u91cc\u6211\u4e0d\u6e05\u695a\u6765\u6e90\u7684 PTA \u4e0a\u7684\u9898\u76ee\u6216\u8005\u6211\u81ea\u5df1\u7f16\u7684\u5c0f\u9898\u3002\u4e00\u5171\u4e94\u5341\u9053\u9898\uff0c\u5df2\u7ecf\u6309\u7167\u8003\u70b9/\u6613\u9519\u70b9\u5206\u5f00\u4e86\u3002
"},{"location":"programming/exam/exam/#_3","title":"\u6807\u8bc6\u7b26/\u5173\u952e\u5b57","text":"\u8fd9\u7c7b\u9898\u76ee\u4e00\u822c\u662f\u95ee\u54ea\u4e9b\u662f\u5408\u6cd5\u7684\u6807\u8bc6\u7b26\u3001\u54ea\u4e9b\u662f\u5173\u952e\u5b57\u3002\u5bf9\u4e8e\u6807\u8bc6\u7b26\uff0c\u53ea\u9700\u8981\u8003\u8651 int <identifier>;
\u662f\u5426\u5408\u6cd5\uff0c\u5982\u679c\u5408\u6cd5\uff0c\u90a3 <identifier>
\u5c31\u662f\u5408\u6cd5\u7684\u6807\u8bc6\u7b26\uff08\u6216\u8005\u8003\u8651\u662f\u4e0d\u662f\u5173\u952e\u5b57\uff0c\u5982\u679c\u662f\u5173\u952e\u5b57\uff0c\u90a3\u80af\u5b9a\u4e0d\u662f\u5408\u6cd5\u7684\u6807\u8bc6\u7b26\uff09\u3002\u81f3\u4e8e\u5173\u952e\u5b57\uff0c\u53ef\u4ee5\u770b cppreference\u3002
-
(C13A) Which one below is NOT a keyword of the C programming language? _____ A. define B. if C. typedef D. while
define
\u4e0d\u662f\u5173\u952e\u5b57\uff0c\u662f\u9884\u5904\u7406\u6307\u4ee4\uff0c\u4f60\u751a\u81f3\u53ef\u4ee5 int define;
\u800c if
\u3001typedef
\u3001while
\u663e\u7136\u90fd\u662f\u5173\u952e\u5b57\u3002
-
(C14A) Which one below is NOT a valid identifier in the C programming language? _____ A. printf B. _ever C. \"char\" D. true
\u663e\u7136\u9009\u62e9 C\uff0c\u56e0\u4e3a int \"char\";
\u80af\u5b9a\u662f\u975e\u6cd5\u7684\uff0c\u6807\u8bc6\u7b26\u5fc5\u987b\u4ee5\u5b57\u6bcd\u6216\u4e0b\u5212\u7ebf\u5f00\u5934\u3002\u5bf9\u4e8e A\uff0cprintf \u53ea\u662f\u4e00\u4e2a\u51fd\u6570\u540d\uff0c\u4e0d\u662f\u5173\u952e\u5b57\uff0c\u6240\u4ee5\u662f\u5408\u6cd5\u7684\u3002\u5bf9\u4e8e D\uff0cC \u8bed\u8a00\u4e2d true \u5e76\u4e0d\u662f\u5173\u952e\u5b57\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u3002
"},{"location":"programming/exam/exam/#_4","title":"\"\u52a0\u62ec\u53f7\"\u95ee\u9898","text":"\u5373\u6307\u8868\u8fbe\u5f0f\u4e2d\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u7b49\u95ee\u9898\uff0c\u4f8b\u5982\u7ed9\u4e00\u4e2a\u590d\u6742\u7684\u6ca1\u6709\u62ec\u53f7\u7684\u8868\u8fbe\u5f0f\uff0c\u8fd9\u65f6\u4e25\u683c\u6309\u7167\u4f18\u5148\u7ea7\u89c4\u5219\u7ed9\u8868\u8fbe\u5f0f\u5404\u4e2a\u90e8\u5206\u52a0\u4e0a\u62ec\u53f7\uff0c\u7ed3\u679c\u5c31\u6e05\u6670\u4e86\u3002
\u5173\u4e8e\u4f18\u5148\u7ea7\u7684\u9898\u76ee\u8fd9\u91cc\u5c31\u4e0d\u5217\u4e86\uff0c\u53ef\u4ee5\u53bb\u67e5\u9605\u4fee\u4f6c\u7684 note\uff0c\u91cc\u9762\u5199\u7684\u5f88\u6e05\u6670\u4e86\u3002
\u8fd9\u91cc\u7ed9\u51fa\u4e24\u9053\u548c\u4e09\u76ee\u8fd0\u7b97\u7b26 ?: \u6709\u5173\u7684\u9898\u76ee\u3002
-
(C18A) Given: int a=1,b=2,c=3,d=4;
, the value of the expression a<b?a:c<d?c:d
is _____.
\u5bf9\u4e8e\u4e09\u76ee\u8fd0\u7b97\u7b26\uff0c\u4f60\u9700\u8981\u77e5\u9053\u4e00\u4e2a ? \u80af\u5b9a\u8981\u548c\u540e\u9762\u7684\u4e00\u4e2a : \u8fdb\u884c\u914d\u5bf9 \u90a3\u4e48 c<d?c:d
\u8fd9\u90e8\u5206\u4e00\u5b9a\u662f\u4e00\u4f53\u7684\uff0c\u53ef\u4ee5\u7ed9\u5b83\u5de6\u53f3\u52a0\u4e0a\u62ec\u53f7\uff0c\u5c31\u53d8\u6210\u4e86 a<b?a:(c<d?c:d)
\uff0c\u5c31\u5df2\u7ecf\u5f88\u6e05\u6670\u4e86\u3002 \u6240\u4ee5\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u7684\u503c\uff1aa<b \u6210\u7acb\uff0c\u9009\u62e9\u7b2c\u4e00\u4e2a\u7ed3\u679c\u4e5f\u5c31\u662f a\uff0c\u7b54\u6848\u662f 1
-
\u82e5\u5b9a\u4e49 int a=1,b=2,c=3,d=4
\u90a3\u4e48\u8868\u8fbe\u5f0f (a>b?c>a?c-3:c-1:b==c?d-a:d-c)
\u7684\u503c\u4e3a _____.
\u548c\u4e0a\u9762\u540c\u7406\uff0c\u4e0d\u8fc7\u6709\u4e9b\u590d\u6742\u3002\u4f46\u662f\u8fd9\u4e2a\u4e09\u76ee\u8fd0\u7b97\u7b26\u7684\u914d\u5bf9\u8fc7\u7a0b\u6211\u4eec\u53ef\u4ee5\u7c7b\u6bd4\u4e3a\u62ec\u53f7\u5339\u914d\u3002\u5c06 ? \u89c6\u4e3a\u5de6\u62ec\u53f7 (\uff0c: \u89c6\u4e3a\u53f3\u62ec\u53f7 )\uff0c\u90a3\u4e48\u4e00\u4e2a ? \u5e94\u8be5\u548c\u54ea\u4e2a : \u914d\u5bf9\u5c31\u6e05\u6670\u4e86\u3002
(a>b?c>a?c-3:c-1:b==c?d-a:d-c)\n ( ( ) ) ( )\n | +---+ | +---+\n +-----------+\n
\u77e5\u9053\u4e86 ? \u548c : \u914d\u5bf9\u5173\u7cfb\u4e4b\u540e\u5c31\u80fd\u6b63\u786e\u5212\u5206\u7ed3\u6784\u4e86\uff1a a>b? (c>a?c-3:c-1) : (b==c?d-a:d-c)\n
\u6240\u4ee5 a>b \u4e0d\u6210\u7acb\uff0c\u9009\u62e9\u540e\u8005\uff0cb==c \u4e0d\u6210\u7acb\uff0c\u518d\u9009\u62e9\u540e\u8005\uff0c\u7b54\u6848\u662f d-c=1
"},{"location":"programming/exam/exam/#_5","title":"\u6570\u636e\u7c7b\u578b\u53ca\u5b57\u9762\u91cf","text":"\u51e0\u4e2a\u5e38\u89c1\u7684\u6570\u636e\u7c7b\u578b\u4e00\u5b9a\u8981\u77e5\u9053\u5b83\u4eec\u5360\u51e0\u4e2a\u5b57\u8282\u7684\u5927\u5c0f\u3002\u5e76\u4e14\u5728\u8868\u8fbe\u5f0f\u4e2d\u4e5f\u8981\u65f6\u523b\u6ce8\u610f\u5e38\u91cf\u7684\u7c7b\u578b\uff08\u5982\u7b2c\u4e5d\u9898\uff09\u3002
\u5b57\u9762\u91cf\u5373\u4e00\u4e2a\u503c\u7684\u8868\u793a\u65b9\u6cd5\uff1a
- \u6574\u578b\uff1a123 \u8868\u793a\u5341\u8fdb\u5236 123\uff1b0123 \u662f\u516b\u8fdb\u5236\u7684\u8868\u793a\u65b9\u6cd5\uff08\u5f00\u5934\u4e00\u5b9a\u52a0 0\uff0c0123 \u7b49\u4ef7\u4e8e 83\uff09\uff0c0x123 \u662f\u5341\u516d\u8fdb\u5236\u7684\u8868\u793a\u65b9\u6cd5\uff08\u5f00\u5934\u4e00\u5b9a\u52a0 0x\uff0c0x123 \u7b49\u4ef7\u4e8e 291\uff09
- \u5b57\u7b26\u578b\uff1a
- \u8bb0\u4f4f\u4e00\u4e2a\u5b57\u7b26\u7c7b\u578b\u5b9e\u9645\u4e0a\u5c31\u76f8\u5f53\u4e8e\u4e00\u4e2a\u5b57\u8282\u7684\u6574\u578b\uff0c\u6240\u4ee5\u53ef\u4ee5\u901a\u8fc7\u6570\u503c\u6765\u8868\u793a\uff1achar c = 65; \u5c31\u76f8\u5f53\u4e8e char c = 'A';
- \u540c\u65f6 \u5728\u5f15\u53f7\u91cc\u6709\u8f6c\u4e49\u7684\u6548\u679c\uff0c\u6bd4\u5982 '\\n' '\\t' \u90fd\u4ee3\u8868\u4e00\u4e2a\u5b57\u7b26\uff0c\u800c '\\\\' \u624d\u4f1a\u8868\u793a\u4e00\u4e2a \u5b57\u7b26\uff1b
- \u518d\u8fdb\u4e00\u6b65\uff0c \u540e\u9762\u53ef\u4ee5\u63a5\u6700\u591a\u4e09\u4e2a\u6570\u5b57\u6765\u4f7f\u7528\u516b\u8fdb\u5236\u8868\u793a\u4e00\u4e2a\u5b57\u8282\uff0c\u4e14\u9047\u5230 0-7 \u8303\u56f4\u4e4b\u5916\u7684\u6570\u5b57\u4f1a\u7ed3\u675f\u5f53\u524d\u5b57\u8282\uff0c\u6bd4\u5982 '\\101' \u4e5f\u8868\u793a 'A'\uff0c\u800c '\\08' \u56e0\u4e3a 8 \u8d85\u8fc7\u4e86\u516b\u8fdb\u5236\u8303\u56f4\uff0c\u6240\u4ee5\u8fd9\u662f\u4e24\u4e2a\u5b57\u7b26\u653e\u5230\u4e86\u4e00\u4e2a\u5355\u5f15\u53f7\u91cc\uff0c\u4e0d\u662f\u6b63\u786e\u7684\u7528\u6cd5\uff0c\u5982\u679c\u5199\u6210\u5b57\u7b26\u4e32\uff0c\u5219 \"\\08\" \u8868\u793a\u4e24\u4e2a\u5b57\u7b26\uff1b
- \\x \u540e\u9762\u63a5 0-9A-F \u5b57\u7b26\u901a\u8fc7\u5341\u516d\u8fdb\u5236\u6765\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\u3002\u4e0d\u8fc7\u5e76\u4e0d\u4f1a\u6709\u957f\u5ea6\u9650\u5236\uff0c\u6bd4\u5982 '\\x00000041' \u4e5f\u662f\u4e00\u4e2a\u5b57\u7b26\uff0c\u540c\u6837\u9047\u5230\u8303\u56f4\u5916\u7684\u5b57\u7b26\u5c31\u7ed3\u675f\u3002
-
(C13A) For code below:
unsigned short sht = 0;\nsht--;\n
What will be the value of sht
after the execution? _____ A. -1 B. 65535 C. 32767 D. 65536 sht \u662f unsigned short \u7c7b\u578b\uff0c\u662f\u4e24\u4e2a\u5b57\u8282\u7684\uff0c\u6240\u4ee5\u8303\u56f4\u4e3a 0-65535\u3002 \u65e0\u7b26\u53f7\u6574\u578b\u4ece 0 \u51cf\u53bb 1 \u4f1a\u4e0b\u6ea2\u5230\u6700\u5927\u503c\uff0c\u5bf9\u4e8e\u6b64\u9898\u4e5f\u5c31\u662f 65535\uff0c\u9009 B
-
(C13A) Which literal below is 124 in decimal(\u5341\u8fdb\u5236)? _____ A. 0124 B. 124d C. 0x124 D. 0174
\u6839\u636e\u524d\u9762\u8bf4\u5230\u7684\uff0cA. 0124 \u662f\u516b\u8fdb\u5236\u8868\u793a\u6cd5\uff0c\u5b83\u7b49\u4e8e\u5341\u8fdb\u5236\u7684 84\uff1bB. 124d \u6ca1\u6709\u8fd9\u79cd\u8868\u793a\u65b9\u6cd5\uff0c\u662f\u8bed\u6cd5\u9519\u8bef\u7684\uff1bC. 0x124 \u662f\u5341\u516d\u8fdb\u5236\u8868\u793a\u6cd5\uff0c\u7b49\u4e8e\u5341\u8fdb\u5236\u7684 292\uff1bD. 0174 \u516b\u8fdb\u5236\uff0c\u7b49\u4e8e\u5341\u8fdb\u5236 124\uff0c\u9009 D
-
(C16A) In the following notations, _____ can express a character constant(\u5b57\u7b26\u5e38\u91cf) correctly. A. '\\x100' B. 125 C. '\\08' D. '\\'
A. '\\x100' \u662f\u5341\u516d\u8fdb\u5236\u8868\u793a\u6cd5\uff0c\u4f46\u662f\u8d85\u51fa\u4e86\u4e00\u4e2a\u5b57\u8282\u7684\u8303\u56f4\uff0c\u662f\u8bed\u6cd5\u9519\u8bef\u7684\uff1bB. 125 \u901a\u8fc7\u4e00\u4e2a\u6574\u6570\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\uff0c\u800c\u4e14\u5728 ASCII \u7801\u8303\u56f4\u5185\uff0c\u80af\u5b9a\u662f\u5408\u6cd5\u7684\uff08\u5b9e\u9645\u4e0a\u8868\u793a\u7684\u5c31\u662f\u5b57\u7b26 '}'\uff09\uff1bC. '\\08' \u524d\u9762\u8bf4\u8fc7\u4e86\uff0c\\0 8 \u662f\u4e24\u4e2a\u5b57\u7b26\uff0c\u6324\u5230\u4e86\u4e00\u4e2a\u5355\u5f15\u53f7\u91cc\uff0c\u662f\u9519\u8bef\u7684\u7528\u6cd5\uff1bD. '\\' \u4e2d \u4f1a\u5c06 ' \u8f6c\u4e49\uff0c\u6240\u4ee5\u76f8\u5f53\u4e8e\u8fd9\u4e2a\u5355\u5f15\u53f7\u6ca1\u6709\u95ed\u5408\uff0c\u662f\u8bed\u6cd5\u9519\u8bef\u7684\u3002\u6240\u4ee5\u9009 B\u3002
-
(C17A) In the following notations, _____ can NOT express a single-character constant(\u5355\u5b57\u7b26\u5e38\u91cf) correctly. A. '%c' B. 127 C. '\\077' D. 55
A. '%c' \u540c\u6837\u662f\u4e24\u4e2a\u5b57\u7b26\u6324\u5230\u4e86\u4e00\u4e2a\u5355\u5f15\u53f7\u91cc\uff0c\u662f\u9519\u8bef\u7528\u6cd5\uff1bBCD \u90fd\u53ef\u4ee5\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\uff0c\u6240\u4ee5\u9009 A
-
\u4ee5\u4e0b\u8868\u8fbe\u5f0f\u54ea\u4e2a\u662f\u4e0d\u6b63\u786e\u7684 _____. A. 0.5%2 B. 3&(0.5+0.5) C. 4.6<<2 D. 2==(3/2)
\u8981\u6ce8\u610f\u8fd0\u7b97\u7b26\u4e24\u4fa7\u7684\u6570\u636e\u7c7b\u578b\uff0c\u53ea\u6709 D \u7684 == \u4e24\u4fa7\u90fd\u662f int\uff0c\u662f\u5408\u6cd5\u7684\u3002\u800c ABC \u7684\u64cd\u4f5c\u6570\u90fd\u51fa\u73b0\u4e86 double \u7c7b\u578b\uff0c% & << \u8fd0\u7b97\u7b26\u4e0d\u80fd\u7528\u5728 double \u4e0a\uff0c\u8bed\u6cd5\u9519\u8bef\u3002
"},{"location":"programming/exam/exam/#_6","title":"\u6570\u7ec4\u4e0e\u6307\u9488","text":"\u6307\u9488\u662f C \u8bed\u8a00\u7684\u7075\u9b42\uff0c\u4e5f\u662f\u8003\u8bd5\u5e38\u8003\u6613\u9519\u7684\u77e5\u8bc6\u70b9\uff0c\u7279\u522b\u662f\u548c\u6570\u7ec4\u4e00\u8d77\u51fa\u73b0\u65f6\u3002
\u51e0\u4e2a\u9700\u8981\u8bb0\u4f4f\u7684\u77e5\u8bc6\u70b9\uff1aa[b] \u548c *(a+b) \u5728\u4f7f\u7528\u65f6\u5b8c\u5168\u7b49\u4ef7\uff1b\u4e8c\u7ef4\u6570\u7ec4\u65e0\u6cd5\u9000\u5316\u4e3a\u4e8c\u7ea7\u6307\u9488\uff1b\u6570\u7ec4\u540d\u4e0d\u80fd\u88ab\u91cd\u65b0\u8d4b\u503c\u3002
-
(C13A) Given the declaration: int a[10], *p=a;
\uff0cthe expression _____ is NOT correct. A. a[9] B. p[5] C. *p++ D. a++
a \u662f\u4e00\u4e2a\u6570\u7ec4\uff0cp \u662f\u4e00\u4e2a\u6307\u9488\uff0c\u5c06 a \u8d4b\u503c\u7ed9 p \u65f6\u5373\u5c06 a \u7684\u9996\u5730\u5740\u8d4b\u503c\u7ed9 p\u3002 a[9] \u80af\u5b9a\u662f\u5408\u6cd5\u7684\uff0c\u56e0\u4e3a p[5] \u7b49\u4ef7\u4e8e *(p+5)\uff0c\u4e5f\u662f\u5408\u6cd5\u7684\uff0c*p++ \u53d6\u4e86\u5f53\u524d p \u6307\u5411\u7684\u503c\uff0c\u5e76\u5c06 p \u6307\u9488 ++\uff0c\u662f\u5408\u6cd5\u7684\u3002 \u800c D. a++ \u4e2d\u5305\u542b\u4e86\u5bf9 a \u7684\u91cd\u65b0\u8d4b\u503c\uff08\u5c06 a+1 \u8d4b\u503c\u7ed9 a\uff09\uff0c\u7531\u4e8e\u6570\u7ec4\u540d\u4e0d\u80fd\u88ab\u8d4b\u503c\uff0c\u6240\u4ee5\u662f\u9519\u8bef\u7684\uff0c\u9009 D\u3002
-
(C13A) Given the declaration: int a[3][3]={1,2,3,4,5,6,7,8,9};
, the value of a[-1][5]
is _____.
\u9996\u5148\u6765\u770b a[-1]\uff0c\u5373 (a-1)\uff0ca-1 \u4f1a\u4ee5\u4e09\u4e2a int \u4e3a\u5355\u4f4d\u5411\u5de6\u79fb\u52a8\uff0c\u5373 (a-1) \u662f\u4e00\u4e2a\u6307\u5411\u5982\u4e0b\u4f4d\u7f6e\u7684\u6307\u9488\uff1a
0 0 0 1 2 3 4 5 6 7 8 9\n ^\n |\n*(a-1) = p\n
\u73b0\u5728\u6211\u4eec\u5c06 a[-1] \u4e5f\u5c31\u662f *(a-1) \u89c6\u4e3a p\uff0c\u90a3\u6211\u4eec\u8981\u627e\u7684\u7ed3\u679c\u5c31\u662f p[5]\uff0c\u6b64\u65f6 p \u662f\u4e00\u4e2a\u6307\u5411 int \u7c7b\u578b\u7684\u6307\u9488\uff0c*(p+5) \u5c31\u76f8\u5f53\u4e8e\u627e\u5230\u5b83\u6307\u5411\u7684\u4f4d\u7f6e\u53f3\u4fa7\u7b2c 5 \u4e2a int \u7684\u503c\uff0c\u4e5f\u5c31\u662f 3\u3002 -
(C14A) Given the declaration: int a[3][2]={1,2,3,4,5,6};
what is the value of expression (a[1]+1)[0]
? _____.
\u540c\u4e0a\u9898\u4e00\u6837\u5206\u6790\u5373\u53ef\uff0c\u65f6\u523b\u8bb0\u5f97 a[b] \u7b49\u4ef7\u4e8e *(a+b)\u3002\u4ee5\u4e0b\u662f\u8d3a\u8001\u5e08\u66fe\u7ecf\u7684\u56fe\uff1a
a -> {\na[0] -> {1, 2}\na[1] -> {3, 4}\n ^\n +--- a[1] + 1\na[2] -> {5, 6}\n }\n
\u6240\u4ee5 (a[1]+1)[0] \u5c31\u662f *(a[1]+1) = 4 -
(C15A/C16A) For the declarations: char *s, str[10];
, statement _____ is completely correct. A. strcpy(s, \"hello\"); B. str=\"hello\"+1 C. s=*&(str+1) D. s=str+1
\u8fd9\u91cc\u6d89\u53ca\u5230\u4e86\u4e00\u4e2a\u91ce\u6307\u9488\u7684\u95ee\u9898\uff0c\u4e0b\u9762\u4f1a\u4e13\u95e8\u6709\u4e00\u4e2a\u90e8\u5206
A. \u5c06 \"hello\" \u62f7\u8d1d\u5230 s \u6307\u5411\u7684\u7a7a\u95f4\u3002\u4f46\u662f s \u6307\u5411\u4ec0\u4e48\u5462\uff1f\u4f60\u5e76\u4e0d\u6e05\u695a\uff0c\u4e5f\u5c31\u662f\u8bf4 s \u662f\u4e00\u4e2a\u91ce\u6307\u9488\uff0c\u4f60\u4e0d\u6e05\u695a\u5b83\u6307\u5411\u54ea\u91cc\uff0c\u4e5f\u5c31\u81ea\u7136\u4e0d\u80fd\u5411\u5b83\u6307\u5411\u7684\u7a7a\u95f4\u4e2d\u5199\u5165\u6570\u636e B. str \u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u540d\u4e0d\u80fd\u88ab\u8d4b\u503c\uff0c\u6240\u4ee5\u662f\u9519\u7684 C. str+1 \u4e0d\u80fd\u88ab\u53d6\u5730\u5740\uff0c\u56e0\u4e3a\u8fd9\u662f\u8ba1\u7b97\u8fc7\u7a0b\u4e2d\u7684\u4e00\u4e2a\u6570\uff0c\u800c\u4e0d\u662f\u5b9e\u9645\u5b58\u5728\u5185\u5b58\u4e2d\u7684\u6570\uff0c\u6240\u4ee5\u662f\u9519\u7684 D. str+1 \u8868\u793a\u7684\u5c31\u662f str \u6570\u7ec4\u4e2d\u7b2c\u4e8c\u4e2a\u5143\u7d20\u7684\u5730\u5740\uff0c\u5c06\u5176\u8d4b\u503c\u7ed9 s\uff0c\u662f\u6b63\u786e\u7684
-
(C16A) Given: double a[]={1, 2, 3, 4, 5};
, the value of expression (int)&a[3] - (int)&a[0]
is _____
\u7531\u4e8e\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u90fd\u662f\u8fde\u7eed\u5b58\u50a8\u7684\uff0c\u6240\u4ee5 a[3] \u7684\u5730\u5740\u51cf\u53bb a[0] \u7684\u5730\u5740\u5c31\u662f a[3] \u4e0e a[0] \u4e4b\u95f4\u7684\u8ddd\u79bb\uff0c\u4e5f\u5c31\u662f 3 \u4e2a double \u7c7b\u578b\u7684\u5927\u5c0f\uff0c\u5373 3 * sizeof(double) = 24
\u8fd9\u91cc\u9700\u8981\u548c 17 \u9898\u8fdb\u884c\u4e00\u4e0b\u5bf9\u6bd4\uff0c17 \u9898\u91cc\u6211\u4eec\u518d\u8be6\u7ec6\u8bf4\u660e
-
(C17A) The following code fragment will output _____.
char *week[]={\"Mon\", \"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\",\"Sun\"}, **pw=week;\nchar c1, c2;\nc1 = (*++pw)[1];\nc2 = *++pw[1];\nprintf(\"%c#%c#\", c1, c2);\n
\u9996\u5148 c1 = (*++pw)[1]\uff0c++pw \u4f7f pw \u6307\u5411\u4e86 week[1]\uff0c\u7136\u540e (*++pw) \u5c31\u662f week[1]\uff0c\u518d [1] \u5c31\u662f week[1][1] \u4e5f\u5c31\u662f 'u' \u7136\u540e c2 = *++pw[1]\uff0c\u8fd9\u91cc\u7684\u7406\u89e3\u65b9\u5f0f\u4e00\u5b9a\u662f\u5bf9 pw[1] \u8fdb\u884c ++\uff0cpw[1] \u6b64\u65f6\u662f week[2]\uff0c\u7136\u540e\u5c06\u5176\u81ea\u589e\u5f97\u5230\u6307\u5411 week[2][1] \u7684\u6307\u9488\uff0c\u518d\u89e3\u5f15\u7528\u5f97\u5230 'e'
-
(C17A) For the declaration: int a[3][4]={{0,1,2},{4,5,6},{7,8}};
, the value of the element of a[1][-2]
is _____.
\u548c 11\u300112 \u9898\u7c7b\u4f3c\u5206\u6790\u5373\u53ef
a -> {\n a[0] -> {0, 1, 2, 0}\n ^\n +---- a[1][-2]\n a[1] -> {4, 5, 6, 0}\n a[2] -> {7, 8, 0, 0}\n}\n
-
\u4ee5\u4e0b\u4ee3\u7801\u7684\u8f93\u51fa\u4e3a _____.
int a[] = {1, 2, 3, 4, 5};\nint *p = a, *q = &a[2];\nprintf(\"%lu\", q-p);\n
\u9996\u5148\u8fd9\u9053\u9898\u7684\u8f93\u51fa\u662f 2 \u800c\u4e0d\u662f 2*sizeof(int)=8\uff0c\u56e0\u4e3a q\u3001p \u6307\u9488\u76f8\u51cf\u7684\u610f\u4e49\u5b9e\u9645\u4e0a\u662f\u8ba1\u7b97\u4e24\u4e2a\u6307\u9488\u5dee\u4e86\u51e0\u4e2a\u201c\u5355\u4f4d\u201d\u7684\u8ddd\u79bb\uff0c\u8fd9\u91cc\u4e00\u4e2a\u5355\u4f4d\u5c31\u662f\u4e00\u4e2a int \u7684\u957f\u5ea6\uff0c\u5b83\u4eec\u5dee\u4e86\u4e24\u4e2a int\uff0c\u6240\u4ee5\u662f 2
\u6307\u9488\u76f8\u51cf\u5e76\u4e0d\u662f\u5c06\u5176\u503c\uff08\u4e5f\u5c31\u662f\u5730\u5740\uff09\u76f8\u51cf\uff0c\u5982\u679c\u8fd9\u662f\u9884\u671f\u884c\u4e3a\uff0c\u90a3\u4e48\u5e94\u8be5\u4f7f\u7528\u4ee5\u4e0b\u4e24\u79cd\u5199\u6cd5\uff1a
printf(\"%d\", (int)q - (int)p); // \u5373 14 \u9898\u4e2d\u5199\u6cd5\nprintf(\"%d\", (char*)q - (char*)p); // \u8f6c\u4e3a char* \u7c7b\u578b\u6307\u9488\uff0c\u5355\u4f4d\u5c31\u662f\u4e00\u4e2a\u5b57\u8282\uff0c\u548c\u5730\u5740\u76f8\u51cf\u6548\u679c\u76f8\u540c\n
-
\u4ee5\u4e0b\u54ea\u4e2a\u5b9a\u4e49\u4e2d p \u4e0d\u662f\u6307\u9488 _____. A. char **p; B. char (*p)[10]; C. char *p[6]; D. \u524d\u4e09\u9879\u4e2d p \u90fd\u662f\u6307\u9488
\u8be6\u7ec6\u5206\u6790\u53ef\u4ee5\u770b\u8d3a\u8001\u5e08\u300a\u6d45\u8c08 C \u8bed\u8a00\u7684\u6570\u636e\u7c7b\u578b\u300b\u4e2d\u63cf\u8ff0\u7684 Clockwise/Spiral Rule
A \u4e2d p \u663e\u7136\u662f\u4e00\u4e2a\u4e8c\u7ea7\u6307\u9488\uff0cB \u4e2d p \u662f\u4e00\u4e2a\u6307\u5411\u957f\u5ea6\u4e3a 10 \u7684\u6570\u7ec4\u7684\u6307\u9488\uff0cC \u4e2d p \u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a 6 \u7684\u6307\u9488\u6570\u7ec4\uff08\u5373\u4e00\u4e2a\u6570\u7ec4\uff0c\u5185\u90e8\u5143\u7d20\u662f\u6307\u9488\uff09
\u8fd8\u6709\u4e00\u70b9\u8981\u6ce8\u610f\uff0c\u6570\u7ec4\u548c\u6307\u9488\u662f\u4e24\u79cd\u7c7b\u578b
-
\u5bf9\u4e8e\u51fd\u6570\u58f0\u660e void f(char **p)
\uff0c\u4ee5\u4e0b\u54ea\u4e2a var \u7684\u5b9a\u4e49\u4f1a\u4f7f f(var) \u8bed\u6cd5\u9519\u8bef _____. A. char var[10][10]; B. char *var[10]; C. void *var = NULL; D. char *v=NULL, **var=&v;
BD \u4e00\u822c\u6ca1\u4ec0\u4e48\u95ee\u9898\uff0c\u5927\u90e8\u5206\u540c\u5b66\u4e0d\u7406\u89e3 A \u548c C
A. \u4e8c\u7ef4\u6570\u7ec4\u4e0d\u80fd\u9000\u5316\u4e3a\u4e8c\u7ea7\u6307\u9488\uff0c\u6240\u4ee5\u80af\u5b9a\u662f\u9519\u7684 C. \u5728 C \u8bed\u8a00\u4e2d\uff0cvoid* \u8868\u793a\u300c\u6307\u5411\u4efb\u610f\u7c7b\u578b\u7684\u6307\u9488\u300d\uff0c\u800c\u8fd9\u4e2a\u300c\u4efb\u610f\u7c7b\u578b\u300d\u4e5f\u53ef\u4ee5\u662f char*\uff08\u5373\u6307\u5411 char \u7684\u6307\u9488\uff09\uff0c\u6240\u4ee5\u5b83\u53ef\u4ee5\u4ee3\u8868\u300c\u6307\u5411\u6307\u5411 char \u7684\u6307\u9488\u7684\u6307\u9488\u300d\uff08char**\uff09\uff0c\u6240\u4ee5\u662f\u5bf9\u7684
-
\u5bf9\u4e8e\u5b9a\u4e49 char s[2][3] = {\"ab\", \"cd\"}, *p=(char*)s
\uff0c\u4ee5\u4e0b\u54ea\u4e2a\u8868\u8fbe\u5f0f\u662f\u6b63\u786e\u7684\u4e14\u503c\u7b49\u4e8e s[1][1] _____. A. *(s+3) B. *s+2 C. p[1][1] D. *++p+2
s -> {\n s[0] -> {'a', 'b', '\\0'}\n s[1] -> {'c', 'd', '\\0'}\n}\n
A. *(s+3) \u7b49\u4ef7\u4e8e s[3]\uff0c\u9996\u5148\u7c7b\u578b\u4e0a\u5b83\u5c31\u4e0d\u5bf9 B. \u540c\u6837 *s+2 \u4e5f\u662f\u6307\u9488\uff0c\u7c7b\u578b\u4e0a\u5c31\u80af\u5b9a\u4e0d\u5bf9 C. p \u6b64\u65f6\u662f char* \u7c7b\u578b\uff0c\u4e0d\u80fd\u8fdb\u884c\u4e24\u6b21\u89e3\u5f15\u7528\uff0c\u8bed\u6cd5\u9519\u8bef D. ++p \u5c06 p \u6307\u5230\u4e86 'b' \u5934\u4e0a\uff0c\u89e3\u5f15\u7528\u5f97\u5230 'b' \u518d\u52a0\u4e8c\u5f97\u5230 'd' \u7b49\u4e8e s[1][1]\uff0c\u9009 D
"},{"location":"programming/exam/exam/#_7","title":"\u5b57\u7b26\u4e32\u76f8\u5173","text":"\u5b57\u7b26\u4e32\u4e5f\u662f\u4e00\u4e2a\u5f88\u5bb9\u6613\u51fa\u9519\u7684\u8003\u70b9\uff0c\u6211\u63a8\u8350\u7684\u7406\u89e3\u65b9\u5f0f\u662f\uff1aC \u8bed\u8a00\u4e2d\u4e0d\u5b58\u5728\u5b57\u7b26\u4e32\uff0c\u53ea\u6709\u5b57\u7b26\u6570\u7ec4\uff0c\u800c\u5b57\u7b26\u4e32\u662f\u4e00\u79cd\u5bf9\u4e8e\u5b57\u7b26\u6570\u7ec4\u7684\u4eba\u4e3a\u7406\u89e3\u65b9\u5f0f\uff0c\u5373\u4ece\u5f00\u5934\u76f4\u5230\u7b2c\u4e00\u4e2a '\\0' \u6807\u5fd7\u4e86\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u6240\u4ee5 \"abc\" \u548c {'a', 'b', 'c', '\\0'} \u662f\u7b49\u4ef7\u7684\u3002
\u53e6\u4e00\u4e2a\u9700\u8981\u7262\u8bb0\u7684\u77e5\u8bc6\u70b9\u662f\uff0c\u5f53\u7a0b\u5e8f\u4e2d\u51fa\u73b0\u5b57\u7b26\u4e32\u5e38\u91cf\u7684\u65f6\u5019\uff0c\u8981\u5c06\u5176\u89c6\u4e3a\u6307\u5411\u8be5\u5b57\u7b26\u4e32\u7684\u9996\u5b57\u7b26\u7684\u6307\u9488\u6765\u5904\u7406\u3002\u800c\u4e14\u5728\u521d\u59cb\u5316\u5b57\u7b26\u6570\u7ec4\u65f6\u9664\u5916\uff08char s[] = \"abc\"; \u5e76\u4e0d\u662f\u628a \"abc\" \u9996\u5b57\u7b26\u5730\u5740\u8d4b\u503c\u7ed9\u4e86 s\uff09\u3002
\u5bf9\u4e8e char *s = \"abc\" \u548c char s[] = \"abc\" \u6211\u4eec\u5728\u7b2c 31 \u9898\u4e2d\u518d\u8be6\u7ec6\u8fdb\u884c\u533a\u5206\u3002
-
(C13A) Given: char format[] = \"No.%d%c\"
; the statement printf(format, 3, *(\"xyz\"+2));
will print out _____.
\"xyz\" \u8fd9\u91cc\u5f53\u4f5c\u6307\u5411 'x' \u7684\u6307\u9488\uff0c\u52a0 2 \u5219\u6307\u5230\u4e86 'z'\uff0c\u89e3\u5f15\u7528\u5c31\u5f97\u5230\u4e86 'z' \u8fd9\u4e2a\u5b57\u7b26\u3002\u6240\u4ee5\u8f93\u51fa\u4e3a No.3z
-
(C14A/C15A) Given the following code fragment, the loop condition str[i]!='\\0'
could be replaced by which choice? _____.
char str[20]=\"hello, world\";\nfor (i = 0; str[i] != '\\0'; i++) putchar(str[i]);\n
A. str[i] B. i < 20 C. !(str[i] = '\\0') D. i <= 20 \u8fd8\u8981\u8bb0\u4f4f\u7684\u4e00\u70b9\u662f\uff0c'\\0' \u5c31\u662f 0\uff0c\u6240\u4ee5\u8fd9\u9898\u91cc str[i] != '\\0' \u548c A \u662f\u5b8c\u5168\u7b49\u4ef7\u7684\u3002\uff08C \u5dee\u4e86\u4e00\u4e2a\u7b49\u53f7\uff09 B \u9519\u8bef\u7684\u539f\u56e0\u662f\uff0c'\\0' \u4e5f\u662f\u5b57\u7b26\uff0c\u8fd9\u6837\u5c31\u4e00\u5b9a\u4f1a\u8f93\u51fa 20 \u4e2a\u5b57\u7b26\u6765\uff0c\u5373\u4f7f\u5b9e\u9645\u4e0a\u4f60\u770b\u4e0d\u89c1 '\\0' \u8fd9\u4e2a\u5b57\u7b26\uff0c\u4f46\u5b83\u4eec\u786e\u5b9e\u88ab\u8f93\u51fa\u4e86
-
(C14A) The value of expression !*(\"2015-01-28\"+5)
is _____
\u5b57\u7b26\u4e32\u5e38\u91cf\u51fa\u73b0\u5728\u7a0b\u5e8f\u91cc\u5f53\u4f5c\u6307\u5411\u9996\u5b57\u7b26\u7684\u6307\u9488\u5904\u7406\uff0c\u6240\u4ee5 \"2015-01-28\"+5 \u5373\u8868\u793a\u6307\u5411 '0' \u4f4d\u7f6e\u7684\u6307\u9488\uff0c\u89e3\u5f15\u7528\u5f97\u5230 '0'\u3002\u6240\u4ee5\u8fd9\u9898\u5316\u4e3a\u4e86 !'0' \u7684\u503c\u3002
\u4e00\u5b9a\u8981\u533a\u5206\u6e05\u695a '0' \u548c '\\0'\uff0c'0'==48 \u800c '\\0'==0\uff0c\u6240\u4ee5 !'0' \u662f !48 \u5373 0
-
(C14A) The output of the code below is _____.
char x[] = \"hello,world\\012345\";\nprintf(\"%d#%d#\"\uff0csizeof(x)\uff0cstrlen(x));\n
\u590d\u4e60\u4e00\u4e0b\u524d\u9762\u8bf4\u8fc7\u7684\u5b57\u7b26\u5b57\u9762\u91cf\u7684\u8868\u793a
\u8fd9\u91cc x \u5c31\u76f8\u5f53\u4e8e 'h', 'e', 'l', 'l', 'o', ',', 'w', 'o', 'r', 'l', 'd', '\\012', '3', '4', '5', '\\0'\uff0c\u6240\u4ee5 sizeof(x) \u8ba1\u7b97\u5360\u4e86\u591a\u5c11\u7a7a\u95f4\uff0c\u4e00\u5171 16 \u4e2a\u5b57\u8282\uff0c\u7ed3\u679c\u4e3a 16\u3002\u800c strlen(x) \u8ba1\u7b97\u7b2c\u4e00\u4e2a '\\0' \u524d\u6709\u51e0\u4e2a\u5b57\u7b26\uff0c\u8fd9\u91cc\u6709 15 \u4e2a\uff08'\\012' \u4e2d\u7684 \\0 \u5e76\u4e0d\u7b97 '\\0'\uff09\uff0c \u7ed3\u679c\u4e3a 15\u3002
-
(C17A) The value of expression !\"01-21-2018\"[7]
is _____
\u540c 23 \u9898\uff0c\u8fd9\u91cc \"01-21-2018\"[7] \u6307\u5411\u4e86 '0'\uff0c!'0' \u4e3a 0
-
(C17A) Given: char s[]=\"123\\029\\08\";
, then sizeof(s)
and strlen(s)
will be _____ respectively.
\u540c 24 \u9898\uff0c\u8fd9\u91cc s \u5b57\u7b26\u6570\u7ec4\u76f8\u5f53\u4e8e '1', '2', '3', '\\02', '9', '\\0', '8', '\\0'\uff0c\u4e00\u5171 8 \u4e2a\uff0c\u6240\u4ee5 sizeof(s) \u4e3a 8\u3002\u7b2c\u4e00\u4e2a '\\0' \u524d\u6709 5 \u4e2a\uff0c\u6240\u4ee5 strlen(s) \u4e3a 5\u3002
-
(C17A) The value of expression strcmp(\"abcabc\",\"aabbcc\"+1) < 0
is _____.
strcmp(s1, s2) \u5f53 s1 < s2 \u65f6\u8fd4\u56de\u4e00\u4e2a\u8d1f\u6570\uff0c\u5f53 s1 > s2 \u65f6\u8fd4\u56de\u4e00\u4e2a\u6b63\u6570\uff0c\u5f53 s1 == s2 \u65f6\u8fd4\u56de 0\u3002\u6240\u4ee5\u8fd9\u9898\u76f8\u5f53\u4e8e\u6bd4\u8f83 \"abcabc\" \u548c \"abbcc\"\uff0c\"abcabc\" > \"abbcc\"\uff0c\u6240\u4ee5\u8fd4\u56de\u4e00\u4e2a\u6b63\u6570\uff0c\u7ed3\u679c\u4e3a 0
\u5177\u4f53\u5b57\u7b26\u4e32\u6bd4\u8f83\u5927\u5c0f\u7684\u65b9\u5f0f\u79f0\u4e3a\u201c\u5b57\u5178\u5e8f\u201d\uff0c\u4e5f\u5c31\u662f\u8bf4\u5047\u8bbe\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u5728\u82f1\u6587\u8bcd\u5178\u4e2d\uff0c\u90a3\u4e48\u5b83\u4eec\u7684\u5927\u5c0f\u5173\u7cfb\u5c31\u662f\u5728\u8bcd\u5178\u4e2d\u51fa\u73b0\u7684\u5148\u540e\u5173\u7cfb\uff08\u5148\u51fa\u73b0\u7684\u5c0f\uff09
-
(C18A) The value of expression !(\"01/24/2019\"+5)[5]
is _____.
\u540c 23 \u9898\uff0c\u8fd9\u91cc\u76f8\u5f53\u4e8e !*(\"01/24/2019\"+10)\u3002\u5176\u4e2d\u5b57\u7b26\u4e32\u52a0 10 \u540e\u6307\u5411\u4e86\u7ed3\u5c3e\u9690\u85cf\u7684 '\\0'\uff0c\u800c '\\0' \u5c31\u662f 0\uff0c\u6240\u4ee5\u53d6\u53cd\u4e3a 1
-
\u4ee5\u4e0b\u4ee3\u7801\u6bb5\u7684\u8f93\u51fa\u4e3a _____.
char c[] = \"I\\t\\r\\\\\\0will\\n\";\nprintf(\"%d\", strlen(c));\n
\u540c 24 \u9898\uff0c\u8fd9\u91cc c \u5b57\u7b26\u6570\u7ec4\u76f8\u5f53\u4e8e 'I', '\\t', '\\r', '\\', '\\0', 'w', 'i', 'l', 'l', '\\n', '\\0'\uff0c\u7b2c\u4e00\u4e2a '\\0' \u524d\u6709 4 \u4e2a\uff0c\u6240\u4ee5 strlen\u00a9 \u4e3a 4\u3002
-
\u4ee5\u4e0b\u4ee3\u7801\u6bb5\u7684\u8f93\u51fa\u4e3a _____.
char a[] = \"abc\";\nchar b[] = {'a', 'b', 'c'};\nprintf(\"%d#%d#\", sizeof(a), sizeof(b));\n
\"abc\" \u53ef\u4ee5\u5f53\u4f5c {'a', 'b', 'c', '\\0'}\uff0c\u6240\u4ee5 sizeof(a) \u4e3a 4\uff0csizeof(b) \u4e3a 3\u3002
-
\u4ee5\u4e0b\u4ee3\u7801\u662f\u5426\u5b58\u5728\u9519\u8bef\uff0c\u5982\u679c\u6709\u8bf7\u6307\u51fa\u54ea\u91cc\u6709\u95ee\u9898 _____.
char *a = \"hello\";\nchar b[] = \"hello\";\na[0] = 'H';\nb[0] = 'H';\n
\u8fd9\u91cc\u6211\u4eec\u8981\u533a\u5206\u7684\u662f a \u548c b\u3002a \u5c31\u662f\u4e00\u4e2a\u5b57\u7b26\u6307\u9488\uff0c\u5b83\u6307\u5411\u4e86 \"hello\" \u7684\u5f00\u5934\uff0c\u800c\u8fd9\u4e2a \"hello\" \u5b58\u5728\u4e8e\u9759\u6001\u5b58\u50a8\u533a\u4e2d\uff0c\u662f\u53ea\u8bfb\u7684\uff0c\u4e0d\u80fd\u8fdb\u884c\u4fee\u6539\uff0c\u6240\u4ee5 a[0] = 'H' \u4f1a\u5728\u8fd0\u884c\u65f6\u4ea7\u751f\u9519\u8bef\uff08\u53ef\u4ee5\u901a\u8fc7\u7f16\u8bd1\uff0c\u4f46\u662f\u8fd0\u884c\u4f1a\u62a5\u9519\uff09 \u800c b \u662f\u4e00\u4e2a\u5b57\u7b26\u6570\u7ec4\uff0c\u5b83\u81ea\u5e26\u4e86\u6808\u4e0a\u7a7a\u95f4\uff0c\u5728\u521d\u59cb\u5316\u8d4b\u503c\u7684\u65f6\u5019 \"hello\" \u4f1a\u88ab\u590d\u5236\u5230 b \u7684\u7a7a\u95f4\u4e2d\uff0c\u6240\u4ee5 b[0] = 'H' \u662f\u5408\u6cd5\u7684\u3002
"},{"location":"programming/exam/exam/#_8","title":"\u91ce\u6307\u9488\u76f8\u5173","text":"13 \u9898\u4e2d\u51fa\u73b0\u4e86\u4e00\u4e2a\u91ce\u6307\u9488\uff0c\u5373\u6ca1\u6709\u88ab\u8d4b\u503c\uff0c\u4e0d\u77e5\u9053\u6307\u5411\u4ec0\u4e48\u7684\u6307\u9488\u3002\u8fd9\u6837\u7684\u6307\u9488\u4e0d\u80fd\u8fdb\u884c\u89e3\u5f15\u7528\uff08\u4f1a\u62a5\u9519\uff09\uff0c\u56e0\u4e3a\u5b83\u968f\u673a\u6307\u5411\u7684\u4f4d\u7f6e\u5927\u6982\u7387\u662f\u4f60\u4e0d\u53ef\u7528\u7684\u7a7a\u95f4\u3002
\u8981\u6e05\u695a\u7684\u662f\uff0c\u58f0\u660e\u4e00\u4e2a\u6307\u9488\u53ea\u4f1a\u5206\u914d\u4e00\u4e2a\u7ed9\u6307\u9488\u53d8\u91cf\u7684\u7a7a\u95f4\uff08\u8fd9\u90e8\u5206\u7a7a\u95f4\u7528\u6765\u5b58\u50a8\u5b83\u6307\u5411\u7684\u4f4d\u7f6e\u7684\u5730\u5740\u503c\uff09\uff0c\u800c\u4e0d\u4f1a\u5206\u914d\u6307\u5411\u7684\u7a7a\u95f4\u3002\u4f7f\u4e00\u4e2a\u6307\u9488\u53ef\u7528\u53ef\u4ee5\u5c06\u5176\u5b83\u53d8\u91cf\u53d6\u5730\u5740\u8d4b\u503c\u7ed9\u5b83\uff0c\u8fd9\u6837\u5b83\u6307\u5411\u7684\u4f4d\u7f6e\u5c31\u662f\u6709\u6548\u7684\u3002\u6216\u8005\u901a\u8fc7 malloc \u6765\u65b0\u5206\u914d\u4e00\u5757\u5806\u4e0a\u7684\u5185\u5b58\uff0cmalloc \u7684\u8fd4\u56de\u503c\u5c31\u662f\u8fd9\u5757\u5185\u5b58\u7684\u9996\u5730\u5740\uff0c\u4e5f\u662f\u4f60\u53ef\u7528\u7684\u3002
-
(C13A) In the following code fragments, item _ is correct. A. int *p; scanf(\"%d\", &p); B. int *p; scanf(\"%d\", p); C. int k, *p=&k; scanf(\"%d\", p); D. int k, *p; *p=&k; scanf(\"%d\", p);
A. \u8fd9\u91cc\u5b9e\u9645\u4e0a\u662f\u8bfb\u5165\u4e86\u6570\u636e\u5199\u5230\u4e86 p \u6307\u9488\u7684\u7a7a\u95f4\u4e0a\uff08\u5373\u901a\u8fc7\u8f93\u5165\u6765\u7ed9\u6307\u9488\u8d4b\u503c\uff09\uff0c\u662f\u9519\u8bef\u7684\u64cd\u4f5c\uff1b B. \u8fd9\u91cc\u8bfb\u5165\u6570\u636e\u5199\u5230\u4e86 p \u6307\u5411\u7684\u7a7a\u95f4\u4e2d\uff0c\u800c p \u662f\u4e00\u4e2a\u91ce\u6307\u9488\uff0c\u4e0d\u80fd\u5411\u5b83\u6307\u5411\u7684\u7a7a\u95f4\u5199\u5165\u6570\u636e\uff0c\u662f\u9519\u8bef\u7684\uff1b C. \u8fd9\u91cc\u5c06 k \u7684\u5730\u5740\u8d4b\u503c\u7ed9\u4e86 p\uff0c\u6240\u4ee5\u8bfb\u5165\u4f1a\u5199\u5230 k \u4e2d\uff0c\u662f\u6b63\u786e\u7684\uff0c\u9009 C\uff1b D. \u8fd9\u91cc *p=&k \u4e00\u53e5\u5b9e\u9645\u4e0a\u662f\u5c06 k \u7684\u5730\u5740\u5199\u5165 p \u6307\u5411\u7684\u7a7a\u95f4\u4e2d\uff0c\u540c\u7406\uff0cp \u662f\u91ce\u6307\u9488\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u662f\u9519\u8bef\u7684\u3002
Note
\u8fd9\u91cc\u591a\u8bf4\u4e00\u5634 scanf \u7684\u4f5c\u7528\uff0cscanf \u8981\u8bfb\u53d6\u6570\u636e\u5199\u5230\u5185\u5b58\u4e2d\uff0c\u6240\u4ee5\u53c2\u6570\u4e3a\u6307\u9488\u3002 \u4f8b\u5982 int n; scanf(\"%d\", &n); \"%d\" \u544a\u8bc9 scanf \u6211\u8981\u8bfb\u53d6\u4e00\u4e2a\u6574\u578b \u8bfb\u5230\u54ea\u91cc\u2014\u2014\u2014\u2014\u8bfb\u5230\u53d8\u91cf n \u7684\u5185\u5b58\u7a7a\u95f4\u4e2d n \u5b58\u5728\u54ea\u91cc\u2014\u2014\u2014\u2014n \u7684\u5730\u5740 \u600e\u4e48\u5f97\u5230 n \u7684\u5730\u5740\u2014\u2014\u2014\u2014\u901a\u8fc7 & \u53d6\u5730\u5740
-
\u5047\u8bbe scanf
\u8bed\u53e5\u6267\u884c\u65f6\u8f93\u5165 ABCDE<\u56de\u8f66>
\uff0c\u80fd\u4f7f puts(s)
\u8bed\u53e5\u6b63\u786e\u8f93\u51fa ABCDE
\u7684\u7a0b\u5e8f\u6bb5\u662f _____. A. char s[5] = {\"ABCDE\"}; puts(s); B. char s[5] = {'A', 'B', 'C', 'D', 'E'}; puts(s); C. char *s; scanf(\"%s\", s); puts(s); D. char *s; s=\"ABCDE\"; puts(s);
A. s \u7684\u5927\u5c0f\u53ea\u6709 5 \u4e2a\u5b57\u8282\uff0c\u653e\u4e0d\u4e0b\u6700\u540e\u7684 '\\0'\uff0c\u6240\u4ee5 puts \u53ef\u80fd\u51fa\u9519 B. \u7ed3\u5c3e\u6ca1\u6709 '\\0'\uff0cputs \u53ef\u80fd\u51fa\u9519 C. \u5411\u91ce\u6307\u9488 s \u5199\u5165\u4e86\u6570\u636e\uff0c\u4e00\u5b9a\u51fa\u9519 D. \u5c06\u9759\u6001\u5b58\u50a8\u533a\u4e2d \"ABCDE\" \u7684\u9996\u5730\u5740\u7ed9\u4e86 s\uff0c\u7136\u540e\u8f93\u51fa\uff0c\u5b8c\u5168\u6b63\u786e\uff0c\u9009 D
"},{"location":"programming/exam/exam/#_9","title":"\"\u5947\u602a\"\u7684\u8868\u8fbe\u5f0f/\u8bed\u53e5","text":"\u4e00\u4e9b\u5b8c\u5168\u8bed\u6cd5\u6b63\u786e\uff0c\u4f46\u662f\u53ef\u80fd\u4f1a\u6df7\u6dc6\u89c6\u542c\u8ba9\u4f60\u7406\u89e3\u9519\u8bef\u7684\u8868\u8fbe\u5f0f/\u8bed\u53e5\u3002
-
(C13A) Given: char c='@'
;, the value of expression 'A' <= c <= 'Z'
is _____.
\u4e00\u4e2a\u7ecf\u5178\u95ee\u9898\uff0c'A' <= c <= 'Z' \u5e76\u4e0d\u662f\u5224\u65ad c \u5728\u4e0d\u5728 A-Z \u8303\u56f4\u5185\uff0c\u800c\u662f\u7b49\u4ef7\u4e8e ('A' <= c) <= 'Z'\u3002\u5176\u4e2d 'A' <= c \u4e00\u5b9a\u662f 0 \u6216 1\uff0c\u65e0\u8bba\u5982\u4f55\u90fd\u5c0f\u4e8e 'Z'\uff0c\u6240\u4ee5\u7ed3\u679c\u4e3a 1\u3002
-
(C13A) After executing the code below, the value of y is _____.
int x = 0, y = 0, z = 0;\nz = (x==1) && (y=2);\n
\u8fd9\u91cc\u6d89\u53ca\u5230\u4e86 || \u548c && \u7684\u201c\u77ed\u8def\u201d\u6027\u8d28\uff1a\u5f53 && \u5de6\u8fb9\u4e3a\u5047\u65f6\uff0c\u6574\u4f53\u4ee5\u5b9a\u4f4d\u5047\uff0c\u5219\u53f3\u8fb9\u4e0d\u518d\u8ba1\u7b97\uff1b\u5f53 || \u5de6\u8fb9\u4e3a\u771f\u65f6\uff0c\u6574\u4f53\u4e00\u5b9a\u4e3a\u771f\uff0c\u5219\u53f3\u8fb9\u4e0d\u518d\u8ba1\u7b97\u3002
\u8fd9\u91cc x==1 \u5df2\u7ecf\u4e3a\u5047\uff0c\u6240\u4ee5\u53f3\u4fa7\u7684 y=2 \u4e0d\u518d\u6267\u884c\uff0cy \u4ecd\u7136\u4e3a 0\u3002
-
(C17A) After executing the following code fragment, the output is _____.
int i, b; i = b = 1;\nswitch (i) {\n case 0: b += 1;\n case 1: b += 2;\n case 3: switch (b) {\n case 3: i++;\n default: break;\n }\n i += 1;\n}\nprintf(\"%d#%d#\", i, b);\n
case \u53ea\u89c4\u5b9a\u4e86\u8d77\u70b9\uff0c\u800c\u4f55\u65f6\u9000\u51fa switch \u5757\u5219\u7531 break \u51b3\u5b9a\uff0c\u53ea\u8981\u6ca1\u6709\u9047\u5230 break\uff0c\u5219\u4e00\u76f4\u5411\u4e0b\u6267\u884c\uff08\u5373\u4f7f\u78b0\u5230\u4e86\u4e0b\u4e00\u4e2a case\uff09
\u8fd9\u9898\u91cc i \u4e3a 1\uff0c\u8fdb\u5165\u4e86 case 1 \u4e2d\uff0cb \u53d8\u4e3a\u4e86 3\uff0c\u7d27\u63a5\u7740\u56e0\u4e3a\u6ca1\u6709 break \u8fd8\u4f1a\u8fdb\u5165\u5230 case 3 \u4e2d\uff0c\u6b64\u65f6 b \u4e3a 3 \u8fdb\u5165\u4e86 case 3 \u6267\u884c\u4e86 i++\uff0c\u7136\u540e\u8fdb\u5165 default \u6267\u884c\u4e86 break\uff0c\u9000\u51fa\u540e\u53c8\u6267\u884c\u4e86 i+=1\uff0c\u6240\u4ee5\u6700\u7ec8 i \u548c b \u90fd\u4e3a 3\u3002
-
\u4e0b\u5217\u4ee3\u7801\u6267\u884c\u540e m \u548c n \u7684\u503c\u5206\u522b\u4e3a _____.
int a=1, b=2, c=3, d=4, m=1, n=2, v;\nv = (m=a>b) && (n=c>d);\n
\u540c 35 \u9898\uff0c(m=a>b) \u5df2\u7ecf\u4e3a\u5047\uff08\u5c06 a>b \u5373 0 \u8d4b\u503c\u7ed9 m\uff0c\u7136\u540e\u5224\u65ad m \u662f\u5426\u4e3a 0\uff0c\u662f 0\uff0c\u90a3\u4e48\u6574\u4f53\u5c31\u662f\u5047\uff09\uff0c\u53f3\u4fa7\u7684 (n=c>d) \u4e0d\u518d\u6267\u884c\uff0c\u6240\u4ee5\u6700\u7ec8 m=0, n=2\u3002
-
\u4ee5\u4e0b\u4ee3\u7801\u8bed\u6cd5\u6b63\u786e\u7684\u662f _____. A. for ( ); B. do { } while ( ); C. while ( ) ; D. for ( ; ; ) ;
while \u540e\u7684\u62ec\u53f7\u4e2d\u5fc5\u987b\u6709\u6761\u4ef6\u8868\u8fbe\u5f0f\uff0c\u6240\u4ee5 BC \u9519\u8bef\uff1bfor \u540e\u9762\u7684\u62ec\u53f7\u4e2d\u5fc5\u987b\u6709\u4e24\u4e2a\u5206\u53f7\u5206\u5272\u7684\u4e09\u4e2a\u8bed\u53e5\uff0c\u6240\u4ee5 A \u9519\u8bef\u3002 D \u662f\u6b63\u786e\u7684\uff0cfor( ; ; ) \u5c31\u8868\u793a\u6b7b\u5faa\u73af\uff0c\u800c\u540e\u9762\u7684 ; \u8868\u793a\u5faa\u73af\u4f53\u4e3a\u7a7a\uff0c\u8bed\u6cd5\u5b8c\u5168\u6b63\u786e\uff0c\u662f\u4e00\u4e2a\u5f7b\u5e95\u7684\u6b7b\u5faa\u73af\u3002
-
\u6709\u5b9a\u4e49 int a = 1;
\uff0c\u5219\u8868\u8fbe\u5f0f (a=4*5,a*2),a+6
\u7684\u503c\u4e3a _____.
\u8fd9\u91cc\u7684\u8003\u70b9\u662f\u300c\u9017\u53f7\u8868\u8fbe\u5f0f\u300d\uff0c\u9017\u53f7\u8868\u8fbe\u5f0f\u5728\u6267\u884c\u65f6\u4ece\u5de6\u5230\u53f3\u4f9d\u6b21\u6267\u884c\u9017\u53f7\u5206\u5272\u7684\u5404\u4e2a\u90e8\u5206\uff0c\u7136\u540e\u8868\u8fbe\u5f0f\u6700\u7ec8\u7684\u503c\u4e3a\u6700\u53f3\u4fa7\u7684\u503c\u3002 \u8fd9\u91cc\u5148\u6267\u884c\u4e86 a=4*5\uff0c\u7136\u540e\u6267\u884c\u4e86 a*2\uff08\u6ca1\u6709\u4efb\u4f55\u6548\u679c\uff09\uff0c\u6700\u7ec8\u7684\u503c\u4e3a a+6 = 20+6 = 26\u3002
-
\u5b9a\u4e49 int a[][3] = {{1, 2, 3}, (4, 5, 6)}
\u662f\u5426\u6b63\u786e _\uff0c\u5982\u679c\u6b63\u786e\uff0c\u90a3\u4e48 a[1][0]
\u7684\u503c\u4e3a ___.
\u8fd9\u91cc\u4e5f\u662f\u4e00\u4e2a\u9017\u53f7\u8868\u8fbe\u5f0f\u7684\u5e94\u7528\uff0c\u4e0d\u8fc7 (4, 5, 6) \u51fa\u73b0\u5728\u8fd9\u91cc\u5f88\u5bb9\u6613\u6df7\u6dc6\u8ba9\u4eba\u4ee5\u4e3a\u662f\u4e00\u4e2a\u6570\u7ec4\u3002\u5176\u5b9e\u8fd9\u9053\u9898\u7684\u5b9a\u4e49\u76f8\u5f53\u4e8e int a[][3] = {{1, 2, 3}, 6}
\uff0c\u6240\u4ee5 a[1][0] \u503c\u4e3a 6\u3002
"},{"location":"programming/exam/exam/#sizeof","title":"sizeof \u95ee\u9898","text":"sizeof \u662f C \u8bed\u8a00\u4e2d\u7684\u4e00\u4e2a\u8fd0\u7b97\u7b26\uff0c\u800c\u4e0d\u662f\u51fd\u6570\uff0c\u5b83\u7684\u4f5c\u7528\u662f\u67e5\u8be2\u5360\u636e\u7684\u7a7a\u95f4\u5b57\u8282\u6570\u3002\u4f8b\u5982 sizeof(int) \u8ba1\u7b97\u4e00\u4e2a int \u5360\u7684\u5b57\u8282\u6570\uff0c\u4e5f\u5c31\u662f 4\uff1bint a[2]; sizeof(a) \u8ba1\u7b97 a \u8fd9\u4e2a\u6570\u7ec4\u5360\u7684\u5b57\u8282\u6570\uff0c\u4e5f\u5c31\u662f 2 \u4e2a int\uff0c\u5373 2*4=8\u3002
-
(C18A) Given: short s[][5]={301,302,303,304,305,306,307,308,309,0};
, the values of sizeof(s)
and strlen((char *)s)
will be _____ respectively.
\u4e00\u4e2a short \u5360\u4e24\u4e2a\u5b57\u8282\uff0c301 \u7684\u5b58\u50a8\u65b9\u5f0f\u662f\u5b58\u50a8 0x2d 0x01 \u4e24\u4e2a\u5b57\u8282\uff08\u5c0f\u7aef\u5e8f\uff09\uff0c\u6240\u4ee5 s \u6570\u7ec4\u5728\u5185\u5b58\u4e2d\u4e3a\uff1a
2d 01 2e 01 2f 01 30 01 31 01 32 01 33 01 34 01 35 01 00 00 \n
\u4e00\u5171 20 \u4e2a\u5b57\u8282\uff0c\u6240\u4ee5 sizeof(s) = 20\uff0c\u800c strlen((char *)s) = 18\uff08\u7b2c\u4e00\u4e2a 00 \u524d\u7684\u5b57\u8282\u6570\uff09 -
\u4ee5\u4e0b\u4ee3\u7801\u7684\u8f93\u51fa\u4e3a _____.
char c[100] = \"1234\";\nprintf(\"%d#%d#\", sizeof(c), strlen(c));\n
sizeof\u00a9 = 100\uff0cstrlen\u00a9 = 4\uff0c\u4e0d\u591a\u89e3\u91ca
-
\u4ee5\u4e0b\u4ee3\u7801\u7684\u8f93\u51fa\u4e3a _____.
void func(int a[5]) {\n printf(\"%d\", sizeof(a));\n}\nint main() {\n int a[5] = {0};\n printf(\"%d\\n\", sizeof(a));\n func(a);\n}\n
\u8fd9\u91cc\u9996\u5148\u8f93\u51fa\u6570\u7ec4 a \u5360\u7684\u5b57\u8282\u6570\uff0c\u4e5f\u5c31\u662f 4*5=20\u3002\u7136\u540e\u5c06 a \u4f20\u5165 func \u51fd\u6570\u540e\uff0ca \u9000\u5316\u4e3a\u4e86\u6307\u9488\uff08\u5373\u4f7f\u51fd\u6570\u524d\u9762\u91cc\u7c7b\u578b\u8fd8\u662f int[5]\uff09\uff0c\u5728 func \u51fd\u6570\u4e2d\u8ba1\u7b97 sizeof(a) \u7684\u8bdd\u8f93\u51fa\u7684\u5c31\u662f\u6307\u9488\u5360\u7684\u5927\u5c0f\uff0c\u8fd9\u4e2a\u503c\u662f\u4e0d\u4e00\u5b9a\u7684\uff0c\u5728 32 \u4f4d\u67b6\u6784\u4e2d\u662f 4\uff0c\u5728 64 \u4f4d\u67b6\u6784\u4e2d\u662f 8\u3002
"},{"location":"programming/exam/exam/#_10","title":"\u5173\u4e8e\u8f93\u5165\u8f93\u51fa","text":"\u683c\u5f0f\u5316\u8f93\u5165\u8f93\u51fa\uff08printf\uff0cscanf\uff09\u8fd8\u6709\u4e24\u79cd\u53d8\u4f53\uff1asprintf\uff0csscanf \u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\u5b57\u7b26\u4e32\uff08char\uff09\uff0c\u4f1a\u8f93\u51fa\u5230\u5b57\u7b26\u4e32\u4e2d/\u4ece\u5b57\u7b26\u4e32\u4e2d\u8bfb\u53d6\u8f93\u5165\uff1bfprintf\uff0cfscanf \u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\u6587\u4ef6\u6307\u9488\uff08FILE\uff09\uff0c\u4f1a\u8f93\u51fa\u5230\u6587\u4ef6\u4e2d/\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u8f93\u5165\u3002\u800c printf scanf \u5219\u662f\u8f93\u51fa\u5230\u6807\u51c6\u8f93\u51fa/\u4ece\u6807\u51c6\u8f93\u5165\u8bfb\u53d6\u8f93\u5165\u3002stdin stdout \u662f\u4e24\u4e2a\u7279\u6b8a\u7684\u6587\u4ef6\uff0c\u6240\u4ee5 printf scanf \u5206\u522b\u7b49\u4ef7\u4e8e fprintf(stdout, ...) \u548c fscanf(stdin, ...)\u3002
\u5173\u4e8e scanf \u7684\u8fd4\u56de\u503c\uff0c\u5b83\u8fd4\u56de\u6b63\u5e38\u8bfb\u53d6\u7684\u53d8\u91cf\u4e2a\u6570\uff0c\u5982\u679c\u9047\u5230\u4e86\u6587\u4ef6\u7ed3\u5c3e\uff0c\u5219\u8fd4\u56de EOF \u5373 -1\u3002
-
(C16A) For the code below:
int a, b; char c;\nscanf(\"%d%c%d\",&a,&c,&b);\n
If let a=1,b=2,c='+'
, the input _____ is NOT correct. A. 1+2<ENTER> B. <BLANK><ENTER>1+<ENTER>2<ENTER> C. <ENTER>1<ENTER>+<BLANK>2<ENTER> D. <BLANK><BLANK>1+<BLANK><BLANK>2<ENTER> \u9700\u8981\u6ce8\u610f\u7684\u662f %d \u4f1a\u5ffd\u7565\u6570\u5b57\u5de6\u8fb9\u7684\u7a7a\u767d\u5b57\u7b26\uff08\u5305\u62ec\u7a7a\u683c\u3001\u6362\u884c\u7b49\uff09\uff0c\u800c %c \u4f1a\u7acb\u5373\u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26\u3002 A. \u5b8c\u5168\u6b63\u786e\uff0c\u6ca1\u4ec0\u4e48\u597d\u8bf4\u7684 B. 1 \u524d\u9762\u7684\u7a7a\u767d\u548c\u6362\u884c\u5ffd\u7565\u4e86\uff0c%c \u8bfb\u4e86 '+'\uff0c\u63a5\u4e0b\u6765 %d \u5ffd\u7565\u4e86\u6362\u884c\u8bfb\u4e86 2 C. 1 \u524d\u9762\u6362\u884c\u5ffd\u7565\u4e86\uff0c\u63a5\u4e0b\u6765 %c \u7acb\u5373\u8bfb\u5230\u4e86\u4e00\u4e2a '\\n'\uff0c\u7136\u540e\u51fa\u73b0\u4e86 '+' \u5bfc\u81f4\u540e\u9762 %d \u8bfb\u53d6\u5931\u8d25\uff08\u5982\u679c\u8fd9\u65f6\u68c0\u67e5 scanf \u7684\u8fd4\u56de\u503c\uff0c\u5e94\u8be5\u662f 2 \u800c\u4e0d\u662f 3\uff09 D. \u4e0e B \u540c\u7406\u662f\u6b63\u786e\u7684
-
(C18A) The statement printf(\"%%d%d\", 012);
will print out _____.
\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u4e2d\uff0c%% \u8868\u793a\u8f93\u51fa\u4e00\u4e2a %\uff0c\u63a5\u4e0b\u6765 d \u5b57\u7b26\u539f\u6837\u8f93\u51fa\uff0c\u7136\u540e %d \u8f93\u51fa 012\uff08\u516b\u8fdb\u5236\uff0c\u8f6c\u4e3a\u5341\u8fdb\u5236\u4e3a 10\uff09\uff0c\u6240\u4ee5\u8f93\u51fa\u4e3a %d10
-
\u4ee5\u4e0b\u4ee3\u7801\u7684\u8f93\u51fa\u4e3a _____.
int x = -1;\nprintf(\"%d\", (unsigned int)x);\n
unsigned int \u7684\u8f6c\u6362\u5e76\u4e0d\u4f1a\u6539\u53d8 x \u7684\u4e8c\u8fdb\u5236\u503c\uff08\u800c\u662f\u4ee5\u65e0\u7b26\u53f7\u7684\u65b9\u5f0f\u6765\u7406\u89e3\u8fd9\u6bb5\u6570\u636e\uff09\uff0c\u800c\u5bf9\u4e8e printf \u6765\u8bf4\uff0c\u5b83\u8981\u8f93\u51fa\u7684\u662f\u4e00\u4e2a %d\uff0c\u5373\u6709\u7b26\u53f7\u6570\uff08\u65e0\u7b26\u53f7\u7528 %u\uff09\uff0c\u6240\u4ee5\u8f93\u51fa\u65f6\u8fd8\u662f\u4f1a\u5f53\u4f5c\u6709\u7b26\u53f7\u6574\u578b\u6765\u7406\u89e3\uff0c\u5373\u8f93\u51fa -1\u3002
-
\u4ee5\u4e0b\u4ee3\u7801\u7684\u8f93\u51fa\u4e3a _____.
char str[100] = \"ZhejiangU 1 3 5\", s[10];\nint n;\nsscanf(str, \"%s %*d %d %*d\", s, &n);\nprintf(\"%s\", &s[n]);\n
%*d \u8868\u793a\u8bfb\u53d6\u4e00\u4e2a\u6574\u578b\uff0c\u4f46\u662f\u76f4\u63a5\u5ffd\u7565\uff0c\u4e0d\u5b58\u5230\u53d8\u91cf\u4e2d\u3002 \u6240\u4ee5 sscanf \u8bfb\u53d6\u5230\u7684 n \u662f\u7b2c\u4e8c\u4e2a\u6570\u5b57\u4e5f\u5c31\u662f 3\uff0c\u7136\u540e\u8f93\u51fa s[3] \u5f00\u59cb\u7684\u5b57\u7b26\u4e32\uff0c\u5373 jiangU\u3002
"},{"location":"programming/exam/exam/#_11","title":"\u4e00\u4e9b\u602a\u9898","text":"\u4e00\u4e9b\u6ca1\u4ec0\u4e48\u610f\u4e49\u7684\u602a\u9898\uff0c\u4e0d\u8981\u6df1\u7a76\uff0c\u9009\u62e9\u4e00\u4e2a\u6700\u6b63\u786e\u3001\u6ca1\u6709\u4e89\u8bae\u7684\u5c31\u53ef\u4ee5\u4e86\u3002
-
(C15A) In the following expressions, _____ is meanless(\u65e0\u610f\u4e49) A. \"hello,world\"-\"hello\" B. 'w'-'h' C. \"hello\"+10/4 D. 'a'+3/2
A \u5b57\u7b26\u4e32\u5e38\u91cf\u76f8\u51cf\u76f8\u5f53\u4e8e\u4e24\u4e2a\u5b57\u7b26\u4e32\u9996\u5730\u5740\u76f8\u51cf\uff0c\u6ca1\u6709\u610f\u4e49 BCD \u90fd\u80fd\u8bf4\u51fa\u70b9\u610f\u4e49\u6765\uff0c\u6240\u4ee5\u6700\u4f18\u9009 A\u3002
-
(C18A) Which of the following expressions is meaningful(\u6709\u610f\u4e49\u7684)? _____ A. \"hello\"*2 B. 'w'*'h' C. \"hello\"[1] D. \"hello\"-'h'
\u540c\u6837\uff0cA \u5b57\u7b26\u4e32\u9996\u5730\u5740\u4e58\u4ee5 2 \u6ca1\u6709\u610f\u4e49\uff0cB \u4e24\u4e2a\u5b57\u7b26\u4e32 ASCII \u7801\u76f8\u4e58\u4e5f\u6ca1\u5565\u5927\u610f\u4e49\u3002D \u5b57\u7b26\u4e32\u9996\u5730\u5740\u51cf 'h' \u4e5f\u5c31\u662f 104\uff0c\u4e5f\u6ca1\u5565\u610f\u4e49\u3002 C \"hello\"[1] \u8868\u793a *(\"hello\"+1) \u5373 'e'\uff0c\u8fd8\u7b97\u6709\u70b9\u610f\u4e49\uff0c\u6700\u4f18\u9009 C
-
(C17A) Which of the following is correct\uff1f _____.
int main() {\n int n[10];\n ...\n fun(n);\n ...\n}\nint fun(int a[]) {\n ...\n}\n
A. Within the function fun, a is an initial address of an array, whose value cannot be changed. B. Within the function main, the reference such as &n is invalid. C. Because of call-by-value, the elements of the array n cannot be changed within the fun. D. Within the function fun, the reference such as &a is invalid. AC \u80af\u5b9a\u662f\u9519\u7684\uff0cA. fun \u51fd\u6570\u91cc a \u662f\u4e00\u4e2a\u5c40\u90e8\u6307\u9488\u53d8\u91cf\uff08\u6570\u7ec4\u9000\u5316\u4e86\uff09\uff0c\u5b83\u7684\u503c\u53ef\u4ee5\u6539\u53d8\uff1bC. main \u51fd\u6570\u628a n \u7684\u5730\u5740\u4f20\u7ed9\u4e86 fun \u51fd\u6570\u4f5c\u4e3a a \u7684\u503c\uff0c\u6240\u4ee5\u53ef\u4ee5\u901a\u8fc7 a \u6307\u9488\u6765\u8bbf\u95ee n \u6570\u7ec4\u5904\u7684\u5185\u5b58\uff0c\u53ef\u4ee5\u6539\u53d8 n \u6570\u7ec4\u7684\u5143\u7d20\u3002
BD \u5c31\u6bd4\u8f83\u602a\u4e86\uff0c\u6211\u7684\u7406\u89e3\u65b9\u5f0f\u662f \"Within the function\" \u4ee3\u8868\u4e86\u51fd\u6570\u7ea7\u4f5c\u7528\u57df\uff0c\u800c main \u51fd\u6570\u91cc n \u7684\u4f5c\u7528\u57df\u4e0d\u662f\u201c\u51fd\u6570\u7ea7\u201d\u7684\uff0c\u800c\u662f\u5728 int n[10]; \u4e00\u53e5\u4ee5\u4e0b\uff0cmain \u51fd\u6570\u5927\u62ec\u53f7\u4e4b\u4e0a\u3002\u800c fun \u4e2d a \u5728\u6574\u4e2a\u51fd\u6570\u5185\u90fd\u53ef\u4ee5\u4f7f\u7528\u3002\u8fd9\u662f\u4e8c\u8005\u7684\u6700\u5927\u533a\u522b\uff0c\u786c\u8981\u9009\u4e00\u4e2a\u80af\u5b9a\u9009 B\u3002
"},{"location":"programming/exam/exam/#_12","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u4e13\u9898\u5386\u5e74\u5377\u7ecf\u5178\u9898\u76ee\u89e3\u6790","text":"\u56fe\u5f62\u5e93\u76f8\u5173\u5185\u5bb9\u5df2\u4e0d\u518d\u51fa\u73b0\u5728\u8bfe\u7a0b\u4e2d
\u76ee\u524d\uff0c\u8bfe\u6539\u5df2\u7ecf\u5220\u53bb\u4e86\u56fe\u5f62\u5e93\u76f8\u5173\u5185\u5bb9\uff0c\u8fd9\u90e8\u5206\u5185\u5bb9\u4e0d\u4f1a\u518d\u51fa\u73b0\u5728\u6559\u5b66\u548c\u8003\u8bd5\u4e2d\uff0c\u6211\u4eec\u4e5f\u4f1a\u9010\u6b65\u5c06\u5176\u79fb\u9664\u3002
"},{"location":"programming/exam/exam/#_13","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)
"},{"location":"programming/exam/exam/#_14","title":"\u540e\u7f00\u8868\u8fbe\u5f0f","text":"\u8fd9\u4e1c\u897f\u524d\u4e24\u4e09\u5e74\u90fd\u8003\u4e86\uff0c\u9700\u8981\u4e86\u89e3\u4e00\u4e0b\u3002\u5173\u4e8e\u8868\u8fbe\u5f0f\u6811\u7684\u76f8\u5173\u5185\u5bb9\u8bf7\u53c2\u89c1\uff1a
- \u8868\u8fbe\u5f0f\u6c42\u503c - OI Wiki (oi-wiki.org)
- \u6811\u57fa\u7840 - OI Wiki (oi-wiki.org)
\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
- \u4e2d\u7f00\u8868\u8fbe\u5f0f\uff1a\u5bf9\u8fd9\u68f5\u6811\u8fdb\u884c\u4e2d\u5e8f\u904d\u5386\uff0c\u5373\u5de6\u3001\u6839\u3001\u53f3
- a+b*(c-d)-(e/f)
- \u524d\u7f00\u8868\u8fbe\u5f0f\uff1a\u5bf9\u8fd9\u68f5\u6811\u8fdb\u884c\u5148\u5e8f\u904d\u5386\uff0c\u5373\u6839\u3001\u5de6\u3001\u53f3
- -+a*b-cd/ef
- \u540e\u7f00\u8868\u8fbe\u5f0f\uff1a\u5bf9\u8fd9\u68f5\u6811\u8fdb\u884c\u540e\u5e8f\u904d\u5386\uff0c\u5373\u5de6\u3001\u53f3\u3001\u6839\u3002\u6ce8\u610f\u5230\u5de6\u53f3\u5b50\u8282\u70b9\u90fd\u6bd4\u6839\u5148\u904d\u5386\uff0c\u6240\u4ee5\u53ef\u4ee5\u4e00\u8def\u5f80\u4e0b\u627e\u5230\u6700\u6df1\u7684\u5b50\u8282\u70b9\uff0c\u7136\u540e\u5411\u4e0a\u89e3\u6790\u3002
- abcd-*+ef/-
\u503c\u5f97\u4e00\u63d0\u7684\u662f\u540e\u7f00\u8868\u8fbe\u5f0f\u5177\u6709\u51e0\u4e2a\u65b9\u4fbf\u7684\u6027\u8d28\uff1a
- \u8ba1\u7b97\u540e\u7f00\u8868\u8fbe\u5f0f\uff0c\u53ea\u9700\u8981\u7ef4\u62a4\u4e00\u4e2a\u6570\u5b57\u6808\uff0c\u6bcf\u6b21\u9047\u5230\u4e00\u4e2a\u8fd0\u7b97\u7b26\uff0c\u5c31\u53d6\u51fa\u4e24\u4e2a\u6808\u9876\u5143\u7d20\uff0c\u5c06\u8fd0\u7b97\u7ed3\u679c\u91cd\u65b0\u538b\u5165\u6808\u4e2d\u3002
- \u540e\u7f00\u8868\u8fbe\u5f0f\u4e0e\u8868\u8fbe\u5f0f\u6811\u4e00\u4e00\u5bf9\u5e94\u3002\u540e\u7f00\u8868\u8fbe\u5f0f\u4e0d\u9700\u8981\u62ec\u53f7\u8868\u793a\uff0c\u5b83\u7684\u8fd0\u7b97\u987a\u5e8f\u662f\u552f\u4e00\u786e\u5b9a\u7684\u3002
"},{"location":"programming/exam/exam/#2020-2021","title":"2020-2021 \u5e74\u5377","text":" - \u9009\u62e9\u9898 1
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
- A\uff1a
char *
- B\uff1a\u8be5\u8868\u8fbe\u5f0f\u5b9e\u9645\u4e3a
&(t->name[0])
\uff0c\u5373 char *
\u7c7b\u578b\u3002 - C\uff1a
char *
- D\uff1a
*(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
- \u9009\u62e9\u9898 3 \u6307\u9488\u7c7b\u578b
\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
- A\uff1a
p
\u662f\u51fd\u6570\u540d - B\uff1a
p
\u662f\u51fd\u6570\u540d - C\uff1a
p
\u662f\u6307\u5411 int[5]
\u7684\u6307\u9488 - D\uff1a
p
\u662f\u4e00\u4e2a\u6570\u7ec4
- \u9009\u62e9\u9898 4 \u5b58\u50a8\u7c7b\u522b\u9650\u5b9a\u7b26
C \u8bed\u8a00\u4e2d\u4e00\u5171\u6709 5 \u4e2a\u5b58\u50a8\u7c7b\u522b\u9650\u5b9a\u7b26\uff0c\u8bf7\u56de\u5fc6\u5b83\u4eec\u7684\u4f5c\u7528\uff1a
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\u3002 register
\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\u3002 extern
\uff1a\u7528\u4e8e\u5168\u5c40\u53d8\u91cf\uff0c\u8868\u793a\u53d8\u91cf\u5728\u5176\u4ed6\u6587\u4ef6\u4e2d\u5b9a\u4e49\u3002 -
static
\uff1a
- \u7528\u4e8e\u5c40\u90e8\u53d8\u91cf\uff0c\u8868\u793a\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u4e0e\u7a0b\u5e8f\u8fd0\u884c\u76f8\u540c\u3002
- \u7528\u4e8e\u5168\u5c40\u53d8\u91cf\uff0c\u8868\u793a\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u4ec5\u9650\u4e8e\u5f53\u524d\u6587\u4ef6\u3002
-
_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
- \u9009\u62e9\u9898 5 \u51fd\u6570\u6307\u9488
\u89c1 2019 \u5e74\u9009\u62e9\u9898 6
- \u9009\u62e9\u9898 8 \u6570\u636e\u7ed3\u6784\u7684\u4f7f\u7528
\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
- \u7b80\u7b54\u9898 1.1 \u540e\u7f00\u8868\u8fbe\u5f0f
\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
- \u7b80\u7b54\u9898 5 \u6392\u5e8f\u7b97\u6cd5\u6700\u4f18\u60c5\u51b5
\u89c1\u5e38\u89c1\u95ee\u9898-\u7b97\u6cd5\u590d\u6742\u5ea6
\u5f15\u7528\u4e00\u4e0b ztgg \u7684\u89e3\u91ca\uff1a
- \u5e73\u5747\u60c5\u51b5\u4e0b\uff0c\u63d2\u5165\u5143\u7d20\u5bfc\u81f4\u7684\u79fb\u52a8\u4f9d\u65e7\u662f \\(O(n)\\) \u7684\uff0c\u5e76\u6ca1\u6709\u4f18\u5316\uff0c\u6240\u4ee5\u603b\u590d\u6742\u5ea6\u8fd8\u662f \\(O(n^2)\\)\u3002\uff08\u6279\u6ce8\uff1a\u4ea4\u6362\u7684\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\)\uff0c\u6bd4\u8f83\u7684\u590d\u6742\u5ea6\u4e3a \\(O(n\\log n)\\)\uff0c\u524d\u8005\u8f83\u5927\uff0c\u5360\u636e\u4e3b\u5bfc\u5730\u4f4d\uff09\u3002
- \u6700\u4f73\u60c5\u51b5\u5e94\u8be5\u662f\u63d2\u5165\u5143\u7d20\u65f6\uff0c\u4e0d\u9700\u8981\u79fb\u52a8\u539f\u6765\u7684\u5143\u7d20\uff0c\u4e5f\u5c31\u662f\u6570\u7ec4\u5df2\u7ecf\u6392\u597d\u5e8f\u4e86\u3002\u8fd9\u4e2a\u60c5\u51b5\u4e0b\uff0c\u6bcf\u6b21\u63d2\u5165\u53ea\u6709\u4e8c\u5206\u67e5\u627e\u7684\u4ee3\u4ef7\uff0c\u5373\u4e3a \\(O(n\\log n)\\)\u3002
- \u7b80\u7b54\u9898 6 \u961f\u5217\u64cd\u4f5c
\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
- \u7a0b\u5e8f\u586b\u7a7a 3
\u8fd9\u51e0\u4e2a\u7a7a\u90fd\u9700\u8981\u82b1\u4e00\u4f1a\u513f\u65f6\u95f4\u6765\u63a8\u65ad\u7684\uff1a
InitGraphics()
\u4e00\u5b9a\u8981\u8bb0\u5f97 - \u8bb0\u4f4f\u51e0\u79cd\u56de\u8c03\u51fd\u6570\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c
void registerTimerEvent(TimerEventCallback callback)
\u4e0e void startTimer(int id,int timeinterval)
\u914d\u5bf9\u4f7f\u7528\uff0c\u5b83\u4eec\u5404\u81ea\u7684\u53c2\u6570\u610f\u4e49\u3002 - \u8ba1\u65f6\u5668\u56de\u8c03\u51fd\u6570\u600e\u4e48\u5199\uff1f\u53c2\u6570
timerID
\u662f\u7528\u6765\u505a\u4ec0\u4e48\u7684\uff1f - \u7b2c 14 \u7a7a\u53ef\u80fd\u4e0d\u5bb9\u6613\u60f3\u5230\uff0c\u53cd\u6b63\u8bb0\u4f4f\u5728\u6bcf\u6b21\u753b\u70b9\u4ec0\u4e48\u4e1c\u897f\u4e4b\u524d\uff0c\u90fd\u8981\u68c0\u67e5\u753b\u7b14\u4f4d\u7f6e\u662f\u5426\u6b63\u786e\uff0c\u8fd9\u5728\u7ed8\u5236\u5206\u5f62\u56fe\u5f62\u65f6\u4e5f\u5f88\u91cd\u8981\u3002
- \u7b97\u6cd5\u8bbe\u8ba1 1 \u94fe\u8868\u5faa\u73af\u68c0\u6d4b
\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
- \u7b97\u6cd5\u8bbe\u8ba1 2 \u6709\u5e8f\u6570\u7ec4\u539f\u5730\u53bb\u91cd
\u770b\u5230\u8fd9\u9053\u9898\u4f60\u6709\u6ca1\u6709\u60f3\u8d77\u5b57\u7b26\u4e32\u53bb\u7a7a\u683c\u7684\u4e00\u4e2a\u4f8b\u7a0b\uff1f
char *a;\nfor(int i = 0, j = 0; i < length; i++){\n if(a[i] != ' ')\n a[j++] = a[i];\n}\n
\u6709\u5e8f\u6570\u7ec4\u53bb\u91cd\u4e0e\u8fd9\u4e2a\u7b97\u6cd5\u4e5f\u6709\u4e9b\u7c7b\u4f3c\uff0c\u53ea\u662f\u6bd4\u8f83\u6761\u4ef6\u6362\u6210 a[i]!=a[j]
\u4e86\u800c\u5df2\u3002
"},{"location":"programming/exam/exam/#2019-2020","title":"2019-2020 \u5e74\u5377","text":" - \u9009\u62e9\u9898 1 \u9012\u5f52\u51fd\u6570
- D \u9879 \u8c03\u7528\u6808\u4f4d\u4e8e\u5806\u6808\u6bb5\uff08Stack Segment\uff09\uff0c\u5728\u8fd0\u884c\u65f6\u521b\u5efa\uff0c\u4e5f\u6709\u81ea\u5df1\u7684\u5927\u5c0f\uff0c\u4e0d\u80fd\u8d8a\u754c\u8bbf\u95ee\u3002\u8d8a\u754c\u9020\u6210\u6bb5\u9519\u8bef\uff08Segmentation Fault\uff09\u3002\u6bcf\u6b21\u9012\u5f52\u8c03\u7528\u6dfb\u52a0\u6808\u5e27\uff0c\u9020\u6210\u7684\u8d8a\u754c\u79f0\u4e3a\u6808\u6ea2\u51fa\uff08Stack Overflow\uff09\u3002\u5806\u6808\u6bb5\u4e2d\u4fdd\u5b58\u7740\u51fd\u6570\u8c03\u7528\u5173\u7cfb\u548c\u5c40\u90e8\u53d8\u91cf\u3002\u5c40\u90e8\u53d8\u91cf\u8fc7\u5927\u4e5f\u53ef\u80fd\u9020\u6210\u6808\u6ea2\u51fa\u3002
- \u9009\u62e9\u9898 2 \u65f6\u95f4\u590d\u6742\u5ea6\u5206\u6790
- \u9009\u62e9\u9898 6 \u51fd\u6570\u6307\u9488
\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. [...]
- \u51fd\u6570\u6307\u9488\uff1a\u6307\u5411\u51fd\u6570\u7684\u6307\u9488\u4e2d\u50a8\u5b58\u7740\u51fd\u6570\u4ee3\u7801\u7684\u8d77\u59cb\u5904\u5730\u5740\uff0c\u8981\u6307\u660e\u51fd\u6570\u7684\u7c7b\u578b\uff0c\u8981\u6307\u660e\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u548c\u5f62\u53c2\u7c7b\u578b\u3002\u628a\u51fd\u6570\u540d\u66ff\u6362\u6210
(*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
- \u7b2c\u4e00\u79cd\u5f62\u5f0f\uff0c\u5148\u89e3\u5f15\u7528\u51fd\u6570\u6307\u9488\u518d\u8c03\u7528\u8be5\u51fd\u6570\uff0c\u8fd9\u4e2a\u601d\u8def\u5f88\u76f4\u63a5\u3002
- \u7b2c\u4e8c\u79cd\u5f62\u5f0f\uff0c\u6765\u6e90\u662f\u4e0a\u9762\u7684\u8d4b\u503c\u8bed\u53e5\uff0c\u5728\u4e0a\u9762\u7684\u8d4b\u503c\u8bed\u5883\u4e0b\uff0c\u6307\u9488\u548c\u51fd\u6570\u540d\u53ef\u4ee5\u4e92\u6362\u4f7f\u7528\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.
- \u9009\u62e9\u9898 7 \u51fd\u6570\u6307\u9488
\u540c\u6837\u4f9d\u636e\u4e0a\u9762\u7684\u8bb2\u89e3\u80fd\u591f\u9009\u51fa\u6b63\u786e\u7b54\u6848
- \u9009\u62e9\u9898 8 \u51fd\u6570\u53c2\u6570
\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
- \u9009\u62e9\u9898 9 \u56fe\u5f62\u5e93
\u8bf7 WK \u73ed\u540c\u5b66\u4e00\u5b9a\u8981\u53bb\u770b\u8f85\u5b66\u7fa4\u91cc\u5176\u4ed6\u8001\u5e08\u7684\u56fe\u5f62\u5e93\u8bfe\u4ef6
- \u9009\u62e9\u9898 10 \u8fd8\u662f\u51fd\u6570\u6307\u9488
- \u7b2c\u4e00\u884c\uff1a
F
\u5b9a\u4e49\u4e3a int (int)
\u7c7b\u578b\u7684\u51fd\u6570\u3002 - \u7b2c\u4e8c\u884c\uff1a\u58f0\u660e\u4e24\u4e2a\u7c7b\u578b\u4e3a
F
\u7684\u51fd\u6570 g
\u548c h
\u3002\u5176\u5b9e\u5c31\u662f int g(int a)
\u548c int h(int a)
\u3002 - \u7b2c\u4e09\u884c\uff1a\u58f0\u660e\u4e00\u4e2a\u6570\u7ec4
p
\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\u3002 - \u8ba9\u6211\u4eec\u4ece\u5185\u5f80\u5916\u8bfb\u8fd9\u4e2a\u58f0\u660e\uff1a
p
\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\u3002 - \u7528
g
\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
- C \u9879\uff1a\u663e\u7136\u7c7b\u578b\u5339\u914d\u3002
- D \u9879\uff1a\u5bf9\u51fd\u6570\u53d6\u5730\u5740\uff0c\u5f97\u5230
int (*)(int)
\uff0c\u4e0e int (**)(int)
\u7c7b\u578b\u4e0d\u5339\u914d\u3002
- \u7b80\u7b54\u9898 1
\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
- \u7b80\u7b54\u9898 3
\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
- \u7b80\u7b54\u9898 4
\u8ba9\u6211\u4eec\u770b main()
\u51fd\u6570\u7684\u7b2c\u4e00\u884c\u7684\u8868\u8fbe\u5f0f\uff1a
- \u5916\u5c42\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\u3002 - \u5185\u5c42\uff1a
h(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\u3002 - \u5185\u5c42\u8c03\u7528\u540e\uff0c\u5916\u5c42\u5c31\u76f8\u5f53\u4e8e
h(100)
\u4e86\uff0c\u56e0\u4e3a h
\u672c\u6765\u5c31\u662f H
\u7c7b\u578b\u7684\u51fd\u6570\u3002
- \u7a0b\u5e8f\u586b\u7a7a 3
geblib.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*)
- \u5b8f\u5c55\u5f00\u4e3a
((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\u3002 - \u8fd9\u4e2a\u8c03\u7528\u5c31\u8fd4\u56de\u4e86\u4e00\u4e2a
char*
\u7684\u6307\u9488\u3002
-
FreeBlock()
\u51fd\u6570\uff1a
- \u539f\u578b\uff1a
void FreeBlock(void *ptr)
- \u4e0e
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
- \u7b97\u6cd5\u8bbe\u8ba1 1 \u5206\u5f62
\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
- \u57fa\u51c6\u60c5\u5f62\uff1a\u957f\u5ea6\u7f29\u5c0f\u5230\u67d0\u503c\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
- \u7b97\u6cd5\u8bbe\u8ba1 2 \u5217\u8868\u53d8\u5e8f
\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/exam/exam/#2018-2019","title":"2018-2019 \u5e74\u5377","text":" - \u9009\u62e9\u9898 4 \u9012\u5f52\u8ba1\u7b97
\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
- \u9009\u62e9\u9898 6 \u7b97\u6cd5\u590d\u6742\u5ea6\u5206\u6790
\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
- \u9009\u62e9\u9898 9 \u9012\u589e\u8fd0\u7b97\u7b26
\u524d\u7f00\u9012\u589e\u8fd0\u7b97\u7b26\u5148\u9012\u589e\u518d\u4f7f\u7528\u3002
- \u7b80\u7b54\u9898 1.2
\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
- \u7b80\u7b54\u9898 2 \u6570\u636e\u4e0e\u5b57\u8282
\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
- \u7b80\u7b54\u9898 3 \u94fe\u8868\u64cd\u4f5c
\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
- \u7b80\u7b54\u9898 4 \u94fe\u8868\u64cd\u4f5c
\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
- \u7b80\u7b54\u9898 5 \u53cc\u5411\u6808
\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
- \u5148\u770b
main()
\u4e2d\u7684 Push()
\uff0c\u8fd9\u600e\u4e48\u6bd4\u5e73\u5e38\u7684 Push()
\u591a\u4e00\u4e2a\u53c2\u6570\u5462\uff1f - \u518d\u770b\u7c7b\u578b\u5b9a\u4e49\uff0c\u600e\u4e48\u6709\u4e24\u4e2a
Top
\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\u3002 Push()
\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
- \u7b80\u7b54\u9898 6 \u4e0d\u77e5\u9053\u662f\u4ec0\u4e48
\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
- \u7a0b\u5e8f\u586b\u7a7a 2 \u5faa\u73af\u961f\u5217\u5b9e\u73b0
\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
- \u7a0b\u5e8f\u586b\u7a7a 3 \u56fe\u5f62\u5e93
\u53c2\u89c1\u5e38\u89c1\u95ee\u9898-\u56fe\u5f62\u5e93-\u8ba1\u65f6\u5668
- \u7b97\u6cd5\u8bbe\u8ba1 1 \u5bfb\u627e\u7b2c\u4e00\u4e2a\u516c\u5171\u8282\u70b9
\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
- \u7b97\u6cd5\u8bbe\u8ba1 2 \u4e8c\u5206\u63d2\u5165\u6392\u5e8f
\u8fd9\u9898\u7b80\u5355\uff0c\u4e0d\u4f5c\u89e3\u6790\u3002\u53c2\u7b54\u4e2d\u6f0f\u4e86\u68c0\u67e5 minPos == rh
\u7684\u60c5\u51b5\uff0c\u60f3\u60f3\u8fd9\u6837\u4f1a\u9020\u6210\u4ec0\u4e48\u540e\u679c\uff1f
"},{"location":"programming/exam/exam/#2017-2018","title":"2017-2018 \u5e74\u5377","text":" - \u9009\u62e9\u9898 1 \u6570\u636e\u7c7b\u578b\u4e0e\u6307\u9488\u64cd\u4f5c
- C \u9879\uff1a
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 - D \u9879\uff1a\u6bcf\u6b21
*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
- \u9009\u62e9\u9898 7 \u5192\u6ce1\u6392\u5e8f
\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
- \u5982\u679c\u5728\u4e0a\u4e00\u8f6e\u7684 Bubble \u4e2d\uff0c\u6ca1\u6709\u53d1\u751f\u4efb\u4f55\u4ea4\u6362\uff0c\u5219\u8bf4\u660e\u8fd9\u4e2a\u5e8f\u5217\u4e5f\u662f\u6709\u5e8f\u7684\uff0c\u4e0d\u518d\u9700\u8981\u540e\u7eed\u64cd\u4f5c\u4e86\u3002
\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
- \u9009\u62e9\u9898 9 \u5b58\u50a8\u7c7b\u522b\u9650\u5b9a\u7b26
- D \u9879\uff1a
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
- \u7b80\u7b54\u9898 1.(2) \u5199\u51fd\u6570\u58f0\u660e
\u5148\u60f3\u60f3\u81ea\u5df1\u4f1a\u600e\u4e48\u8c03\u7528\u8fd9\u4e2a fun
\u51fd\u6570\u624d\u80fd\u5f97\u5230 void
\u7c7b\u578b\uff1a
- \u7b2c\u4e00\u6b65\uff0c\u8c03\u7528\u51fd\u6570\u83b7\u53d6\u8fd4\u56de\u503c\uff1a
fun(int)
\u3002 - \u7b2c\u4e8c\u6b65\uff0c\u89e3\u5f15\u7528\u8fd4\u56de\u503c\uff0c\u83b7\u5f97\u51fd\u6570\uff0c\u8c03\u7528\u8be5\u51fd\u6570\uff1a
(*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
- \u7b80\u7b54\u9898 5 \u6700\u5927\u5b50\u5217\u548c
\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
- \u7b80\u7b54\u9898 6 \u4f8f\u5112\u6392\u5e8f
\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
- \u7a0b\u5e8f\u586b\u7a7a 2 \u591a\u9879\u5f0f\u8ba1\u7b97
\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
- \\((((3x)x^2)+2x)x + 1\\)
\u8fd9\u6837\u505a\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u51cf\u5c11\u4e86\u8ba1\u7b97\u4e58\u79ef\u7684\u6b21\u6570\u3002
\u540c\u6837\u6ce8\u610f ->
\u8fd0\u7b97\u7b26\u7684\u4f7f\u7528\u3002
"},{"location":"programming/exam/exam/#2016-2017","title":"2016-2017 \u5e74\u5377","text":" - \u9009\u62e9\u9898 1 \u5012\u5e8f\u6808
\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\u7b54\u9898 1.(2) \u5199\u51fd\u6570\u6307\u9488
\u7b80\u5355\u51fd\u6570\u6307\u9488\uff0c\u76f4\u63a5\u8fd9\u6837\u8bb0\uff1atypedef \u8fd4\u56de\u7c7b\u578b (*\u65b0\u540d\u5b57)(\u53c2\u6570\u5217\u8868)
- \u7b80\u7b54\u9898 3 \u5947\u5076\u6392\u5e8f
\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
- \u7b80\u7b54\u9898 4 \u94fe\u8868\u64cd\u4f5c
\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
- \u7b80\u7b54\u9898 5 \u56e0\u6570\u5206\u89e3
\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
- \u7a0b\u5e8f\u586b\u7a7a 1 \u8ba1\u6570\u6392\u5e8f
\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\u3002 output_array[count[input_array[i]]] = input_array[i]
\u6211\u4eec\u6765\u62c6\u89e3\u4e00\u4e0b\uff1a intput_array[i]
\u5c31\u662f\u7b2c i
\u4e2a\u5143\u7d20 - \u628a\u5b83\u653e\u5230
count[]
\u5c31\u80fd\u67e5\u5230\u8fd9\u4e2a\u6570\u5e94\u8be5\u653e\u7f6e\u7684\u8d77\u59cb\u4f4d\u7f6e\u3002 - \u6240\u4ee5\u7b2c 4 \u7a7a\u5f53\u7136\u8981\u9012\u589e\u5566\u3002
- \u7a0b\u5e8f\u586b\u7a7a 3 \u5dee\u96c6
\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/exam/exam/#2015-2016","title":"2015-2016 \u5e74\u5377","text":" - \u9009\u62e9\u9898 5 \u5b8f\u7684\u5c55\u5f00
\u5b8f\u5c55\u5f00\u53ea\u662f\u7b80\u5355\u7684\u6587\u672c\u66ff\u6362\u3002
- \u5148\u5c55\u5f00
DD
\u5f97\u5230 SQ(2*3) - SQ(2+3)
\uff0c\u5f97\u5230 2 * 3 * 2 * 3 - 2 + 3 * 2 + 3
- \u5148\u5c55\u5f00
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/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
- \u4f5c\u4e3a\u53d6\u5740\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\u6570
- \u4f5c\u4e3a
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\u7b26 C \u6807\u51c6\u5b9a\u4e49\uff0c\u6807\u8bc6\u7b26\u662f\u6570\u5b57\u3001\u4e0b\u5212\u7ebf\u3001\u5c0f\u5199\u53ca\u5927\u5199\u62c9\u4e01\u5b57\u6bcd\u7684\u4efb\u610f\u957f\u5ea6\u5e8f\u5217\uff08\u4e0d\u8ba8\u8bba Unicode \u5b57\u7b26\uff09\u3002\u5408\u6cd5\u7684\u6807\u8bc6\u7b26\u5fc5\u987b\u4ee5\u975e\u6570\u5b57\u5b57\u7b26\u5f00\u59cb\uff0c\u4ee5\u533a\u522b\u4e8e\u6574\u6570\u5e38\u91cf\u6216\u6d6e\u70b9\u5e38\u91cf\u3002
\u6807\u8bc6\u7b26\u80fd\u6307\u4ee3\u4e0b\u5217\u7c7b\u578b\u7684\u5b9e\u4f53\uff1a
- \u5bf9\u8c61
- \u51fd\u6570
- \u6807\u7b7e\uff08struct\u3001union \u6216\u679a\u4e3e\uff09
- \u7ed3\u6784\u4f53\u6216\u8054\u5408\u4f53\u6210\u5458
- \u679a\u4e3e\u5e38\u91cf
- typedef \u540d
- \u6807\u53f7\u540d
- \u5b8f\u540d
- \u5b8f\u5f62\u53c2\u540d
\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
\u6b63\u786e\u6dfb\u52a0\u9650\u5b9a\u4e0e\u5b58\u50a8\u7c7b\u578b\u8bf4\u660e \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u53ea\u6709\u51fa\u73b0\u5728 *
\u4e0e\u6807\u8bc6\u7b26\u4e4b\u95f4\u7684\u9650\u5b9a\u624d\u4f1a\u88ab\u8d4b\u4e88\u6307\u9488\u7c7b\u578b\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 char * const p;
\u58f0\u660e\u4e86\u4e00\u4e2a\u7c7b\u578b\u4e3a char *
\u7684\u3001\u503c\u4e0d\u53ef\u53d8\u7684\u6307\u9488 p
\uff0c\u5b83\u6307\u5411\u7684\u5bf9\u8c61\u7c7b\u578b\u4e3a char
\uff0c\u503c\u53ef\u901a\u8fc7\u6307\u9488 p
\u6539\u53d8\uff1b\u800c\u8bed\u53e5 const char * p;
\u58f0\u660e\u4e86\u4e00\u4e2a\u7c7b\u578b\u4e3a const char *
\u7684\u3001\u503c\u53ef\u53d8\u7684\u6307\u9488 p
\uff0c\u5b83\u6307\u5411\u7684\u5bf9\u8c61\u7c7b\u578b\u4e3a const char
\uff0c\u503c\u4e0d\u53ef\u901a\u8fc7\u6307\u9488 p
\u6539\u53d8\u3002
\u53e6\u5916\uff0c\u5b58\u50a8\u7c7b\u578b\u8bf4\u660e\u7b26\u5e76\u6ca1\u6709\u7c7b\u4f3c\u7684\u8bed\u4e49\uff0c\u5b83\u5fc5\u987b\u7f6e\u4e8e *
\u4e4b\u524d\u3002\u4ece\u8bed\u6cd5\u4e0a\u8bf4\uff0c\u5b83\u4eec\u5c5e\u4e8e\u8bf4\u660e\u7b26\u800c\u975e\u9650\u5b9a\u7b26\uff0c\u4e0d\u5e94\u7f6e\u4e8e *
\u4e0e\u6807\u8bc6\u7b26\u4e4b\u95f4\uff1b\u4ece\u8bed\u4e49\u4e0a\u6765\u8bf4\uff0c\u8bb0\u5f55\u88ab\u5f15\u7528\u5bf9\u8c61\u7c7b\u578b\u7684\u76ee\u7684\u662f\u4ece\u76ee\u6807\u5185\u5b58\u5730\u5740\u6b63\u786e\u8bfb\u53d6\u6570\u636e\uff0c\u800c\u4e86\u89e3\u6307\u5411\u5bf9\u8c61\u7684\u5b58\u50a8\u7c7b\u578b\u5bf9\u8fd9\u4e00\u76ee\u7684\u6beb\u65e0\u5e2e\u52a9\u3002
\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u58f0\u660e\u4e2d *
\u53ea\u5bf9\u76f4\u63a5\u7ed3\u5408\u7684\u6807\u8bc6\u7b26\u751f\u6548\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5982\u679c\u901a\u8fc7\u8bed\u53e5 int * a, b;
\u58f0\u660e\u53d8\u91cf a
\u4e0e b
\uff0c\u90a3\u4e48\u53ea\u6709 a
\u4f1a\u88ab\u8ba4\u5b9a\u4e3a\u6307\u9488\u7c7b\u578b\u3002
\u5728\u58f0\u660e\u6307\u5411\u67d0\u4e9b\u7c7b\u578b\u5bf9\u8c61\u7684\u6307\u9488\u65f6\uff0c\u53ef\u901a\u8fc7\u62ec\u53f7\u4f7f *
\u4f18\u5148\u4e0e\u6807\u8bc6\u7b26\u7ed3\u5408\uff0c\u4ee5\u907f\u514d\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u5dee\u5f02\u5bfc\u81f4\u7684\u6b67\u4e49\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 int *arr[3];
\u58f0\u660e\u4e86\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int *
\u4e14\u957f\u5ea6\u4e3a 3 \u7684\u6570\u7ec4 arr
\uff1b\u8bed\u53e5 int (*ptr)[3];
\u5219\u58f0\u660e\u4e86\u4e00\u4e2a\u6307\u9488 ptr
\uff0c\u5b83\u6307\u5411\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int
\u4e14\u957f\u5ea6\u4e3a 3 \u7684\u6570\u7ec4\u3002
\u6b64\u5916\uff0c\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u7c7b\u578b\u53ef\u4ee5\u662f\u4e0d\u5b8c\u6574\u7c7b\u578b\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 int (*p)[];
\u8868\u660e\u6307\u9488 p
\u6307\u5411\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int
\uff0c\u4e14\u957f\u5ea6\u672a\u77e5\u7684\u6570\u7ec4\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u4e0d\u5173\u5fc3\u6570\u7ec4\u957f\u5ea6\uff0c\u6216\u8005\u6570\u7ec4\u957f\u5ea6\u9700\u8981\u5728\u4e4b\u540e\u7684\u7a0b\u5e8f\u4e2d\u901a\u8fc7\u67d0\u4e9b\u65b9\u6cd5\u786e\u5b9a\u3002\u76f8\u5bf9\u5e94\u5730\uff0c\u65e0\u6cd5\u5bf9\u89e3\u5f15\u7528 p
\u7684\u7ed3\u679c\u4f7f\u7528 sizeof
\u8fd0\u7b97\u7b26\u3002
\u901a\u7528\u6307\u9488\u7c7b\u578b void *
\u7531\u4e8e void
\u4e5f\u5c5e\u4e8e\u4e0d\u5b8c\u6574\u7c7b\u578b\uff0cvoid *
\u540c\u6837\u662f\u5408\u6cd5\u7684\u6307\u9488\u7c7b\u578b\u3002\u5b83\u7684\u5b9e\u9645\u542b\u4e49\u662f\u6307\u9488\u6307\u5411\u4e00\u4e2a\u7c7b\u578b\u672a\u77e5\u7684\u5bf9\u8c61\uff0c\u4e5f\u5373\u6307\u9488\u53ef\u4ee5\u6307\u5411\u4efb\u4f55\u7c7b\u578b\u7684\u5bf9\u8c61\u3002\u81ea\u7136\u5730\uff0c\u6211\u4eec\u65e0\u6cd5\u89e3\u5f15\u7528\u8be5\u7c7b\u578b\u7684\u6307\u9488\u5bf9\u8c61\u3002\u4e0d\u8fc7\uff0c\u5b83\u53ef\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u4efb\u610f\u5176\u4ed6\u7c7b\u578b\u7684\u6307\u9488\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002
\u867d\u7136 C \u8bed\u8a00\u5728 C11 \u6807\u51c6\u524d\u5e76\u672a\u63d0\u4f9b\u6cdb\u578b\u7279\u6027\uff0c\u4f46\u901a\u8fc7\u5f15\u5165 void *
\u7c7b\u578b\u53c2\u6570\uff0c\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u8bbe\u8ba1\u901a\u7528\u63a5\u53e3\uff0c\u4f7f\u7528\u76f8\u540c\u4ee3\u7801\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002\u4e00\u4e2a\u5178\u578b\u7684\u4f8b\u5b50\u662f\uff0cstdlib.h
\u4e2d\u5b9a\u4e49\u7684 qsort
\u4e0e bsearch
\u65b9\u6cd5\u90fd\u901a\u8fc7\u5c06\u6570\u7ec4\u6307\u9488 ptr
\u7684\u7c7b\u578b\u89c4\u5b9a\u4e3a void *
\uff0c\u5b9e\u73b0\u4e86\u65e0\u89c6\u6570\u7ec4\u5143\u7d20\u7c7b\u578b\u91cd\u7528\u6392\u5e8f\u4ee3\u7801\u7684\u6548\u679c\u3002
\u5f53\u7136\uff0c\u56e0\u4e3a\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u7c7b\u578b\u672a\u77e5\uff0c\u6b64\u65f6 C \u8bed\u8a00\u7f16\u8bd1\u5668\u65e0\u6cd5\u5e2e\u4f60\u68c0\u67e5\u7c7b\u578b\u517c\u5bb9\u95ee\u9898\uff0c\u6240\u4ee5\u4f7f\u7528 void *
\u7c7b\u578b\u6307\u9488\u65f6\u9700\u4e07\u5206\u5c0f\u5fc3\u3002
"},{"location":"programming/topic/pointers/#_8","title":"\u503c\u4e0e\u8fd0\u7b97","text":"\u901a\u8fc7\u6307\u9488\u83b7\u5f97\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u8fc7\u7a0b\u79f0\u4e3a\u89e3\u5f15\u7528\uff0c\u7531\u8fd0\u7b97\u7b26 *
\u5b8c\u6210\uff1b\u901a\u8fc7\u67d0\u4e2a\u5bf9\u8c61\u83b7\u5f97\u6307\u5411\u8be5\u5bf9\u8c61\u6307\u9488\u7684\u8fc7\u7a0b\u79f0\u4e3a\u53d6\u5740\uff0c\u7531\u8fd0\u7b97\u7b26 &
\u5b8c\u6210\u3002
\u7ed3\u5408\u8d4b\u503c\u64cd\u4f5c\uff0c\u53ef\u6839\u636e\u9700\u8981\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u5e76\u4fee\u6539\u6307\u5411\u7684\u5bf9\u8c61\uff0c\u6216\u4ee4\u6307\u9488\u6307\u5411\u4e0d\u540c\u7684\u5bf9\u8c61\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5bf9\u4e8e int
\u7c7b\u578b\u53d8\u91cf a
\uff0c\u8bed\u53e5 p = &a;
\u5c06\u4f7f\u6307\u9488 p
\u7684\u503c\u8bbe\u4e3a a
\u7684\u5185\u5b58\u5730\u5740\uff0c\u4e5f\u5373\u4ee4 p
\u6307\u5411 a
\uff1b\u5728\u6b64\u57fa\u7840\u4e0a\uff0c\u8bed\u53e5 *p = 1;
\u5c06\u6539\u53d8 p \u6307\u5411\u7684\u5bf9\u8c61\uff0c\u4e5f\u5373\u53d8\u91cf a
\u7684\u503c\u3002
\u4e0d\u8fc7\uff0c\u5728\u7f16\u5199\u8868\u8fbe\u5f0f\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u7684\u5f71\u54cd\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8868\u8fbe\u5f0f *p++
\u5c06\u4f7f\u6307\u9488 p
\u7684\u503c\u81ea\u589e 1\uff0c\u800c\u8868\u8fbe\u5f0f (*p)++
\u5c06\u4f7f\u6307\u9488 p
\u6307\u5411\u5bf9\u8c61\u7684\u503c\u81ea\u589e 1\u3002
\u7406\u89e3\u521d\u59cb\u5316\u8bed\u53e5\u4e2d\u7684 *
\u8fd0\u7b97\u7b26
C \u8bed\u8a00\u7684\u8bed\u6cd5\u529b\u56fe\u4f7f\u58f0\u660e\u548c\u4f7f\u7528\u76f8\u4e00\u81f4\u3002
\u5728\u9605\u8bfb\u6307\u9488\u521d\u59cb\u5316\u8bed\u53e5\u65f6\uff0c\u4f60\u53ef\u80fd\u5e38\u5e38\u6df7\u6dc6 *
\u7684\u58f0\u660e\u4e0e\u89e3\u5f15\u7528\u8bed\u6cd5\u3002\u6b63\u786e\u5206\u8fa8\u7684\u8981\u70b9\u5728\u4e8e\uff0c\u521d\u59cb\u5316\u8bed\u53e5\u5206\u4e3a\u58f0\u660e\u548c\u521d\u59cb\u5316\u5668\u4e24\u90e8\u5206\uff0c\u5176\u4e2d\u8d4b\u503c\u53f7 =
\u524d\u7684\u90e8\u5206\u4e3a\u58f0\u660e\uff0c\u8d4b\u503c\u53f7\u53ca\u5176\u540e\u7684\u90e8\u5206\u4e3a\u521d\u59cb\u5316\u5668\u3002
\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5728\u8bed\u53e5 int *ip = *ipp;
\u4e2d\uff0cint *ip
\u4e3a\u58f0\u660e\uff0c= *ipp
\u4e3a\u521d\u59cb\u5316\u5668\uff0c\u8fd9\u6761\u8bed\u53e5\u7684\u542b\u4e49\u662f\uff1a\u58f0\u660e\u4e00\u4e2a\u6307\u5411 int
\u7c7b\u578b\u5bf9\u8c61\u7684\u6307\u9488 ip
\uff0c\u5e76\u5c06\u5b83\u7684\u521d\u59cb\u503c\u8bbe\u4e3a ipp
\u6307\u5411\u5bf9\u8c61\u7684\u503c\u3002
\u91ce\u6307\u9488
\u58f0\u660e\u81ea\u52a8\u4f5c\u7528\u57df\u7684\u5bf9\u8c61\u540e\uff0cC \u8bed\u8a00\u4ec5\u4fdd\u8bc1\u53ef\u4ee5\u6b63\u5e38\u8bbf\u95ee\u5e76\u4fee\u6539\u8be5\u5bf9\u8c61\uff0c\u800c\u4e0d\u4fdd\u8bc1\u5176\u521d\u59cb\u5185\u5bb9\uff0c\u8fd9\u70b9\u5bf9\u6307\u9488\u540c\u6837\u6210\u7acb\u3002\u5982\u679c\u58f0\u660e\u4e86\u4e00\u4e2a\u6307\u9488\u5374\u6ca1\u6709\u8d4b\u503c\uff0c\u8fd9\u4e2a\u6307\u9488\u7684\u6307\u5411\u4fbf\u65e0\u6cd5\u786e\u5b9a\uff0c\u6211\u4eec\u79f0\u5b83\u4e3a\u91ce\u6307\u9488\u3002
\u56e0\u4e3a\u91ce\u6307\u9488\u53ef\u80fd\u6307\u5411\u4efb\u610f\u5185\u5b58\u6bb5\uff0c\u4e0d\u52a0\u9274\u522b\u7684\u968f\u610f\u4f7f\u7528\u53ef\u80fd\u5bfc\u81f4\u8bbf\u95ee\u975e\u6cd5\u5185\u5b58\u3001\u635f\u574f\u6b63\u5e38\u6570\u636e\uff0c\u751a\u81f3\u9020\u6210\u5176\u4ed6\u672a\u77e5\u540e\u679c\u3002\u5c1d\u8bd5\u89e3\u5f15\u7528\u91ce\u6307\u9488\u662f\u6bb5\u9519\u8bef\uff08Segmentation Fault\uff09\u7684\u4e3b\u8981\u8bf1\u56e0\u4e4b\u4e00\u3002\u56e0\u6b64\uff0c\u58f0\u660e\u6307\u9488\u65f6\u52a1\u5fc5\u5b8c\u6210\u521d\u59cb\u5316\u3002
\u6bcf\u79cd\u7c7b\u578b\u7684\u6307\u9488\u90fd\u542b\u6709\u4e00\u4e2a\u8be5\u7c7b\u578b\u7684\u7279\u6b8a\u503c\uff0c\u79f0\u4e3a\u7a7a\u6307\u9488\u503c\u3002\u503c\u4e3a\u7a7a\u7684\u6307\u9488\u4e0d\u6307\u5411\u4efb\u4f55\u5bf9\u8c61\uff0c\u4e14\u89e3\u5f15\u7528\u7a7a\u6307\u9488\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\u3002\u53ef\u4f7f\u7528\u7a7a\u6307\u9488\u7b26\u53f7\u5e38\u91cf NULL
\u4e3a\u6307\u9488\u8d4b\u7a7a\u503c\uff0c\u5b83\u5728 stdio.h
\u3001stdlib.h
\u3001string.h
\u3001stddef.h
\u7b49\u5e38\u7528\u5e93\u4e2d\u5747\u6709\u5b9a\u4e49\u3002\u6839\u636e C \u8bed\u8a00\u6807\u51c6\uff0cNULL
\u7684\u503c\u4e3a 0\u3002
\u7a7a\u6307\u9488\u5e38\u91cf NULL
\u7684\u503c \u6839\u636e C \u6807\u51c6\u5b9a\u4e49\uff0c\u5b8f NULL
\u662f\u5b9e\u73b0\u5b9a\u4e49\u7684\u7a7a\u6307\u9488\u5e38\u91cf\uff0c\u5b83\u53ef\u4ee5\u662f\u503c\u4e3a 0 \u7684\u6574\u6570\u5e38\u91cf\u8868\u8fbe\u5f0f\uff0c\u6216\u8005\u88ab\u8f6c\u6362\u4e3a void *
\u7c7b\u578b\u7684\u6b64\u7c7b\u8868\u8fbe\u5f0f\u3002
\u90a3\u4e48\uff0c\u4e3a\u4ec0\u4e48 NULL
\u7684\u503c\u88ab\u89c4\u5b9a\u4e3a 0 \u5462\uff1f
\u4f60\u53ef\u80fd\u4f1a\u731c\u60f3\uff0c\u8fd9\u662f\u56e0\u4e3a\u5185\u5b58\u5730\u5740 0x0 \u88ab\u7cfb\u7edf\u9884\u7559\u3002\u5bf9\u65e9\u671f\u64cd\u4f5c\u7cfb\u7edf\u800c\u8a00\uff0c\u8fd9\u79cd\u8bf4\u6cd5\u662f\u6210\u7acb\u7684\uff1b\u4f46\u662f\u73b0\u5728\uff0c\u4e0d\u540c\u5e73\u53f0\u5bf9\u7a7a\u6307\u9488\u7684\u503c\u5df2\u7ecf\u6709\u8bb8\u591a\u4e0d\u540c\u7684\u89c4\u5b9a\u3002\u65e0\u8bba NULL
\u7684\u503c\u88ab\u5982\u4f55\u5b9a\u4e49\uff0c\u94fe\u63a5\u5668\u90fd\u5e94\u5c06\u7a7a\u6307\u9488\u7684\u503c\u6539\u4e3a\u76ee\u6807\u5e73\u53f0\u6307\u5b9a\u7684\u7a7a\u6307\u9488\u503c\u3002\u4e3a\u4e86\u5f3a\u8c03\u8fd9\u4e00\u70b9\uff0cC++11 \u5f15\u5165\u4e86 nullptr
\u5173\u952e\u5b57\uff0c\u4f46 C \u6807\u51c6\u5e76\u672a\u5bf9\u6b64\u4f5c\u4efb\u4f55\u4fee\u6539\u3002
\u56de\u5230\u95ee\u9898\u672c\u8eab\uff0c\u5c06 0 \u89c6\u4f5c\u7279\u6b8a\u503c\u7684\u4e60\u60ef\u662f\u4e00\u4e2a\u6bd4\u8f83\u6709\u8bf4\u670d\u529b\u7684\u7406\u7531\u3002\u6b64\u5916\uff0c\u5c06 NULL
\u5b9a\u4e49\u4e3a 0 \u4e5f\u53ef\u4ee5\u7b80\u5316\u8868\u8fbe\u5f0f\uff0c\u5373\u5229\u7528 C \u8bed\u8a00\u5c06 0 \u89c6\u4e3a false \u7684\u7279\u6027\uff0c\u7b80\u5316\u5bf9\u6307\u9488\u662f\u5426\u4e3a\u7a7a\u7684\u5224\u65ad\u3002
\u4e24\u4e2a\u7c7b\u578b\u517c\u5bb9\u7684\u6307\u9488\u95f4\u7684\u8d4b\u503c\u8fd0\u7b97\u3001\u6bd4\u8f83\u8fd0\u7b97\u4e0e\u51cf\u6cd5\u8fd0\u7b97\u662f\u6709\u6548\u7684\u3002\u82e5\u6307\u9488\u7c7b\u578b\u4e0d\u517c\u5bb9\uff0c\u5219\u9700\u8981\u8fdb\u884c\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u3002\u8fd9\u79cd\u8fd0\u7b97\u4ec5\u5728\u5c11\u6570\u60c5\u5f62\u4e0b\u6709\u610f\u4e49\uff0c\u5982\u4e24\u4e2a\u6307\u9488\u4f4d\u4e8e\u540c\u4e00\u6570\u7ec4\u5185\u65f6\u3002
\u6307\u9488\u4e0e\u6574\u6570\u95f4\u7684\u52a0\u6cd5\u6216\u51cf\u6cd5\u8fd0\u7b97\u4e5f\u662f\u6709\u6548\u7684\uff0c\u5176\u542b\u4e49\u662f\u4ee4\u6307\u9488\u524d\u79fb\u6216\u540e\u79fb\u82e5\u5e72\u4e2a\u6307\u5411\u5bf9\u8c61\u7684\u957f\u5ea6\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8868\u8fbe\u5f0f p + n
\u7684\u503c\uff0c\u4ee3\u8868\u6307\u9488 p
\u5f53\u524d\u6307\u5411\u7684\u5bf9\u8c61\u4e4b\u540e\u7b2c n \u4e2a\u5bf9\u8c61\u7684\u5730\u5740\u3002\u8fd9\u79cd\u8fd0\u7b97\u5728\u6570\u7ec4\u4e0e\u5b57\u7b26\u4e32\u64cd\u4f5c\u4e2d\u5341\u5206\u5e38\u89c1\u3002
\u867d\u7136\u5185\u5b58\u5730\u5740\u5f80\u5f80\u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u4f46\u662f\u6307\u9488\u4e0e\u6574\u6570\u4e4b\u95f4\u4e0d\u80fd\u76f8\u4e92\u8f6c\u6362\uff0c0 \u662f\u552f\u4e00\u7684\u4f8b\u5916\uff1a\u5e38\u91cf 0 \u53ef\u4ee5\u8d4b\u503c\u7ed9\u6307\u9488\uff0c\u6307\u9488\u4e5f\u53ef\u4e0e\u5e38\u91cf 0 \u8fdb\u884c\u6bd4\u8f83\u3002\u663e\u7136\uff0c\u6b64\u65f6\u5e38\u91cf 0 \u5c06\u88ab\u89c6\u4e3a\u7a7a\u6307\u9488 NULL
\u3002
\u9664\u4ee5\u4e0a\u8fd0\u7b97\u5916\uff0c\u5176\u4ed6\u5f62\u5f0f\u7684\u6307\u9488\u8fd0\u7b97\u90fd\u662f\u975e\u6cd5\u7684\u3002
"},{"location":"programming/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\u975e\u6cd5\u7684\u3002
\u4e0d\u8fc7\uff0c\u5982\u679c\u6211\u4eec\u671f\u671b\u51fd\u6570\u4ea7\u751f\u526f\u4f5c\u7528\uff0c\u503c\u4f20\u9012\u7684\u65b9\u5f0f\u4fbf\u65e0\u6cd5\u6ee1\u8db3\u9700\u6c42\u3002\u4e3a\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u5f15\u5165\u6307\u9488\u7c7b\u578b\u7684\u53c2\u6570\uff0c\u4ee5\u8fbe\u5230\u4fee\u6539\u5176\u4ed6\u5bf9\u8c61\u7684\u76ee\u7684\u3002
\u6848\u4f8b\uff1a\u4ea4\u6362\u51fd\u6570 \u5047\u8bbe fake_swap
\u51fd\u6570\u5b9a\u4e49\u5982\u4e0b\uff1a
void fake_swap(int x, int y) {\n int tmp = x;\n x = y;\n y = tmp;\n}\n
\u8c03\u7528\u90e8\u5206\u5982\u4e0b\uff1a
int a = 1, b = 2;\nfake_swap(a, b);\n
\u5728\u8c03\u7528 fake_swap
\u51fd\u6570\u540e\u68c0\u67e5 a
\u3001b
\u7684\u503c\uff0c\u53ef\u53d1\u73b0\u5b83\u4eec\u7684\u503c\u5e76\u6ca1\u6709\u4ea4\u6362\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u8c03\u7528 fake_swap
\u51fd\u6570\u65f6\uff0c\u5b9e\u53c2 a
\u3001b
\u7684\u503c\u88ab\u590d\u5236\u7ed9\u5f62\u53c2 x
\u3001y
\uff0c\u51fd\u6570\u4ec5\u4fee\u6539\u4e86\u5f62\u53c2\u7684\u503c\uff0c\u5e76\u672a\u5f71\u54cd\u51fd\u6570\u5916\u90e8\u7684\u5b9e\u53c2\u3002
\u73b0\u5728\uff0c\u6211\u4eec\u5c06 fake_swap
\u51fd\u6570\u4fee\u6539\u4e3a\uff1a
void swap(int *x, int *y) {\n int tmp = *x;\n *x = *y;\n *y = tmp;\n}\n
\u8c03\u7528\u90e8\u5206\u5982\u4e0b\uff1a
int a = 1, b = 2;\nswap(&a, &b);\n
\u5728\u8c03\u7528 swap
\u51fd\u6570\u540e\u68c0\u67e5 a
\u3001b
\u7684\u503c\uff0c\u53ef\u53d1\u73b0\u5b83\u4eec\u7684\u503c\u5df2\u7ecf\u4ea4\u6362\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u8c03\u7528 swap
\u51fd\u6570\u65f6\uff0c\u5b9e\u53c2 a
\u3001b
\u7684\u5730\u5740\u88ab\u590d\u5236\u7ed9\u5f62\u53c2 x
\u3001y
\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0cx
\u3001y
\u5206\u522b\u6307\u5411 a
\u3001b
\u3002\u51fd\u6570\u4fee\u6539\u4e86 x
\u3001y
\u6307\u5411\u5bf9\u8c61\u7684\u503c\uff0c\u4e5f\u5c31\u662f a
\u3001b
\u7684\u503c\uff0c\u56e0\u6b64\u867d\u7136 a
\u3001b
\u5728\u51fd\u6570\u5916\u90e8\uff0c\u4f46\u5b83\u4eec\u7684\u503c\u5df2\u88ab\u6210\u529f\u4fee\u6539\u3002
C \u8bed\u8a00\u4e2d\u7684\u51fd\u6570\u53ea\u6709\u4e00\u4e2a\u8fd4\u56de\u503c\u3002\u82e5\u8981\u8fd4\u56de\u591a\u4e2a\u503c\uff0c\u53ef\u5c06\u6240\u6709\u8fd4\u56de\u503c\u653e\u5165\u7ed3\u6784\u4f53\u4e2d\uff1b\u4f46\u662f\uff0c\u8fd9\u9700\u8981\u989d\u5916\u58f0\u660e\u4e00\u4e2a\u4e34\u65f6\u4f7f\u7528\u7684\u7ed3\u6784\u4f53\u7c7b\u578b\uff0c\u62c6\u89e3\u7ed3\u6784\u4f53\u7684\u8fc7\u7a0b\u4e5f\u8017\u65f6\u8017\u529b\u3002\u4e00\u4e2a\u66f4\u597d\u7684\u65b9\u6848\u662f\uff0c\u5411\u51fd\u6570\u4f20\u9012\u6307\u9488\u53c2\u6570\uff0c\u7531\u51fd\u6570\u901a\u8fc7\u6307\u9488\u5c06\u7ed3\u679c\u5199\u5165\u76ee\u6807\u5bf9\u8c61\u3002\u6211\u4eec\u7ecf\u5e38\u4f7f\u7528\u7684 scanf
\u51fd\u6570\u4fbf\u662f\u4e00\u4e2a\u5178\u578b\u4f8b\u5b50\u3002
"},{"location":"programming/topic/pointers/#_11","title":"\u64cd\u4f5c\u6570\u7ec4","text":"\u4e00\u822c\u800c\u8a00\uff0c\u63d0\u5230\u201c\u6570\u7ec4\u201d\u65f6\uff0c\u6211\u4eec\u8ba8\u8bba\u7684\u65e2\u53ef\u4ee5\u662f\u6570\u7ec4\u7c7b\u578b\uff0c\u4e5f\u53ef\u4ee5\u662f\u6570\u7ec4\u7c7b\u578b\u7684\u5bf9\u8c61\u3002
\u6307\u9488\u4e0e\u6570\u7ec4\u7684\u5173\u7cfb\u5341\u5206\u5bc6\u5207\uff0c\u5b83\u4eec\u4e4b\u95f4\u7684\u8f6c\u6362\u4e5f\u662f C \u8bed\u8a00\u4e2d\u6700\u5e38\u89c1\u7684\u7c7b\u578b\u8f6c\u6362\u4e4b\u4e00\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u7528\u6307\u9488\u7f16\u5199\u7684\u7a0b\u5e8f\u6bd4\u7528\u6570\u7ec4\u7f16\u5199\u7684\u7a0b\u5e8f\u6267\u884c\u901f\u5ea6\u5feb\uff0c\u4f46\u53ef\u8bfb\u6027\u76f8\u5bf9\u8f83\u5dee\u3002
\u9605\u8bfb\u5efa\u8bae
\u4e0b\u6587\u7684\u8ba8\u8bba\u4e2d\u4f1a\u8bb2\u89e3\u6570\u7ec4\u7684\u90e8\u5206\u7279\u6027\uff0c\u4e0d\u8fc7\u4ecd\u7136\u5efa\u8bae\u5728\u719f\u6089\u6570\u7ec4\u540e\u9605\u8bfb\u3002
"},{"location":"programming/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
- \u4f5c\u4e3a\u53d6\u5730\u5740\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\u6570
- \u4f5c\u4e3a sizeof \u7684\u64cd\u4f5c\u6570
- \u4f5c\u4e3a\u7528\u4e8e\u6570\u7ec4\u521d\u59cb\u5316\u7684\u5b57\u7b26\u4e32\u5b57\u9762\u91cf
\u7684\u8bed\u5883\u65f6\uff0c\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u3002
\u4e60\u60ef\u4e0a\uff0c\u6211\u4eec\u5c06\u6570\u7ec4\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u8fc7\u7a0b\uff0c\u79f0\u4e3a\u6570\u7ec4\u9000\u5316\u4e3a\u6307\u9488\u3002
C \u6807\u51c6\u89c4\u5b9a\uff0c\u8868\u8fbe\u5f0f E1[E2]
\u7b49\u4ef7\u4e8e (*((E1) + (E2)))
\u3002\u8fd9\u610f\u5473\u7740\uff0c\u6570\u7ec4\u5143\u7d20\u5728\u5185\u5b58\u4e2d\u8fde\u7eed\u3002\u53e6\u5916\uff0c\u5982\u679c\u786e\u4fe1\u76f8\u5e94\u5143\u7d20\u5b58\u5728\uff0c\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u8d85\u51fa\u6570\u7ec4\u8303\u56f4\u7684\u4e0b\u6807\uff0c\u8bbf\u95ee\u6570\u7ec4\u524d\u540e\u7684\u5143\u7d20\u3002
\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c
C \u8bed\u8a00\u4e0d\u4f1a\u68c0\u67e5\u6570\u7ec4\u4e0b\u6807\u662f\u5426\u8d85\u8fc7\u6570\u7ec4\u957f\u5ea6\uff0c\u5bf9\u6307\u9488\u4e5f\u51e0\u4e4e\u6ca1\u6709\u9650\u5236\u63aa\u65bd\u3002\u5c1d\u8bd5\u8bbf\u95ee\u8d85\u51fa\u6570\u7ec4\u8fb9\u754c\u7684\u5185\u5b58\u5730\u5740\uff0c\u53ef\u80fd\u5bfc\u81f4\u4e0e\u5c1d\u8bd5\u89e3\u5f15\u7528\u91ce\u6307\u9488\u7b49\u540c\u7684\u5371\u5bb3\u3002\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c\u662f\u6bb5\u9519\u8bef\u7684\u4e3b\u8981\u8bf1\u56e0\u4e4b\u4e00\u3002\u56e0\u6b64\uff0c\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u524d\uff0c\u52a1\u5fc5\u5145\u5206\u68c0\u67e5\u6307\u5b9a\u7684\u4e0b\u6807\u4e0e\u6307\u9488\u504f\u79fb\u91cf\u662f\u5426\u5728\u6570\u7ec4\u8303\u56f4\u5185\u3002
\u7531\u4e8e\u590d\u5236\u6570\u7ec4\u7684\u5f00\u9500\u7ecf\u5e38\u5927\u5230\u4e0d\u53ef\u63a5\u53d7\uff0cC \u6807\u51c6\u89c4\u5b9a\uff0c\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u65f6\u6570\u7ec4\u4e5f\u5e94\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u5176\u9996\u5143\u7d20\u6307\u9488\u3002\u6240\u4ee5\uff0c\u5728\u8bed\u6cd5\u5c42\u9762\u4e0a\uff0c\u51fd\u6570\u58f0\u660e\u4e0e\u5b9a\u4e49\u4e2d\uff0c\u5f62\u5982 char str[]
\u7684\u5f62\u53c2\u58f0\u660e\u4e0e char *str
\u662f\u7b49\u4ef7\u7684\uff0c\u4e0d\u8fc7\u524d\u8005\u53ef\u4ee5\u63d0\u9192\u51fd\u6570\u7f16\u5199\u8005\u4e0e\u4f7f\u7528\u8005\u7559\u610f str
\u7684\u5b9e\u9645\u542b\u4e49\u3002\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f20\u5165\u6307\u5411\u5176\u4ed6\u5143\u7d20\u7684\u6307\u9488\uff0c\u8fd9\u5728\u4f20\u53c2\u8fc7\u7a0b\u4e2d\u6ca1\u6709\u533a\u522b\u3002
\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd4\u56de\u7c7b\u578b\u4e2d\u7684\u6570\u7ec4\u4e0d\u4f1a\u81ea\u52a8\u8f6c\u6362\u6210\u6307\u9488\uff0c\u56e0\u6b64\u5f62\u5982 char func() [];
\u7684\u51fd\u6570\u58f0\u660e\u662f\u975e\u6cd5\u7684\u3002
\u6570\u7ec4\u7c7b\u578b\u4e0e\u6307\u9488\u7c7b\u578b\u7684\u533a\u522b
\u5c3d\u7ba1\u5728\u7a0b\u5e8f\u4e2d\u6570\u7ec4\u7ecf\u5e38\u9000\u5316\u4e3a\u6307\u9488\uff0c\u6211\u4eec\u4ecd\u5e94\u8be5\u533a\u5206\u8fd9\u4e24\u4e2a\u7c7b\u578b\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8003\u8651\u5982\u4e0b\u7684\u7a0b\u5e8f\u7247\u6bb5\uff08C \u6807\u51c6\u89c4\u5b9a sizeof
\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u4e3a\u65e0\u7b26\u53f7\u6574\u578b size_t
\uff0c\u5e94\u4f7f\u7528 %zu
\u683c\u5f0f\u6307\u793a\u7b26\u8f93\u51fa\uff09\uff1a
int a[3], *p;\nprintf(\"%zu %zu\", sizeof(a), sizeof(p));\n
\u5b83\u5c06\u4f1a\u8f93\u51fa 12 8
\u3002\u8fd9\u662f\u56e0\u4e3a\uff0ca
\u662f\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int
\u4e14\u957f\u5ea6\u4e3a 3 \u7684\u6570\u7ec4\u5bf9\u8c61\uff0c\u5728\u591a\u6570\u7cfb\u7edf\u4e2d int
\u7c7b\u578b\u957f\u5ea6\u4e3a 4 \u5b57\u8282\uff0c\u56e0\u6b64 a
\u7684\u957f\u5ea6\u4e3a 12 \u5b57\u8282\uff1b\u800c p
\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u5728\u5e38\u7528\u7684 64 \u4f4d\u7cfb\u7edf\u4e2d\u957f\u5ea6\u4e3a 8 \u5b57\u8282\u3002
\u53e6\u5916\uff0c\u6307\u9488\u7684\u503c\u53ef\u5728\u4efb\u610f\u65f6\u523b\u901a\u8fc7\u8d4b\u503c\u4fee\u6539\uff0c\u800c\u6570\u7ec4\u4e0d\u80fd\u88ab\u8d4b\u503c\u3002
"},{"location":"programming/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
\u6848\u4f8b\uff1a\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u591a\u7ef4\u6570\u7ec4\u5143\u7d20 \u6839\u636e C \u6807\u51c6\u89c4\u5b9a\uff0c\u4e0d\u96be\u63a8\u65ad\u51fa\u8868\u8fbe\u5f0f a[i][j]
\u4e0e\u8868\u8fbe\u5f0f *(*(a + i) + j)
\u7b49\u4ef7\u3002\u4e0d\u8fc7\uff0c\u540e\u8005\u7684\u6c42\u503c\u8fc7\u7a0b\u76f8\u6bd4\u524d\u8005\u66f4\u52a0\u62bd\u8c61\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u5c06\u4ee5\u6b64\u4e3a\u4f8b\u9010\u6b65\u5206\u6790\u5176\u6c42\u503c\u8fc7\u7a0b\u3002
-
\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
"},{"location":"programming/topic/pointers/#_14","title":"\u5b57\u7b26\u4e32","text":"\u6211\u4eec\u77e5\u9053\uff0cC \u8bed\u8a00\u4e2d\u7684\u5b57\u7b26\u4e32\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u7a7a\u5b57\u7b26\uff08\u79f0\u4e3a\u4e2d\u6b62\u5b57\u7b26\uff09\u7ed3\u5c3e\u7684\u5b57\u7b26\u6570\u7ec4\u3002\u56e0\u6b64\uff0c\u4e0a\u4e00\u5c0f\u8282\u7684\u8ba8\u8bba\u540c\u6837\u9002\u7528\u4e8e\u8fd9\u4e00\u5c0f\u8282\u3002
\u7531\u4e8e\u5b57\u7b26\u4e32\u540c\u65f6\u5177\u6709\u6570\u7ec4\u7684\u5c5e\u6027\uff0c\u8ba8\u8bba\u4e0e\u5185\u5b58\u7a7a\u95f4\u6709\u5173\u7684\u6982\u5ff5\u4e0e\u64cd\u4f5c\u65f6\uff0c\u4e3a\u907f\u514d\u6df7\u6dc6\uff0c\u6211\u4eec\u5c06\u6570\u7ec4\u5bf9\u8c61\u5360\u7528\u7684\u5b57\u8282\u6570\u79f0\u4e3a\u5176\u5927\u5c0f\uff0c\u5c06\u5b9e\u9645\u7ec4\u6210\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u6570\u79f0\u4e3a\u5176\u957f\u5ea6\u3002\u4e00\u4e2a\u76f4\u89c2\u7406\u89e3\u662f\uff0c\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u8ba1\u5165\u4e2d\u6b62\u5b57\u7b26\uff0c\u800c\u5176\u957f\u5ea6\u4e0d\u8ba1\u5165\u3002
\u5728 C \u8bed\u8a00\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u662f\u7531\u4e00\u5bf9 \"
\u5305\u56f4\u7684\u4efb\u610f\u957f\u5ea6\u7684\u5b57\u7b26\u5e8f\u5217\uff0c\u5176\u4e2d\u7684\u5b57\u7b26\u53ef\u4ee5\u662f\u4e00\u822c\u5b57\u7b26\u6216\u8f6c\u4e49\u5b57\u7b26\uff0c\u5982 \"abc\"
\u3001\"x y\\nz\"
\u3001\"\"
\u3002\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u672b\u5c3e\u9690\u5f0f\u5305\u542b\u4e2d\u6b62\u5b57\u7b26\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\"\"
\u4ee3\u8868\u5927\u5c0f\u4e3a 1 \u7684\u5b57\u7b26\u6570\u7ec4\uff0c\u5b83\u7684\u552f\u4e00\u5143\u7d20\u4e3a '\\0'
\u3002
\u542b\u7a7a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u5b57\u9762\u91cf \u82e5\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5b57\u7b26\u5e8f\u5217\u5185\u5305\u542b\u7a7a\u5b57\u7b26\uff0c\u5219\u5b83\u8868\u793a\u542b\u6709\u591a\u4e8e\u4e00\u6761\u5b57\u7b26\u4e32\u7684\u6570\u7ec4\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5bf9\u4e8e\u5b57\u7b26\u4e32\u5b57\u9762\u91cf \"abc\\0\"
\uff0c\u5b83\u5305\u542b \"abc\"
\u548c \"\"
\u4e24\u4e2a\u5b57\u7b26\u4e32\u3002
\u4f60\u53ef\u4ee5\u901a\u8fc7 sizeof
\u8fd0\u7b97\u7b26\u548c strlen
\u51fd\u6570\u9a8c\u8bc1\u7a0b\u5e8f\u884c\u4e3a\u3002
\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u7c7b\u578b\u4e3a char [N]
\uff0c\u5176\u4e2d N
\u662f\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\uff0c\u5305\u62ec\u9690\u5f0f\u7684\u4e2d\u6b62\u5b57\u7b26\u3002\u663e\u7136\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u4e5f\u9075\u5b88\u6570\u7ec4\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u89c4\u5219\u3002
\u5c1d\u8bd5\u4fee\u6539\u5b57\u7b26\u4e32\u5b57\u9762\u91cf
\u867d\u7136\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u7c7b\u578b\u6ca1\u6709\u6307\u5b9a\u4e3a const
\uff0c\u4f46\u5b83\u5b9e\u9645\u4e0a\u4e5f\u662f\u5e38\u91cf\u3002\u5c1d\u8bd5\u4fee\u6539\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\u3002\u4e00\u822c\u800c\u8a00\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5185\u5bb9\u4f1a\u88ab\u653e\u5165\u53ea\u8bfb\u5185\u5b58\u4e2d\uff0c\u56e0\u6b64\u5c1d\u8bd5\u4fee\u6539\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u9519\u8bef\u3002
\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u672a\u9000\u5316\u60c5\u5f62 \u8003\u8651\u5982\u4e0b\u7a0b\u5e8f\u7247\u6bb5\uff1a
char *str = \"abc\";\nprintf(\"%zu %zu\\n\", sizeof(\"abc\"), sizeof(str));\n
\u5b83\u5c06\u4f1a\u8f93\u51fa 4 8
\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u6b64\u65f6\u5b57\u7b26\u4e32\u5b57\u9762\u91cf \"abc\"
\u88ab\u4f5c\u4e3a sizeof
\u7684\u64cd\u4f5c\u6570\uff0c\u4e0d\u4f1a\u9000\u5316\u4e3a\u6307\u9488\uff0c\u56e0\u6b64\u8868\u8fbe\u5f0f sizeof(\"abc\")
\u7684\u7ed3\u679c\u662f\u5b57\u7b26\u4e32\u6570\u7ec4\u7684\u5927\u5c0f\u3002
\u4e0d\u96be\u60f3\u5230\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5176\u6548\u679c\u76f8\u5f53\u4e8e\u4f7f\u7528\u5bf9\u5e94\u7684\u5b57\u7b26\u6570\u7ec4\u5e38\u91cf\u521d\u59cb\u5316\u3002\u4e0e\u4e00\u822c\u7684\u6570\u7ec4\u521d\u59cb\u5316\u7c7b\u4f3c\uff0c\u6570\u7ec4\u957f\u5ea6\u53ef\u7531\u521d\u59cb\u5316\u5668\u9690\u5f0f\u6307\u5b9a\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 char str[] = \"abc\";
\u7b49\u4ef7\u4e8e\u8bed\u53e5 char str[] = {'a', 'b', 'c', '\\0'};
\uff0c\u5b83\u58f0\u660e\u5e76\u521d\u59cb\u5316\u4e86\u4e00\u4e2a\u957f\u5ea6\u4e3a 4 \u7684\u5b57\u7b26\u6570\u7ec4 str
\u3002
\u6570\u7ec4\u7684\u5927\u5c0f\u53ef\u4ee5\u6bd4\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5927\u5c0f\u5c11 1\uff0c\u6b64\u65f6\u4e2d\u6b62\u5b57\u7b26\u5c06\u88ab\u5ffd\u7565\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 char str[3] = \"abc\";
\u7b49\u4ef7\u4e8e\u8bed\u53e5 char str[3] = {'a', 'b', 'c'};
\u3002
\u6848\u4f8b\uff1a\u9519\u8bef\u7684\u5b57\u7b26\u6570\u7ec4\u521d\u59cb\u5316 \u8003\u8651\u5982\u4e0b\u7a0b\u5e8f\u7247\u6bb5\uff1a
char str[3] = \"abc\";\nchar backdoor[] = \"xyz\";\nprintf(\"%s\", str);\n
\u5b83\u5c06\u4f1a\u8f93\u51fa abcxyz
\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf \"abc\"
\u7684\u5927\u5c0f str
\u7684\u5927\u5c0f\u5927 1\uff0c\u521d\u59cb\u5316\u65f6\u4e2d\u6b62\u5b57\u7b26\u88ab\u5ffd\u7565\uff0cstr
\u6700\u7ec8\u88ab\u521d\u59cb\u5316\u4e3a {'a', 'b', 'c'}
\u3002\u5c06\u5176\u89c6\u4e3a\u5b57\u7b26\u4e32\u5e76\u8f93\u51fa\u65f6\uff0c\u7531\u4e8e str
\u5185\u4e0d\u542b\u4e2d\u6b62\u5b57\u7b26\uff0c\u8f93\u51fa\u51fd\u6570\u5c06\u4f1a\u7ee7\u7eed\u8bbf\u95ee str
\u540e\u7684\u5185\u5b58\u5730\u5740\uff0c\u5373\u51fa\u73b0\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c\u95ee\u9898\u3002
\u7531\u4e8e C \u6807\u51c6\u5e76\u672a\u5bf9\u5b57\u9762\u91cf\u7684\u5185\u5b58\u6392\u5e03\u4f5c\u4efb\u4f55\u89c4\u5b9a\uff0c\u5728\u4e0d\u540c\u73af\u5883\u4e0b\u5b57\u7b26\u4e32\u5e38\u91cf backdoor
\u7684\u5185\u5b58\u5730\u5740\u53ef\u80fd\u4f4d\u4e8e str
\u7684\u5185\u5b58\u5730\u5740\u4e4b\u524d\u3002\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u6539\u53d8\u58f0\u660e\u987a\u5e8f\u4ee5\u8fbe\u5230\u7c7b\u4f3c\u7684\u8f93\u51fa\u6548\u679c\u3002
\u6839\u636e\u9690\u5f0f\u8f6c\u6362\u89c4\u5219\uff0c\u5728\u591a\u6570\u8868\u8fbe\u5f0f\u4e2d\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u5c06\u4f1a\u9690\u5f0f\u8f6c\u6362\u4e3a\u6307\u5411\u5b83\u7684\u6307\u9488\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8be5\u6307\u9488\u7684\u503c\u662f\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5185\u5b58\u5730\u5740\u3002\u7c7b\u4f3c\u5730\uff0c\u88ab\u7528\u4e8e\u5bf9\u6307\u9488\u7684\u521d\u59cb\u5316\u65f6\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u4e5f\u4f1a\u9000\u5316\u4e3a\u6307\u9488\u3002
\u5728\u51fd\u6570\u5185\u4fee\u6539\u5b57\u7b26\u4e32\u65f6\uff0c\u4f20\u5165\u7684\u5b57\u7b26\u6570\u7ec4\u5c06\u4f1a\u9000\u5316\u4e3a\u6307\u9488\uff0c\u6570\u7ec4\u7684\u5927\u5c0f\u4fe1\u606f\u56e0\u6b64\u4e22\u5931\u3002\u53ef\u4ee5\u60f3\u5230\uff0c\u5b57\u7b26\u4e32\u672b\u5c3e\u7684\u7a7a\u5b57\u7b26\u6b63\u662f\u4e3a\u8fd9\u79cd\u60c5\u5f62\u8bbe\u8ba1\u7684\u3002
\u7b80\u5316\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570
\u5173\u4e8e\u5229\u7528\u6307\u9488\u7f16\u5199\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\u7684\u6280\u5de7\uff0c\u4f60\u53ef\u4ee5\u53c2\u8003\u300aC \u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u300b\uff08\u4e5f\u5c31\u662f\u7a0b\u8bbe\u8bfe\u7a0b\u4f7f\u7528\u7684\u8bfe\u672c\uff09\u4e2d\u7ed9\u51fa\u7684 strcpy
\u4e0e strcmp
\u51fd\u6570\u7684\u5b9e\u73b0\u8fed\u4ee3\u3002\u672c\u6587\u5bf9\u6b64\u4e0d\u518d\u8d58\u8ff0\u3002
C \u8bed\u8a00\u6807\u51c6\u5e93\u4e2d\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\uff0c\u5b83\u4eec\u5927\u591a\u88ab\u5b9a\u4e49\u5728 string.h
\u5934\u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528\u65f6\u5747\u9700\u4fdd\u8bc1\u63d0\u4f9b\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u7b26\u5408\u7ea6\u5b9a\u3002
\u4e2d\u6b62\u5b57\u7b26\u7f3a\u5931
\u6807\u51c6\u5e93\u4e2d\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\u901a\u8fc7\u68c0\u67e5\u4e2d\u6b62\u5b57\u7b26\u5224\u65ad\u662f\u5426\u5230\u8fbe\u5b57\u7b26\u4e32\u672b\u5c3e\u3002\u56e0\u6b64\uff0c\u5728\u4fee\u6539\u5b57\u7b26\u4e32\u65f6\u52a1\u5fc5\u6ce8\u610f\u4fdd\u7559\u4e2d\u6b62\u5b57\u7b26\u3002\u5982\u679c\u4e2d\u6b62\u5b57\u7b26\u7f3a\u5931\uff0c\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\u5c06\u4f1a\u5bfc\u81f4\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c\u95ee\u9898\u3002
"},{"location":"programming/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
- \u4f5c\u4e3a\u53d6\u5740\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\u6570
- \u4f5c\u4e3a
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
"},{"location":"programming_lecture/","title":"\u7a0b\u8bbe\u8f85\u5b66\u8bfe\u7a0b \u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057","text":"\u6b22\u8fce\u6765\u5230\u7afa\u9662\u7a0b\u8bbe\u8f85\u5b66\u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057\u7248\u5757 \ud83e\udd17\u3002\u4f60\u53ef\u4ee5\u5728\u5de6\u4fa7\u5bfc\u822a\u680f\u4e2d\u8be6\u7ec6\u6d4f\u89c8\u672c\u6a21\u5757\u7684\u5185\u5bb9\u3002
"},{"location":"programming_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
- \u7f16\u8bd1\u65f6\u6211\u7684\u4ee3\u7801\u7ecf\u5386\u4e86\u4ec0\u4e48\uff1f\u64cd\u4f5c\u7cfb\u7edf\u5982\u4f55\u8fd0\u884c\u6211\u7684\u7a0b\u5e8f\uff1f\u5982\u4f55\u4f7f\u7528\u8c03\u8bd5\u5668\u5feb\u901f\u5b9a\u4f4d\u9519\u8bef\uff1f
- \u6307\u9488\u7a76\u7adf\u662f\u4ec0\u4e48\uff1f\u5185\u5b58\u4e2d\u7684\u6570\u636e\u662f\u5982\u4f55\u7ec4\u7ec7\u7684\uff1f
- C \u6807\u51c6\u5e93\u4e2d\u7684 I/O \u51fd\u6570\u5982\u4f55\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u4ea4\u4e92\uff1f
- C \u6807\u51c6\u5e93\u662f\u5982\u4f55\u7f16\u5199\u7684\uff1f\u600e\u6837\u5199\u51fa\u5177\u6709\u5de5\u4e1a\u5f3a\u5ea6\u7684\u5065\u58ee\u4ee3\u7801\uff1f
- \u5982\u4f55\u4f7f\u7528\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\uff1f
\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u80fd\u591f\u4e3a\u4f60\u5f00\u542f\u4ece C \u8bed\u8a00\u5230\u8ba1\u7b97\u673a\u79d1\u5b66\u4e0e\u6280\u672f\u7684\u771f\u6b63\u7684\u5927\u95e8\u3002\u5982\u679c\u5bf9\u8bfe\u7a0b\u5185\u5bb9\u6709\u4efb\u4f55\u7591\u95ee\u548c\u5efa\u8bae\uff0c\u6b22\u8fce\u4f60\u8054\u7cfb\u6211\u4eec\u3002\u4f60\u53ef\u4ee5\u5728\u4ed3\u5e93\u4e2d\u53d1\u8d77 issue \u6216\u53d1\u9001\u90ae\u4ef6\u5230 zhubaolin228@gmail.com
\u3002
"},{"location":"programming_lecture/#_3","title":"\u8bfe\u7a0b\u5b89\u6392","text":"2023-2024 \u5b66\u5e74\uff0c\u7a0b\u8bbe\u8f85\u5b66\u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057\u8bfe\u9898\u7ec4\u540c\u5b66\u6709\uff1a
- \u6731\u5b9d\u6797 \u6df7\u5408 2205
- \u674e\u82f1\u7426 \u56fe\u7075 2201
- \u8c22\u96c6 \u6df7\u5408 2206
- \u80e1\u80b2\u73ae \u6df7\u5408 2206
- \u82cf\u715c\u7a0b \u56fe\u7075 2201
- \u5b59\u5146\u6c5f \u6df7\u5408 2204
\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\u653e Bilibili
\u5185\u5bb9\u63d0\u8981 - C \u8bed\u8a00\u7a0b\u5e8f\u57fa\u672c\u7ed3\u6784
- \u7f16\u8bd1\u8fc7\u7a0b\uff1a\u4ece\u6e90\u4ee3\u7801\u5230\u53ef\u6267\u884c\u6587\u4ef6
- \u7f16\u8bd1\u5668\u548c\u5f00\u53d1\u5957\u4ef6\uff1a
gcc
\u3001clang
\u548c llvm
\u7a76\u7adf\u662f\u4ec0\u4e48\uff1f - \u8c03\u8bd5\u5668\uff1a\u5982\u4f55\u4f7f\u7528
gdb
\u6216 lldb
\u8bbe\u7f6e\u65ad\u70b9\u3001\u627e\u5230\u6bb5\u9519\u8bef\u7684\u6839\u6e90\uff1f
\u5982\u4f55\u98df\u7528\u672c\u8bb2\u4e49 \u4f5c\u4e3a\u5728\u7ebf\u8bb2\u4e49\uff0c\u6211\u4f1a\u5c3d\u91cf\u5199\u5f97\u8be6\u7ec6\u4e00\u4e9b\uff0c\u4e3a\u540c\u5b66\u4eec\u63d0\u4f9b\u590d\u4e60\u548c\u8fdb\u4e00\u6b65\u6269\u5c55\u7684\u6307\u5f15\u3002\u56e0\u4e3a\u65f6\u95f4\u6709\u9650\uff0c\u5728\u8bfe\u4e0a\u6211\u65e0\u6cd5\u8986\u76d6\u8bb2\u4e49\u4e2d\u6240\u6709\u7684\u5185\u5bb9\u3002\u540c\u5b66\u4eec\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u4e60\u60ef\u9009\u62e9\u5728\u8bfe\u524d\u8bfe\u540e\u6d4f\u89c8\u672c\u8bb2\u4e49\uff5e
\u672c\u6b21\u8bfe\u7684\u6838\u5fc3\u5185\u5bb9\u4ece\u300c\u7a0b\u5e8f\u7684\u7f16\u8bd1\u8fc7\u7a0b\u300d\u5f00\u59cb\u3002\u524d\u9762\u7684\u5185\u5bb9\u4f5c\u4e3a\u9884\u5907\u77e5\u8bc6\uff0c\u5728\u8bfe\u4e0a\u5c06\u4f1a\u5feb\u901f\u5e26\u8fc7\u3002
"},{"location":"programming_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
- \u8ba1\u7b97\u673a\u662f\u5982\u4f55\u8bfb\u61c2\u6211\u5199\u7684\u4ee3\u7801\u7684\uff1f
- \u6211\u7684\u7a0b\u5e8f\u603b\u662f\u51fa\u95ee\u9898\uff0c\u6211\u8be5\u5982\u4f55\u5feb\u901f\u627e\u5230\u9519\u8bef\u7684\u6839\u6e90\uff1f
\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 \u80fd\u8bfb\u61c2\u4ec0\u4e48\uff1f
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 \u90fd\u505a\u4e9b\u4ec0\u4e48\uff1f
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\u5b50 c = a + b;\n
add $t0, $t1, $t2\n
01 2a 40 20\n
void multstore(long x, long y, long *dest) {\n long t = mult2(x, y);\n *dest = t;\n}\n
multstore:\n pushq %rbx\n movq %rdx, %rbx\n call mult2\n movq %rax, (%rbx)\n popq %rbx\n ret\n
53 48 89 d3 48 83 ec 08 e8 00 00 00 00 48 89 03 5b c3\n
\u4e3a\u4ec0\u4e48\u9700\u8981\u9ad8\u7ea7\u8bed\u8a00\uff1f - \u673a\u5668\u8bed\u8a00\u548c\u6c47\u7f16\u8bed\u8a00\u90fd\u662f\u975e\u5e38\u5e95\u5c42\u7684\u8bed\u8a00\uff0c\u7a0b\u5e8f\u5458\u9700\u8981\u5173\u6ce8\u8ba1\u7b97\u673a\u7684\u7ec6\u8282\uff0c\u8fd9\u4f7f\u5f97\u7a0b\u5e8f\u7684\u53ef\u8bfb\u6027\u5f88\u5dee\u3002\u4f7f\u7528\u9ad8\u7ea7\u8bed\u8a00\uff0c\u7a0b\u5e8f\u5458\u80fd\u5c06\u6ce8\u610f\u529b\u8f6c\u79fb\u5230\u8981\u89e3\u51b3\u7684\u95ee\u9898\u4e0a\u6765\u3002
- \u673a\u5668\u8bed\u8a00\u548c\u6c47\u7f16\u8bed\u8a00\u90fd\u662f\u4e0e\u5177\u4f53 CPU \u76f8\u5173\u7684\uff0c\u7a0b\u5e8f\u5458\u9700\u8981\u4e3a\u4e0d\u540c\u7684 CPU \u7f16\u5199\u4e0d\u540c\u7684\u7a0b\u5e8f\uff0c\u53ef\u79fb\u690d\u6027\u5dee\u3002\u4f7f\u7528\u9ad8\u7ea7\u8bed\u8a00\uff0c\u7a0b\u5e8f\u5458\u53ea\u9700\u8981\u5199\u4e00\u6b21\u7a0b\u5e8f\uff0c\u518d\u4f7f\u7528\u7f16\u8bd1\u5668\u5c31\u80fd\u5c06\u5176\u7ffb\u8bd1\u6210\u80fd\u5728\u7279\u5b9a CPU \u7684\u673a\u5668\u8bed\u8a00\u3002
\u524d\u77bb\uff1a\u7b2c\u56db\u4ee3\u548c\u7b2c\u4e94\u4ee3\u7f16\u7a0b\u8bed\u8a00 \u7f16\u7a0b\u8bed\u8a00\u4ecd\u5728\u53d1\u5c55\u6f14\u5316\u3002\u76ee\u524d\u5df2\u7ecf\u6709\u4e86\u7b2c\u56db\u4ee3\u548c\u7b2c\u4e94\u4ee3\u7f16\u7a0b\u8bed\u8a00\u7684\u6982\u5ff5\u3002\u7b2c\u4e09\u4ee3\u7684\u7f16\u7a0b\u8bed\u8a00\u867d\u7136\u662f\u7528\u8bed\u53e5\u7f16\u7a0b\u800c\u4e0d\u76f4\u63a5\u7528\u6307\u4ee4\u7f16\u7a0b\uff0c\u4f46\u8bed\u53e5\u4e5f\u5206\u4e3a\u8f93\u5165\u3001\u8f93\u51fa\u3001\u57fa\u672c\u8fd0\u7b97\u3001\u6d4b\u8bd5\u5206\u652f\u548c\u5faa\u73af\u7b49\u51e0\u79cd\uff0c\u548c\u6307\u4ee4\u6709\u76f4\u63a5\u7684\u5bf9\u5e94\u5173\u7cfb\u3002\u800c\u7b2c\u56db\u4ee3\u4ee5\u540e\u7684\u7f16\u7a0b\u8bed\u8a00\u66f4\u591a\u662f\u63cf\u8ff0\u8981\u505a\u4ec0\u4e48\uff08Declarative\uff09\u800c\u4e0d\u63cf\u8ff0\u5177\u4f53\u4e00\u6b65\u4e00\u6b65\u600e\u4e48\u505a\uff08Imperative\uff09\uff0c\u5177\u4f53\u4e00\u6b65\u4e00\u6b65\u600e\u4e48\u505a\u5b8c\u5168\u7531\u7f16\u8bd1\u5668\u6216\u89e3\u91ca\u5668\u51b3\u5b9a\uff0c\u4f8b\u5982SQL\u8bed\u8a00\uff08SQL\uff0cStructured Query Language\uff0c\u7ed3\u6784\u5316\u67e5\u8be2\u8bed\u8a00\uff09\u5c31\u662f\u8fd9\u6837\u7684\u4f8b\u5b50\u3002
\u5bf9\u673a\u5668\u8bed\u8a00\u6709\u5174\u8da3\uff1f \u8fd9\u91cc\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5c06\u6c47\u7f16\u8bed\u8a00\u8f6c\u6362\u4e3a MIPS \u6307\u4ee4\u96c6\u673a\u5668\u8bed\u8a00\u7684\u57fa\u7840\u4f8b\u5b50\uff0c\u6709\u5174\u8da3\u53ef\u4ee5\u4e86\u89e3\u4e00\u4e0b\u3002
"},{"location":"programming_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
- \u8f93\u5165\uff08Input\uff09\uff1a\u4ece\u952e\u76d8\u3001\u6587\u4ef6\u6216\u8005\u5176\u5b83\u8bbe\u5907\u83b7\u53d6\u6570\u636e\u3002
- \u8f93\u51fa\uff08Output\uff09\uff1a\u628a\u6570\u636e\u663e\u793a\u5230\u5c4f\u5e55\uff0c\u6216\u8005\u5b58\u5165\u4e00\u4e2a\u6587\u4ef6\uff0c\u6216\u8005\u53d1\u9001\u5230\u5176\u5b83\u8bbe\u5907\u3002
- \u57fa\u672c\u8fd0\u7b97\uff1a\u6267\u884c\u6700\u57fa\u672c\u7684\u6570\u5b66\u8fd0\u7b97\uff08\u52a0\u51cf\u4e58\u9664\uff09\u548c\u6570\u636e\u5b58\u53d6\u3002
- \u6d4b\u8bd5\u548c\u5206\u652f\uff1a\u6d4b\u8bd5\u67d0\u4e2a\u6761\u4ef6\uff0c\u7136\u540e\u6839\u636e\u4e0d\u540c\u7684\u6d4b\u8bd5\u7ed3\u679c\u6267\u884c\u4e0d\u540c\u7684\u540e\u7eed\u6307\u4ee4\u3002
- \u5faa\u73af\uff1a\u91cd\u590d\u6267\u884c\u4e00\u7cfb\u5217\u64cd\u4f5c\u3002
\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
- \u7b49\u4ef7\u4e8e
(a--) - b
\u3002\u6309\u7167\u8d2a\u5fc3\u6cd5\uff0c\u7f16\u8bd1\u5668\u8bfb\u5165\u4e24\u4e2a\u8fde\u7eed\u7684 -
\u53f7\u540e\uff0c\u5df2\u7ecf\u4e0d\u53ef\u80fd\u518d\u7ec4\u6210\u4e00\u4e2a\u6709\u610f\u4e49\u7684\u7b26\u53f7\uff0c\u56e0\u6b64\u8fd9\u4e2a\u7b26\u53f7\u88ab\u786e\u5b9a\u4e3a\u540e\u7f00\u9012\u51cf\u8fd0\u7b97\u7b26\u3002\u63a5\u7740\u8bfb\u53d6\u4e0b\u4e00\u4e2a\u7b26\u53f7\u3002 - \u7b49\u4ef7\u4e8e
(a--) - b
- \u7b49\u4ef7\u4e8e
a - (--b)
- \u7b49\u4ef7\u4e8e
y = x
\u3002/*
\u88ab\u8d2a\u5fc3\u6cd5\u89e3\u91ca\u4e3a\u6ce8\u91ca\u7684\u5f00\u5934\u3002 - \u7b49\u4ef7\u4e8e
y = x / (*p)
- \u7b49\u4ef7\u4e8e
(n--) > 0
- \u7b49\u4ef7\u4e8e
(n--) > 0
- \u7b49\u4ef7\u4e8e
(n-) -> 0
\u3002\u8fd9\u662f\u4e00\u4e2a\u65e0\u6548\u7684\u8bed\u53e5\uff0cn-
\u672c\u8eab\u4e0d\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u8868\u8fbe\u5f0f\uff0c\u4e5f\u65e0\u6cd5\u7528\u4f5c ->
\u7684\u64cd\u4f5c\u6570\u3002 - \u7b49\u4ef7\u4e8e
((a++)++) + b
\u3002\u8bf7\u601d\u8003\u4e00\u4e0b\uff0c\u8fd9\u4e2a\u8bed\u53e5\u6709\u6548\u5417\uff1f
\u8bed\u6cd5\uff1a\u6807\u8bc6\u7b26\u3001\u8868\u8fbe\u5f0f\u548c\u8bed\u53e5 \u4e3a\u4e86\u4fbf\u4e8e\u521d\u5b66\u8005\u7406\u89e3\uff0c\u6211\u4eec\u91c7\u7528\u4e00\u5957\u7b80\u5316\u7684\u8bed\u6cd5\u89c4\u5219\uff1a
- \u6807\u8bc6\u7b26\uff08Identifier\uff09\uff1a\u5c31\u662f\u300c\u540d\u5b57\u300d\uff0c\u7528\u4e8e\u6307\u4ee3\u5404\u79cd\u5b9e\u4f53\uff0c\u6bd4\u5982\uff1a\u5bf9\u8c61\u3001\u7c7b\u578b\u3001\u51fd\u6570\u3001\u6807\u7b7e\u3001\u5b8f\u7b49\u7b49\u3002
\u5bf9\u8c61\u7684\u4e0d\u540c\u542b\u4e49 \u5728\u8fd9\u91cc\uff0c\u5bf9\u8c61\uff08Object\uff09\u7684\u542b\u4e49\u4e0e C++ \u4e2d\u4e0d\u540c\u3002\u8fd9\u91cc\u7684\u5bf9\u8c61\u6307\u6570\u636e\u5b58\u50a8\u7684\u4e00\u4e2a\u533a\u57df\uff0c\u5176\u5185\u5bb9\u53ef\u4ee5\u8868\u793a\u503c\u3002\u6bd4\u5982\u4e0b\u9762\u7684\u8bed\u53e5\u521b\u5efa\u4e86\u4e00\u4e2a\u5bf9\u8c61\uff1a
int a;\n
\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u7684\u610f\u601d\u5c31\u662f\u5206\u914d\u4e86\u4e00\u5757\u5b58\u50a8\u7a7a\u95f4\u3002\u6807\u8bc6\u7b26 a
\u7528\u4e8e\u6307\u4ee3\u8fd9\u4e2a\u5bf9\u8c61\u3002\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u6709\u5927\u5c0f\u3001\u751f\u5b58\u671f\u3001\u5b58\u50a8\u5668\u3001\u503c\u7b49\u5c5e\u6027\uff0c\u6211\u4eec\u5c06\u5728\u4e0b\u8282\u8bfe\u8be6\u7ec6\u5c55\u5f00\u3002
- \u8868\u8fbe\u5f0f\uff08Expression\uff09\uff1a\u7531\u8fd0\u7b97\u7b26\uff08
+-*/%
\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
- CPPReference\uff1a\u6807\u8bc6\u7b26
- CPPReference\uff1a\u8868\u8fbe\u5f0f
- CPPReference: \u8bed\u53e5
\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
- \u51fd\u6570\u540d\uff1a\u51fd\u6570\u7684\u540d\u5b57\uff0c\u7528\u6765\u8c03\u7528\u51fd\u6570\u3002
- \u51fd\u6570\u540d\u4e0e\u53d8\u91cf\u540d\u7684\u547d\u540d\u89c4\u5219\u76f8\u540c\u3002
- \u53c2\u6570\uff1a\u51fd\u6570\u7684\u8f93\u5165\uff0c\u53ef\u4ee5\u6709\u591a\u4e2a\u3002
- \u8fd4\u56de\u503c\uff1a\u51fd\u6570\u7684\u8f93\u51fa\uff0c\u53ea\u80fd\u6709\u4e00\u4e2a\u3002
\u4e0b\u9762\u8fd9\u884c\u8bed\u53e5\u88ab\u79f0\u4e3a\u51fd\u6570\u7b7e\u540d\uff08Function Signature\uff09\u6216\u51fd\u6570\u539f\u578b\uff08Function Prototype\uff09\u3002\u5b83\u7ed9\u51fa\u4e86\u51fd\u6570\u5bf9\u5916\u7684\u4e00\u5207\u4fe1\u606f\uff1a
int MyFunc(int a, int b);\n
\u4ece\u91cc\u9762\u770b\uff0c\u51fd\u6570\u662f\u4e00\u7ec4\u6307\u4ee4\u7684\u96c6\u5408\uff0c\u5b83\u4eec\u6309\u7167\u4e00\u5b9a\u7684\u987a\u5e8f\u6267\u884c\uff0c\u5b8c\u6210\u67d0\u4e2a\u7279\u5b9a\u7684\u529f\u80fd\u3002
\u5f53\u6211\u4eec\u8c03\u7528\u4e00\u4e2a\u51fd\u6570\u65f6\uff0c\u6211\u4eec\u5e94\u5f53\u6309\u7167\u51fd\u6570\u7b7e\u540d\u4e2d\u7684\u8981\u6c42\u4f20\u5165\u53c2\u6570\uff0c\u5e76\u53ef\u4ee5\u83b7\u5f97\u5b83\u7684\u8fd4\u56de\u503c\u3002\u5728\u51fd\u6570\u7b7e\u540d\u7684\u8bed\u5883\u4e0b\uff0cvoid
\u8868\u793a\u7a7a\uff0c\u5373\u4e0d\u5b58\u5728\u3002\u4e0b\u9762\u7684\u8fd9\u4e2a\u51fd\u6570\u6ca1\u6709\u53c2\u6570\uff0c\u4e5f\u6ca1\u6709\u8fd4\u56de\u503c\u3002
void MyFunc(void);\n
\u56e0\u4e3a\u6211\u4eec\u6bd4\u8f83\u5173\u5fc3\u51fd\u6570\u8fd4\u56de\u503c\u7684\u7c7b\u578b\uff0c\u6709\u65f6\u4f1a\u628a\u51fd\u6570\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u79f0\u4e3a\u8fd9\u4e2a\u51fd\u6570\u7684\u201c\u7c7b\u578b\u201d\uff0c\u6bd4\u5982\u4f1a\u8bf4 MyFunc
\u8fd9\u4e2a\u51fd\u6570\u662f\u4e00\u4e2a void
\u51fd\u6570\u3002
\u5173\u4e8e void
Q\uff1avoid
\u5230\u5e95\u6709\u54ea\u4e9b\u542b\u4e49\uff1f
A: \u4e0b\u9762\u662f void
\u7684\u4e00\u822c\u7528\u6cd5
void
\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\uff0c\u8868\u793a\u51fd\u6570\u4e0d\u63a5\u53d7\u53c2\u6570\u3002 void
\u4f5c\u4e3a\u51fd\u6570\u8fd4\u56de\u503c\uff0c\u8868\u793a\u51fd\u6570\u4e0d\u8fd4\u56de\u503c\u3002 void*
\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
- \u8fd4\u56de\u503c\uff1a\u51fd\u6570\u8c03\u7528\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0c\u5b83\u7684\u503c\u5c31\u662f\u51fd\u6570\u7684\u8fd4\u56de\u503c\u3002
- \u526f\u4f5c\u7528\uff1a\u9664\u4e86\u8fd4\u56de\u503c\u4ee5\u5916\u7684\u529f\u80fd\u7edf\u79f0\u4e3a\u526f\u4f5c\u7528\u3002
\u4e00\u4e9b\u4f8b\u5b50\uff1a
\u51fd\u6570\u7b7e\u540d \u8fd4\u56de\u503c\u7684\u542b\u4e49 \u526f\u4f5c\u7528 int printf(const char *format, ...);
\u6253\u5370\u7684\u5b57\u7b26\u6570 \u6253\u5370\u5b57\u7b26\u4e32\u5230\u6807\u51c6\u8f93\u51fa int scanf(const char *format, ...);
\u8bfb\u53d6\u7684\u5b57\u7b26\u6570 \u4ece\u6807\u51c6\u8f93\u5165\u8bfb\u53d6\u5b57\u7b26\u4e32 int rand(void);
\u751f\u6210\u7684\u968f\u673a\u6570 \u65e0 void exit(int status);
\u65e0 \u9000\u51fa\u7a0b\u5e8f \u6bcf\u4e2a C \u8bed\u8a00\u7a0b\u5e8f\u90fd\u5fc5\u987b\u5305\u542b\u4e00\u4e2a main
\u51fd\u6570\uff0c\u5b83\u662f\u7a0b\u5e8f\u7684\u5165\u53e3\u3002main
\u7684\u51fd\u6570\u7b7e\u540d\u4e00\u822c\u662f\u8fd9\u6837\u7684\uff1a
int main(void);\nint main(int argc, char *argv[]); //\u4ee5\u540e\u5b66\u547d\u4ee4\u884c\u53c2\u6570\u5c31\u4f1a\u7528\u5230\u8fd9\u79cd\u5f62\u5f0f\n
main
\u7684\u8c03\u7528\u8005\u662f\u64cd\u4f5c\u7cfb\u7edf\u3002\u64cd\u4f5c\u7cfb\u7edf\u770b\u5230 main
\u7684\u7b7e\u540d\u4e2d\u8bf4\u8fd4\u56de\u503c\u4e3a int
\uff0c\u56e0\u6b64\u7cfb\u7edf\u4f1a\u7b49\u5f85 main
\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u3002\u8fd9\u4e2a\u6574\u6570\u4e00\u822c\u88ab\u7528\u4e8e\u544a\u77e5\u64cd\u4f5c\u7cfb\u7edf\u7a0b\u5e8f\u7684\u6267\u884c\u72b6\u6001\uff0c0
\u8868\u793a\u6b63\u5e38\u7ed3\u675f\uff0c\u5176\u4ed6\u503c\u53ef\u4ee5\u4f20\u9012\u5176\u4ed6\u4fe1\u606f\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48 main
\u7684\u672b\u5c3e\u5e94\u5f53\u5199 return 0
\u3002\u5982\u679c main
\u51fd\u6570\u4e2d\u6ca1\u6709 return
\u8bed\u53e5\uff0c\u6709\u4e9b\u7f16\u8bd1\u5668\u4f1a\u4e3a\u4f60\u8865\u5168\uff08\u5176\u4ed6\u51fd\u6570\u4e0d\u4f1a\uff09\u3002\u4f46\u8bf7\u8bb0\u5f97\u5199\u4e0a\uff0c\u8fd9\u662f\u4f60\u7684\u8d23\u4efb\u3002
\u6ca1\u6709\u8fd4\u56de\u503c\u7684\u51fd\u6570\u4e5f\u53ef\u4ee5\u4f7f\u7528 return
\u8bed\u53e5\uff0c\u6b64\u65f6\u5b83\u6ca1\u6709\u8fd4\u56de\u503c\u7684\u4f5c\u7528\uff0c\u800c\u662f\u7ed3\u675f\u5f53\u524d\u51fd\u6570\u7684\u6267\u884c\u5e76\u8fd4\u56de\u3002\u4f8b\u5b50\uff1a
void print_logarithm(double x)\n{\n if (x <= 0.0) {\n printf(\"Positive numbers only, please.\\n\");\n return;\n }\n printf(\"The log of x is %f\", log(x));\n}\n
\u5176\u4ed6\u5efa\u8bae \u6bcf\u4e2a\u51fd\u6570\u90fd\u5e94\u8be5\u8bbe\u8ba1\u5f97\u5c3d\u53ef\u80fd\u7b80\u5355\uff0c\u7b80\u5355\u7684\u51fd\u6570\u624d\u5bb9\u6613\u7ef4\u62a4\u3002\u5e94\u9075\u5faa\u4ee5\u4e0b\u539f\u5219\uff1a
-
\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
\u6269\u5c55\uff1a\u7f16\u8bd1\u548c\u89e3\u91ca \u7b80\u5355\u4e86\u89e3\u4e00\u4e0b\u5c31\u597d\u3002
\u5c06\u9ad8\u7ea7\u8bed\u8a00\u7f16\u5199\u7684\u6e90\u4ee3\u7801\u8f6c\u5316\u6210\u673a\u5668\u8bed\u8a00\u7684\u76ee\u6807\u7a0b\u5e8f\u7684\u8fc7\u7a0b\u7edf\u79f0\u4e3a\u7ffb\u8bd1\uff08Translation\uff09\u3002\u7ffb\u8bd1\u7684\u65b9\u5f0f\u6709\u4e24\u79cd\uff1a\u7f16\u8bd1\uff08Compile\uff09\u548c\u89e3\u91ca\uff08Interpret\uff09\u3002\u7f16\u8bd1\u5c06\u6574\u4e2a\u7a0b\u5e8f\u7ffb\u8bd1\u6210\u673a\u5668\u8bed\u8a00\uff0c\u89e3\u91ca\u5219\u662f\u8fb9\u7ffb\u8bd1\u8fb9\u6267\u884c\u3002
C \u8bed\u8a00\u662f\u5178\u578b\u7684\u7f16\u8bd1\u578b\u8bed\u8a00\uff0c\u6e90\u4ee3\u7801\u9700\u8981\u7ecf\u8fc7\u7f16\u8bd1\u540e\u624d\u80fd\u8fd0\u884c\uff0c\u800c\u7f16\u8bd1\u9636\u6bb5\u5e76\u4e0d\u4f1a\u6267\u884c\u7a0b\u5e8f\u3002Python \u5219\u662f\u5178\u578b\u7684\u89e3\u91ca\u578b\u8bed\u8a00\uff0c\u9010\u53e5\u6267\u884c\u6e90\u4ee3\u7801\uff0c\u4e0d\u9700\u8981\u4ea7\u751f\u53ef\u6267\u884c\u6587\u4ef6\u3002
\u8fd9\u4e9b\u63cf\u8ff0\u7684\u90fd\u662f\u4e00\u79cd\u8bed\u8a00\u7684\u5178\u578b\u7528\u6cd5\u3002\u4e8b\u5b9e\u4e0a C \u8bed\u8a00\u4e5f\u5f00\u53d1\u51fa\u4e86\u76f8\u5e94\u7684\u89e3\u91ca\u5668\uff0cPython \u4e5f\u5f00\u53d1\u51fa\u4e86\u76f8\u5e94\u7684\u7f16\u8bd1\u5668\u3002\u4e24\u79cd\u7ffb\u8bd1\u65b9\u5f0f\u5404\u6709\u4f18\u52a3\u3002
"},{"location":"programming_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\u6811 printf(\"%d:%d is %d minutes after 00:00\\n\", hour, minute, hour * 60 + minute);\n
\u7f16\u8bd1\u5668\u5728\u7ffb\u8bd1\u8fd9\u6761\u8bed\u53e5\u65f6\uff0c\u9996\u5148\u6839\u636e\u4e0a\u8ff0\u8bed\u6cd5\u89c4\u5219\u628a\u8fd9\u4e2a\u8bed\u53e5\u89e3\u6790\u6210\u4e0b\u56fe\u6240\u793a\u7684\u8bed\u6cd5\u6811\uff0c\u7136\u540e\u518d\u6839\u636e\u8bed\u6cd5\u6811\u751f\u6210\u76f8\u5e94\u7684\u6307\u4ee4\u3002\u8bed\u6cd5\u6811\u7684\u672b\u7aef\u7684\u662f\u4e00\u4e2a\u4e2aToken\uff0c\u6bcf\u4e00\u6b65\u5c55\u5f00\u5229\u7528\u4e00\u6761\u8bed\u6cd5\u89c4\u5219\u3002
\u7406\u89e3\u7ec4\u5408\uff08Composition\uff09\u89c4\u5219\u662f\u7406\u89e3\u8bed\u6cd5\u89c4\u5219\u7684\u5173\u952e\u6240\u5728\uff0c\u6b63\u56e0\u4e3a\u53ef\u4ee5\u6839\u636e\u8bed\u6cd5\u89c4\u5219\u4efb\u610f\u7ec4\u5408\uff0c\u6211\u4eec\u624d\u53ef\u4ee5\u7528\u7b80\u5355\u7684\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u8868\u8fbe\u5f0f\u3001\u8bed\u53e5\u642d\u5efa\u51fa\u4efb\u610f\u590d\u6742\u7684\u7a0b\u5e8f\uff0c\u4ee5\u540e\u6211\u4eec\u5b66\u4e60\u65b0\u7684\u8bed\u6cd5\u89c4\u5219\u65f6\u4f1a\u8fdb\u4e00\u6b65\u4f53\u4f1a\u5230\u8fd9\u4e00\u70b9\u3002\u4ece\u4e0a\u9762\u7684\u4f8b\u5b50\u53ef\u4ee5\u770b\u51fa\uff0c\u8868\u8fbe\u5f0f\u4e0d\u5b9c\u8fc7\u5ea6\u7ec4\u5408\uff0c\u5426\u5219\u4f1a\u7ed9\u9605\u8bfb\u548c\u8c03\u8bd5\u5e26\u6765\u56f0\u96be\u3002
\u8868\u8fbe\u5f0f\u4e0d\u5b9c\u8fc7\u5ea6\u7ec4\u5408 \u8fd9\u6d89\u53ca\u4ee3\u7801\u53ef\u8bfb\u6027\u95ee\u9898\u3002\u770b\u770b\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\uff1a
double distance(double x1, double y1, double x2, double y2)\n{\n return sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));\n}\n
\u8fd9\u6837\u5199\u5f88\u7b80\u6d01\uff0c\u4f46\u5982\u679c\u5199\u9519\u4e86\u5462\uff1f\u53ea\u77e5\u9053\u662f\u8fd9\u4e00\u957f\u4e32\u8868\u8fbe\u5f0f\u6709\u9519\uff0c\u6839\u672c\u4e0d\u77e5\u9053\u9519\u5728\u54ea\uff0c\u800c\u4e14\u6574\u4e2a\u51fd\u6570\u5c31\u4e00\u4e2a\u8bed\u53e5\uff0c\u63d2printf\u90fd\u6ca1\u5730\u65b9\u63d2\u3002\u6240\u4ee5\u7528\u4e34\u65f6\u53d8\u91cf\u6709\u5b83\u7684\u597d\u5904\uff0c\u4f7f\u7a0b\u5e8f\u66f4\u6e05\u6670\uff0c\u8c03\u8bd5\u66f4\u65b9\u4fbf\uff0c\u800c\u4e14\u6709\u65f6\u5019\u53ef\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\uff0c\u4f8b\u5982\u4e0a\u9762\u8fd9\u4e00\u884c\u8868\u8fbe\u5f0f\u8981\u628a(x2-x1)\u8ba1\u7b97\u4e24\u904d\uff0c\u5982\u679c\u7b97\u5b8c(x2-x1)\u628a\u7ed3\u679c\u5b58\u5728\u4e00\u4e2a\u4e34\u65f6\u53d8\u91cfdx\u91cc\uff0c\u5c31\u4e0d\u9700\u8981\u518d\u7b97\u7b2c\u4e8c\u904d\u4e86\uff08\u867d\u7136\u8fd9\u4e9b\u4f18\u5316\u73b0\u4ee3\u7f16\u8bd1\u5668\u90fd\u4f1a\u66ff\u4f60\u81ea\u52a8\u5b8c\u6210\uff09\u3002\u4e0b\u9762\u8fd9\u4e2a\u7248\u672c\u662f\u53ef\u8bfb\u6027\u9ad8\u7684\u4ee3\u7801\uff1a
double distance(double x1, double y1, double x2, double y2)\n{\n double dx = x2 - x1;\n double dy = y2 - y1;\n double dsquared = dx * dx + dy * dy;\n double result = sqrt(dsquared);\n\n return result;\n}\n
\u7801\u98ce\u4e0d\u662f\u6b7b\u7684\uff0c\u8bf7\u540c\u5b66\u4eec\u89c6\u60c5\u51b5\u5207\u6362\u7801\u98ce\u3002
"},{"location":"programming_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
- \u8003\u8bd5\u662f\u5168\u82f1\u6587\u3002\u5982\u679c\u5e73\u5e38\u4e0d\u592a\u770b\u82f1\u6587\u6587\u6863/\u6ca1\u600e\u4e48\u5b66/\u82f1\u8bed\u5f88\u5dee\u7684\u540c\u5b66\uff0c\u81f3\u5c11\u4f60\u8003\u524d\u505a\u5386\u5e74\u5377\u7684\u65f6\u5019\u8981\u628a\u751f\u8bcd\u5168\u90e8\u6284\u4e0b\u6765\u8bb0\u4e00\u904d\u3002
- \u4e00\u5b9a\u4e00\u5b9a\u4e00\u5b9a\u8981\u505a\u5386\u5e74\u5377\u3002\u4e0d\u8981\u4ee5\u4e3a\u81ea\u5df1\u4f1a\u5199\u70b9\u4ee3\u7801\u5c31\u80fd\u5e94\u4ed8\u8003\u8bd5\u4e86\uff0c\u5176\u5b9e\u8003\u8bd5\u548c\u4f60\u5199\u4ee3\u7801\u6c34\u5e73\u5e76\u4e0d\u5448\u6b63\u76f8\u5173\u3002\u8003\u8bd5\u7684\u9898\u76ee\u90fd\u662f\u5f88\u7ec6\u8282\u7684\uff0c\u5f88\u591a\u90fd\u662f\u4f60\u5e73\u5e38\u4e0d\u4f1a\u6ce8\u610f\u5230\u7684\uff0c\u6240\u4ee5\u4e00\u5b9a\u8981\u505a\u5386\u5e74\u5377\uff0c\u505a\u5b8c\u4e86\u8fd8\u8981\u770b\u770b\u7b54\u6848\uff0c\u770b\u770b\u81ea\u5df1\u54ea\u91cc\u505a\u9519\u4e86\uff0c\u54ea\u91cc\u6ca1\u6ce8\u610f\u5230\u3002\u8fd9\u91cc\u5c55\u793a\u4e00\u4e2a\u53bb\u5e74 C \u5c0f\u8003\u8bd5\u5e72\u788e\u4e00\u7247\u4eba\u7684\u9009\u62e9\u9898\uff1a
\u5e72\u788e\u4e00\u7247\u4eba\u7684\u9009\u62e9\u9898 Suppose T
is a type name and t
is a variable of type T
. Which of the following is NOT a valid expression?
A. sizeof(T)
B. sizeof(t)
C. sizeof T
D. sizeof t
\u7b54\u6848 \u7b54\u6848\u662f C\uff0c\u4e0d\u77e5\u9053\u4f60\u731c\u5bf9\u4e86\u5417\uff1f
\u5927\u5bb6\u4e00\u822c\u5199\u4ee3\u7801 sizeof
\u540e\u9762\u90fd\u4f1a\u52a0\u62ec\u53f7\u7684\u5bf9\u5427\uff0c\u4f46\u4f60\u77e5\u9053\u4e3a\u4ec0\u4e48\u5417\uff1f\u60f3\u8981\u77e5\u9053\u4e3a\u4ec0\u4e48\uff0c\u9700\u8981\u56de\u987e\u524d\u9762\u5b66\u4e60\u7684\u8bed\u6cd5\u77e5\u8bc6\u3002
sizeof
\u662f\u4e00\u4e2a\u8fd0\u7b97\u7b26\uff0c\u5b83\u6709\u4e24\u79cd\u4f7f\u7528\u65b9\u5f0f\uff1a
sizeof(\u7c7b\u578b)\nsizeof \u8868\u8fbe\u5f0f\n
\u6211\u4eec\u77e5\u9053\uff0ct
\u662f\u8868\u8fbe\u5f0f\uff0c(t)
\u4e5f\u662f\u8868\u8fbe\u5f0f\u3002sizeof(T)
\u7684\u4f7f\u7528\u7b26\u5408\u89c4\u8303\u3002\u56e0\u6b64 A\u3001B\u3001D \u90fd\u662f\u6b63\u786e\u7684\u3002\u4e3a\u4ec0\u4e48\u4e0d\u89c4\u5b9a sizeof \u7c7b\u578b
\u7684\u7528\u6cd5\u5462\uff1f\u56e0\u4e3a\u8fd9\u53ef\u80fd\u5f15\u8d77\u6b67\u4e49\uff0c\u6709\u4e9b\u7c7b\u578b\u540d\u5c31\u643a\u5e26\u7a7a\u683c\uff0c\u6bd4\u5982\uff1ashort int
\u3001struct node
\u7b49\u7b49\u3002\u4e86\u89e3\u4e86\u8fd9\u4e9b\u77e5\u8bc6\uff0c\u4f60\u80fd\u8bf4\u8bf4\u4e0b\u9762\u7684\u8bed\u53e5\u662f\u5426\u5408\u6cd5\u5417\uff1f\u5982\u679c\u5408\u6cd5\uff0c\u4f60\u80fd\u89e3\u91ca\u5b83\u7684\u542b\u4e49\u5417\uff1f\u5982\u679c\u4e0d\u89c4\u5b9a\u7c7b\u578b\u5fc5\u987b\u5e26\u62ec\u53f7\uff0c\u53ef\u80fd\u4f1a\u4ea7\u751f\u54ea\u4e9b\u4e8c\u4e49\u6027\uff1f
sizeof int***p\nsizeof(int)*p\nsizeof int * + 1\n
\u5982\u679c\u4f60\u60f3\u7684\u8bdd\uff0c\u53ef\u4ee5\u518d\u6765\u4e24\u9053\uff1a
C \u5927 16 \u5e74\u9009\u62e9\u9898 In the following notations, _____ can express a character constant( \u5b57\u7b26\u5e38\u91cf ) correctly.
A. '\\x100'
B. 125
C. '\\08'
D. '\\'
\u7b54\u6848 B
"},{"location":"programming_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
- \u9884\u5904\u7406\uff1a\u7531 C \u9884\u5904\u7406\u5668\uff08C Preprocessor\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u6e90\u4ee3\u7801\u4e2d\u7684\u5b8f\u5b9a\u4e49\u5c55\u5f00\uff0c\u5c06\u5934\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u63d2\u5165\u5230\u6e90\u4ee3\u7801\u4e2d\uff0c\u5220\u9664\u6ce8\u91ca\u7b49\u3002\u9884\u5904\u7406\u540e\u7684\u4ee3\u7801\u6587\u4ef6\u4ee5
.i
\u4e3a\u540e\u7f00\u3002 - \u7f16\u8bd1\uff1a\u7531 C \u7f16\u8bd1\u5668\uff08C Compiler\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u9884\u5904\u7406\u540e\u7684\u6587\u4ef6\u7ffb\u8bd1\u6210\u6c47\u7f16\u8bed\u8a00\u3002\u7f16\u8bd1\u540e\u5f97\u5230\u7684\u6c47\u7f16\u4ee3\u7801\u6587\u4ef6\u4ee5
.s
\u4e3a\u540e\u7f00\u3002 - \u6c47\u7f16\uff1a\u7531\u6c47\u7f16\u5668\uff08Assembler\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u6c47\u7f16\u4ee3\u7801\u7ffb\u8bd1\u6210\u673a\u5668\u8bed\u8a00\u3002\u6c47\u7f16\u540e\u5f97\u5230\u7684\u673a\u5668\u4ee3\u7801\u6587\u4ef6\u4ee5
.o
\u4e3a\u540e\u7f00\u3002 - \u94fe\u63a5\uff1a\u7531\u94fe\u63a5\u5668\uff08Linker\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u591a\u4e2a\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u94fe\u63a5\u540e\u5f97\u5230\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4ee5
.exe
\u4e3a\u540e\u7f00\u3002
"},{"location":"programming_lecture/lecture1/lecture1/#gcc","title":"\u89e3\u8bfb gcc
\u663e\u793a\u7684\u8be6\u7ec6\u4fe1\u606f","text":"\u4e0b\u9762\u8fd9\u4e9b\u6587\u672c\u662f gcc -v -o prog main.c sum.c
\u547d\u4ee4\u7684\u8f93\u51fa\u7ed3\u679c\u3002
gcc \u7684\u8f93\u51fa\u4fe1\u606f \u70b9\u51fb\u6587\u672c\u4e2d\u5e26\u5706\u5708\u7684 +
\u53f7\u53ef\u4ee5\u5c55\u5f00\u8be6\u7ec6\u4fe1\u606f\uff0c\u9ad8\u4eae\u7684\u884c\u662f\u8fd0\u884c\u67d0\u4e2a\u7f16\u8bd1\u5de5\u5177\u7684\u5177\u4f53\u547d\u4ee4\u3002
<!--(1)!-->Using built-in specs.\nCOLLECT_GCC=gcc\nCOLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper\nOFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa\nOFFLOAD_TARGET_DEFAULT=1\nTarget: x86_64-linux-gnu\nConfigured with: ../src/configure -v --with-pkgversion='Ubuntu 12.3.0-1ubuntu1~23.04' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-12-DAPbBt/gcc-12-12.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-DAPbBt/gcc-12-12.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu\nThread model: posix\nSupported LTO compression algorithms: zlib zstd\ngcc version 12.3.0 (Ubuntu 12.3.0-1ubuntu1~23.04) \nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n<!--(2)!--> /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -quiet -v -imultiarch x86_64-linux-gnu main.c -quiet -dumpdir prog- -dumpbase main.c -dumpbase-ext .c -mtune=generic -march=x86-64 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/ccClT5M4.s\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nignoring nonexistent directory \"/usr/local/include/x86_64-linux-gnu\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/include-fixed\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include\"\n<!--(3)!-->#include \"...\" search starts here:\n#include <...> search starts here:\n /usr/lib/gcc/x86_64-linux-gnu/12/include\n /usr/local/include\n /usr/include/x86_64-linux-gnu\n /usr/include\nEnd of search list.\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nCompiler executable checksum: d9353c3f0a32d3e91a16ba312e2a9024\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n<!--(4)!--> as -v --64 -o /tmp/ccEgqpgY.o /tmp/ccClT5M4.s\nGNU assembler version 2.40 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.40\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n<!--(5)!--> /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -quiet -v -imultiarch x86_64-linux-gnu sum.c -quiet -dumpdir prog- -dumpbase sum.c -dumpbase-ext .c -mtune=generic -march=x86-64 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/ccClT5M4.s\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nignoring nonexistent directory \"/usr/local/include/x86_64-linux-gnu\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/include-fixed\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include\"\n#include \"...\" search starts here:\n#include <...> search starts here:\n /usr/lib/gcc/x86_64-linux-gnu/12/include\n /usr/local/include\n /usr/include/x86_64-linux-gnu\n /usr/include\nEnd of search list.\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nCompiler executable checksum: d9353c3f0a32d3e91a16ba312e2a9024\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n as -v --64 -o /tmp/ccxMA26W.o /tmp/ccClT5M4.s\nGNU assembler version 2.40 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.40\nCOMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/\nLIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../:/lib/:/usr/lib/\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog.'\n<!--(6)!--> /usr/lib/gcc/x86_64-linux-gnu/12/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/12/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper -plugin-opt=-fresolution=/tmp/ccyzC2ZB.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o prog /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/12/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/12 -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/12/../../.. /tmp/ccEgqpgY.o /tmp/ccxMA26W.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/12/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crtn.o\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog.'\n
- \u6700\u5f00\u5934\u662f
gcc
\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u5305\u62ec\u5b83\u8fd0\u884c\u7684\u5e73\u53f0\u3001\u914d\u7f6e\u7684\u9009\u9879\u7b49\u3002 - \u8fd9\u91cc\u8c03\u7528\u4e86
cc1
\u5b8c\u6210\u9884\u5904\u7406\u548c\u7f16\u8bd1\u9636\u6bb5\uff0c\u5c06\u6e90\u4ee3\u7801\u6587\u4ef6 main.c
\u7f16\u8bd1\u6210\u4e86 ASCII \u7f16\u7801\u7684\u6c47\u7f16\u6587\u4ef6 /tmp/ccCWi0p2.s
\u3002 - \u8fd9\u91cc\u663e\u793a\u4e86\u5934\u6587\u4ef6\u641c\u7d22\u8def\u5f84\uff0c\u5982\u679c\u4f60\u7f16\u8bd1\u65f6\u62a5\u9519\u7f3a\u5c11\u5934\u6587\u4ef6\uff0c\u53ef\u4ee5\u68c0\u67e5\u4e00\u4e0b\u8fd9\u91cc\u6709\u6ca1\u6709\u5305\u542b\u5bf9\u5e94\u7684\u8def\u5f84\u3002
- \u8fd9\u91cc\u8c03\u7528\u4e86
as
\u5b8c\u6210\u6c47\u7f16\u9636\u6bb5\uff0c\u5c06\u6c47\u7f16\u6587\u4ef6 /tmp/ccCWi0p2.s
\u7ffb\u8bd1\u6210\u4e86\u673a\u5668\u8bed\u8a00\u6587\u4ef6 /tmp/ccAnKDEo.o
\u3002 - \u63a5\u4e0b\u6765\u53c8\u5bf9
sum.c
\u91cd\u590d\u9884\u5904\u7406\u3001\u7f16\u8bd1\u548c\u6c47\u7f16\u7684\u8fc7\u7a0b\uff0c\u5f97\u5230\u4e86 /tmp/ccgMFTqK.o
\u3002 - \u6700\u540e\u8c03\u7528
collect2
\uff08\u8fd9\u662f ld
\u7684\u5305\u88c5\u7a0b\u5e8f\uff09\u5b8c\u6210\u94fe\u63a5\u9636\u6bb5\uff0c\u5c06\u4e24\u4e2a\u6e90\u4ee3\u7801\u751f\u6210\u7684\u76ee\u6807\u6587\u4ef6 /tmp/ccAnKDEo.o
\u548c /tmp/ccgMFTqK.o
\u4e0e\u5176\u4ed6\u5f88\u591a\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u6210\u4e86\u53ef\u6267\u884c\u6587\u4ef6 prog
\u3002\u8fd9\u5c31\u662f\u4f60\u80fd\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u7684\u7a0b\u5e8f\u3002
\u4e3a\u4ec0\u4e48\u6ca1\u6709\u770b\u89c1\u9884\u5904\u7406\u5668 cpp
\u7684\u6267\u884c\u5462\uff1f \u67d0\u4e9b\u7248\u672c\u7684 gcc
\u4f1a\u5c06\u9884\u5904\u7406\u5668 cpp
\u548c\u7f16\u8bd1\u5668 gcc
\u5408\u5e76\u6210\u4e00\u4e2a\u6307\u4ee4\uff0c\u6bd4\u5982\u4e0a\u9762\u7684 cc1
\uff0c\u8fd9\u6837\u5c31\u4e0d\u7528\u5355\u72ec\u8c03\u7528 cpp
\u4e86\u3002
\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u8be6\u89e3\u5176\u4e2d\u7684\u6bcf\u4e00\u4e2a\u9636\u6bb5\u4ee5\u53ca\u53ef\u80fd\u4f1a\u53d1\u751f\u7684\u95ee\u9898\u3002
"},{"location":"programming_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
- \u7528\u53cc\u5f15\u53f7
#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 - \u7528\u5c16\u62ec\u53f7
#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
- \u9519\u8bef\uff08Error\uff09\uff1a\u7f16\u8bd1\u5668\u65e0\u6cd5\u7ee7\u7eed\u8fdb\u884c\u7f16\u8bd1\u3002\u6bd4\u5982\uff1a\u63d0\u4f9b\u7684\u53c2\u6570\u5217\u8868\u4e0d\u5339\u914d\u3001\u4f7f\u7528\u4e86\u672a\u5b9a\u4e49\u7684\u53d8\u91cf\u3001\u51fd\u6570\u7b49\u3002
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
- \u8b66\u544a\uff08Warning\uff09\uff1a\u8fdd\u53cd\u4e86\u8bed\u6cd5\uff0c\u4f46\u80fd\u591f\u7ee7\u7eed\u7f16\u8bd1\uff0c\u7f16\u8bd1\u51fa\u6765\u7684\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u679c\u5f88\u53ef\u80fd\u4e0e\u4f60\u60f3\u8c61\u7684\u4e0d\u4e00\u6837\u3002\u6bd4\u5982\uff1a\u8f6c\u4e49\u5b57\u7b26\u4e0e\u6570\u636e\u7c7b\u578b\u4e0d\u5339\u914d\u3001\u53d1\u751f\u4e86\u9690\u5f0f\u8f6c\u6362\u7b49\u3002
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\u63a5 hello.o
\u4e2d\u5305\u542b\u4e86 hello.c
\u4e2d\u7684 C \u8bed\u8a00\u4ee3\u7801\u7ffb\u8bd1\u6210\u7684\u4e8c\u8fdb\u5236\u4ee3\u7801\u4ee5\u53ca\u4e00\u4e9b\u6570\u636e\uff0c\u6bd4\u5982\u5b57\u7b26\u4e32 Hello, world.\\n
\u3002\u5982\u679c\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00 hello.o
\uff0c\u4f60\u4f1a\u770b\u89c1\u4e00\u5806\u4e71\u7801\uff0c\u5176\u4e2d\u5939\u6742\u7740\u4e00\u4e9b\u5b57\u7b26\u3002\u56e0\u4e3a\u5b57\u7b26\u5728\u6e90\u6587\u4ef6\u548c\u5185\u5b58\u4e2d\u90fd\u662f\u7528 ASCII \u7f16\u7801\u7684\uff0c\u6240\u4ee5 ASCII \u5b57\u7b26\u4ecd\u80fd\u88ab\u6587\u672c\u7f16\u8f91\u5668\u8bc6\u522b\uff0c\u4f46\u5176\u4ed6\u7684\u673a\u5668\u6307\u4ee4\u548c\u6570\u636e\u53ea\u4f1a\u88ab\u89e3\u8bfb\u4e3a\u4e71\u7801\u3002
\u5982\u679c\u8fd0\u884c ./hello.o
\uff0c\u7ec8\u7aef\u4f1a\u544a\u8bc9\u4f60\u8fd9\u4e2a\u6587\u4ef6\u4e0d\u80fd\u88ab\u64cd\u4f5c\u7cfb\u7edf\u6267\u884c\u3002
exec: Failed to execute process: './hello.o' the file could not be run by the operating system.\n
\u5b83\u8fd8\u7f3a\u5c11\u4e00\u4e9b\u4e1c\u897f\uff0c\u5982\uff1a
- \u542f\u52a8\u4ee3\u7801\uff1a\u542f\u52a8\u7a0b\u5e8f\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u5c06\u63a7\u5236\u6743\u4ea4\u7ed9\u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\uff0c\u4f46\u8fd9\u4e2a\u5165\u53e3\u70b9\u4e0d\u662f
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\u3002
\u4e00\u4e2a\u4e0d\u5e26\u542f\u52a8\u4ee3\u7801\u7684\u4f8b\u5b50 Linux \u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u4e00\u822c\u662f _start
\uff0c\u5b83\u5b8c\u6210\u4e00\u4e9b\u5185\u5b58\u521d\u59cb\u5316\u7684\u5de5\u4f5c\uff0c\u7136\u540e\u8df3\u8f6c\u5230 main
\u51fd\u6570\u3002\u6211\u4eec\u5728\u94fe\u63a5\u9636\u6bb5\u4e0d\u5e26\u4e0a\u542b\u6709\u542f\u52a8\u4ee3\u7801\u7684\u76ee\u6807\u6587\u4ef6\uff0c\u770b\u770b\u5728\u7f3a\u5c11 _start
\u7684\u60c5\u51b5\u4e0b\u4f1a\u53d1\u751f\u4ec0\u4e48\u3002
$ ld hello.o -o hello -lc --dynamic-linker /lib64/ld-linux-x86-64.so.2\nld: warning: cannot find entry symbol _start; defaulting to 0000000000401030\n$ ./hello\nHello World.\nfish: Job 1, './hello' terminated by signal SIGSEGV (Address boundary error)\n
\u8fd9\u4e2a\u7a0b\u5e8f\u6e90\u4ee3\u7801\u6b63\u5e38\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u6bb5\u9519\u8bef\u5462\uff1f
\u5728\u94fe\u63a5\u9636\u6bb5\uff0cld
\u7684\u8f93\u51fa\u8868\u660e\u627e\u4e0d\u5230\u5165\u53e3\u70b9 _start
\uff0c\u56e0\u6b64\u628a\u5165\u53e3\u70b9\u9ed8\u8ba4\u653e\u5728\u4e86 0000000000401030
\u5904\u7684\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u662f main
\u51fd\u6570\u3002\u56e0\u6b64\uff0c\u5f53\u7a0b\u5e8f\u6267\u884c\u5230 main
\u51fd\u6570\u7684\u6700\u540e\u4e00\u6761\u6307\u4ee4\u65f6\uff0c\u4f1a\u7ee7\u7eed\u5f80\u4e0b\u6267\u884c\uff0c\u4f46\u6b64\u65f6\u6808\u5df2\u7ecf\u88ab\u6e05\u7a7a\uff0c\u56e0\u6b64\u4f1a\u53d1\u751f\u6bb5\u9519\u8bef\u3002
\u4f7f\u7528 gdb
\u67e5\u770b\u9519\u8bef\u4f4d\u7f6e\uff1a
Program received signal SIGSEGV, Segmentation fault.\n0x0000000000000001 in ?? ()\n
\u8bc1\u5b9e\u4e86\u4e0a\u9762\u7684\u5206\u6790\u3002
crt
\u662f C Runtime \u7684\u7f29\u5199\u3002C \u8bed\u8a00\u76f8\u5173\u542f\u52a8\u4ee3\u7801\u5728\u8fd9\u4e9b\u76ee\u6807\u6587\u4ef6\u4e2d\uff1a
crt1.o
\uff1a\u8d1f\u8d23\u542f\u52a8\uff0c\u5305\u542b _start
\u548c\u672a\u5b9a\u4e49\u7684 __libc_start_main
\u548c main
\u3002 crti.o
\uff1a\u521d\u59cb\u5316 crtbegin.o
\uff1a\u6784\u9020\uff08C++\u4f9d\u8d56\uff09 crtend.o
\uff1a\u6790\u6784\uff08C++\u4f9d\u8d56\uff09 crtn.o
\uff1a\u7ed3\u675f
Linux \u5e73\u53f0\u4e0b\uff0c\u5b83\u4eec\u7684\u94fe\u63a5\u987a\u5e8f\u4e3a\uff1a
ld crt1.o crti.o [user_objects] [system_libraries] crtn.o\n
- \u5e93\u51fd\u6570\uff1a\u51e0\u4e4e\u6240\u6709 C \u7a0b\u5e8f\u90fd\u4f1a\u7528\u5230\u6807\u51c6\u5e93\u4e2d\u7684\u51fd\u6570\uff0c\u6bd4\u5982
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
\u52a8\u6001\u94fe\u63a5 \u5f53\u4f60\u7684\u7a0b\u5e8f\u4e0e\u52a8\u6001\u5e93\u94fe\u63a5\u65f6\uff0c\u7a0b\u5e8f\u4e2d\u521b\u5efa\u4e86\u4e00\u4e2a\u8868\u3002\u5728\u7a0b\u5e8f\u8fd0\u884c\u524d\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5c06\u9700\u8981\u7684\u5916\u90e8\u51fd\u6570\u7684\u673a\u5668\u7801\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u8fd9\u5c31\u662f\u52a8\u6001\u94fe\u63a5\u8fc7\u7a0b\u3002
\u4e0e\u9759\u6001\u94fe\u63a5\u76f8\u6bd4\uff0c\u52a8\u6001\u94fe\u63a5\u4f7f\u7a0b\u5e8f\u6587\u4ef6\u66f4\u5c0f\uff0c\u56e0\u4e3a\u4e00\u4e2a\u52a8\u6001\u5e93\u53ef\u4ee5\u88ab\u591a\u4e2a\u7a0b\u5e8f\u5171\u4eab\uff0c\u8282\u7701\u78c1\u76d8\u7a7a\u95f4\u3002\u90e8\u5206\u64cd\u4f5c\u7cfb\u7edf\u8fd8\u5141\u8bb8\u52a8\u6001\u5e93\u4ee3\u7801\u5728\u5185\u5b58\u4e2d\u7684\u5171\u4eab\uff0c\u8fd8\u80fd\u591f\u8282\u7701\u5185\u5b58\u3002\u52a8\u6001\u5e93\u5347\u7ea7\u65f6\uff0c\u4e5f\u4e0d\u9700\u8981\u91cd\u5199\u7f16\u8bd1\u4f60\u7684\u7a0b\u5e8f\u3002
\u5728 Linux \u7cfb\u7edf\u4e0a\uff0c\u52a8\u6001\u5e93\u7684\u6587\u4ef6\u540d\u4ee5 .so
\u7ed3\u5c3e\uff0c\u6bd4\u5982 libm.so
\u3002\u5728 Window \u4e0a\uff0c\u52a8\u6001\u5e93\u7684\u6587\u4ef6\u540d\u4ee5 .dll
\u7ed3\u5c3e\uff0c\u6bd4\u5982 libm.dll
\u3002
\u52a8\u6001\u94fe\u63a5\u5177\u6709\u4e0a\u9762\u63cf\u8ff0\u7684\u4f18\u70b9\uff0c\u56e0\u6b64 GCC \u5c3d\u53ef\u80fd\u5730\u6267\u884c\u52a8\u6001\u94fe\u63a5\u3002
\u94fe\u63a5\u76f8\u5173\u7684\u95ee\u9898\u53ef\u80fd\u51fa\u73b0\u5728\u94fe\u63a5\u65f6\uff08\u9759\u6001\u94fe\u63a5\uff09\u3001\u7a0b\u5e8f\u8fd0\u884c\u524d\u548c\u8fd0\u884c\u4e2d\uff08\u52a8\u6001\u94fe\u63a5\uff09\u3002\u4e0b\u9762\u65f6\u4e00\u4e9b\u5e38\u89c1\u7684\u95ee\u9898\u3002
\u672a\u5b9a\u4e49\u7684\u5f15\u7528
\u5f53\u540c\u5b66\u4eec\u5f00\u59cb\u4f7f\u7528\u5176\u4ed6\u5e93\u6784\u5efa\u5927\u578b\u9879\u76ee\u65f6\uff0c\u8fd9\u6216\u8bb8\u4f1a\u6210\u4e3a\u6700\u5934\u75bc\u7684\u95ee\u9898\u3002\u9996\u5148\u5e94\u5f53\u9605\u8bfb\u5e93\u7684\u4f7f\u7528\u8bf4\u660e\uff0c\u63a5\u4e0b\u6765\u641c\u7d22\u7f3a\u5931\u7684\u7b26\u53f7\u53ef\u80fd\u4f4d\u4e8e\u54ea\u4e9b\u5e93\u6587\u4ef6\u4e2d\u3002
\u7f3a\u5931 .dll
\u5e38\u7528 Windows \u7684\u540c\u5b66\u591a\u591a\u5c11\u5c11\u89c1\u8fc7\u8fd9\u4e2a\u62a5\u9519\uff0c\u53ef\u4ee5\u53bb\u7f51\u4e0a\u641c\u7d22\u76f8\u5e94 .dll
\u6587\u4ef6\u653e\u7f6e\u5230\u6b63\u786e\u7684\u76ee\u5f55\u3002
\u7f3a\u5931 .so
Linux \u4e0a\u7684\u52a8\u6001\u5e93\u4e00\u822c\u901a\u8fc7 apt
\u7ba1\u7406\uff0c\u641c\u7d22\u76f8\u5e94\u7684\u5305\u5e76\u5b89\u88c5\u5373\u53ef\u3002
\u4e0b\u9762\u8fd9\u884c\u547d\u4ee4\u5728\u6211\u7684\u7cfb\u7edf\u4e0a\u5b8c\u6210\u4e86 hello
\u7a0b\u5e8f\u7684\u6b63\u786e\u94fe\u63a5\uff0c\u4e0d\u4e00\u5b9a\u80fd\u5728\u4f60\u7684\u7cfb\u7edf\u4e0a\u8fd0\u884c\u3002\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u67e5\u627e\u5e93\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u8ba9\u5b83\u6210\u529f\u8fd0\u884c\u3002
ld --output hello --dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crti.o -lc hello.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crtn.o\n
"},{"location":"programming_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
- \u5982\u679c\u662f\u76ee\u6807\u6587\u4ef6\uff0c\u94fe\u63a5\u5668\u5c06\u8bb0\u5f55\u5176\u4e2d\u7684\u7b26\u53f7\u5b9a\u4e49\u548c\u5f15\u7528\u3002
- \u5982\u679c\u662f\u5e93\u6587\u4ef6\uff0c\u94fe\u63a5\u5668\u5c06\u5c1d\u8bd5\u5339\u914d\u524d\u9762\u8bb0\u5f55\u7684\u672a\u89e3\u6790\u7684\u7b26\u53f7\u5b9a\u4e49\u548c\u5f15\u7528\u3002\u89e3\u6790\u5b8c\u6210\u540e\uff0c\u8be5\u5e93\u4e2d\u6ca1\u6709\u88ab\u4f7f\u7528\u7684\u7b26\u53f7\u5c06\u88ab\u4e22\u5f03\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
- C \u8bed\u8a00\u57fa\u7840\u77e5\u8bc6\u4e0d\u7262\uff1a\u7f16\u8bd1\u90fd\u8fc7\u4e0d\u4e86\uff0c\u4e0d\u5f00
-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\u3002 - \u6ca1\u6709\u4e8b\u5148\u60f3\u597d\u7a0b\u5e8f\u7684\u903b\u8f91\uff1a\u5efa\u8bae\u5728\u52a8\u624b\u5199\u4ee3\u7801\u524d\uff0c\u5148\u60f3\u597d\u81ea\u5df1\u7a0b\u5e8f\u7684\u903b\u8f91\u548c\u6b65\u9aa4\u3002\u8fb9\u5199\u8fb9\u60f3\u7684\u540e\u679c\u5927\u6982\u7387\u662f\u4ee3\u7801\u5199\u5f97\u4e00\u5768\uff08\u9664\u975e\u4f60\u975e\u5e38\u719f\u7ec3\uff09\u3002
- \u4e0d\u4e86\u89e3\u57fa\u672c\u7684\u8c03\u8bd5\u6280\u672f\uff0c\u4e0d\u4f1a\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\uff1a\u672c\u8282\u8bfe\u6211\u4eec\u5c06\u4e3a\u5927\u5bb6\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002
"},{"location":"programming_lecture/lecture1/lecture1/#fprintfstderr","title":"fprintf(stderr)
\u662f\u4f60\u6700\u597d\u7684\u670b\u53cb","text":"\u867d\u7136\u63a5\u4e0b\u6765\u8981\u4ecb\u7ecd\u7684 gdb
\u529f\u80fd\u5f3a\u5927\uff0c\u4f46\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u7b80\u5355\u5730\u6253\u5370\u53d8\u91cf\u5c31\u80fd\u5e2e\u4f60\u5b9a\u4f4d\u95ee\u9898\u6240\u5728\u3002
\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528 fprintf(stderr, ...)
\u6253\u5370\u8c03\u8bd5\u4fe1\u606f\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5b9a\u4f4d\u5230\u7a0b\u5e8f\u4e2d\u7684\u9519\u8bef\u3002fprintf
\u5411\u6307\u5b9a\u7684\u6d41\u8f93\u51fa\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0cstderr
\u662f\u6807\u51c6\u9519\u8bef\u6d41\uff0c\u5b83\u4e0d\u4f1a\u88ab\u7f13\u51b2\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u5728\u7a0b\u5e8f\u5d29\u6e83\u65f6\u770b\u5230\u6700\u540e\u7684\u8c03\u8bd5\u4fe1\u606f\uff08\u8fd9\u4e9b\u8f93\u5165\u8f93\u51fa\u7684\u77e5\u8bc6\u4f1a\u5728\u540e\u9762\u7684\u8bfe\u7a0b\u4e2d\u5b66\u5230\uff09\u3002
\u4ee5\u4e00\u4e2a\u5f02\u5e38\u7ec8\u6b62\u7684\u7a0b\u5e8f\u4e3a\u4f8b\uff1a
#include <stdio.h>\n#include <stdlib.h>\n\nint main(void)\n{\n printf(\"printf \");\n fprintf(stderr, \"fprintf \");\n abort();\n}\n
\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a
$ ./debug\nfprintf fish: Job 1, './debug' terminated by signal SIGABRT (Abort)\n
\u53ef\u4ee5\u770b\u5230\u53ea\u6709 fprintf
\u51fd\u6570\u7684\u8f93\u51fa\u3002\u5982\u679c\u5728 printf
\u8bed\u53e5\u540e\u9762\u52a0\u4e0a\u6362\u884c\u7b26\uff0c\u4f60\u4f1a\u53d1\u73b0 printf
\u7684\u8f93\u51fa\u4e5f\u88ab\u6253\u5370\u51fa\u6765\u4e86\u3002\u56e0\u4e3a\u5f53\u8f93\u51fa\u7f13\u51b2\u533a\u9047\u5230 \\n
\u65f6\u4e5f\u4f1a\u7acb\u5373\u8f93\u51fa\u3002
\u6b64\u5916\uff0c\u5c06\u9519\u8bef\u4fe1\u606f\u5bfc\u5411\u6807\u51c6\u9519\u8bef\u6d41\u8fd8\u6709\u53e6\u4e00\u4e2a\u597d\u5904\uff0c\u5c31\u662f\u4f60\u53ef\u4ee5\u5206\u522b\u6536\u96c6\u8c03\u8bd5\u4fe1\u606f\u548c\u6b63\u5e38\u8f93\u51fa\u3002\u6bd4\u5982\u4f60\u53ef\u4ee5\u5c06\u8c03\u8bd5\u4fe1\u606f\u91cd\u5b9a\u5411\u5230\u4e00\u4e2a\u6587\u4ef6\uff0c\u800c\u5c06\u6b63\u5e38\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u53e6\u4e00\u4e2a\u6587\u4ef6\u3002
$ ./debug 2> debug.log 1> output.log\n
"},{"location":"programming_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
gets.cchar *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\u3002 r
\u6216 run [args]
\uff1a\u8fd0\u884c\u7a0b\u5e8f\u3002[args]
\u662f\u53ef\u9009\u7684\u547d\u4ee4\u884c\u53c2\u6570\u3002 b
\u6216 break <line>
\uff1a\u5728\u6307\u5b9a\u884c\u8bbe\u7f6e\u65ad\u70b9\u3002 b
\u6216 break <function>
\uff1a\u5728\u6307\u5b9a\u51fd\u6570\u8bbe\u7f6e\u65ad\u70b9\u3002 b
\u6216 break *<address>
\uff1a\u5728\u6307\u5b9a\u5730\u5740\u8bbe\u7f6e\u65ad\u70b9\u3002 info breakpoints
\uff1a\u67e5\u770b\u65ad\u70b9\u4fe1\u606f\u3002 delete breakpoints <number>
\uff1a\u5220\u9664\u6307\u5b9a\u7f16\u53f7\u7684\u65ad\u70b9\u3002 continue
\uff1a\u7ee7\u7eed\u6267\u884c\u7a0b\u5e8f\u3002 next
\uff1a\u6267\u884c\u4e0b\u4e00\u884c\u3002 step
\uff1a\u6267\u884c\u4e0b\u4e00\u884c\uff0c\u5982\u679c\u9047\u5230\u51fd\u6570\u8c03\u7528\uff0c\u8fdb\u5165\u51fd\u6570\u5185\u90e8\u3002 print <variable>
\uff1a\u6253\u5370\u53d8\u91cf\u7684\u503c\u3002 print <expression>
\uff1a\u6253\u5370\u8868\u8fbe\u5f0f\u7684\u503c\u3002 watch <expression>
\uff1a\u76d1\u89c6\u8868\u8fbe\u5f0f\u7684\u503c\uff0c\u5f53\u503c\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u7a0b\u5e8f\u4f1a\u505c\u4e0b\u6765\u3002 backtrace
\uff1a\u67e5\u770b\u51fd\u6570\u8c03\u7528\u6808\u3002 finish
\uff1a\u6267\u884c\u5b8c\u5f53\u524d\u51fd\u6570\u540e\u505c\u4e0b\u6765\u3002 q
\u6216 quit
\uff1a\u9000\u51fa gdb
\u3002 help
\uff1a\u67e5\u770b\u5e2e\u52a9\u4fe1\u606f\u3002
"},{"location":"programming_lecture/lecture1/lecture1/#_22","title":"\u68c0\u67e5\u7a0b\u5e8f\u60c5\u51b5","text":"Linux \u7cfb\u7edf\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u8bbe\u5907\u6587\u4ef6 /dev/zero
\uff0c\u5b83\u80fd\u591f\u4f5c\u4e3a\u8f93\u5165\uff0c\u63d0\u4f9b\u65e0\u7a77\u65e0\u5c3d\u7684 0
\u5b57\u8282\u3002\u6211\u4eec\u5c06\u5b83\u4f5c\u4e3a\u8f93\u5165\uff0c\u770b\u770b\u7a0b\u5e8f\u4f1a\u53d1\u751f\u4ec0\u4e48\u3002
(gdb) file gets\nReading symbols from gets...\n(gdb) run < /dev/zero\nStarting program: /mnt/f/Code/_repo/study-assist/docs/programming_lecture/lecture1/code/gets < /dev/zero\n[Thread debugging using libthread_db enabled]\nUsing host libthread_db library \"/lib/x86_64-linux-gnu/libthread_db.so.1\".\n\nProgram received signal SIGSEGV, Segmentation fault.\n0x00005555555551b2 in gets (s=0x7fffffffd760 \"\") at gets.c:8\n8 *dest++ = c;\n
\u56e0\u4e3a\u7a0b\u5e8f\u8bbf\u95ee\u4e86\u975e\u6cd5\u7684\u5730\u5740\u7a7a\u95f4\uff0c\u7cfb\u7edf\u5411\u7a0b\u5e8f\u53d1\u9001\u4fe1\u53f7 SIGSEGV
\uff0c\u7a0b\u5e8f\u7ec8\u6b62\u8fd0\u884c\u3002gdb
\u4f1a\u81ea\u52a8\u505c\u5728\u53d1\u751f\u9519\u8bef\u7684\u4f4d\u7f6e\uff0c\u8fd9\u91cc\u662f gets.c
\u7684\u7b2c 8 \u884c\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 backtrace
\u547d\u4ee4\u67e5\u770b\u51fd\u6570\u8c03\u7528\u6808\u3002
(gdb) backtrace\n#0 0x00005555555551b2 in gets (s=0x7fffffffd760 \"\") at gets.c:8\n#1 0x000055555555521b in echo () at gets.c:18\n#2 0x0000000000000000 in ?? ()\n
\u4f7f\u7528 print
\u547d\u4ee4\u67e5\u770b\u5404\u4e2a\u53d8\u91cf\u7684\u503c\u3002print/x
\u80fd\u591f\u6307\u5b9a\u4ee5\u5341\u516d\u8fdb\u5236\u7684\u5f62\u5f0f\u6253\u5370\u53d8\u91cf\u7684\u503c\u3002
(gdb) print dest\n$1 = 0x7ffffffff001 <error: Cannot access memory at address 0x7ffffffff001>\n(gdb) print s\n$2 = 0x7fffffffd760 \"\"\n(gdb) print dest - s\n$3 = 6305\n(gdb) print c\n$4 = 0\n
gdb
\u4e3a\u4f60\u505a\u4e86\u4e00\u4e9b\u63d0\u793a\uff0c\u6bd4\u5982 dest
\u73b0\u5728\u6240\u6307\u5411\u7684\u5730\u5740 0x7ffffffff001
\u662f\u7a0b\u5e8f\u65e0\u6cd5\u8bbf\u95ee\u7684\u3002\u68c0\u67e5 dest - s
\u7684\u503c\u6211\u4eec\u77e5\u9053\u6b64\u65f6 dest
\u6307\u5411\u7684\u5730\u5740\u5df2\u7ecf\u662f s
\u540e 6305 \u4e2a\u5b57\u8282\uff0c\u8fdc\u8fdc\u8d85\u51fa\u4e86\u6570\u7ec4 s
\u7684\u7a7a\u95f4\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u68c0\u67e5\u5f53\u524d\u8f93\u5165\u7684\u5b57\u7b26 c
\uff0c\u5b83\u663e\u7136\u662f 0
\u3002
"},{"location":"programming_lecture/lecture1/lecture1/#_23","title":"\u65ad\u70b9\u8c03\u8bd5","text":"\u4f7f\u7528 break <filename>:<line>
\u53ef\u4ee5\u5728\u6307\u5b9a\u6587\u4ef6\u6307\u5b9a\u884c\u8bbe\u7f6e\u65ad\u70b9\u3002\u5bf9\u4e8e\u5355\u6587\u4ef6\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u7701\u7565\u6e90\u4ee3\u7801\u6587\u4ef6\u540d\u3002break
\u8fd8\u53ef\u4ee5\u63a5\u6536\u51fd\u6570\u540d\u548c\u5730\u5740\u4f5c\u4e3a\u53c2\u6570\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u6761\u4ef6\u8868\u8fbe\u5f0f\uff0c\u8bf7\u4f7f\u7528 help break
\u67e5\u770b\u8be6\u7ec6\u7528\u6cd5\u3002
\u6211\u4eec\u5728\u7a0b\u5e8f\u7b2c 8 \u884c *dest++=c
\u5904\u8bbe\u7f6e\u4e00\u4e2a\u65ad\u70b9\uff0c\u7136\u540e\u8fd0\u884c\u7a0b\u5e8f\u3002
(gdb) b 8\nBreakpoint 1 at 0x11a3: file gets.c, line 8.\n(gdb) r < /dev/zero\nStarting program: /mnt/f/Code/_repo/study-assist/docs/programming_lecture/lecture1/code/gets < /dev/zero\n\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8 *dest++ = c;\n(gdb) print dest - s\n$1 = 0\n
next
\u547d\u4ee4\u5c06\u4f1a\u5355\u884c\u6267\u884c\u7a0b\u5e8f\uff0c\u4e14\u4e0d\u4f1a\u8fdb\u5165\u51fd\u6570\u5185\u90e8\uff08\u5373\u628a\u6574\u4e2a\u51fd\u6570\u5f53\u4f5c\u4e00\u884c\uff09\u3002step
\u4f1a\u8fdb\u5165\u51fd\u6570\u5185\u90e8\u4e00\u884c\u4e00\u884c\u6267\u884c\u3002continue
\u547d\u4ee4\u5c06\u7ee7\u7eed\u6267\u884c\u7a0b\u5e8f\uff0c\u76f4\u5230\u4e0b\u4e00\u4e2a\u65ad\u70b9\u3002
(gdb) next\n7 while((c = getchar()) != '\\n' && c != EOF)\n(gdb) next\nBreakpoint 1,gets (s=0x7fffffffd760 \"\") at gets.c:8\n8 *dest++ = c;\n(gdb) print dest - s\n$2 =1\n(gdb) continue\nContinuing.\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8 *dest++ = c;\n(gdb) print dest - s\n$3 = 2\n
next
\u548c step
\u547d\u4ee4\u90fd\u53ef\u4ee5\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\uff0c\u8868\u793a\u6267\u884c\u591a\u5c11\u884c\uff0c\u4e14\u4f1a\u5728\u65ad\u70b9\u5904\u505c\u4e0b\u3002continue
\u547d\u4ee4\u4e5f\u53ef\u4ee5\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\uff0c\u8868\u793a\u5ffd\u7565\u63a5\u4e0b\u6765\u5730\u591a\u5c11\u4e2a\u65ad\u70b9\u3002
(gdb) next 20\n\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8 *dest++ = c;\n(gdb) print dest - s\n$4 = 3\n(gdb) continue 20\nWill ignore next 19 crossings of breakpoint 1. Continuing.\n\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8 *dest++ = c;\n(gdb) print dest - s\n$5 = 23\n
\u8c03\u8bd5\u6280\u5de7 \u76f4\u63a5\u6309 Enter \u952e\uff0cgdb
\u4f1a\u91cd\u590d\u4e0a\u4e00\u6761\u547d\u4ee4\u3002\u8fd9\u6837\u5c31\u4e0d\u7528\u4e00\u76f4\u8f93\u5165 next
\u6216 step
\u4e86\u3002
\u5728\u4e00\u4e9b\u66f4\u4e3a\u590d\u6742\u7684\u7a0b\u5e8f\u4e2d\uff0c\u4f7f\u7528 gdb
\u8c03\u8bd5\u7684\u4f18\u8d8a\u6027\u5c31\u9010\u6e10\u663e\u73b0\u51fa\u6765\u4e86\u3002\u4f60\u4e0d\u7528\u9891\u7e41\u66f4\u6539\u6e90\u4ee3\u7801\u63d2\u5165 printf
\u8bed\u53e5\uff0c\u53ea\u9700\u8981\u5728 gdb
\u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u7136\u540e\u9010\u6b65\u6267\u884c\u7a0b\u5e8f\uff0c\u67e5\u770b\u53d8\u91cf\u7684\u503c\uff0c\u5c31\u80fd\u627e\u5230\u9519\u8bef\u6240\u5728\u3002
\u8fdb\u4e00\u6b65\u5b66\u4e60
\u7531\u4e8e\u4e2a\u4eba\u6c34\u5e73\u4e0d\u8db3\u4ee5\u53ca\u65f6\u95f4\u6709\u9650\uff0c\u6ca1\u80fd\u5199\u51fa\u4e00\u4e2a\u4f53\u9a8c\u8f83\u597d\u7684 GDB \u8c03\u8bd5\u5b9e\u9a8c\u3002\u5341\u5206\u5e0c\u671b\u540c\u5b66\u4eec\u5728\u8bfe\u540e\u53bb\u770b\u770b\u8fd9\u7bc7\u6587\u7ae0Linux C \u4e00\u7ad9\u5f0f\u7f16\u7a0b\uff1a\u7b2c 10 \u7ae0 gdb\uff0c\u628a\u8fd9\u8fb9\u7684\u8c03\u8bd5\u5b9e\u4f8b\u90fd\u8fc7\u4e00\u904d\uff5e
"},{"location":"programming_lecture/lecture1/lecture1/#_24","title":"\u53c2\u8003\u8d44\u6599","text":"\u53c2\u8003\u8d44\u6599 - GCC and Make - A Tutorial on how to compile, link and build C/C++ applications
- Understanding GCC warnings
- The GCC warning flags every C programmer should know about
- What Is /lib64/ld-linux-x86-64.so.2?
- GDB Tutorial: A Walkthrough with Examples
- \u770b\u4e91\uff1aLinux C \u4e00\u7ad9\u5f0f\u5b66\u4e60
"},{"location":"programming_lecture/lecture1/pre_class/","title":"\u8bfe\u524d\uff1a\u51c6\u5907\u5f00\u53d1\u4e0e\u8c03\u8bd5\u73af\u5883","text":"Info
\u672c\u6587\u6863\u66f4\u6539\u81ea\u5468\u5065\u5747\u5b66\u957f\u4e3a\u56fe\u7075\u7a0b\u7b97\u8bfe\u7a0b\u51c6\u5907\u7684\u8d44\u6599\uff0c\u611f\u8c22\u5468\u5065\u5747\u5b66\u957f\u7684\u4ed8\u51fa\u3002
\u5185\u5bb9\u63d0\u8981
\u5728\u53c2\u4e0e\u7ebf\u4e0b\u6388\u8bfe\u524d\uff0c\u540c\u5b66\u4eec\u6700\u597d\u80fd\u591f\u5b89\u88c5\u597d\u76f8\u5173\u7684\u5f00\u53d1\u73af\u5883\uff0c\u4ee5\u4fbf\u80fd\u591f\u66f4\u597d\u7684\u8ddf\u968f\u8001\u5e08\u7684\u8bb2\u89e3\u3002
- \u547d\u4ee4\u884c\u7b80\u4ecb
- WSL \u5b89\u88c5\u5f15\u5bfc
- \u5728 Windows \u4e0a\u5b89\u88c5 C \u8bed\u8a00\u7f16\u8bd1\u5668
- VSCode \u5b89\u88c5\u4e0e\u914d\u7f6e
\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
- \u6253\u5f00\u8fd9\u4e2a\u7f51\u5740\uff1awww.onlinegdb.com\u3002
- \u5b83\u5df2\u7ecf\u4e3a\u4f60\u5199\u597d C \u8bed\u8a00\u7684 Hello World \u7a0b\u5e8f\u6e90\u7801\u3002
- \u5728\u53f3\u4e0a\u89d2\u9009\u62e9 C \u8bed\u8a00\uff0c\u7136\u540e\u70b9\u51fb\u5de6\u4e0a\u89d2\u7684
Run
\u3002 - \u5728\u4e0b\u65b9\uff0c\u4f60\u5c31\u53ef\u4ee5\u770b\u89c1\u7a0b\u5e8f\u7684\u8f93\u51fa\u3002
- \u6309\u4e0b Enter \u952e\u79bb\u5f00\u7ec8\u7aef\u3002\u4e0b\u65b9\u4f1a\u663e\u793a\u51e0\u4e2a\u9009\u9879\uff1a
- Command Line Arguments\uff1a\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u4f60\u4eec\u5e94\u8be5\u4e0d\u4f1a\u5b66\u5230\uff1f
- Standard Input\uff1a\u6807\u51c6\u8f93\u5165\u3002\u4f60\u53ef\u4ee5\u9009\u62e9 Interactive Console\uff08\u5c31\u662f\u6b63\u5e38\u5730\u7528\u952e\u76d8\u548c\u7a0b\u5e8f\u4ea4\u4e92\uff09\u6216\u8005 Text\uff08\u9884\u5148\u51c6\u5907\u4e00\u4e9b\u6587\u672c\u81ea\u52a8\u8f93\u5165\uff0c\u901a\u5e38\u7528\u4e8e\u6d4b\u8bd5 PTA \u7684\u6837\u4f8b\u6570\u636e\uff09\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
- Mac \u548c Linux \u7528\u6237
- \u5b89\u88c5\u597d\u4e86 WSL \u7684 Windows \u7528\u6237
- \u5b89\u88c5\u597d\u4e86 MinGW\u3001MSVC\u3001Cygwin\u3001tdm-gcc \u7b49\u7f16\u8bd1\u5668\u7684 Windows \u7528\u6237
\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
- \u70b9\u51fb\u9875\u9762\u4e2d\u7684\u56fe\u7247\u53ef\u4ee5\u653e\u5927\u67e5\u770b\u3002
- \u5982\u679c\u5b89\u88c5\u8fc7\u7a0b\u9047\u5230\u56f0\u96be\uff0c\u53ef\u4ee5\u5728\u8f85\u5b66\u7fa4\u63d0\u95ee\uff0c\u6216\u79c1\u6233\u6388\u8bfe\u5b66\u957f\uff5e
"},{"location":"programming_lecture/lecture1/pre_class/#shell","title":"Shell \u4f7f\u7528\u62fe\u9057","text":"\u672c\u8282\u6211\u4eec\u8981\u8ba4\u8bc6\u4e00\u4e2a\u5373\u5c06\u6210\u4e3a\u4f60\u7684\u8001\u670b\u53cb\u7684\u4e1c\u897f\u2014\u2014Shell\u3002\u4e0b\u9762\u662f\u540c\u5b66\u4eec\u63a5\u4e0b\u6765\u4f1a\u7ecf\u5e38\u89c1\u5230\u7684\u51e0\u4e2a\u540d\u8bcd\uff1a
- Terminal \u7ec8\u7aef\uff1a\u4e0b\u56fe\u4e2d\uff0c\u8fd9\u4e2a\u7a97\u53e3\u5c31\u662f Windows Terminal\u3002\u5b83\u8d1f\u8d23\u63a5\u6536\u4f60\u7684\u8f93\u5165\uff0c\u628a\u8f93\u5165\u4f20\u9012\u7ed9 Shell\uff0c\u7136\u540e\u628a Shell \u7684\u8f93\u51fa\u663e\u793a\u7ed9\u4f60\u3002\u4f60\u53ef\u4ee5\u4ece\u56fe\u4e2d\u770b\u5230\uff0c\u4e00\u4e2a Terminal \u53ef\u4ee5\u8fde\u63a5\u5230\u591a\u4e2a Shell\uff0c\u5c31\u50cf\u4e00\u53f0\u663e\u793a\u5668\u53ef\u4ee5\u8fde\u63a5\u5230\u591a\u53f0\u7535\u8111\u4e00\u6837\u3002\u628a Terminal \u7406\u89e3\u4e3a\u952e\u76d8\u548c\u663e\u793a\u5668\u5c31\u597d\u3002
- Shell \u547d\u4ee4\u89e3\u91ca\u5668\uff1a\u63a5\u6536\u4f60\u7ed9\u51fa\u7684\u547d\u4ee4\u3001\u6267\u884c\u5e76\u7ed9\u51fa\u54cd\u5e94\u7684\uff0c\u5c31\u662f Shell\u3002\u5982\u679c\u628a Terminal \u7406\u89e3\u4e3a\u952e\u76d8\u548c\u663e\u793a\u5668\uff0c\u90a3\u4e48 Shell \u5c31\u662f\u4e3b\u673a\u3002
- Prompt \u63d0\u793a\u7b26\uff1aShell \u4f1a\u7ed9\u4f60\u4e00\u4e2a\u63d0\u793a\u7b26\uff0c\u544a\u8bc9\u4f60\u5b83\u5df2\u7ecf\u51c6\u5907\u597d\u63a5\u6536\u4f60\u7684\u547d\u4ee4\u4e86\u3002\u5728 Linux \u4e2d\uff0c\u63d0\u793a\u7b26\u4e00\u822c\u662f
$
\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 - Command Line Interface \u547d\u4ee4\u884c\u4ea4\u4e92\u754c\u9762\uff1a\u5f53\u6211\u4eec\u4f7f\u7528\u6587\u672c\u547d\u4ee4\u4e0e\u8ba1\u7b97\u673a\u4ea4\u4e92\u65f6\uff0c\u6211\u4eec\u5c31\u5728\u4f7f\u7528 CLI\u3002\u8fd9\u4e0e\u6211\u4eec\u65e5\u5e38\u751f\u6d3b\u4e2d\u4f7f\u7528\u9f20\u6807\u7684\u56fe\u5f62\u4ea4\u4e92\u754c\u9762\uff08Graphical User Interface\uff0cGUI\uff09\u4e0d\u540c\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
- \u901f\u5ea6\u5feb\uff1a\u5728\u547d\u4ee4\u884c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5feb\u901f\u5730\u8f93\u5165\u547d\u4ee4\uff0c\u800c\u4e0d\u9700\u8981\u4f7f\u7528\u9f20\u6807\u70b9\u51fb\u83dc\u5355\u3002
- \u53ef\u7f16\u7a0b\uff1a\u4f60\u53ef\u4ee5\u7f16\u5199\u811a\u672c\uff0c\u8ba9\u8ba1\u7b97\u673a\u81ea\u52a8\u6267\u884c\u4e00\u7cfb\u5217\u547d\u4ee4\u3002
- \u53ef\u8fdc\u7a0b\uff1a\u4f60\u53ef\u4ee5\u901a\u8fc7\u7f51\u7edc\u8fde\u63a5\u5230\u8fdc\u7a0b\u8ba1\u7b97\u673a\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u4e0e\u5176\u4ea4\u4e92\u3002
\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
"},{"location":"programming_lecture/lecture1/pre_class/#wsl","title":"WSL \u5b89\u88c5\u7b80\u5355\u5f15\u5bfc\uff08\u53ef\u9009\uff09","text":"\u63a8\u8350\u88c5\u4e00\u88c5\uff0c\u5982\u679c\u4e3b\u529b\u673a\u662f Windows \u5728\u4ee5\u540e\u5c06\u5bf9 WSL \u6709\u8f83\u5927\u9700\u6c42
WSL\uff0c\u5168\u79f0 Windows Subsystem for Linux\uff08\u9002\u7528\u4e8e Linux \u7684 Windows \u5b50\u7cfb\u7edf\uff09\uff0c\u662f\u4e00\u9879\u5141\u8bb8\u5f00\u53d1\u8005\u4e0d\u4f9d\u9760\u5355\u72ec\u7684\u865a\u62df\u673a\u6216\u53cc\u542f\u52a8 (dual booting) \u800c\u5728 Windows \u4e0a\u8fd0\u884c Linux \u73af\u5883\u7684\u529f\u80fd\u3002
"},{"location":"programming_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
- \u8bbe\u7f6e\u4e00\u4e2a\u7528\u6237\u540d\uff0c\u5efa\u8bae\u5168\u82f1\u6587\u65e0\u7a7a\u683c
- \u82e5\u6709\u7a7a\u683c\uff0c\u5c06\u4f1a\u53ea\u53d6\u7b2c\u4e00\u4e2a\u7a7a\u683c\u524d\u9762\u7684\u5185\u5bb9\u4f5c\u4e3a\u4f60\u7684\u7528\u6237\u540d
- \u8f93\u5165\u5bc6\u7801\uff0c\u6ce8\u610f\u4f60\u8f93\u5165\u7684\u5b57\u7b26\u4e0d\u4f1a\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\uff0c\u9700\u8981\u76f2\u6253
- \u5982\u679c\u6253\u4e86\u4e71\u4e03\u516b\u7cdf\u7684\u5b57\u7b26\u4e0d\u8981\u614c\uff0c\u786e\u8ba4\u5bc6\u7801\u65f6\u6545\u610f\u6253\u9519\u4f1a\u91cd\u65b0\u8ba9\u4f60\u8bbe\u7f6e\u5bc6\u7801
- \u786e\u8ba4\u5bc6\u7801\u4e0e\u8f93\u5165\u5bc6\u7801\u4e00\u81f4\u624d\u4f1a\u8bbe\u7f6e\u6210\u529f
\u8fd9\u6837\u5c31\u5b8c\u6210\u4e86 WSL2 Ubuntu \u7684\u5b89\u88c5\u3002
\u9519\u8bef\uff1a0x80370114
- \u9996\u5148\u68c0\u67e5\u81ea\u5df1\u662f\u5426\u4e3a Windows 10 \u6216\u8005 Windows 11 \u5bb6\u5ead\u7248\u3002\u8fd9\u4e24\u4e2a\u7248\u672c\u53ef\u80fd\u7f3a\u5931 Hyper-V \u670d\u52a1\uff08WSL \u80cc\u540e\u7684\u865a\u62df\u5316\u652f\u6301\u6280\u672f\uff09\u3002\u8bf7\u6309\u7167\u77e5\u4e4e\uff1a\u5982\u4f55\u5728 Windows 11 Home \u4e2d\u542f\u7528 Hyper-V\u8fd9\u7bc7\u6587\u7ae0\u7684\u65b9\u6cd5\u542f\u7528 Hyper-V\u3002
- \u5982\u679c\u4ecd\u65e0\u6cd5\u89e3\u51b3\uff0c\u518d\u6309\u7167\u77e5\u4e4e\uff1awin10\u4f7f\u7528wsl2\u5b89\u88c5ubuntu\u9047\u52300x80370114\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6cd5\u8fd9\u7bc7\u6587\u7ae0\u91cd\u65b0\u542f\u52a8\u865a\u62df\u673a\u5e73\u53f0\u3002
\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
- \u53ef\u9009\u7684\u5b89\u88c5\u9879
- \u53ef\u4ee5\u5168\u9009\u3002\u5982\u679c\u786e\u5b9a\u4e0d\u9700\u8981\u4e00\u4e9b\u4e1c\u897f\u53ef\u4ee5\u4e0d\u9009\uff0c\u6bd4\u5982\u786e\u5b9a\u81ea\u5df1\u4e0d\u4f1a\u518d\u9700\u8981\u8c03\u8bd5 32 \u4f4d\u7a0b\u5e8f\u7684\u8bdd\u53ef\u4ee5\u4e0d\u9009 gdb32\u3002
- Start Menu items
- \u770b\u4e2a\u4eba\u610f\u613f\uff0c\u53ef\u4ee5\u4e0d\u9009
- Add to PATH
- \u5efa\u8bae\u9009\u4e0a\u3002\u5982\u679c\u4e0d\u9009\u6216\u8005\u5fd8\u9009\u4e86\uff0c\u5c06\u4f1a\u9700\u8981\u81ea\u5df1\u914d\u7f6e tdm-gcc \u7684\u73af\u5883\u53d8\u91cf\u8def\u5f84\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
"},{"location":"programming_lecture/lecture1/pre_class/#vscode","title":"VSCode \u5b89\u88c5\u4e0e\u914d\u7f6e","text":"VSCode \u7684\u5168\u79f0\u662f Visual Studio Code\uff0c\u6ce8\u610f\u5b83\u548c Visual Studio \u5b8c\u5168\u662f\u4e24\u4e2a\u4e1c\u897f
\u4e0d\u5efa\u8bae\u5b89\u88c5 Visual Studio\uff0c\u9664\u975e\u4f60\u6e05\u695a\u4f60\u5b89\u88c5\u5b83\u662f\u4e3a\u4e86\u4ec0\u4e48
\u5728\u8fd9\u91cc\u4ec5\u4ecb\u7ecd Visual Studio Code \u7684\u5b89\u88c5\u3002\u9664\u4e86\u8001\u5e08\u7684\u89c6\u9891\u4e4b\u5916\uff0c\u5927\u5bb6\u5b89\u88c5\u914d\u7f6e\u65f6\u8fd8\u53ef\u4ee5\u53c2\u8003 GZTime \u7684\u6559\u7a0b\uff0c\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bf4\u8fd8\u4e0d\u9519\u3002
"},{"location":"programming_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
WindowsMac Windows \u7684 exe \u5b89\u88c5\u53ef\u4ee5\u5168\u9009\u9ed8\u8ba4\u9009\u9879\u4e00\u8def Next\uff0c\u6bd4\u8f83\u719f\u6089\u7684\u540c\u5b66\u53ef\u4ee5\u81ea\u5b9a\u4e49\u9009\u9879\uff1a
- \u5b89\u88c5\u76ee\u5f55
- \u63a8\u8350\u9ed8\u8ba4 C \u76d8\uff0c\u53ef\u80fd\u8fd0\u884c\u901f\u5ea6\u66f4\u5feb\uff0c\u4e5f\u53ef\u4ee5\u907f\u514d\u4e00\u4e9b\u6743\u9650\u95ee\u9898
- \u5c06 \u201c\u901a\u8fc7 Code \u6253\u5f00\u201d \u64cd\u4f5c\u6dfb\u52a0\u5230 Windows \u8d44\u6e90\u7ba1\u7406\u5668\u6587\u4ef6/\u76ee\u5f55\u4e0a\u4e0b\u6587\u83dc\u5355
- \u9009\u4e2d\u8be5\u9879\u540e\uff0c\u9009\u4e2d\u6587\u4ef6\u6216\u8005\u6587\u4ef6\u5939\uff0c\u53f3\u952e\u83dc\u5355\u4e2d\u4f1a\u51fa\u73b0
\u901a\u8fc7 Code \u6253\u5f00
\u7684\u9009\u9879 - \u5982\u679c\u5e0c\u671b\u53f3\u952e\u83dc\u5355\u4e0d\u90a3\u4e48\u81c3\u80bf\u7684\u8bdd\u53ef\u4ee5\u4e0d\u9009\u8fd9\u4e00\u9879
- \u672c\u4eba\u6ca1\u6709\u9009\u62e9\u8be5\u9009\u9879\uff0c\u53ef\u4ee5\u81ea\u884c\u601d\u8003\u9009\u62e9
- \u5c06 Code \u6ce8\u518c\u4e3a\u53d7\u652f\u6301\u7684\u6587\u4ef6\u7c7b\u578b\u7684\u7f16\u8f91\u5668\uff08\u63a8\u8350\uff09
- \u6253\u5f00\u53d7\u652f\u6301\u7684\u6587\u4ef6\u7c7b\u578b\u65f6\uff0cVSCode \u5c06\u4f1a\u6210\u4e3a\u53ef\u9009\u9879
- \u6dfb\u52a0\u5230 PATH\uff08\u63a8\u8350\uff09
- \u5728\u547d\u4ee4\u884c\u7a97\u53e3/\u7ec8\u7aef\u53ef\u4ee5\u7528
code
\u547d\u4ee4\u6253\u5f00 VSCode
Mac \u7684\u5305\u4e0b\u8f7d\u4e0b\u6765\u4e4b\u540e\u62d6\u5165 Application
\u6587\u4ef6\u5939\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c
- \u6dfb\u52a0\u5230 PATH\uff1a\u5982\u679c\u9700\u8981\u5728\u547d\u4ee4\u884c\u7a97\u53e3/\u7ec8\u7aef\u7528
code
\u547d\u4ee4\u6253\u5f00 VSCode\uff0c\u90a3\u4e48\u9700\u8981\u5982\u4e0b\u64cd\u4f5c - \u6253\u5f00 VSCode \u754c\u9762
- \u4f7f\u7528 Shift + Command + P \u6253\u5f00\u547d\u4ee4\u9762\u677f
- \u8f93\u5165
shell command
\uff0c\u9009\u62e9 Shell Command: Install \u2018code\u2019 command in PATH
\u56de\u8f66\u6267\u884c
"},{"location":"programming_lecture/lecture1/pre_class/#_4","title":"\u63d2\u4ef6\u5b89\u88c5","text":"\u6253\u5f00 VSCode \u540e\uff0c\u5728\u5de6\u4fa7\u7ad6\u680f\u5bfb\u627e\u4e0b\u9762\u8fd9\u4e2a\u56fe\u6807\uff1a
\u70b9\u51fb\u8fd9\u4e2a\u56fe\u6807\u5c31\u8fdb\u5165\u4e86\u63d2\u4ef6\u7ba1\u7406\u3002\u5efa\u8bae\u53ef\u4ee5\u5b89\u88c5\u4e0b\u9762\u4e24\u4e2a\u63d2\u4ef6\uff1a
- C/C++: \u5fae\u8f6f\u81ea\u5bb6\u7684\u63d2\u4ef6\uff0c\u53ef\u7528\u4e8e\u8bed\u6cd5\u8bc6\u522b\u3001\u4ee3\u7801\u9ad8\u4eae
- Chinese(Simplified): \u754c\u9762\u6c49\u5316\u63d2\u4ef6\uff08\u53ef\u9009\uff09
\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
- \u8bb0\u5f97\u4fdd\u5b58\u6587\u4ef6\u540e\u518d gcc \u7f16\u8bd1\uff0c\u53ef\u4ee5\u8003\u8651\u5f00\u542f\u81ea\u52a8\u4fdd\u5b58
- \u5982\u4e0b\u56fe\u6240\u793a\uff0c\u627e\u5230\u5de6\u4e0b\u89d2\u7684\u9f7f\u8f6e\u70b9\u51fb\u540e\u9009\u62e9 Setting \u6216\u8005\u8bbe\u7f6e\uff0c\u51fa\u73b0\u7684\u8bbe\u7f6e\u9875\u9762\u4e2d\u641c\u7d22
auto
\u53ef\u4ee5\u627e\u5230\u5982\u56fe\u6240\u793a\u7684 Auto Save
\u8bbe\u7f6e\u9879\uff0c\u8bbe\u7f6e\u4e3a afterDelay \u5373\u53ef - afterDelay \u662f\u5bf9\u6587\u4ef6\u505a\u51fa\u4fee\u6539\u5c31\u5b9e\u65f6\u4fdd\u5b58\uff0c\u5982\u679c\u5acc\u4fdd\u5b58\u9891\u7387\u8fc7\u9ad8\u53ef\u4ee5\u9009\u62e9 onFocusChange \u6216\u8005 onWindowsChange
- \u6211\u672c\u4eba\u4f7f\u7528\u7684\u662f onFocusChange\uff0c\u8fd9\u6837\u79fb\u52a8\u5230\u7ec8\u7aef\u51c6\u5907\u7f16\u8bd1\u8fd0\u884c\u65f6\u6e90\u4ee3\u7801\u6587\u4ef6\u5c31\u4f1a\u81ea\u52a8\u4fdd\u5b58\uff0c\u65e2\u81ea\u52a8\u4fdd\u5b58\u53c8\u4e0d\u4f1a\u4fdd\u5b58\u592a\u9891\u7e41
- \u5efa\u8bae\u5de5\u4f5c\u76ee\u5f55\u548c\u6587\u4ef6\u540d\u5168\u82f1\u6587\uff0c\u7ed9\u51fa\u4ee5\u4e0b\u51e0\u4e2a\u53cd\u9762\u6848\u4f8b\uff1a
- \u6587\u4ef6\u540d
\u4f5c\u4e1a.c
- \u5de5\u4f5c\u76ee\u5f55
\u7f16\u7a0b
- \u5de5\u4f5c\u76ee\u5f55\u53eb
Coding
\uff0c\u4f46\u662f\u7edd\u5bf9\u8def\u5f84\u662f D:/\u5b66\u4e60\u8d44\u6599/Coding
- \u53ef\u4ee5\u6307\u5b9a\u7f16\u8bd1\u751f\u6210\u7684\u6587\u4ef6\u540d\uff0c\u6bd4\u5982\u4f60\u60f3\u8981\u8f93\u51fa\u6587\u4ef6\u540d\u4e3a
hello.exe
\uff0c\u5c31\u53ef\u4ee5\u6267\u884c gcc test.c -o hello.exe\n
- \u66f4\u591a\u7684 gcc \u9009\u9879\u548c VSCode \u6269\u5c55\u529f\u80fd\u7559\u5f85\u4f60\u4eec\u63a2\u7d22
"},{"location":"programming_lecture/lecture1/pre_class/#vscode-wsl","title":"VSCode + WSL\uff08\u53ef\u9009\uff09","text":"\u524d\u9762\u9009\u62e9\u5b89\u88c5\u4e86 WSL \u7684\u4f7f\u7528 Windows \u4e3b\u529b\u673a\u7684\u540c\u5b66\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\uff0c\u975e\u5e38\u6709\u7528\u7684\u529f\u80fd
\u4ee5\u4e0b\u5f15\u5bfc\u4e3b\u8981\u6309\u7167 Microsoft \u7684\u5b98\u65b9\u6587\u6863\uff0c\u4e5f\u53ef\u4ee5\u53c2\u8003\u5176\u4e2d\u6587\u7248\u3002
"},{"location":"programming_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
- Ctrl + Shift + P\uff0c\u5728\u51fa\u73b0\u7684\u547d\u4ee4\u6846\u4e2d\u8f93\u5165 WSL\uff0c\u9009\u62e9
WSL: Connect to WSL in New Window
\uff08\u6216 WSL: \u5728\u65b0\u7a97\u53e3\u4e2d\u8fde\u63a5\u5230 WSL
\uff09 - \u5c06\u6253\u5f00\u4e00\u4e2a\u65b0\u7684 VSCode \u7a97\u53e3\uff0c\u91cc\u9762\u5df2\u7ecf\u8fde\u63a5\u5230\u9ed8\u8ba4\u7684 WSL \u73af\u5883
\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
"},{"location":"programming_lecture/lecture2/after_class/","title":"\u8bfe\u540e\u62d3\u5c55\uff1a\u7a0b\u5e8f\u548c\u6570\u636e\u5728\u8ba1\u7b97\u673a\u4e2d\u662f\u5982\u4f55\u5b58\u50a8\u7684\uff1f","text":"\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
- \u5b83\u8ba9\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u4ee5\u4e3a\u81ea\u5df1\u5728\u72ec\u5360\u5730\u4f7f\u7528\u4e3b\u5b58\u3002
- \u6bcf\u4e2a\u8fdb\u7a0b\u770b\u5230\u7684\u5185\u5b58\u90fd\u662f\u4e00\u81f4\u7684\uff0c\u79f0\u4e3a\u865a\u62df\u5730\u5740\u7a7a\u95f4\u3002
- \u4e00\u81f4\u6027\u6307\u7684\u662f\u5730\u5740\u7a7a\u95f4\u7684\u4e00\u81f4\u3002\u6bd4\u5982\u53f3\u56fe\u4e2d\uff0c\u5730\u5740\u7a7a\u95f4\u6700\u4e0a\u9762\u7684\u533a\u57df\u4fdd\u7559\u7ed9\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u4ee3\u7801\u548c\u6570\u636e\uff0c\u5e95\u90e8\u533a\u57df\u5b58\u653e\u7528\u6237\u8fdb\u7a0b\u7684\u4ee3\u7801\u548c\u6570\u636e\uff0c\u8fd9\u4e9b\u5bf9\u6240\u6709\u8fdb\u7a0b\u6765\u8bf4\u90fd\u662f\u4e00\u81f4\u7684\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
- \u672a\u5206\u914d\uff1a\u672a\u5206\u914d\uff0c\u4e0d\u5360\u7528\u4efb\u4f55\u78c1\u76d8\u7a7a\u95f4
- \u7f13\u5b58\u7684\uff1a\u5df2\u5206\u914d\uff0c\u5df2\u7ecf\u7f13\u5b58\u5728\u7269\u7406\u5185\u5b58\u4e2d
- \u672a\u7f13\u5b58\u7684\uff1a\u5df2\u5206\u914d\uff0c\u672a\u7f13\u5b58\u5728\u7269\u7406\u5185\u5b58\u4e2d
"},{"location":"programming_lecture/lecture2/after_class/#_5","title":"\u865a\u62df\u5730\u5740\u7a7a\u95f4\u7684\u7ed3\u6784","text":"\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
- \u7a0b\u5e8f\u4ee3\u7801\u548c\u6570\u636e\uff08\u53ea\u8bfb\uff09
- \u5bf9\u6240\u6709\u7684\u8fdb\u7a0b\u6765\u8bf4\uff0c\u4ee3\u7801\u4ece\u67d0\u4e2a\u56fa\u5b9a\u7684\u5730\u5740\u5f00\u59cb\u3002
- \u8fd9\u4e2a\u533a\u57df\u662f\u76f4\u63a5\u6309\u7167\u53ef\u6267\u884c\u76ee\u6807\u6587\u4ef6\u7684\u5185\u5bb9\u521d\u59cb\u5316\u7684\u3002
- \u8fdb\u7a0b\u4e00\u5f00\u59cb\u8fd0\u884c\u65f6\u5c31\u6307\u5b9a\u4e86\u5927\u5c0f\u3002
- \u5806
- \u8c03\u7528
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
- \u5171\u4eab\u5e93
- \u5b58\u653e C \u6807\u51c6\u5e93\u548c\u6570\u5b66\u5e93\u7b49\u5171\u4eab\u5e93\u7684\u4ee3\u7801\u548c\u6570\u636e\u3002
- \u6808
- \u5904\u4e8e\u7528\u6237\u5730\u5740\u7a7a\u95f4\u7684\u9876\u90e8\u3002
- \u7f16\u8bd1\u5668\u7528\u5b83\u6765\u5b9e\u73b0\u51fd\u6570\u8c03\u7528\u3002
- \u6808\u53ef\u4ee5\u52a8\u6001\u5730\u6269\u5c55\u548c\u6536\u7f29\u3002\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6\uff0c\u6808\u7684\u5927\u5c0f\u90fd\u4f1a\u589e\u52a0\uff1b\u6bcf\u6b21\u8fd4\u56de\u65f6\uff0c\u6808\u7684\u5927\u5c0f\u90fd\u4f1a\u51cf\u5c11\u3002
- \u5185\u6838\u865a\u62df\u5185\u5b58
- \u4e0d\u5141\u8bb8\u5e94\u7528\u7a0b\u5e8f\u8bfb\u5199\u8fd9\u4e2a\u533a\u57df\uff0c\u4e5f\u4e0d\u80fd\u8c03\u7528\u5176\u4e2d\u7684\u4ee3\u7801\u3002
- \u7a0b\u5e8f\u53ea\u80fd\u8c03\u7528\u5185\u6838\u5bf9\u8fd9\u5757\u533a\u57df\u6267\u884c\u64cd\u4f5c\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
- \u4e3b\u5b58\u4e2d\u5b58\u653e\u4e86\u4e00\u4e2a\u67e5\u8be2\u8868\uff0c\u7528\u4e8e\u52a8\u6001\u5730\u7ffb\u8bd1\u865a\u62df\u5730\u5740\u3002\u8be5\u8868\u7531\u64cd\u4f5c\u7cfb\u7edf\u7ba1\u7406\u3002
- CPU \u82af\u7247\u4e0a\u7684\u5185\u5b58\u7ba1\u7406\u5355\u5143\uff08Memory Management Unit\uff09\u8d1f\u8d23\u4f7f\u7528\u67e5\u8be2\u8868\u7ffb\u8bd1\u865a\u62df\u5730\u5740\u3002
"},{"location":"programming_lecture/lecture2/lecture2/","title":"\u8bb2\u4e49\uff1aC \u8bed\u8a00\u7684\u7c7b\u578b\u7cfb\u7edf\u4e0e\u5185\u5b58\u6a21\u578b","text":"\u65bd\u5de5\u4e2d
\u672c\u9875\u9762\u6b63\u5728\u65bd\u5de5\uff1a
- \u5c06\u8f83\u96be\u5185\u5bb9\u8fc1\u79fb\u5230\u8bfe\u540e\u6a21\u5757\u3002\u5c31\u7a0b\u5e8f\u8bbe\u8ba1\u8fd9\u95e8\u8bfe\u6765\u8bf4\uff0c\u9700\u8981\u8bb2\u8ff0\u7684\u5185\u5bb9\u62bd\u8c61\u7a0b\u5ea6\u8f83\u9ad8\uff0c\u5982\u5927\u7aef\u6cd5\u3001\u5c0f\u7aef\u6cd5\u7b49\u5177\u4f53\u5185\u5bb9\u5219\u65e0\u9700\u8bb2\u89e3\u3002\u4e0e\u8ba1\u7b97\u673a\u7cfb\u7edf\u6709\u5173\u7684\u5185\u5bb9\u5e94\u5f53\u8fc1\u79fb\u5230\u6269\u5c55\u6a21\u5757
- \u4f18\u5316\u8bb2\u4e49\u7ed3\u6784
Abstract
- \u7a0b\u5e8f\u5185\u5b58\u7a7a\u95f4\u7684\u5e03\u5c40
- C \u7c7b\u578b\u7cfb\u7edf\u7684\u63cf\u8ff0
- \u5982\u4f55\u9605\u8bfb\u58f0\u660e
- \u5982\u4f55\u7ba1\u7406\u5185\u5b58
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":" - \u5341\u8fdb\u5236\uff1a
20231029
- \u4e8c\u8fdb\u5236\uff1a
[0b] 1001101001011001101110101
- \u516b\u8fdb\u5236\uff1a
[0o] 115131565
- \u5341\u516d\u8fdb\u5236\uff1a
[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
- \u274c \u96f6\u57c3\u514b\u65af\u5341\u516b\uff0c\u96f6\u53c9\u5341\u516b\uff0c\u96f6\u4e58\u5341\u516b
- \u2705 \u96f6\u57c3\u514b\u65af\u4e00\u516b\uff0c\u96f6\u53c9\u4e00\u516b
0o23
- \u274c \u96f6\u6b27\u4e8c\u5341\u4e09
- \u2705 \u96f6\u6b27\u4e8c\u4e09
0b1010
- \u274c \u96f6\u5e01\u4e00\u5343\u96f6\u4e00\u5341
- \u2705 \u96f6\u5e01\u4e00\u96f6\u4e00\u96f6
0x10000
- \u274c \u96f6\u57c3\u514b\u65af\u4e00\u4e07\uff0c\u96f6\u53c9\u4e00\u4e07\uff0c\u96f6\u4e58\u4e00\u4e07
- \u2705 \u96f6\u57c3\u514b\u65af\u4e00\u96f6\u96f6\u96f6\u96f6\uff0c\u96f6\u53c9\u4e00\u96f6\u96f6\u96f6\u96f6
"},{"location":"programming_lecture/lecture2/lecture2/#ascii","title":"ASCII","text":"\u6bcf\u4e2a\u5b57\u7b26\u5bf9\u5e94\u4e00\u4e2a\u6570\u5b57\uff0c\u5373\u5176 ASCII \u7801\u3002\u5982 A
\u7684 ASCII \u7801\u4e3a 65
\uff0ca
\u7684 ASCII \u7801\u4e3a 97
\u3002
"},{"location":"programming_lecture/lecture2/lecture2/#_3","title":"\u7c7b\u578b\u7cfb\u7edf","text":"\u7c7b\u578b\u662f\u4e0e\u6570\u636e\u76f8\u5173\u7684\u5c5e\u6027\uff0c\u5b83\u51b3\u5b9a\u4e86\u6570\u636e\u7684\u5b58\u50a8\u65b9\u5f0f\u548c\u53ef\u8fdb\u884c\u7684\u64cd\u4f5c\u3002
\u53d8\u91cf\u662f\u6570\u636e\u7684\u8f7d\u4f53\uff0c\u5b83\u662f\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u7684\u4e00\u5757\u7a7a\u95f4\uff0c\u6709\u7c7b\u578b\u548c\u503c\u3002
"},{"location":"programming_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
- \u5176\u7c7b\u578b\u4e3a
int
\uff0c\u6545\u5360\u7528 4 \u5b57\u8282\u3002
"},{"location":"programming_lecture/lecture2/lecture2/#_7","title":"\u57fa\u672c\u7c7b\u578b","text":"\u7c7b\u578b - cppreference.com
\u6574\u6570\u7c7b\u578b\uff1achar
short
int
long
long long
\u5176\u4e2d\uff0c\u9664\u4e86 char
\u4ee5\u5916\u7684\u7c7b\u578b\u9ed8\u8ba4\u4e3a signed
\uff0c\u5373\u6709\u7b26\u53f7\u6570\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cint
\u5c31\u662f signed int
\u3002\u5c06 signed
\u6362\u4e3a unsigned
\uff0c\u5c31\u5f97\u5230\u4e86\u65e0\u7b26\u53f7\u6570\u3002
\u90a3\u4e48 char
\u5462\uff1f
char
signed char
unsigned char
\u662f\u4e09\u4e2a\u4e0d\u540c\u7684\u7c7b\u578b\uff0c\u5c3d\u7ba1\u5728\u5927\u591a\u6570\u5b9e\u73b0\u4e2d\uff0cchar
\u8868\u73b0\u4e3a\u6709\u7b26\u53f7\u6570\u3002
\u5b57\u7b26\u7c7b\u578b\u89e3\u60d1 \u6216\u8bb8\u4f60\u4f1a\u548c\u6211\u540c\u6837\u5bf9\u4ee5\u4e0b\u51e0\u4e2a\u95ee\u9898\u611f\u5230\u56f0\u60d1\uff1a
- \u4e3a\u4ec0\u4e48\u5b57\u7b26\u5e38\u91cf\u7684\u7c7b\u578b\u662f
int
\u4e14\u957f\u5ea6\u662f 4 \u4e2a\u5b57\u8282\uff1f - \u4e3a\u4ec0\u4e48
getchar()
\u7b49\u51fd\u6570\u8fd4\u56de int
\u800c\u4e0d\u662f char
\uff1f - \u5bbd\u5b57\u7b26\u3001\u591a\u5b57\u8282\u5b57\u7b26\u548c Unicode \u7a76\u7adf\u5982\u4f55\u4f7f\u7528\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
- \u5b57\u7b26\u5e38\u91cf\u7684\u7c7b\u578b\u4e3a\u4ec0\u4e48\u662f
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
- What is the purpose of multi character constants in C? - Quora
- \u5b57\u7b26\u5e38\u91cf - cppreference.com
int c = getchar()
? Why int
? : C_Programming (reddit.com) - \u9690\u5f0f\u8f6c\u6362 - cppreference.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
"},{"location":"programming_lecture/lecture2/lecture2/#_8","title":"\u5b9a\u957f\u6574\u6570\u7c7b\u578b\u4e0e\u5176\u4ed6\u6574\u6570\u7c7b\u578b","text":"\u5728 stdint.h
\u4e2d\u5b9a\u4e49\uff0c\u5982 int8_t
uint8_t
int16_t
uint16_t
int32_t
uint32_t
int64_t
uint64_t
\u3002
sizeof
\u8fd0\u7b97\u7b26\u4e0e offsetof
\u5b8f\u7684\u7ed3\u679c\uff1asize_t
\uff0c\u8db3\u591f\u8868\u793a\u4efb\u4f55\u5bf9\u8c61\u7684\u5927\u5c0f\u3002\u5e38\u88ab\u5b9a\u4e49\u4e3a unsigned long
\u3002
\u5728 stddef.h
\u4e2d\u5b9a\u4e49\uff0cptrdiff_t
\u8868\u793a\u4e24\u4e2a\u6307\u9488\u76f8\u51cf\u7684\u7ed3\u679c\u3002\u5e38\u88ab\u5b9a\u4e49\u4e3a long
\u3002
\u5982\u4f55\u8f93\u51fa\u8fd9\u4e9b\u6574\u6570\u7c7b\u578b\uff1f \u5728 inttypes.h
\u4e2d\u5b9a\u4e49\u4e86\u4e00\u7cfb\u5217\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0c\u5982 PRId32
\u4e00\u822c\u5c55\u5f00\u4e3a \"d\"
\uff0c\u800c PRIu64
\u53ef\u80fd\u5c55\u5f00\u4e3a \"llu\"
\u3002
\u8fd9\u4e9b\u5b9a\u4e49\u5728\u4e0d\u540c\u7684\u5e73\u53f0\u4e0a\u53ef\u80fd\u6709\u6240\u4e0d\u540c\u3002\u4f7f\u7528\u8fd9\u4e9b\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u53ef\u4ee5\u4fdd\u8bc1\u5728\u4e0d\u540c\u5e73\u53f0\u4e0a\u8f93\u51fa\u6b63\u786e\u7684\u7ed3\u679c\uff08\u4e14\u4e0d\u4f1a\u5f15\u53d1\u7f16\u8bd1\u5668\u8b66\u544a\uff09\u3002
uint64_t i = 0xdeadbeefcafebabe;\nprintf(\"%\" PRIu64 \"\\n\", i); // \u5e94\u5f53\u5305\u542b inttypes.h\n
\u5bf9\u4e8e size_t
\u548c ptrdiff_t
\uff0c\u53ef\u4ee5\u4f7f\u7528 %zu
\u548c %td
\u3002
"},{"location":"programming_lecture/lecture2/lecture2/#_9","title":"\u7ed3\u6784\u4f53\u3001\u8054\u5408\u4f53\u3001\u679a\u4e3e\u7c7b\u578b","text":"\u679a\u4e3e\u7c7b\u578b\u5b9e\u8d28\u4e0a\u662f\u6574\u6570\u7c7b\u578b\u3002\u5b83\u7684\u503c\u662f\u7531\u7f16\u8bd1\u5668\u81ea\u52a8\u5206\u914d\u7684\uff08\u4e00\u822c\u4ece 0 \u5f00\u59cb\uff09\uff0c\u4e5f\u53ef\u624b\u52a8\u6307\u5b9a\u3002
\u7ed3\u6784\u4f53\u7684\u5927\u5c0f\u662f\u5176\u6210\u5458\u5927\u5c0f\u7684\u603b\u548c\uff0c\u52a0\u4e0a\u5bf9\u9f50\u6240\u9700\u7684\u586b\u5145\u5b57\u8282\u3002
struct point {\n int x;\n long y;\n};\nstruct point p = {1234, -5678};\nMAGIC(p);\n\nunion un_t {\n long l;\n double d;\n};\nunion un_t un;\nun.d = 3.14159265358979323;\nMAGIC(un);\n\nenum en_t { ENA, ENB, ENC = 114514 };\nMAGIC_R(ENA);\nMAGIC_R(ENC);\n\nMAGIC_PTR(&p.x);\nMAGIC_PTR(&p.y);\nMAGIC_PTR(&un.l);\nMAGIC_PTR(&un.d);\n
\u5728\u5c0f\u7aef\u5e8f\u8ba1\u7b97\u673a\u4e0a\u53ef\u80fd\u7684\u8fd0\u884c\u7ed3\u679c =====\np: 16 (0x10) byte\n0000 d2 04 00 00 00 00 00 00 d2 e9 ff ff ff ff ff ff\n=====\nun: 8 (0x8) byte\n0000 18 2d 44 54 fb 21 09 40\n=====\nENA: 4 (0x4) bytes\n0000 00 00 00 00\n=====\nENC: 4 (0x4) bytes\n0000 52 bf 01 00\n&p.x: 0x16d3cee18\n&p.y: 0x16d3cee20\n&un.l: 0x16d3cee10\n&un.d: 0x16d3cee10\n
"},{"location":"programming_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
"},{"location":"programming_lecture/lecture2/lecture2/#typedef","title":"\u4f7f\u7528 typedef
\u4e3a\u73b0\u6709\u7684\u7c7b\u578b\u5b9a\u4e49\u522b\u540d","text":"int a;\n
\u4f60\u5df2\u7ecf\u5f88\u719f\u6089\u8fd9\u6837\u7684\u58f0\u660e\u4e86\uff0c\u5bf9\u5427\uff1fa
\u662f\u4e00\u4e2a int
\u7c7b\u578b\u7684\u53d8\u91cf\u3002
typedef int a;\n
\u8fd9\u5c31\u662f\u8bf4\uff0ca
\u73b0\u5728\u5c31\u662f int
\u7684\u522b\u540d\u3002\u4f60\u53ef\u4ee5\u8fd9\u6837\u4f7f\u7528\u5b83\uff1a
a b; // \u7b49\u4ef7\u4e8e int b;\n
\u6211\u4eec\u4e4b\u524d\u63d0\u5230\u8fc7\u7684 size_t
\u3001ptrdiff_t
\u3001int8_t
\u7b49\u7c7b\u578b\uff0c\u5c31\u662f\u901a\u8fc7 typedef
\u5b9a\u4e49\u7684\u3002
\u8003\u8bd5\u4e2d\u8fd8\u4f1a\u8981\u6c42\u4f60\u9605\u8bfb\u4ee3\u7801\u7247\u6bb5\uff0c\u4e3a\u5f62\u53c2\u7b49\u4f4d\u7f6e\u586b\u5199\u7c7b\u578b\u58f0\u660e\u3002\u8bf7\u53c2\u8003\u5386\u5e74\u5377\u603b\u7ed3\u4e2d\u7684\u4f8b\u9898\u3002
C \u4e0e C++ \u7684 struct
\u5e76\u4e0d\u5b8c\u5168\u4e00\u81f4
\u5bf9\u4e8e\u7ed3\u6784\u4f53
struct point {\n int x;\n int y;\n}\n
\u5728 C++ \u4e2d\uff0c\u6b64\u58f0\u660e\u5f15\u5165\u7684\u65b0\u7c7b\u578b\u540d\u4e3a point
\uff0c\u800c\u5728 C \u4e2d\uff0c\u6b64\u58f0\u660e\u5f15\u5165\u7684\u65b0\u7c7b\u578b\u540d\u4e3a struct point
\u3002point
\u672c\u8eab\u4e0d\u662f\u4e00\u4e2a\u7c7b\u578b\u540d\u3002
\u4e0b\u9762\u7684\u5199\u6cd5\u662f\u5e38\u89c1\u7684\uff1a
typedef struct point point;\n
\u6b64\u5373\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7c7b\u578b\u540d point
\uff0c\u5176\u4e3a struct point
\u7684\u522b\u540d\u3002
"},{"location":"programming_lecture/lecture2/lecture2/#_11","title":"\u5185\u5b58\u6a21\u578b","text":"\u5728 C \u8bed\u8a00\u7684\u5185\u5b58\u6a21\u578b\u4e2d\uff0c\u5b57\u8282\uff08byte\uff09\u662f\u6700\u5c0f\u7684\u53ef\u5bfb\u5740\u7684\u5185\u5b58\u5355\u5143\uff0c\u5176\u88ab\u5b9a\u4e49\u4e3a\u4e00\u7cfb\u5217\u8fde\u7eed\u7684\u4f4d\uff08bit\uff09\u3002\u53ef\u5bfb\u5740\u610f\u5473\u7740\u6bcf\u4e2a\u5b57\u8282\u90fd\u62e5\u6709\u5176\u7f16\u53f7\uff0c\u5373\u5730\u5740\u3002
MAGIC_PTR(&i);\nMAGIC_PTR(&ll);\nMAGIC_PTR(&d);\nMAGIC_PTR(&f);\n\nMAGIC_SIZED(f, 0x20);\n
"},{"location":"programming_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
\uff09 - \u901a\u8fc7
psi
\u53ef\u4ee5\u8bbf\u95ee i
\u5173\u8054\u7684\u5bf9\u8c61\uff08*psi
\uff09 psi
\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\u503c 2 * i
\u6216 &i
\u6216 &psi
\uff0c\u4e0d\u662f\u6807\u8bc6\u7b26\uff0c\u662f\u53f3\u503c
const 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":" - \u9759\u6001\u5b58\u50a8\u671f\uff08static\uff09 \u5728\u7a0b\u5e8f\u5f00\u59cb\u65f6\u521b\u5efa\uff0c\u5728\u7a0b\u5e8f\u7ed3\u675f\u65f6\u9500\u6bc1\u3002\u5982\u5168\u5c40\u53d8\u91cf\u548c\u9759\u6001\u53d8\u91cf\u3002
- \u81ea\u52a8\u5b58\u50a8\u671f\uff08automatic\uff09 \u5728\u7a0b\u5e8f\u8fdb\u5165\u4f5c\u7528\u57df\u65f6\u521b\u5efa\uff0c\u5728\u7a0b\u5e8f\u79bb\u5f00\u4f5c\u7528\u57df\u65f6\u9500\u6bc1\u3002\u5982\u5c40\u90e8\u53d8\u91cf\u3002
- \u52a8\u6001\u5206\u914d\u5b58\u50a8\u671f\uff08allocated\uff09 \u5728\u7a0b\u5e8f\u663e\u5f0f\u5730\u5206\u914d\u5185\u5b58\u65f6\u521b\u5efa\uff0c\u5728\u7a0b\u5e8f\u663e\u5f0f\u5730\u91ca\u653e\u5185\u5b58\u65f6\u9500\u6bc1\u3002\u5982
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
"},{"location":"programming_lecture/lecture2/lecture2/#_20","title":"\u51fd\u6570\u539f\u578b\u4f5c\u7528\u57df","text":"\u51fd\u6570\u539f\u578b\u4e2d\u7684\u53d8\u91cf\u540d\u3002\u4ece\u5b9a\u4e49\u5904\u5230\u51fd\u6570\u539f\u578b\u7ed3\u675f\u3002
\u53ea\u5728\u4f60\u4f7f\u7528 VLA \u65f6\u9700\u8981\u6ce8\u610f\u8fd9\u4e00\u987a\u5e8f\uff1a
void use_VLA(int n, int m, ar[n][m]);\n
"},{"location":"programming_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
- C \u7684\u8f93\u5165\u8f93\u51fa\u6a21\u578b\uff1a\u7f13\u51b2\u4e0e\u6d41\u7684\u6982\u5ff5
- C \u6807\u51c6 I/O \u51fd\u6570
- \u6587\u4ef6\u7f16\u7801\u4e0e\u6587\u4ef6\u8f93\u5165\u8f93\u51fa
"},{"location":"programming_lecture/lecture3/lecture3/#c","title":"C \u7684\u8f93\u5165\u8f93\u51fa\u6a21\u578b","text":""},{"location":"programming_lecture/lecture3/lecture3/#_1","title":"\u7f13\u51b2","text":"\u5e7f\u4e49\u7684\u7f13\u51b2\u533a\u662f\u5185\u5b58\u7a7a\u95f4\u7684\u4e00\u90e8\u5206\uff0c\u5728\u5185\u5b58\u4e2d\u9884\u7559\u4e86\u4e00\u5b9a\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c\u7528\u6765\u6682\u65f6\u4fdd\u5b58\u8f93\u5165\u548c\u8f93\u51fa\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
- buffer\u7f13\u51b2\u533a\u5b58\u50a8\u901f\u5ea6\u4e0d\u540c\u6b65\u7684\u8bbe\u5907\u6216\u8005\u4f18\u5148\u7ea7\u4e0d\u540c\u7684\u8bbe\u5907\u4e4b\u95f4\u7684\u4f20\u8f93\u6570\u636e\uff0c\u6bd4\u5982\u952e\u76d8\u3001\u9f20\u6807\u7b49\uff1b\u6b64\u5916\uff0cbuffer\u4e00\u822c\u662f\u7528\u5728\u5199\u5165\u78c1\u76d8\u7684\uff1b
- Cache\u7f13\u5b58\u533a\u662f\u4f4d\u4e8eCPU\u548c\u4e3b\u5185\u5b58\u4e4b\u95f4\u7684\u5bb9\u91cf\u8f83\u5c0f\u4f46\u901f\u5ea6\u5f88\u5feb\u7684\u5b58\u50a8\u5668\uff0cCache\u4fdd\u5b58\u7740CPU\u521a\u7528\u8fc7\u7684\u6570\u636e\u6216\u5faa\u73af\u4f7f\u7528\u7684\u6570\u636e\uff1bCache\u7f13\u5b58\u533a\u7684\u8fd0\u7528\u4e00\u822c\u662f\u5728I/O\u7684\u8bf7\u6c42\u4e0a
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
- \u5b8c\u5168\u7f13\u51b2\uff1a\u4ec5\u7f13\u51b2\u533a\u586b\u6ee1\u65f6\u5237\u65b0\u7f13\u51b2\u533a\uff08\u5c06\u5185\u5bb9\u53d1\u9001\u81f3\u76ee\u7684\u5730\uff09\uff0c\u901a\u5e38\u7528\u4e8e\u6587\u4ef6\u8f93\u5165\u3002\u7f13\u51b2\u533a\u7684\u5927\u5c0f\u53d6\u51b3\u4e8e\u7cfb\u7edf\uff0c\u5e38\u89c1\u5927\u5c0f\u4e3a512bits\u548c4096bits\u3002
- \u884c\u7f13\u51b2\uff1a\u51fa\u73b0\u6362\u884c\u7b26\u65f6\u5237\u65b0\u7f13\u51b2\u533a\uff0c\u901a\u5e38\u7528\u4e8e\u952e\u76d8\u8f93\u5165\u3002\u6240\u4ee5\u5728\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
\u6211\u53ef\u4ee5\u66f4\u6539\u8f93\u5165\u65b9\u5f0f\u5417\uff1f UNIX \u5e93\u4e2d\u6709 ioctl()
\u51fd\u6570\u7528\u4e8e\u6307\u5b9a\u5f85\u8f93\u5165\u7684\u7c7b\u578b\uff0c\u4f46\u8fd9\u4e0d\u5c5e\u4e8e C \u6807\u51c6\u3002
ANSI C \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 setbuf()
\u548c setvbuf()
\u63a7\u5236\u7f13\u51b2\uff0c\u4f46\u53d7\u9650\u4e8e\u7cfb\u7edf\u7684\u8bbe\u7f6e\u3002
"},{"location":"programming_lecture/lecture3/lecture3/#_2","title":"\u6d41","text":"C \u5e93\u63d0\u4f9b\u7684\u8f93\u5165\u8f93\u51fa\u65b9\u5f0f\u79f0\u4e3a\u6807\u51c6 I/O\uff0c\u5b83\u4eec\u662f\u5efa\u7acb\u5728\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u5e95\u5c42 I/O \u4e0a\u7684\u3002\u5e95\u5c42 I/O \u4e4b\u95f4\u5e38\u5e38\u4f1a\u6709\u4e00\u4e9b\u5dee\u5f02\uff1a
\u5404\u4e2a\u7cfb\u7edf\u7684\u6587\u4ef6\u5dee\u5f02
\u5dee\u5f02 UNIX Windows MacOS \u6362\u884c\u7b26 \\n
LF \\r\\n
CRLF \\n
(\u8f83\u65e9\u7684 MacOS \u4f7f\u7528 \\r
)LF \u6587\u4ef6\u7ed3\u675f\u7b26 ^D
^Z
^D
\u6ce8\uff1a\u5982 ^Z
\u4ee3\u8868 Ctrl+Z
\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8be5\u7ec4\u5408\u952e\u7ed3\u675f\u952e\u76d8\u8f93\u5165\u3002
\u6587\u4ef6\u7ed3\u5c3e\u4e5f\u4e0d\u4e00\u5b9a\u7531\u6587\u4ef6\u7ed3\u675f\u7b26\u6807\u8bb0\u3002\u4e8b\u5b9e\u4e0a\uff0cUNIX \u7cfb\u7edf\u50a8\u5b58\u6587\u4ef6\u5927\u5c0f\u4fe1\u606f\uff0c\u4f9d\u636e\u6587\u4ef6\u5927\u5c0f\u4fe1\u606f\u51b3\u5b9a\u6587\u4ef6\u672b\u5c3e\u3002
\u4ece\u6982\u5ff5\u4e0a\u770b\uff0cC \u5904\u7406\u7684\u662f\u6d41\u800c\u4e0d\u662f\u6587\u4ef6\u3002\u4e0d\u540c\u5c5e\u6027\u548c\u4e0d\u540c\u79cd\u7c7b\u7684\u8f93\u5165\uff0c\u7531\u5c5e\u6027\u66f4\u7edf\u4e00\u7684\u6d41\u6765\u8868\u793a\u3002\u6d41\u544a\u8bc9\u6211\u4eec\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u5904\u7406\u6587\u4ef6\u7684\u65b9\u5f0f\u6765\u5904\u7406\u952e\u76d8\u8f93\u5165\u3002
C\u8bed\u8a00\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
- \u4e0e\u6807\u51c6\u8f93\u5165\u6d41\u5173\u8054\uff0c\u7528\u4e8e\u8bfb\u53d6\u4f20\u7edf\u7684\u8f93\u5165\u3002\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u5f53\u4e14\u4ec5\u5f53\u80fd\u786e\u5b9a\u6d41\u4e0d\u5f15\u7528\u4ea4\u4e92\u5f0f\u8bbe\u5907\u65f6\u8be5\u6d41\u4e3a\u5b8c\u5168\u7f13\u51b2\u3002
- \u4e0e\u6807\u51c6\u8f93\u51fa\u6d41\u5173\u8054\uff0c\u7528\u4e8e\u5199\u5165\u4f20\u7edf\u7684\u8f93\u51fa\u3002\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u5f53\u4e14\u4ec5\u5f53\u80fd\u786e\u5b9a\u6d41\u4e0d\u5f15\u7528\u4ea4\u4e92\u5f0f\u8bbe\u5907\u65f6\u8be5\u6d41\u4e3a\u5b8c\u5168\u7f13\u51b2\u3002
- \u4e0e\u6807\u51c6\u9519\u8bef\u6d41\u5173\u8054\uff0c\u7528\u4e8e\u5199\u5165\u8bca\u65ad\u8f93\u51fa\u3002\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u8be5\u6d41\u4e0d\u4e3a\u5b8c\u5168\u7f13\u51b2\u3002
\u6587\u4ef6\u63cf\u8ff0\u7b26
\u5f53\u4e00\u4e2a\u7a0b\u5e8f\u6210\u529f\u5411\u64cd\u4f5c\u7cfb\u7edf\u8bf7\u6c42\u8bbf\u95ee\u4e00\u4e2a\u6253\u5f00\u7684\u6587\u4ef6, \u5185\u6838\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6307\u5411\u5185\u6838\u4e2d\u5168\u5c40\u6587\u4ef6\u8868(global file table)\u4e2d\u7684\u5165\u53e3\u70b9(entry)\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26. \u6587\u4ef6\u8868\u5165\u53e3\u70b9\u5305\u542b\u5982: \u6587\u4ef6\u7684inode(\u786c\u76d8\u4e2d\u7684\u4f4d\u7f6e), \u5b57\u8282\u504f\u79fb\u91cf(byte offset), \u4ee5\u53ca\u5bf9\u8fd9\u4e2a\u6570\u636e\u6d41\u7684\u8bbf\u95ee\u9650\u5236(\u53ea\u8bfb, \u53ea\u5199\u7b49)\u3002
\u6587\u4ef6\u63cf\u8ff0\u7b26: \u662f\u8ba1\u7b97\u673a\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u88ab\u6253\u5f00\u6587\u4ef6\u7684\u552f\u4e00\u6807\u8bc6. \u5b83\u7528\u6765\u63cf\u8ff0\u4e00\u79cd\u6570\u636e\u8d44\u6e90, \u4ee5\u53ca\u8fd9\u4e2a\u6570\u636e\u8d44\u6e90\u53ef\u4ee5\u5982\u4f55\u88ab\u8bbf\u95ee\u5230\u3002
\u5728 Unix \u7cfb\u7edf\u5f53\u4e2d, \u524d\u4e09\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b260, 1, 2 \u9ed8\u8ba4\u4e3a stdin stdout stderr
"},{"location":"programming_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
"},{"location":"programming_lecture/lecture3/lecture3/#_6","title":"\u65e0\u683c\u5f0f\u8f93\u5165/\u8f93\u51fa","text":"\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
\u529f\u80fd \u51fd\u6570 \u5931\u8d25\u8fd4\u56de\u503c int getchar(void)
int getc(FILE *stream)
int fgetc(FILE *stream)
\u5355\u5b57\u7b26\u8f93\u5165 EOF char *fgets(char *s, int size, FILE *stream)
char *gets_s( char *str, rsize_t n)
\u5b57\u7b26\u4e32\u8f93\u5165 NULL int ungetc(int c, FILE *stream)
\u653e\u56de\u6587\u4ef6\u6d41 EOF int putchar(int c)
int putc(int c, FILE *stream)
int fputc(int c, FILE *stream)
\u5355\u5b57\u7b26\u8f93\u51fa EOF int puts(const char *s)
int fputs(const char *s, FILE *stream)
\u5b57\u7b26\u4e32\u8f93\u51fa EOF \u6ce8\u610f
-
\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()
?
\u90a3\u4e48\u8fd9\u662f\u5426\u4f1a\u9020\u6210 EOF \u4e0d\u80fd\u88ab\u8bc6\u522b\uff0c\u800c\u662f\u88ab\u770b\u4f5c\u5b57\u7b26\u5462\uff1f #define EOF (-1) // unsigned char\u8f6c\u6362\u6210int\u540e\uff0c\u503c\u90fd\u5927\u4e8e\u7b49\u4e8e0\n
\u5bbd\u5b57\u7b26\u8f93\u5165\u8f93\u51fa\u5b9a\u4e49\u4e8e <wchar.h>
\u5934\u6587\u4ef6\u4e2d\uff0c\u533a\u522b\u5728\u4e8e\u5176\u4e00\u4e2a\u5b57\u7b26\u7684\u957f\u5ea6\u4e0d\u540c\u3002C\u8bed\u8a00\u4e2d\u6709\u4e00\u79cd\u7c7b\u578bwchar_t
,\u5176\u957f\u5ea6\u53d6\u51b3\u4e8e\u7f16\u8bd1\u5668\uff1a
- \u5728msvc\u4e2d\uff0c
wchar_t
\u4e3a16\u4f4d\uff0c\u5373unsigned short
\u7c7b\u578b\u3002 - \u5728gcc/Clang\u4e2d\uff0c
wchar_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
\u529f\u80fd \u51fd\u6570 \u5931\u8d25\u8fd4\u56de\u503c int getwchar(void)
int getwc(FILE *stream)
int fgetwc(FILE *stream)
\u5355\u5b57\u7b26\u8f93\u5165 EOF char *fgetws(char *s, int size, FILE *stream)
\u5b57\u7b26\u4e32\u8f93\u5165 NULL int ungetwc(int c, FILE *stream)
\u653e\u56de\u6587\u4ef6\u6d41 EOF int putwchar(int c)
int fputwc(int c, FILE *stream)` \u5355\u5b57\u7b26\u8f93\u51fa EOF int fputws(const char *s, FILE *stream)
\u5b57\u7b26\u4e32\u8f93\u51fa EOF"},{"location":"programming_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
"},{"location":"programming_lecture/lecture3/lecture3/#_8","title":"\u683c\u5f0f\u5b57\u7b26\u4e32","text":"\u683c\u5f0f\u5b57\u7b26\u4e32const char *format
\u7531\u666e\u901a\u591a\u5b57\u8282\u5b57\u7b26\uff08\u9664\u4e86%\uff09\u548c\u8f6c\u6362\u6307\u793a\u6784\u6210\uff0c\u524d\u8005\u88ab\u590d\u5236\u5230\u8f93\u51fa\u6d41\u800c\u65e0\u66f4\u6539\u3002\u6bcf\u4e2a\u8f6c\u6362\u6307\u793a\u62e5\u6709\u4e0b\u5217\u683c\u5f0f\uff1a
- \u5f15\u5165\u7684 % \u5b57\u7b26
- (\u53ef\u9009)\u4e00\u6216\u591a\u4e2a\u4fee\u6539\u8f6c\u6362\u884c\u4e3a\u7684\u6807\u7b7e\uff1a
- - : \u8f6c\u6362\u7ed3\u679c\u5728\u57df\u5185\u5de6\u6821\u6b63\uff08\u9ed8\u8ba4\u4e3a\u53f3\u6821\u6b63\uff09
- +:\u6709\u7b26\u53f7\u8f6c\u6362\u7684\u7b26\u53f7\u59cb\u7ec8\u524d\u7f6e\u4e8e\u8f6c\u6362\u7ed3\u679c\uff08\u9ed8\u8ba4\u7ed3\u679c\u524d\u7f6e\u8d1f\u53f7\u4ec5\u5f53\u5b83\u4e3a\u8d1f\uff09
- \u7a7a\u683c\uff1a\u82e5\u6709\u7b26\u53f7\u8f6c\u6362\u7684\u7ed3\u679c\u4e0d\u4ee5\u7b26\u53f7\u5f00\u59cb\uff0c\u6216\u4e3a\u7a7a\uff0c\u5219\u524d\u7f6e\u7a7a\u683c\u4e8e\u7ed3\u679c\u3002\u82e5\u5b58\u5728 + \u6807\u7b7e\u5219\u5ffd\u7565\u7a7a\u683c\u3002
- # \uff1a\u8fdb\u884c\u66ff\u7528\u5f62\u5f0f\u7684\u8f6c\u6362\u3002\u51c6\u786e\u7684\u6548\u679c\u89c1\u4e0b\u8868\uff0c\u5176\u4ed6\u60c5\u51b5\u4e0b\u884c\u4e3a\u672a\u5b9a\u4e49\u3002
- 0 \uff1a\u5bf9\u4e8e\u6574\u6570\u548c\u6d6e\u70b9\u6570\u8f6c\u6362\uff0c\u4f7f\u7528\u524d\u5bfc\u96f6\u4ee3\u66ff\u7a7a\u683c\u5b57\u7b26\u586b\u5145\u57df\u3002\u5bf9\u4e8e\u6574\u6570\uff0c\u82e5\u663e\u5f0f\u6307\u5b9a\u7cbe\u5ea6\uff0c\u5219\u5ffd\u7565\u6b64\u6807\u7b7e\u3002\u5bf9\u4e8e\u5176\u4ed6\u8f6c\u6362\uff0c\u4f7f\u7528\u6b64\u6807\u7b7e\u5bfc\u81f4\u672a\u5b9a\u4e49\u884c\u4e3a\u3002\u82e5\u5b58\u5728 - \u6807\u7b7e\u5219\u5ffd\u7565 0 \u3002
- (\u53ef\u9009)\u6307\u5b9a\u6700\u5c0f\u57df\u5bbd\u7684\u6574\u6570\u503c\u6216
*
\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 - (\u53ef\u9009)\u540e\u968f\u6574\u6570\u6216
*
\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\u3002 - (\u53ef\u9009)\u6307\u5b9a\u53c2\u6570\u5927\u5c0f\u7684\u957f\u5ea6\u4fee\u9970\u7b26
- \u8f6c\u6362\u683c\u5f0f\u6307\u793a\u7b26
"},{"location":"programming_lecture/lecture3/lecture3/#printf","title":"printf()
\u4e2d\u8f6c\u6362\u8bf4\u660e\u7684\u610f\u4e49","text":"\u8f6c\u6362\u8bf4\u660e\u5b9e\u9645\u4e0a\u662f\u5728\u5c06\u4ee5\u4e8c\u8fdb\u5236\u5b58\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u4e2d\u7684\u503c\u8f6c\u6362\u6210\u4e00\u4e9b\u5217\u5b57\u7b26\u4fbf\u4e8e\u663e\u793a\u3002\u8f6c\u6362\u5b9e\u9645\u4e0a\u662f\u4e00\u79cd\u7ffb\u8bd1\u8bf4\u660e\u3002
\u4f8b\u5982\uff1ad
\uff1a\u5c06\u4e00\u4e2a\u6709\u7b26\u53f7\u7684\u5341\u8fdb\u5236\u6574\u6570\u8f6c\u6362\u6210\u5341\u8fdb\u5236\u6570\u3002
\u4e0b\u9762\u8ba8\u8bba\u51e0\u79cd\u8f6c\u6362\u8bf4\u660e\u7684\u60c5\u51b5\uff1a
-
\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
"},{"location":"programming_lecture/lecture3/lecture3/#scanf","title":"scanf()
","text":"\u5728\u524d\u9762\u6211\u4eec\u4ecb\u7ecd\u4e86printf()
\u4e2d\u7684\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u548c\u8f6c\u6362\u8bf4\u660e\uff0cscanf()
\u4e2d\u4e5f\u6709\u7c7b\u4f3c\u7684\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u548c\u8f6c\u6362\u8bf4\u660e\u3002
\u590d\u6742\u7684\u4f7f\u7528\u65b9\u6cd5\u8bf7\u67e5\u9605scanf\u3002
\u4e0b\u9762\u4ecb\u7ecd\u4e00\u4e9bscanf()
\u7684\u7279\u6027\uff1a
-
scanf()
\u8981\u5c06\u8bfb\u53d6\u7684\u5185\u5bb9\u5b58\u50a8\u5230\u5bf9\u5e94\u53d8\u91cf\u5730\u5740\u4e2d\uff0c\u800c\u4e0d\u662f\u53d8\u91cf\u540d\u3002\u56e0\u6b64\uff0cscanf()
\u7684\u53c2\u6570\u5e94\u8be5\u662f\u53d8\u91cf\u7684\u5730\u5740\u3002
e.g. scanf.c#include <stdio.h>\n#include <stdio.h>\nint main(void)\n{\n int a;\n float b;\n char str[30];\n int c[10];\n\n scanf(\"%d %f\", &a, &b); // \u8bfb\u53d6\u6574\u6570\u548c\u6d6e\u70b9\u6570\n scanf(\"%s\", str); // \u8bfb\u53d6\u5b57\u7b26\u4e32\n scanf(\"%d\", c); // \u8bfb\u53d6\u6574\u6570\u6570\u7ec4\n return 0;\n}\n
-
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
"},{"location":"programming_lecture/lecture3/lecture3/#_9","title":"\u5b9e\u4f8b","text":""},{"location":"programming_lecture/lecture3/lecture3/#_10","title":"\u5b89\u5168\u7684\u8f93\u5165\u51fd\u6570","text":"\u5199\u4e00\u4e2a\u5b89\u5168\u7684\u8f93\u5165\u51fd\u6570
\u4f17\u6240\u5468\u77e5\uff0cC\u8bed\u8a00\u7684gets
\u51fd\u6570\u662f\u4e00\u4e2a\u975e\u5e38\u4e0d\u5b89\u5168\u7684\u51fd\u6570(\u8bf7\u53c2\u8003\u7cfb\u7edf\u77e5\u8bc6\u62fe\u90571)\uff0c\u5728C11\u4e2d\u88ab\u5f03\u7528\uff0c\u8f6c\u4e3agets_s()
\u3002gets()
\u6781\u6709\u53ef\u80fd\u9020\u6210\u7f13\u51b2\u533a\u6ea2\u51fa\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u5199\u4e00\u4e2a\u5b89\u5168\u7684\u8f93\u5165\u51fd\u6570\u3002
s_gets.cchar * 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
"},{"location":"programming_lecture/lecture3/lecture3/#_12","title":"\u6587\u4ef6\u7f16\u7801\u4e0e\u6587\u4ef6\u8f93\u5165\u8f93\u51fa","text":""},{"location":"programming_lecture/lecture3/lecture3/#_13","title":"\u57fa\u7840\u6982\u5ff5","text":""},{"location":"programming_lecture/lecture3/lecture3/#_14","title":"\u4ec0\u4e48\u662f\u6587\u4ef6\uff1f","text":"\u7b80\u5355\u7684\u8bf4\uff0c\u6587\u4ef6\u662f\u5728\u786c\u76d8\u4e0a\u7684\u4e00\u6bb5\u5df2\u547d\u540d\u7684\u50a8\u5b58\u533a\u3002
\u5bf9\u64cd\u4f5c\u7cfb\u7edf\u800c\u8a00\uff0c\u6587\u4ef6\u66f4\u52a0\u590d\u6742\u3002\u6587\u4ef6\u662f\u5177\u6709\u7b26\u53f7\u540d\u7684\uff0c\u5728\u903b\u8f91\u4e0a\u5177\u6709\u5b8c\u6574\u610f\u4e49\u7684\u4e00\u7ec4\u76f8\u5173\u4fe1\u606f\u9879\u7684\u5e8f\u5217\u3002\u6587\u4ef6\u8fd8\u5305\u62ec\u4e86\u4e00\u4e9b\u989d\u5916\u6570\u636e\uff0c\u4fbf\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u786e\u5b9a\u6587\u4ef6\u7684\u79cd\u7c7b\u3002
c_file.c#include<stdio.h>\n#include<string.h>\n\nint main(int argc, char *argv[]){\n const char *str = \"ckc-agc programming lec3\";\n\n FILE *fp1 = fopen(\"test1.txt\", \"wb+\");\n FILE *fp2 = fopen(\"test2.txt\", \"w+\");\n fprintf(fp1, \"%s\\n%s\\n\", str, argv[0]);\n fprintf(fp2, \"%s\\n%s\\n\", str, argv[0]);\n fwrite(str, sizeof(char), strlen(str), fp1);\n\n // fseek(fp1, 0, SEEK_SET);\n // fprintf(fp1, \"%s\\n\", \"SEEK_SET\");\n fseek(fp1, 0, SEEK_END);\n fprintf(fp1, \"%s\\n\", \"SEEK_END\");\n\n rewind(fp1);\n fprintf(fp1, \"%s\\n\", \"rewind\");\n\n fclose(fp1);\n fclose(fp2);\n}\n
$ file c_file.c\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
- ASCII\u5b57\u7b26\u96c6\uff1a 8bit\uff08\u4e00\u4e2a\u5b57\u8282\uff09\uff0c\u80fd\u8868\u793a\u7684\u6700\u5927\u7684\u6574\u6570\u5c31\u662f255\uff082^8-1=255\uff09\u3002ASCII\u7f16\u7801\uff0c\u5360\u75280 - 127\u7528\u6765\u8868\u793a\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e00\u4e9b\u7b26\u53f7\uff0c\u8fd9\u4e2a\u7f16\u7801\u8868\u88ab\u79f0\u4e3aASCII\u7f16\u7801\uff0c\u6bd4\u5982\u5927\u5199\u5b57\u6bcdA\u7684\u7f16\u7801\u662f65\uff0c\u5c0f\u5199\u5b57\u6bcdz\u7684\u7f16\u7801\u662f122\u3002 \u8fd8\u5bf9\u4e00\u4e9b\u5982'\\n'\uff0c'\\t'\uff0c'#'\uff0c'@'\u7b49\u5b57\u7b26\u8fdb\u884c\u4e86\u7f16\u7801\u3002
- base\u5bb6\u65cf\u7f16\u7801:(base16/base32/base64/base58/base85/base100) \u4f7f\u7528\u5bf9\u5e94\u6570\u91cf\u7684\u5b57\u7b26\u7f16\u7801\u4e8c\u8fdb\u5236\u6570\u636e
- GB2312\u7f16\u7801\uff1a 16bit\uff082\u4e2a\u5b57\u8282\uff09\uff0c\u9002\u7528\u4e8e\u6c49\u5b57\u5904\u7406\u3001\u6c49\u5b57\u901a\u4fe1\u7b49\u7cfb\u7edf\u4e4b\u95f4\u7684\u4fe1\u606f\u4ea4\u6362\uff0c\u901a\u884c\u4e8e\u4e2d\u56fd\u5927\u9646\u3002\u4e2d\u56fd\u5927\u9646\u51e0\u4e4e\u6240\u6709\u7684\u4e2d\u6587\u7cfb\u7edf\u548c\u56fd\u9645\u5316\u7684\u8f6f\u4ef6\u90fd\u652f\u6301GB2312\u3002
- GBK\u7f16\u7801\uff1a 16bit\uff082\u4e2a\u5b57\u8282\uff09\uff0c\u517c\u5bb9GB2312\uff0c\u6536\u5f5521003 \u4e2a\u6c49\u5b57\uff0c\u5171\u6709 23940 \u4e2a\u7801\u4f4d\uff0c\u4e0eUnicode\u7ec4\u7ec7\u7684Unicode\u7f16\u7801\u5b8c\u5168\u517c\u5bb9\u3002
- Unicode\u5b57\u7b26\u96c6\uff1a \u4e3a\u4e86\u7edf\u4e00\u6240\u6709\u6587\u5b57\u7684\u7f16\u7801\uff0cUnicode\u5e94\u8fd0\u800c\u751f\uff0c\u8fd9\u662f\u4e00\u79cd\u6240\u6709\u7b26\u53f7\u7684\u7f16\u7801\u3002Unicode \u662f\u56fd\u9645\u6807\u51c6\u5b57\u7b26\u96c6\uff0c\u5b83\u5c06\u4e16\u754c\u5404\u79cd\u8bed\u8a00\u7684\u6bcf\u4e2a\u5b57\u7b26\u5b9a\u4e49\u4e00\u4e2a\u552f\u4e00\u7684\u7f16\u7801\uff0c\u4ee5\u6ee1\u8db3\u8de8\u8bed\u8a00\u3001\u8de8\u5e73\u53f0\u7684\u6587\u672c\u4fe1\u606f\u8f6c\u6362Unicode \u5b57\u7b26\u96c6\u7684\u7f16\u7801\u8303\u56f4\u662f 0x0000 - 0x10FFFF , \u53ef\u4ee5\u5bb9\u7eb3\u4e00\u767e\u591a\u4e07\u4e2a\u5b57\u7b26\uff0c \u6bcf\u4e2a\u5b57\u7b26\u90fd\u6709\u4e00\u4e2a\u72ec\u4e00\u65e0\u4e8c\u7684\u7f16\u7801\uff0c\u4e5f\u5373\u6bcf\u4e2a\u5b57\u7b26\u90fd\u6709\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u503c\u548c\u5b83\u5bf9\u5e94\uff0c\u8fd9\u91cc\u7684\u4e8c\u8fdb\u5236\u6570\u503c\u4e5f\u53eb\u7801\u70b9
- UTF(UTF-8,UTF-16\u7b49)\uff1a Unicode Transformation Format\uff0c\u53ef\u53d8\u957f\u5ea6\u7f16\u7801\uff0c\u901a\u5e38\u4f7f\u75281~4\u5b57\u8282\u4e3a\u6bcf\u4e2a\u5b57\u7b26\u7f16\u7801\uff0c\u517c\u5bb9ASCII\u7f16\u7801\uff0c\u8fd9\u662f\u4e00\u79cdUnicode\u7684\u4e00\u79cd\u8f6c\u6362\u683c\u5f0f\u3002
\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
\u6807\u51c6\u6587\u4ef6 C\u7a0b\u5e8f\u4f1a\u81ea\u52a8\u6253\u5f003\u4e2a\u6587\u4ef6\uff0c\u5b83\u4eec\u88ab\u79f0\u4e3a\u6807\u51c6\u8f93\u5165\uff08standard input\uff09\u3001\u6807\u51c6\u8f93\u51fa\uff08standard output\uff09\u548c\u6807\u51c6\u9519\u8bef\u8f93\u51fa\uff08standard error output\uff09\u3002\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6807\u51c6\u8f93\u5165\u662f\u7cfb\u7edf\u7684\u666e\u901a\u8f93\u5165\u8bbe\u5907\uff0c\u901a\u5e38\u4e3a\u952e\u76d8\uff1b\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u662f\u7cfb\u7edf\u7684\u666e\u901a\u8f93\u51fa\u8bbe\u5907\uff0c\u901a\u5e38\u4e3a\u663e\u793a\u5c4f\u3002
\u901a\u5e38\uff0c\u6807\u51c6\u8f93\u5165\u4e3a\u7a0b\u5e8f\u63d0\u4f9b\u8f93\u5165\uff0c\u5b83\u662f getchar()
\u548c scanf()
\u4f7f\u7528\u7684\u6587\u4ef6\u3002\u7a0b\u5e8f\u901a\u5e38\u8f93\u51fa\u5230\u6807\u51c6\u8f93\u51fa\uff0c\u5b83\u662fputchar()
\u3001puts()
\u548cprintf()
\u4f7f\u7528\u7684\u6587\u4ef6\u3002\u524d\u6587\u63d0\u5230\u7684\u91cd\u5b9a\u5411\u628a\u5176\u4ed6\u6587\u4ef6\u89c6\u4e3a\u6807\u51c6\u8f93\u5165\u6216\u6807\u51c6\u8f93\u51fa\u3002\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u63d0\u4f9b\u4e86\u4e00\u4e2a\u903b\u8f91\u4e0a\u4e0d\u540c\u7684\u5730\u65b9\u6765\u53d1\u9001\u9519\u8bef\u6d88\u606f\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f7f\u7528\u91cd\u5b9a\u5411\u628a\u8f93\u51fa\u53d1\u9001\u7ed9\u6587\u4ef6\u800c\u4e0d\u662f\u5c4f\u5e55\uff0c\u90a3\u4e48\u53d1\u9001\u81f3\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u7684\u5185\u5bb9\u4ecd\u7136\u4f1a\u88ab\u53d1\u9001\u5230\u5c4f\u5e55\u4e0a\u3002\u8fd9\u6837\u5f88\u597d\uff0c\u56e0\u4e3a\u5982\u679c\u628a\u9519\u8bef\u6d88\u606f\u53d1\u9001\u81f3\u6587\u4ef6\uff0c\u5c31\u53ea\u80fd\u6253\u5f00\u6587\u4ef6\u624d\u80fd\u770b\u5230\u3002
\u7406\u89e3\uff1a\u6807\u51c6I/O\u4e2d\u7528FILE\uff08\u6d41\uff09\u8868\u793a\u4e00\u4e2a\u6253\u5f00\u7684\u6587\u4ef6
"},{"location":"programming_lecture/lecture3/lecture3/#_17","title":"\u6d41\u548c\u6587\u4ef6","text":"C \u6807\u51c6\u662f\u8fd9\u6837\u63cf\u8ff0\u4e24\u79cd\u6d41\u7684\uff1a
- \u6587\u672c\u6d41\uff1a\u7ec4\u6210\u6587\u672c\u884c\u7684\u6709\u5e8f\u5b57\u7b26\u5e8f\u5217\uff0c\u6bcf\u4e00\u884c\u7531\u96f6\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u52a0\u4e0a\u6807\u5fd7\u7ed3\u675f\u7684\u6362\u884c\u7b26\u7ec4\u6210\u3002
- \u5b9e\u73b0\u5b9a\u4e49\uff1a\u6700\u540e\u4e00\u884c\u662f\u5426\u9700\u8981\u6362\u884c\u7b26\u3001\u6362\u884c\u7b26\u6b63\u524d\u9762\u7684\u7a7a\u683c\u662f\u5426\u5728\u8bfb\u53d6\u65f6\u51fa\u73b0\u7b49\u3002
- \u4e8c\u8fdb\u5236\u6d41\uff1a\u5b57\u7b26\u7684\u6709\u5e8f\u5e8f\u5217\u3002
\u5173\u4e8e\u6587\u4ef6\u52a8\u4f5c\uff1a
- \u6253\u5f00\u6587\u4ef6\uff1a\u6d41\u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\uff0c\u5c31\u662f\u4e0e\u8be5\u6587\u4ef6\u5173\u8054\u3002
- \u521b\u5efa\u6587\u4ef6\u4f1a\u4e22\u5f03\u5185\u5bb9\u3002
- \u548c\u6d41\u76f8\u5173\u7684\u6587\u4ef6\u5b9a\u4f4d\u7b26\u5b9a\u4f4d\u5728\u6587\u4ef6\u8d77\u59cb\u4f4d\u7f6e\u3002
- \u9644\u52a0\u6a21\u5f0f\u4e0b\u5b9a\u4f4d\u4f4d\u7f6e\u7531\u5b9e\u73b0\u51b3\u5b9a\u3002
- \u5173\u95ed\u6587\u4ef6\uff1a\u5173\u95ed\u6587\u4ef6\u4f1a\u91ca\u653e\u4e0e\u8be5\u6587\u4ef6\u76f8\u5173\u7684\u8d44\u6e90\u3002
"},{"location":"programming_lecture/lecture3/lecture3/#_18","title":"\u7c7b\u578b\u548c\u5b8f","text":"\u5728 <stdio.h>
\u4e2d\u6709\u5982\u4e0b\u4e0e\u6587\u4ef6\u76f8\u5173\u7684\u7c7b\u578b\u548c\u5b8f\uff1a
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\u3002 - \u4e0d\u8981\u8bd5\u56fe\u63a2\u7d22
FILE *
\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\u3002
fpos_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\u3002 stderr
, stdin
, stdout
\u90fd\u662f FILE*
\u7c7b\u578b\u7684\u8868\u8fbe\u5f0f\u3002 EOF
\u5c55\u5f00\u4e3a\u4e00\u4e2a\u8d1f\u7684\u6574\u503c\u5e38\u91cf\u3002 NULL
SEEK_CUR
\u6587\u4ef6\u5f53\u524d\u4f4d\u7f6e SEEK_END
\u6587\u4ef6\u7ed3\u675f\u4f4d\u7f6e SEEK_SET
\u6587\u4ef6\u5f00\u59cb\u4f4d\u7f6e
"},{"location":"programming_lecture/lecture3/lecture3/#_19","title":"\u51fd\u6570","text":""},{"location":"programming_lecture/lecture3/lecture3/#_20","title":"\u6587\u4ef6\u64cd\u4f5c\uff1a","text":" int remove (const char *filename)
int rename (const char *old, const char *new)
FILE *tmpfile(void)
char * tmpnam(char *s)
"},{"location":"programming_lecture/lecture3/lecture3/#_21","title":"\u6587\u4ef6\u8bbf\u95ee\uff1a","text":" int fclose(FILE *stream)
- \u5173\u95ed\u6587\u4ef6\uff0c\u6e05\u7a7a\u6d41\uff08\u6e05\u7a7a\u6d41\u5c31\u662f\u4f20\u9012\u7f13\u51b2\u6570\u636e\uff09\uff0c\u91ca\u653e\u7f13\u51b2\u3002
int fflush(FILE *stream)
- \u7acb\u5373\u5199\u5165\uff08\u8981\u6c42\u4e0a\u4e00\u6b21\u64cd\u4f5c\u662f\u8f93\u51fa\uff09\u3002
FILE *fopen(const char *filename, const char *mode)
- \u6253\u5f00\u6587\u4ef6\uff0c\u8fd4\u56de\u6587\u4ef6\u6d41\u6307\u9488\u3002
FILE *freopen(const char *filename, const char *mode, FILE *stream)
void setbuf(FILE *stream, char *buf)
- \u5b9a\u4e49\u6d41 stream \u5e94\u5982\u4f55\u7f13\u51b2\u3002\u8be5\u51fd\u6570\u5e94\u5728\u4e0e\u6d41 stream \u76f8\u5173\u7684\u6587\u4ef6\u88ab\u6253\u5f00\u65f6\uff0c\u4e14\u8fd8\u672a\u53d1\u751f\u4efb\u4f55\u8f93\u5165\u6216\u8f93\u51fa\u64cd\u4f5c\u4e4b\u524d\u88ab\u8c03\u7528\u4e00\u6b21
int setvbuf(FILE *stream, char *buf, int mode, size_t size)
- \u521b\u5efa\u4f9b\u6807\u51c6I/O\u51fd\u6570\u66ff\u6362\u4f7f\u7528\u7684\u7f13\u51b2\u533a
"},{"location":"programming_lecture/lecture3/lecture3/#mode","title":"mode \u5b57\u7b26\u4e32\u7684\u542b\u4e49\uff1a","text":"flag meaning r read w write (new or cut) a append (new or append) b binary + update \u6ce8\u610f\u4e0a\u9762\u8bcd\u8bed\u7684\u542b\u4e49\uff0cupdate \u548c append \u80fd\u5199\u5165\u7684\u8303\u56f4\u5e94\u8be5\u662f\u4e0d\u540c\u7684\u3002
- append \u6a21\u5f0f\u4e0b\u6240\u6709\u5199\u64cd\u4f5c\u5f3a\u5236\u52a0\u5230\u6587\u4ef6\u7ed3\u675f\u5904\u3002
- update \u6a21\u5f0f\u4e0b\uff0c\u82e5\u4e0d\u8c03\u7528\u6587\u4ef6\u5b9a\u4f4d\u51fd\u6570\uff0c\u8f93\u5165\u8f93\u51fa\u4e0d\u4e00\u5b9a\u76f8\u4e92\u7d27\u8ddf\u3002
\u5bf9\u4e8e UNIX \u8fd9\u79cd\u53ea\u6709\u4e00\u79cd\u6587\u4ef6\u7c7b\u578b\u7684\u7cfb\u7edf\uff0c\u5e26 b
\u4e0e\u5426\u7684\u6a21\u5f0f\u662f\u76f8\u540c\u7684\u3002 C11 \u4e2d\u65b0\u589e\u4e86 x
\uff0c\u5e26\u8be5\u5b57\u6bcd\u7684\u5199\u6a21\u5f0f\u6253\u5f00\u5b58\u5728\u6587\u4ef6\u4f1a\u5931\u8d25\uff08\u76f8\u5f53\u4e8e\u52a0\u4e86\u4fdd\u62a4\uff09\uff0c\u4e14\u5141\u8bb8\u72ec\u5360\u3002
"},{"location":"programming_lecture/lecture3/lecture3/#_22","title":"\u683c\u5f0f\u5316\u8f93\u5165/\u8f93\u51fa","text":"fprintf
,fscanf
,vfprintf
,vprintf
,vsprintf
"},{"location":"programming_lecture/lecture3/lecture3/#_23","title":"\u5b57\u7b26\u8f93\u5165/\u8f93\u51fa","text":"fgetc
,fgets
,fputc
,fputs
,getc
,getchar
,gets_s
/(gets)
,putc
,putchar
,puts
,ungetc
\u5176\u4e2d\uff0cfgetc()
\u4e0e getc()
\u8fd9\u7c7b\u51fd\u6570\u7684\u4e0d\u540c\u662f\u540e\u8005\u53ef\u80fd\u88ab\u5b9e\u73b0\u4e3a\u5b8f\u3002
"},{"location":"programming_lecture/lecture3/lecture3/#io_1","title":"\u76f4\u63a5 I/O","text":" 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)
"},{"location":"programming_lecture/lecture3/lecture3/#_24","title":"\u6587\u4ef6\u5b9a\u4f4d","text":" int fseek(FILE *stream, long int offset, int whence)
whence
\u53ef\u4ee5\u662f SEEK_SET
\u3001SEEK_CUR
\u3001SEEK_END
- \u7b2c\u4e8c\u4e2a\u53c2\u6570\u8868\u793a\u504f\u79fb\u91cf
- \u5c06\u6587\u4ef6\u7c7b\u6bd4\u4e3a\u6570\u7ec4\uff0c\u5355\u4f4d\u662f\u5b57\u8282\u6570
long int ftell(FILE *stream)
- \u8ddd\u6587\u4ef6\u5f00\u59cb\u5904\u7684\u5b57\u8282\u6570
void rewind(FILE *stream)
"},{"location":"programming_lecture/lecture3/lecture3/#_25","title":"\u5176\u4ed6","text":"\u4ee5\u4e0b\u4e24\u4e2a\u51fd\u6570\u7528\u4e8e\u5904\u7406\u66f4\u5927\u578b\u7684\u6587\u4ef6\uff08long
\u65e0\u6cd5\u8868\u793a\u7684\u504f\u79fb\u503c\uff09
int fgetpos(FILE *stream, fpos_t *pos)
int fsetpos(FILE *stream, const fpos_t *pos)
"},{"location":"programming_lecture/lecture3/pre_class/","title":"\u8bfe\u524d\uff1a\u4e00\u4e9b\u6837\u4f8b","text":"\u628a\u8bb2\u4e49\u91cc\u7684\u5c0f\u7a0b\u5e8f\u548c\u547d\u4ee4\u884c\u8dd1\u4e00\u8dd1\uff0c\u601d\u8003\u4e00\u4e0b\u7559\u4e0b\u7684\u95ee\u9898\uff5e
-
\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()
wrong_cnv.c#include <stdio.h>\n#define num 336\n#define b 65618\nint main(void)\n{\n printf(\"num as short and unsigned short: %hd %hu\\n\", num,num);\n printf(\"-num as short and unsigned short: %hd %hu\\n\", -mnum,-mnum);\n printf(\"num as int and char: %d %c\\n\", num, num);\n printf(\"b as int, short, and char: %d %hd %c\\n\",b, b, b);\n\n float n1 = 3.0;\n double n2 = 3.0;\n long n3 = 2000000000;\n long n4 = 1234567890;\n printf(\"%.1e %.1e %.1e %.1e\\n\", n1, n2, n3, n4);\n printf(\"%ld %ld\\n\", n3, n4);\n printf(\"%ld %ld %ld %ld\\n\", n1, n2, n3, n4);\n return 0;\n}\n
\u8be5\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c\u4e3a(\u7531\u4e8e\u5b9e\u73b0\u662f\u672a\u5b9a\u4e49\u7684\uff0c\u90e8\u5206\u7ed3\u679c\u56e0\u7cfb\u7edf\u548c\u7f16\u8bd1\u5668\u800c\u5f02)\uff1a
num as short and unsigned short: 336 336\n-num as short and unsigned short: -336 65200\nnum as int and char: 336 P\nb as int, short, and char: 65618 336 R\n3.0e+00 3.0e+00 2.0e+09 1.2e+09\n2000000000 1234567890\n0 1074266112 0 1074266112\n
\u4f60\u80fd\u89e3\u91ca\u4e3a\u4ec0\u4e48\u4f7f\u7528%ld \u8f93\u51fa long \u7c7b\u578b\u7684\u503c\u65f6\uff0c\u4e5f\u4f1a\u51fa\u73b0\u9519\u8bef\u5417\uff1f
-
\u5173\u4e8escanf()
confusing_scanf.c#include <stdio.h>\nint main(void)\n{\n char c[100] = {0};\n scanf(\"%s\\n\",&c);\n printf(\"%s\",c);\n}\n
\u8fd9\u4e2a\u7a0b\u5e8f\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u5947\u602a\uff1f
-
\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
"},{"location":"programming_lecture/lecture4/after_class/","title":"\u8bfe\u540e\u6269\u5c55\uff1aC \u6807\u51c6\u5e93\u7684\u5b9e\u73b0","text":"\u65bd\u5de5\u4e2d
\u672c\u9875\u9762\u6b63\u5728\u7f16\u8f91\u4e2d\u3002
"},{"location":"programming_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
- \u5408\u683c\u7a0b\u5e8f\u5458\uff1a
<ctype.h> <stdio.h> <stdlib.h> <string.h>\n
- \u719f\u7ec3\u7a0b\u5e8f\u5458\uff1a
<assert.h> <limits.h> <stddef.h> <time.h>\n
- \u4f18\u79c0\u7a0b\u5e8f\u5458\uff1a
<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
- \u5b57\u7b26\u4e32\u3001\u6570\u7ec4\u3001\u6307\u9488\u7b49\u64cd\u4f5c
- \u547d\u540d\u7a7a\u95f4\uff1a\u5e93\u4e2d\u5b9a\u4e49\u4e86 200 \u4e2a\u4ee5\u4e0a\u7684\u540d\u5b57\uff0c\u4f60\u5e94\u5f53\u77e5\u9053 C \u4e2d\u5404\u79cd\u540d\u5b57\u4f1a\u5982\u4f55\u88ab\u89e3\u6790\u3002
\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
- \u4e00\u4e2a\u5b9e\u73b0\u5fc5\u987b\u4e3a\u6bcf\u4e00\u4e2a\u5e93\u51fd\u6570\u63d0\u4f9b\u4e00\u4e2a\u5b9e\u9645\u7684\u51fd\u6570\uff0c\u5373\u4f7f\u5b83\u5df2\u7ecf\u4e3a\u8be5\u51fd\u6570\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5b8f\u3002
- \u4e00\u4e2a\u51fd\u6570\u7684\u4efb\u4f55\u5b8f\u5b9a\u4e49\u90fd\u53ef\u4ee5\u901a\u8fc7\u7528\u62ec\u53f7\u628a\u51fd\u6570\u7684\u540d\u5b57\u62ec\u4f4f\u6765\u5c40\u90e8\u5730\u6291\u5236\u5b83\u3002\u56e0\u4e3a\u8fd9\u4e2a\u540d\u5b57\u540e\u9762\u6ca1\u6709\u8ddf\u7740\u6307\u793a\u4e00\u4e2a\u5b8f\u51fd\u6570\u540d\u5c55\u5f00\u5730\u5de6\u62ec\u53f7\u3002
- \u7528\u6765\u79fb\u9664\u4efb\u4f55\u5b8f\u5b9a\u4e49\u7684
#undef
\u9884\u5904\u7406\u6307\u4ee4\u7684\u4f7f\u7528\u4e5f\u53ef\u4ee5\u4fdd\u8bc1\u5b9e\u9645\u51fd\u6570\u7684\u5f15\u7528\u3002
atoi()
\u7684\u4f7f\u7528\u65b9\u5f0f
- \u53ef\u80fd\u751f\u6210\u4e00\u4e2a\u5b8f\u51fd\u6570\uff1a
#include <stdlib.h>\nconst char *str;\ni = atoi(str);\n
- \u751f\u6210\u4e00\u4e2a\u5b9e\u9645\u51fd\u6570\u5f15\u7528\uff1a
#include <stdlib.h>\n#undef atoi\nconst char *str;\ni = atoi(str);\n
\u6216\u8005 #include <stdlib.h>\nconst char *str;\ni = (atoi)(str);\n
"},{"location":"programming_lecture/lecture4/after_class/#stdioh","title":"<stdio.h>
\u7684\u5b9e\u73b0\uff1a\u7cfb\u7edf\u8c03\u7528\u4e0e\u5185\u6838\u7f16\u7a0b","text":"\u5728\u6211\u4e2a\u4eba\u770b\u6765\uff0c<stdio.h>
\u7684\u5b9e\u73b0\u6700\u5177\u6311\u6218\u6027\u3002\u4f60\u9700\u8981\u5bf9\u5b9e\u73b0\u5bf9\u5e94\u7684\u64cd\u4f5c\u7cfb\u7edf\u6709\u4e00\u5b9a\u7684\u4e86\u89e3\uff0c\u624d\u80fd\u7f16\u5199\u51fa\u5b8c\u5584\u7684\u4ee3\u7801\u3002
\u672c\u8282\u4ee5 UNIX \u548c POSIX \u89c4\u8303\u7684\u7cfb\u7edf\u8c03\u7528\u4e3a\u51c6\u3002
\u4e00\u4e9b\u5386\u53f2\u7684\u80cc\u666f\uff1a\u6587\u4ef6\u3001\u8bbe\u5907\u548c ioctl
- \u6df7\u4e71\u7684\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf
\u6216\u8bb8\u4f60\u5f88\u96be\u60f3\u8c61\uff0cUNIX \u4e4b\u524d\u7684\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf\u4e3a\u6587\u4ef6\u8d4b\u4e88\u4e86\u5f88\u591a\u7c7b\u578b\u4e0a\u7684\u6982\u5ff5\u548c\u3001\u4f5c\u4e86\u5f88\u591a\u533a\u5206\uff0c\u800c\u4e0d\u662f\u6211\u4eec\u73b0\u5728\u6240\u5e7f\u6cdb\u63a5\u53d7\u7684\u300c\u6587\u4ef6\u5c31\u662f\u4e00\u7cfb\u5217\u8fde\u7eed\u7684\u5b57\u8282\u300d\u7684\u6982\u5ff5\u3002\u8fd9\u8fb9\u6709\u4e00\u6bb5\u63cf\u8ff0\uff0c\u4f60\u53ef\u4ee5\u770b\u770b\uff1a
Typically source code was a distinguished type, different from data. Compilers could read source, compiled programs could read and write 'data.' Thus the creation and inspection of Fortran programs was often walled off from the creation and inspection of other files, with completely different ways to edit and print them. This ruled out the use of programs to generate (or even simply copy) Fortran programs.
- \u4e0d\u7edf\u4e00\u7684\u6587\u672c\u8868\u793a\u548c\u8bbe\u5907\u4ea4\u4e92
\u65e9\u671f\u7a0b\u5e8f\u7684\u8f93\u5165\u8f93\u51fa\u65e0\u6cd5\u72ec\u7acb\u4e8e\u8bbe\u5907\u3002\u6bd4\u5982\uff0c\u5728\u4e0a\u4e2a\u4e16\u7eaa 60 \u5e74\u4ee3\u7684 FORTRAN IV \u4e2d\uff0c\u5728\u78c1\u5e26\u673a\u4e0a\u9700\u8981\u7528 READ INPUT TAPE 5
\uff0c\u8bfb\u53d6\u78c1\u76d8\u4e0a\u9700\u8981\u7528 READ INPUT DISK 1
\u3002\u8fd9\u6837\u7684\u4ee3\u7801\u5728\u4e0d\u540c\u7684\u8bbe\u5907\u4e0a\u9700\u8981\u4fee\u6539\uff0c\u975e\u5e38\u4e0d\u65b9\u4fbf\u3002UNIX \u5c06\u8fd9\u4e9b\u6df7\u4e71\u7684\u8bbe\u5907\u4ea4\u4e92\u5c01\u88c5\u5728\u8bbe\u5907\u5904\u7406\u7a0b\u5e8f\u4e2d\u3002\u5728 UNIX \u7cfb\u7edf\u770b\u6765\uff0c\u5916\u56f4\u8bbe\u5907\u6709\u4e09\u79cd\u7c7b\u578b\uff1a\u5b57\u7b26\u8bbe\u5907\uff08Character devices\uff09\u3001\u5757\u8bbe\u5907\uff08Block devices\uff09\u548c\u7f51\u7edc\u8bbe\u5907\uff08Network devices\uff09\u3002\u8fd9\u4e09\u79cd\u8bbe\u5907\u90fd\u88ab\u62bd\u8c61\u4e3a\u6587\u4ef6\uff0c\u4f7f\u7528\u7edf\u4e00\u7684\u6587\u4ef6\u64cd\u4f5c\u63a5\u53e3\u3002
\u5728 Ken Thompson \u4e3a UNIX \u8bbe\u8ba1\u7edf\u4e00\u7684\u5185\u90e8\u6587\u672c\u5f62\u5f0f\u524d\uff0c\u6587\u672c\u8868\u793a\u4e5f\u662f\u5341\u5206\u6df7\u4e71\u7684\u3002\u7ed3\u675f\u4e00\u884c\u662f\u4f7f\u7528\u56de\u8f66\u8fd8\u662f\u56de\u8f66\u52a0\u6362\u884c\uff0c\u8fd8\u662f\u6362\u884c\u7b26\uff0c\u8fd8\u662f\u66f4\u795e\u5947\u7684\u5b57\u7b26\uff1f\u7ec8\u7aef\u80fd\u4e0d\u80fd\u8bc6\u522b\u548c\u5c55\u5f00\u5236\u8868\u7b26\uff1f\u600e\u6837\u7528\u952e\u76d8\u6807\u5fd7\u6587\u4ef6\u7ed3\u675f\uff1f\u8fd9\u4e9b\u95ee\u9898\u7684\u7b54\u6848\u548c\u7ec8\u7aef\u7684\u751f\u4ea7\u5382\u5546\u4e00\u6837\u591a\u3002UNIX \u4f7f\u7528\u7cfb\u7edf\u8c03\u7528 ioctl
\u6765\u8bbe\u7f6e\u4e00\u4e2a\u8bbe\u5907\u7684\u5404\u79cd\u53c2\u6570\uff0c\u8d1f\u8d23\u5bf9\u5185\u90e8\u6362\u884c\u7ea6\u5b9a\u548c\u5404\u79cd\u7ec8\u7aef\u4e4b\u95f4\u7684\u9700\u8981\u8f6c\u6362\u7684\u5b57\u7b26\u8fdb\u884c\u5904\u7406\u3002
UNIX Devices Drivers
\u9884\u5907\u77e5\u8bc6\uff1aUNIX \u7cfb\u7edf\u8c03\u7528
"},{"location":"programming_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
- \u6309\u7167\u8003\u8bd5\u8981\u6c42\uff0c\u628a\u6807\u51c6\u5e93\u4e2d\u5927\u5bb6\u5e94\u8be5\u77e5\u9053\u7684\u5185\u5bb9\u4ecb\u7ecd\u4e00\u904d\u3002
- \u7ed3\u5408\u4e00\u4e9b\u5e94\u7528\u7684\u4f8b\u5b50\uff0c\u4e32\u8bb2\u4e00\u4e0b\u4e4b\u524d\u7684\u8bed\u6cd5\u91cd\u70b9\u3002
\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
"},{"location":"programming_lecture/lecture4/lecture4/#c_1","title":"\u5bfc\u5f15\uff1aC \u6807\u51c6\u5e93\uff0c\u5b66\u4e9b\u4ec0\u4e48\uff1f","text":""},{"location":"programming_lecture/lecture4/lecture4/#_1","title":"\u4e3a\u4ec0\u4e48\u8981\u5b66\u6807\u51c6\u5e93\uff1f","text":"\u6709\u4e00\u4e2a\u7c97\u6d45\u7684\u7406\u7531\uff0c\u5c31\u662f\u56fe\u65b9\u4fbf\u3002\u5047\u8bbe\u6709\u4e0b\u9762\u8fd9\u4e2a\u58f0\u660e\u5728 main
\u51fd\u6570\u4e2d\u6570\u7ec4\uff1a
int a[100];\n
\u6211\u4eec\u77e5\u9053\uff0c\u8fd9\u4e2a\u6570\u7ec4\u4e0d\u4f1a\u88ab\u521d\u59cb\u5316\u3002\u5982\u679c\u60f3\u8981\u628a\u8fd9\u4e2a\u6570\u7ec4\u5168\u90e8\u7f6e\u4e3a 0\uff0c\u4f60\u4f1a\u600e\u4e48\u5199\u5462\uff1f
\u9996\u5148\u4f1a\u6709\u7684\u60f3\u6cd5\u80af\u5b9a\u662f\uff1a
for (int i = 0; i < 100; ++i)\n a[i] = 0;\n
\u5176\u5b9e\u6807\u51c6\u5e93\u63d0\u4f9b\u4e86\u4e00\u4e2a\u51fd\u6570 memset
\uff0c\u7528\u6765\u8bbe\u7f6e\u4e00\u6bb5\u5185\u5b58\u7684\u503c\uff1a
memset(a, 0, sizeof(a));\n
\u662f\u4e0d\u662f\u5f88\u65b9\u4fbf\u5462\uff1f
\u518d\u6765\u4e00\u4e2a\u4f8b\u5b50\uff0c\u628a\u8f93\u5165\u4e2d\u6240\u6709\u7684\u5c0f\u5199\u5b57\u6bcd\u8f6c\u6362\u6210\u5927\u5199\u5b57\u6bcd\u3002\u5047\u8bbe\u8f93\u5165\u5df2\u7ecf\u5b58\u50a8\u5728 char
\u6570\u7ec4 str
\u4e2d\uff0c\u6839\u636e\u73b0\u6709\u7684\u77e5\u8bc6\uff0c\u4f60\u4f1a\u4e0d\u4f1a\u8fd9\u6837\u5199\uff1a
for(int i = 0; i < strlen(str); ++i)\n if ('a' <= str[i] && str[i] <= 'z')\n str[i] -= 'a' - 'A';\n
\u5176\u5b9e\u6807\u51c6\u5e93\u63d0\u4f9b\u4e86\u5224\u65ad\u5b57\u7b26\u5927\u5c0f\u5199\u7684\u51fd\u6570\uff0c\u4e5f\u63d0\u4f9b\u4e86\u8f6c\u6362\u5927\u5c0f\u5199\u7684\u51fd\u6570\uff1a
for(int i = 0; i < strlen(str); ++i)\n if (islower(str[i]))\n str[i] = toupper(str[i]);\n
\u4e0b\u9762\u7684\u8fd9\u6bb5\u4ee3\u7801\uff0c\u662f\u4e0d\u662f\u6bd4\u4e0a\u9762\u7684\u4ee3\u7801\u7b80\u6d01\uff0c\u5e76\u4e14\u4e00\u773c\u770b\u8fc7\u53bb\u5c31\u80fd\u660e\u767d\u610f\u601d\u5462\uff1f
\u603b\u800c\u8a00\u4e4b\uff0cC \u6807\u51c6\u5e93\u529f\u80fd\u5f3a\u5927\uff0c\u5b83\u7684\u91cd\u8981\u6027\u548c\u8bed\u8a00\u672c\u8eab\u4e00\u6837\u3002\u5b66\u4f1a\u4f7f\u7528\u6807\u51c6\u5e93\uff0c\u8ba9\u4f60\u5c11\u9020\u8f6e\u5b50\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3001\u7b80\u6d01\u6027\u548c\u6b63\u786e\u6027\u3002
"},{"location":"programming_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
- \u7c7b\u578b\u5b9a\u4e49
- \u5b8f
- \u51fd\u6570
\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
- \u4f1a\u9605\u8bfb\u51fd\u6570\u539f\u578b/\u51fd\u6570\u58f0\u660e/\u51fd\u6570\u7b7e\u540d\uff08\u5b83\u4eec\u8bf4\u7684\u662f\u4e00\u4e2a\u4e1c\u897f\uff09\uff1a
int main(void);\n
-
\u6307\u9488 \u7684\u6982\u5ff5
- \u5185\u5b58\u3001\u5185\u5b58\u5730\u5740\u3001\u5bf9\u8c61
- \u6307\u9488\u4e5f\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5b83\u7684\u503c\u662f\u4e00\u4e2a\u5185\u5b58\u5730\u5740
-
\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
"},{"location":"programming_lecture/lecture4/lecture4/#ctypeh","title":"<ctype.h>
","text":"\u5934\u6587\u4ef6 <ctype.h>
\u58f0\u660e\u4e86\u51e0\u4e2a\u53ef\u4ee5\u7528\u4e8e\u8bc6\u522b\u548c\u8f6c\u6362\u5b57\u7b26\u7684\u51fd\u6570\u3002
"},{"location":"programming_lecture/lecture4/lecture4/#ascii","title":"\u80cc\u666f\uff1aASCII \u5b57\u7b26\u96c6","text":"ASCII \u5b57\u7b26\u96c6\u4e2d\u7684\u6570\u5b57\u548c\u5b57\u6bcd\u5927\u5bb6\u5e94\u8be5\u90fd\u5f88\u719f\u4e86\uff0c\u8fd9\u8fb9\u518d\u5bf9\u4e24\u7c7b\u5927\u5bb6\u63a5\u89e6\u6bd4\u8f83\u5c11\u7684\u5b57\u7b26\u5206\u7c7b\u7b80\u5355\u505a\u4e2a\u4ecb\u7ecd\u3002
- \u6253\u5370\u5b57\u7b26\uff1a
0x20
~ 0x7E
- \u63a7\u5236\u5b57\u7b26\uff1a
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
"},{"location":"programming_lecture/lecture4/lecture4/#_4","title":"\u5185\u5bb9","text":"\u8fd9\u4e2a\u5934\u6587\u4ef6\u4e2d\u53ea\u6709\u51fd\u6570\uff0c\u6ca1\u6709\u7279\u522b\u7684\u7c7b\u578b\u548c\u5b8f\u3002
\u8fd9\u4e9b\u51fd\u6570\u7684\u610f\u4e49\u548c\u7528\u6cd5\u975e\u5e38\u663e\u7136\uff0c\u56e0\u6b64\u6211\u4e5f\u4e0d\u505a\u6ce8\u91ca\u3002
- \u5b57\u7b26\u5224\u65ad\u51fd\u6570
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
- \u5b57\u7b26\u8f6c\u6362\u51fd\u6570
int tolower(int c);\nint toupper(int c);\n
"},{"location":"programming_lecture/lecture4/lecture4/#_5","title":"\u4f7f\u7528","text":"<ctype.h>
\u4e2d\u7684\u51fd\u6570\u5bf9 ASCII \u5b57\u7b26\u5927\u81f4\u4f5c\u4e86\u5982\u4e0b\u5212\u5206\uff1a
\u63a7\u5236\u5b57\u7b26\u90a3\u4e9b\u4e0d\u7528\u7ba1\uff0c\u4e0d\u8981\u6c42\u7684\u51fd\u6570\u4e0d\u7528\u7ba1\u3002\u53ea\u8981\u8bb0\u5f97 isspace
\u548c isblank
\u7684\u533a\u522b\u5c31\u884c\u4e86\u3002
isspace
\u548c isblank
\u7684\u533a\u522b
- \u7a7a\u683c\u5b57\u7b26\uff1a
isblank
\u4ec5\u5224\u65ad\u7a7a\u683c
\u548c\u6c34\u5e73\u5236\u8868\u7b26 \\t
\u3002 - \u7a7a\u767d\u5b57\u7b26\uff1a
isspace
\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
"},{"location":"programming_lecture/lecture4/lecture4/#ctypeh_1","title":"<ctype.h>
\u7684\u5b9e\u73b0\uff1a\u5b8f\u4e0e\u4f4d\u8fd0\u7b97","text":"\u9605\u8bfb\u672c\u8282\u9700\u8981\u5177\u5907\u7684\u77e5\u8bc6
- \u4f4d\u8fd0\u7b97
\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
- \u5b8f
\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
- \u7b2c\u4e00\u4f4d\u8868\u793a\u662f\u5426\u662f\u6570\u5b57
- \u7b2c\u4e8c\u4f4d\u8868\u793a\u662f\u5426\u662f\u5c0f\u5199\u5b57\u6bcd
- \u7b2c\u4e09\u4f4d\u8868\u793a\u662f\u5426\u662f\u5927\u5199\u5b57\u6bcd
- \u7b2c\u56db\u4f4d\u8868\u793a\u662f\u5426\u662f\u5b57\u6bcd
\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
- \u867d\u7136\u5b8f\u53ef\u80fd\u6bd4\u51fd\u6570\u5feb\uff0c\u4f46\u662f\u5b83\u4eec\u901a\u5e38\u4f1a\u4ea7\u751f\u66f4\u5927\u7684\u4ee3\u7801\u3002\u5982\u679c\u5728\u5f88\u591a\u5730\u65b9\u6269\u5c55\uff0c\u8fd9\u4e2a\u7a0b\u5e8f\u53ef\u80fd\u5927\u5230\u8ba9\u4f60\u65e0\u6cd5\u60f3\u8c61\u3002
-
\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
ctype.h#define _DI 0x20 /* '0'-'9' */\n#define _LO 0x10 /* 'a'-'z' */\n#define _UP 0x02 /* 'A'-'Z' */\n#define _XA 0x200 /* 'a'-'z', 'A'-'Z' */\nextern const short *_Ctype, *_Tolower, *_Toupper;\n#define isalnum(c) (_Ctype[(int)(c)] & (_DI|_LO|_UP|_XA))\n#define tolower(c) _ToLower[(int)(c)]\n
\u8bfb\u4e00\u4e0b\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u60f3\u8c61\u4e00\u4e0b _Ctype
\u8fd9\u4e2a\u67e5\u627e\u8868\u7684\u6837\u5b50\u3002
\u8003\u8003\u4f60\uff0c\u5bf9\u4e8e ASCII \u5b57\u7b26\u96c6\uff0c\u8fd9\u4e2a\u67e5\u627e\u8868\u6709\u591a\u5927\uff1f
\u4f60\u80fd\u60f3\u4e00\u60f3\u6620\u5c04\u8868\u7684\u5b9e\u73b0\u5417\uff1f
\u540c\u6837\uff0c\u7ed9\u51fa\u51fd\u6570\u7248\u672c\u7684\u5b9e\u73b0\uff1a
isalnum.c#include <ctype.h>\n\nint isalnum(int c)\n { /* test for alphanumeric character */\n return (_Ctype[c] & (_DI|_LO|_UP|_XA));\n }\n
\u4e0b\u9762\u4e24\u5e45\u56fe\u5206\u522b\u5c55\u793a\u4e86 _Ctype
\u548c _Toupper
\u7684\u6837\u5b50\uff1a
_Ctype
_Toupper
\u975e\u5e38\u5730\u7b80\u5355\uff0c\u5bf9\u5427\uff1f\u8fd9\u53ef\u6bd4 'a' <= c && c <= 'z'
\u8fd9\u6837\u7684\u5224\u65ad\u8981\u5feb\u5f97\u591a\u3002
"},{"location":"programming_lecture/lecture4/lecture4/#mathh","title":"<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
- \u6700\u5927\u6b63\u503c\uff1a\\(1.7976931348623157 \\times 10^{308}\\)
- \u6700\u5c0f\u6b63\u503c\uff1a\\(2.2250738585072014 \\times 10^{-307}\\)
\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
- \u5982\u679c\u51fd\u6570\u7684\u8f93\u5165\u53c2\u6570\u4f4d\u4e8e\u5b9a\u4e49\u57df\u5916\uff08\u6bd4\u5982
asin
\u8f93\u5165\u4e86\u4e0d\u5728 \\([-1, 1]\\) \u7684\u503c\uff09\uff0c\u4f1a\u53d1\u751f\u5b9a\u4e49\u57df\u9519\u8bef\u3002 - \u5982\u679c\u7ed3\u679c\u4e0d\u80fd\u88ab\u8868\u793a\u4e3a
double
\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
"},{"location":"programming_lecture/lecture4/lecture4/#_7","title":"\u5185\u5bb9","text":" -
\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
"},{"location":"programming_lecture/lecture4/lecture4/#_8","title":"\u4f7f\u7528","text":" - \u8f93\u5165\u8f93\u51fa\u5168\u90fd\u662f
double
\u7c7b\u578b\uff08\u6ce8\u610f\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u5e26\u6765\u7684\u5f71\u54cd\uff09\u3002 - \u4e09\u89d2\u51fd\u6570\u5747\u4e3a\u5f27\u5ea6\u5236\u3002\u89d2\u5ea6\u5230\u5f27\u5ea6\u7684\u8f6c\u6362\u516c\u5f0f\u4e3a\uff1a\\(\\theta = \\frac{\\pi}{180} \\times \\alpha\\)\u3002
- \u6ca1\u6709
PI
\u8fd9\u4e2a\u5b8f\u3002 - \u53ef\u4ee5\u4f7f\u7528
atan(1)*4
\u4ee3\u66ff\u3002 - GCC \u5b9a\u4e49\u4e86\u4e00\u4e9b\u6570\u503c\u5b8f\uff0c\u5b83\u4eec\u90fd\u4ee5
M_
\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
"},{"location":"programming_lecture/lecture4/lecture4/#stringh","title":"<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
- \u7528\u53cc\u5f15\u53f7\u5f15\u8d77\u7684\u5b57\u7b26\u5e8f\u5217\u662f\u5b57\u7b26\u4e32\u3002\u7f16\u8bd1\u5668\u4f1a\u81ea\u52a8\u6dfb\u52a0\u7a7a\u5b57\u7b26\u3002
scanf
\u4f7f\u7528 %s
\u8bfb\u53d6\u7684\u5b57\u7b26\u5e8f\u5217\u662f\u5b57\u7b26\u4e32\u3002scanf
\u4f1a\u81ea\u52a8\u6dfb\u52a0\u7a7a\u5b57\u7b26\u3002 - ......
"},{"location":"programming_lecture/lecture4/lecture4/#_10","title":"\u5185\u5bb9","text":" - \u7c7b\u578b
size_t\n
- \u5b8f
NULL\n
- \u51fd\u6570
- \u590d\u5236\u51fd\u6570
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
- \u8fde\u63a5\u51fd\u6570
char *strcat(char *dest, const char *src);\nchar *strncat(char *dest, const char *src, size_t n);\n
- \u6bd4\u8f83\u51fd\u6570
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
- \u67e5\u627e\u51fd\u6570
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
- \u5176\u4ed6\u51fd\u6570
void *memset(void *s, int c, size_t n);\n// char *strerror(int errnum);\nsize_t strlen(const char *s);\n
"},{"location":"programming_lecture/lecture4/lecture4/#_11","title":"\u4f7f\u7528","text":"\u4f7f\u7528\u524d\uff0c\u81ea\u5df1\u8ba1\u7b97\u5b57\u7b26\u4e32\u957f\u5ea6\u548c\u5269\u4f59\u7a7a\u95f4\uff0c\u8fd9\u662f\u7f16\u7a0b\u8005\u7684\u8d23\u4efb\u3002\u6216\u8005\u4f7f\u7528\u5e26 n
\u7684\u51fd\u6570\u3002
- \u6709\u4e9b\u51fd\u6570\u53ef\u80fd\u8fd4\u56de\u7a7a\u6307\u9488\uff0c\u8bb0\u5f97\u6d4b\u8bd5\u8fd4\u56de\u7684\u6307\u9488\u3002
"},{"location":"programming_lecture/lecture4/lecture4/#stdlibh","title":"<stdlib.h>
","text":"\u5934\u6587\u4ef6 <stdlib.h>
\u662f\u4e00\u4e2a\u5927\u6742\u70e9\uff0c\u4e3a\u4e86\u5b9a\u4e49\u548c\u58f0\u660e\u90a3\u4e9b\u6ca1\u6709\u660e\u663e\u5f52\u5c5e\u7684\u5b8f\u548c\u51fd\u6570\u3002\u6211\u4eec\u4ec5\u4ecb\u7ecd\u5e38\u7528\u7684\u90e8\u5206\uff1a\u6574\u5f62\u6570\u5b66\u3001\u7b97\u6cd5\u3001\u6587\u672c\u8f6c\u6362\u3001\u73af\u5883\u63a5\u53e3\u548c\u5b58\u50a8\u5206\u914d\u3002
"},{"location":"programming_lecture/lecture4/lecture4/#_12","title":"\u80cc\u666f\uff1a\u6307\u9488\u7684\u6982\u5ff5","text":"\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":" - \u5b8f
RAND_MAX\nEXIT_FAILURE\nEXIT_SUCCESS\n
-
\u51fd\u6570
- \u4f2a\u968f\u673a\u5e8f\u5217\u4ea7\u751f\u51fd\u6570
int rand(void);\nvoid srand(unsigned int seed);\n
- \u6574\u6570\u7b97\u672f\u51fd\u6570
int abs(int n);\ndiv_t div(int numer, int denom);\nlong labs(long n);\nldiv_t ldiv(long numer, long denom);\n
- \u67e5\u627e\u548c\u6392\u5e8f\u51fd\u6570
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
- \u6587\u672c\u8f6c\u6362\uff08\u597d\u7528\u7684\uff09
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
- \u73af\u5883\u901a\u4fe1\uff08\u4e0d\u4ecb\u7ecd\uff09
// 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
"},{"location":"programming_lecture/lecture4/lecture4/#_14","title":"\u4f7f\u7528","text":" 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]\\)\u3002 abs
\u548c labs
\u7528\u4e8e\u6c42\u7edd\u5bf9\u503c\u3002div
\u548c ldiv
\u7528\u4e8e\u6c42\u5546\u548c\u4f59\u6570\u3002 qsort
\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
- \u6587\u672c\u8f6c\u6362\u51fd\u6570\u975e\u5e38\u597d\u7528\u3002\u4f60\u518d\u4e5f\u4e0d\u7528\u5199\u8fd9\u6837\u7684\u4ee3\u7801\u4e86\uff08\u5f53\u7136
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\u3002 realloc
\u76f8\u5f53\u4e8e\u7ed3\u5408\u4e86 malloc
\u3001memcpy
\u548c free
\u7684\u529f\u80fd\u3002
"},{"location":"programming_lecture/lecture4/lecture4/#stdioh","title":"<stdio.h>
","text":"\u5173\u4e8e\u6587\u4ef6\u8f93\u5165\u8f93\u51fa......
\u8fd9\u8fb9\u5217\u51fa\u4e86\u6587\u4ef6\u8f93\u5165\u8f93\u51fa\u7684\u5185\u5bb9\uff0c\u7ed9\u5927\u5bb6\u590d\u4e60\u7684\u65f6\u5019\u53c2\u8003\u7528\u3002\u54b1\u4eec\u8fd9\u8282\u8bfe\u4e0d\u8bb2\u3002
"},{"location":"programming_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
"},{"location":"programming_lecture/lecture4/lecture4/#_16","title":"\u6d41\u7684\u6982\u5ff5","text":"\u5404\u79cd\u8f93\u5165\u8f93\u51fa\u8bbe\u5907\u5b9e\u5728\u662f\u592a\u591a\u4e86\uff08\u7ec8\u7aef\u3001\u78c1\u5e26\u9a71\u52a8\u5668\u3001\u7ed3\u6784\u5316\u5b58\u50a8\u8bbe\u5907......\uff09\u3002\u4e3a\u4e86\u7edf\u4e00\u6982\u5ff5\uff0cC \u8bed\u8a00\u4e2d\u7684\u8f93\u5165\u548c\u8f93\u51fa\u8bbe\u5907\u5168\u90fd\u548c\u903b\u8f91\u6570\u636e\u6d41\u76f8\u5bf9\u5e94\u3002
\u6d41\u5c31\u662f\u5b57\u7b26\u5e8f\u5217\u3002
\u4e0d\u7ba1\u7cfb\u7edf\u3001\u786c\u4ef6\u662f\u600e\u4e48\u5b9e\u73b0\u7684\u3002\u8f93\u5165\u8f93\u51fa\u5230\u4e86 C \u7a0b\u5e8f\u8fd9\u91cc\uff0c\u5c31\u7edf\u4e00\u4e3a\u903b\u8f91\u4e0a\u7684\u6d41\u4e86\u3002
\u6d41\u5173\u8054\u5230\u4e00\u4e2a\u7279\u5b9a\u7684\u6587\u4ef6\u3002
"},{"location":"programming_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
- \u6587\u672c\u6587\u4ef6\uff1a\u5982\u679c\u4e00\u4e2a\u6587\u4ef6\u4e2d\u7684\u4e8c\u8fdb\u5236\u503c\u90fd\u662f\u7528\u6765\u8868\u793a\u5b57\u7b26\u7684\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6587\u4ef6\u5c31\u662f\u6587\u672c\u6587\u4ef6\u3002
- \u4e8c\u8fdb\u5236\u6587\u4ef6\uff1a\u5982\u679c\u4e00\u4e2a\u6587\u4ef6\u4e2d\u7684\u4e8c\u8fdb\u5236\u503c\u4ee3\u8868\u5176\u4ed6\u6570\u636e\uff0c\u6bd4\u5982\u673a\u5668\u8bed\u8a00\u4ee3\u7801\u6216\u8005\u6570\u503c\u6570\u636e\u3001\u56fe\u7247\u6216\u97f3\u4e50\uff0c\u8fd9\u4e2a\u6587\u4ef6\u5c31\u662f\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002
\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
- \u8981\u6c42\u6587\u672c\u6587\u4ef6\u4e2d\u6bcf\u4e00\u884c\u7684\u957f\u5ea6\u76f8\u540c\uff0c\u5426\u5219\u7528\u7a7a\u767d\u5b57\u7b26\u586b\u5145\u3002
- \u5728\u6bcf\u884c\u5f00\u59cb\u6807\u51fa\u884c\u7684\u957f\u5ea6\u3002
"},{"location":"programming_lecture/lecture4/lecture4/#_18","title":"\u6d41\u7684\u7c7b\u578b","text":"C \u8bed\u8a00\u63d0\u4f9b\u4e24\u79cd\u6d41\uff1a\u6587\u672c\u6d41\u548c\u4e8c\u8fdb\u5236\u6d41\u3002
- \u6587\u672c\u6d41\uff1a\u7a0b\u5e8f\u6240\u89c1\u7684\u5185\u5bb9\u53ef\u80fd\u548c\u5b9e\u9645\u5185\u5bb9\u4e0d\u540c\u3002\u5982\u679c\u5c06\u6587\u4ef6\u4ee5\u6587\u672c\u6a21\u5f0f\u6253\u5f00\uff0c\u90a3\u4e48\u5728\u8bfb\u53d6\u6587\u4ef6\u65f6\uff0c\u4f1a\u628a\u672c\u5730\u73af\u5883\u8868\u793a\u7684\u6362\u884c\u7b26\u6216\u6587\u4ef6\u7ed3\u5c3e\u6620\u5c04\u4e3a C \u8bed\u8a00\u4e2d\u7684
\\n
\u548c EOF
\u3002 - \u4e8c\u8fdb\u5236\u6d41\uff1a\u7a0b\u5e8f\u6240\u89c1\u7684\u5185\u5bb9\u548c\u5b9e\u9645\u5185\u5bb9\u4e00\u81f4\u3002\u5982\u679c\u5c06\u6587\u4ef6\u4ee5\u4e8c\u8fdb\u5236\u6a21\u5f0f\u6253\u5f00\uff0c\u90a3\u4e48\u5728\u8bfb\u53d6\u6587\u4ef6\u65f6\uff0c\u4f1a\u628a\u6587\u4ef6\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b57\u8282\u90fd\u6620\u5c04\u4e3a C \u8bed\u8a00\u4e2d\u7684
char
\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":" - \u7c7b\u578b
size_t\nFILE\nfpos_t\n
- \u5b8f
stderr\nstdin\nstdout\nNULL\nEOF\nSEEK_CUR\nSEEK_END\nSEEK_SET\n// BUFSIZ\n// FOPEN_MAX\n// FILENAME_MAX\n
- \u51fd\u6570
- \u6587\u4ef6\u64cd\u4f5c\u51fd\u6570\uff08\u4e0d\u505a\u8981\u6c42\uff09
// int remove(const char *filename);\n// int rename(const char *old, const char *new);\n// FILE *tmpfile(void);\n
- \u6587\u4ef6\u8bbf\u95ee\u51fd\u6570
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
- \u683c\u5f0f\u5316\u7684\u8f93\u5165\u8f93\u51fa\u51fd\u6570
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
- \u5b57\u7b26\u8f93\u5165\u8f93\u51fa\u51fd\u6570
// 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
- \u76f4\u63a5\u8f93\u5165\u8f93\u51fa\u51fd\u6570\uff08\u8003\u8bd5\u4e0d\u7ba1\uff09
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
- \u6587\u4ef6\u5b9a\u4f4d\u51fd\u6570\uff08\u8003\u8bd5\u4e0d\u7ba1\uff09
//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
- \u9519\u8bef\u5904\u7406\u51fd\u6570\uff08\u4e0d\u505a\u8981\u6c42\uff09
// void clearerr(FILE *stream);\n// int feof(FILE *stream);\n// int ferror(FILE *stream);\n// void perror(const char *str);\n
"},{"location":"programming_lecture/lecture4/lecture4/#_20","title":"\u4f7f\u7528","text":"\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\u3002 - \u57fa\u672c\u7684\u6253\u5f00\u3001\u5173\u95ed\u6587\u4ef6
fopen
\u3001fclose
\u7684\u4f7f\u7528\u3002 r
\u3001w
\u3001a
\u3001b
\u7b49\u6a21\u5f0f\u7684\u4f7f\u7528\u3002 - \u5728\u4e00\u4e2a
FILE
\u4e2d\u7528 fscanf
\u3001fprintf
\u8bfb\u5199\u6570\u636e\u3002 fread
\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
- \u4e00\u4e2a\u53ef\u9009\u7684\u7cbe\u5ea6\uff1a\u5c0f\u6570\u70b9\u540e\u8ddf\u4e00\u4e2a\u661f\u53f7\u6216\u4e00\u4e2a\u5341\u8fdb\u5236\u6574\u6570\u3002
- \u5982\u679c\u662f\u6574\u6570\uff0c\u8868\u793a\u6700\u5c0f\u6570\u5b57\u4f4d\u6570\u3002
- \u5982\u679c\u662f\u6d6e\u70b9\u6570\uff0c\u8868\u793a\u5c0f\u6570\u70b9\u540e\u7684\u6700\u5927\u4f4d\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
- \u5982\u679c\u8f6c\u6362\u4e0e\u5b57\u7b26\u5339\u914d\u5931\u8d25\uff0c\u8fd9\u4e2a\u8f93\u5165\u5b57\u7b26\u4f1a\u7559\u5728\u8f93\u5165\u6d41\u4e2d\u3002\u5728\u4f60\u4e0b\u4e00\u6b21\u8bfb\u53d6\u5b57\u7b26\u65f6\uff0c\u5b83\u53ef\u80fd\u4f1a\u6363\u4e71\uff01
- \u8fd9\u4e2a\u51fd\u6570\u7684\u53c2\u6570\u662f\u4ec0\u4e48\u7c7b\u578b\uff1f\u4ec0\u4e48\u65f6\u5019\u8be5\u52a0\u53d6\u503c\u7b26
&
\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
- \u6b63\u5e38\uff1a\u8fd4\u56de\u4f20\u8f93\u7684\u5b57\u7b26\u6570
- \u5f02\u5e38\uff1a\u8fd4\u56de\u8d1f\u6570
scanf
\u3001fscanf
\u3001sscanf
- \u6b63\u5e38\uff1a\u8fd4\u56de\u6210\u529f\u5339\u914d\u5e76\u8d4b\u503c\u7684\u8f93\u5165\u9879\u6570
- \u5f02\u5e38\uff1a\u8fd4\u56de
EOF
\u6587\u4ef6\u5b9a\u4f4d\uff08\u4e0d\u505a\u4ecb\u7ecd\uff09 - \u4e09\u79cd\u4fee\u6539\u6587\u4ef6\u5b9a\u4f4d\u7b26\u7684\u53ef\u80fd\uff1a
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\u3002 fseek
\u3001ftell
\u3001rewind
\uff1a\u8f83\u8001\u7684\u4f20\u7edf\u7684\u6587\u4ef6\u5b9a\u4f4d\u51fd\u6570 fgetpos
\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
"},{"location":"programming_lecture/lecture5/lecture5/","title":"\u6307\u9488\u53ca\u94fe\u8868\u76f8\u5173\u77e5\u8bc6\u70b9\u590d\u4e60","text":"\u6458\u8981
\u8003\u8651\u5230\u672c\u6b21\u8f85\u5b66\u65f6\u95f4\u5df2\u8fd1\u671f\u672b\uff0c\u539f\u5148\u5b89\u6392\u7684\u4ecb\u7ecd\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u5185\u5bb9\u5df2\u7ecf\u4e0d\u592a\u5408\u9002\uff0c\u56e0\u6b64\u672c\u6b21\u8f85\u5b66\u65f6\u95f4\u5c06\u4e3b\u8981\u4ecb\u7ecd\u671f\u672b\u8003\u8bd5\u7684\u90e8\u5206\u91cd\u70b9\u77e5\u8bc6\uff0c\u4ee5\u8bb2\u89e3\u6307\u9488\u4e0e\u94fe\u8868\u4e3a\u4e3b\u3002
\u672c\u6b21\u8f85\u5b66\u7684\u4e3b\u8981\u5185\u5bb9\uff1a
- \u7ed3\u5408\u5386\u5e74\u5377\u590d\u4e60\u6307\u9488\u7684\u4f7f\u7528
- \u94fe\u8868\u76f8\u5173\u77e5\u8bc6\u7684\u590d\u4e60
\u5176\u4e2d\u6211\u4eec\u8f85\u5b66\u5b66\u957f\u5199\u7684\u4e13\u9898\u7b14\u8bb0 \u2014\u2014 \u4e13\u9898\u7b14\u8bb0-\u6307\u9488\u6982\u89c8 \u5df2\u7ecf\u5bf9\u6307\u9488\u8fdb\u884c\u4e86\u8be6\u7ec6\u7684\u4ecb\u7ecd\u3002\u672c\u6b21\u8f85\u5b66\u4e0d\u4f1a\u6df1\u6316\u6307\u9488\u7684\u5185\u5b58\u6a21\u578b\u7b49\u7ec6\u8282\uff0c\u4e3b\u8981\u662f\u9488\u5bf9\u5386\u5e74\u5377\u9898\u76ee\uff0c\u4ee5\u53ca\u8f85\u5b66\u7fa4\u4e2d\u540c\u5b66\u4eec\u6240\u95ee\u7684\u6307\u9488\u76f8\u5173\u7684\u95ee\u9898\uff0c\u8fdb\u884c\u4ee5\u5907\u8003\u4e3a\u76ee\u7684\u7684\u590d\u4e60\u3002
"},{"location":"programming_lecture/lecture5/lecture5/#_2","title":"\u6307\u9488\u7684\u57fa\u672c\u64cd\u4f5c","text":""},{"location":"programming_lecture/lecture5/lecture5/#_3","title":"\u6307\u9488\u7684\u58f0\u660e","text":"\u58f0\u660e\u4e00\u4e2a\u6307\u9488\uff1a
VariableType *pointerName;\n
\u5176\u4e2d VariableType
\u4e3a\u6307\u9488\u6307\u5411\u7684\u53d8\u91cf\u7c7b\u578b\uff0cpointerName
\u4e3a\u6307\u9488\u7684\u540d\u79f0\u3002
\u4f8b\u5982\uff1aint *p;
\u58f0\u660e\u4e86\u4e00\u4e2a\u6307\u5411 int
\u7c7b\u578b\u53d8\u91cf\u7684\u6307\u9488\uff0c\u6307\u9488\u7684\u540d\u79f0\u4e3a p
\u3002
\u6ce8\u610f
VariableType
\u4ee3\u8868\u7c7b\u578b\u8bf4\u660e\u7b26\uff0c\u5982 int
\u3001char
\u6216\u8005\u81ea\u5df1\u5b9a\u4e49\u7684 struct
\u7b49\u3002 *
\u5728\u6307\u9488\u58f0\u660e\u4e2d\u4ee3\u8868\u58f0\u660e\u6307\u9488\u7c7b\u578b\u3002\u6ce8\u610f\uff1a*
\u5728\u6307\u9488\u58f0\u660e\u548c\u6307\u9488\u4f7f\u7528\u4e2d\u4ee3\u8868\u7684\u542b\u4e49\u4e0d\u76f8\u540c\uff01\uff01\uff01\uff01\uff01 pointerName
\u4ee3\u8868\u6307\u9488\u7684\u540d\u79f0\uff0c\u9700\u8981\u7b26\u5408\u6807\u8bc6\u7b26\u547d\u540d\u89c4\u8303\u3002
\u9650\u5b9a\u7b26\u5bf9\u6307\u9488\u7684\u9650\u5b9a
\u9650\u5b9a\u7b26\u5728 C \u8bed\u8a00\u4e2d\u7528\u4e8e\u9650\u5b9a\u53d8\u91cf\u7684\u7c7b\u578b\uff0c\u6700\u5e38\u7528\u7684\u4e3a const
\u9650\u5b9a\u7b26\u3002
\u5728\u6307\u9488\u58f0\u660e\u4e2d\uff0c\u9650\u5b9a\u7b26\u51fa\u73b0\u7684\u4f4d\u7f6e\u51b3\u5b9a\u4e86\u9650\u5b9a\u7b26\u662f\u5bf9\u6307\u9488\u672c\u8eab\u7684\u9650\u5b9a\uff0c\u8fd8\u662f\u5bf9\u6307\u9488\u6307\u5411\u7684\u53d8\u91cf\u7684\u9650\u5b9a\u3002
int n;\nconst int * pc = &n; // pc \u662f\u6307\u5411 const int \u7684\u975e const \u6307\u9488\n// *pc = 2; // \u9519\u8bef\uff1a\u4e0d\u80fd\u901a\u8fc7\u4e0d\u5e26\u8f6c\u578b\u7684 pc \u4fee\u6539 n\npc = NULL; // OK\uff1apc \u81ea\u8eab\u53ef\u4fee\u6539\n\nint * const cp = &n; // cp \u662f\u4e00\u4e2a\u6307\u5411\u975e const \u7684 int \u7684 const \u6307\u9488\n*cp = 2; // OK\uff1a\u901a\u8fc7 cp \u4fee\u6539 n\n// cp = NULL; // \u9519\u8bef\uff1acp \u81ea\u8eab\u4e0d\u80fd\u4fee\u6539\n
\u5927\u4f53\u53ea\u9700\u8981\u8bb0\u4f4f\uff1a\u9650\u5b9a\u7b26\u4f1a\u5bf9\u7d27\u968f\u5176\u540e\u7684\u5bf9\u8c61\u8fdb\u884c\u9650\u5b9a\u5373\u53ef\u3002
\u8fdb\u9636\u4e00\u70b9\u7684\u4f8b\u5b50\uff1a
int * const * pcp = &cp; // \u6307\u5411\u6307\u5411\u975e const \u7684 int \u7684 const \u6307\u9488\u7684\u975e const \u6307\u9488\n
"},{"location":"programming_lecture/lecture5/lecture5/#_4","title":"\u591a\u7ea7\u6307\u9488\u7684\u58f0\u660e","text":"\u5bf9\u591a\u7ea7\u6307\u9488\u7684\u58f0\u660e\uff0c\u53ef\u4ee5\u7528\u9012\u5f52\u7684\u65b9\u5f0f\u7406\u89e3\u3002
\u5bf9\u4e8e\u6307\u5411 int
\u7c7b\u578b\u7684\u4e00\u7ea7\u6307\u9488\uff0c\u5176 VariableType
\u4e3a int
\uff1b\u5bf9\u4e8e\u4e8c\u7ea7\u6307\u9488 int **p
\uff0c\u5373\u6307\u5411\u6307\u5411 int
\u7c7b\u578b\u7684\u6307\u9488\u7684\u6307\u9488\uff0c\u5176 VariableType
\u4e3a int *
\u3002
\u4f8b
int var = 1;\nint *p1 = &var;\nint **p = &p;\n
\u4ed6\u4eec\u7684\u6307\u5411\u5173\u7cfb\u662f\uff1a
(int **)p -> (int *)p1 -> (int)var\n
"},{"location":"programming_lecture/lecture5/lecture5/#_5","title":"\u6307\u9488\u6570\u7ec4\u4e0e\u6570\u7ec4\u6307\u9488","text":"\u5f88\u5bb9\u6613\u641e\u6df7\uff0c\u9700\u8981\u6280\u5de7\u6765\u8bc6\u522b\u3002
\u6bd4\u5982\u4e0b\u9762\u4e24\u6761\u58f0\u660e\uff1a
char *p[10]; // \u5927\u5c0f\u4e3a 10 \u7684\u6570\u7ec4\uff0c\u6570\u7ec4\u5143\u7d20\u662f\u6307\u5411 char \u7c7b\u578b\u7684\u6307\u9488\n\nchar (*p)[10]; // \u6307\u9488\uff0c\u6307\u5411\u5927\u5c0f\u4e3a 10 \u7684 char \u6570\u7ec4\n
\u7262\u8bb0\u987a\u65f6\u9488\u87ba\u65cb\u6cd5\u5219\uff08Clockwise/Spiral Rule\uff09\uff08\u8be6\u89c1\u8f85\u5b66\u7fa4\u7fa4\u6587\u4ef6\u4e2d\u7684\u201c\u6d45\u8c08 C \u8bed\u8a00\u7684\u6570\u636e\u7c7b\u578b.pdf\u201d\uff09\u3002
\u4e8e\u662f\uff0c\u4e0a\u9762\u7684\u4e24\u6761\u58f0\u660e\u5c31\u53ef\u4ee5\u516c\u5f0f\u5316\u5730\u89e3\u91ca\uff1a
char *p[10];
: p is an array 10 of pointers to char. char (*p)[10];
: p is a pointer to an array 10 of char.
\u4e0a\u4e00\u8282\u7684\u591a\u7ea7\u6307\u9488\u58f0\u660e\u540c\u6837\u53ef\u4ee5\u7528\u8fd9\u4e2a\u6cd5\u5219\u8fdb\u884c\u89e3\u91ca\u3002
"},{"location":"programming_lecture/lecture5/lecture5/#_6","title":"\u6307\u9488\u7684\u4f7f\u7528","text":""},{"location":"programming_lecture/lecture5/lecture5/#_7","title":"\u6307\u9488\u7684\u89e3\u5f15\u7528","text":"\u89e3\u5f15\u7528\u8fd0\u7b97\u7b26 *
\u7684\u4e00\u822c\u5f62\u5f0f\u4e3a\uff1a
* \u6307\u9488\u8868\u8fbe\u5f0f\n
\u7ed3\u679c\u4e3a\u6307\u4ee3\u88ab\u6307\u5411\u5bf9\u8c61\u7684\u5de6\u503c\u8868\u8fbe\u5f0f\uff0c\u5373\u53ef\u4ee5\u88ab\u8d4b\u503c\u3002
\u8bb0\u4f4f a[b]
\u7b49\u4ef7\u4e8e *(a + b)
\u3002\u8fd9\u4e2a trick \u5728\u4e00\u4e9b\u9898\u76ee\u4e2d\u5f88\u6709\u7528\u3002
\u4f8b\u9898
Given the declaration: int a[3][3]={1,2,3,4,5,6,7,8,9};
, the value of a[-1][5]
is _____.
Answer \u89e3\u7b54\u6765\u81ea\uff1axg \u2014\u2014 \u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66\u5e38\u95ee\u9898\u76ee\u53ca\u89e3\u6790v1.1.pdf
a[-1]
\u7b49\u4ef7\u4e8e *(a - 1)
\uff0ca - 1
\u4f1a\u4ee5 3 \u4e2a int
\u4e3a\u5355\u4f4d\u5411\u5de6\u79fb\u52a8\uff0c\u5373
0 0 0 1 2 3 4 5 6 7 8 9\n ^\n |\np = *(a - 1)\n
\u4ee4 p = *(a - 1)
\uff0c\u5219\u8981\u6c42\u7684\u503c\u53d8\u4e3a p[5]
\uff0c\u7b49\u4ef7\u4e8e *(p + 5)
\u3002\u5c06\u4e0a\u8ff0\u6307\u9488\u53f3\u79fb 5 \u4e2a int
\u5355\u4f4d\uff0c\u5f97\u5230 3\u3002
\u91ce\u6307\u9488
\u5f53\u6307\u9488\u58f0\u660e\u65f6\u672a\u521d\u59cb\u5316\uff0c\u4e14\u8fd8\u672a\u88ab\u8d4b\u503c\uff0c\u5219\u8fd9\u4e2a\u6307\u9488\u6307\u5411\u65e0\u6cd5\u786e\u5b9a\uff0c\u88ab\u79f0\u4e3a \u91ce\u6307\u9488\u3002
\u91ce\u6307\u9488\u53ef\u80fd\u6307\u5411\u4efb\u610f\u5185\u5b58\uff0c\u5bf9\u5176\u8fdb\u884c\u8bbf\u95ee\u53ef\u80fd\u4f1a\u5bfc\u81f4\u975e\u6cd5\u5185\u5b58\u8bbf\u95ee\uff0c\u4ea7\u751f\u6bb5\u9519\u8bef\u3002
\u5728\u8003\u9898\u4e2d\uff0c\u5c1d\u8bd5\u8bbf\u95ee\u91ce\u6307\u9488\u662f\u9519\u8bef\u7684\u64cd\u4f5c\u3002\u5728\u81ea\u5df1\u5199\u4ee3\u7801\u65f6\u4e5f\u7edd\u4e0d\u80fd\u51fa\u73b0\u91ce\u6307\u9488\u8bbf\u95ee\u3002
\u4f8b\u9898
For the declarations: char *s, str[10];
, statement _____ is completely correct.
A. strcpy(s, \"hello\");
B. str=\"hello\"+1
C. s=*&(str+1)
D. s=str+1
\u9009\u9879 A \u5c31\u662f\u7ecf\u5178\u7684\u91ce\u6307\u9488\u8bbf\u95ee\u3002
"},{"location":"programming_lecture/lecture5/lecture5/#_8","title":"\u53d6\u5740\u64cd\u4f5c","text":"\u53d6\u5740\u8fd0\u7b97\u7b26 &
\u65e9\u5728\u5927\u5bb6\u5b66\u4e60\u8f93\u5165\u8f93\u51fa\u7684\u65f6\u5019\u5c31\u5df2\u7ecf\u63a5\u89e6\u8fc7\u4e86\u3002\u5728\u4f7f\u7528 scanf
\u5bf9 int
\u7b49\u7c7b\u578b\u7684\u53d8\u91cf\u8fdb\u884c\u8bfb\u5165\u7684\u65f6\u5019\uff0c\u4f7f\u7528\u7684\u662f\u5982\u4e0b\u5f62\u5f0f\uff1a
int a;\nscanf(\"%d\", &a);\n
\u8fd9\u91cc\u7684 &
\u5bf9 a
\u8fdb\u884c\u53d6\u5740\u64cd\u4f5c\uff0c\u5bf9 a
\u7684\u5730\u5740\u800c\u4e0d\u662f a
\u7684\u503c\u8fdb\u884c\u8bfb\u5165\u3002
\u4e00\u822c\u5730\uff0c\u53d6\u5740\u8fd0\u7b97\u7b26\u6709\u5982\u4e0b\u51e0\u79cd\u5f62\u5f0f\uff1a
& <function>
\uff1a\u53d6\u51fd\u6570\u7684\u5730\u5740\u3002\u8fd9\u4e2a\u4e0d\u505a\u8981\u6c42\u3002 -
& \u5de6\u503c\u8868\u8fbe\u5f0f
\uff1a\u53d6\u5de6\u503c\u8868\u8fbe\u5f0f\u7684\u5730\u5740\u3002\u7ed3\u679c\u4e3a\u6307\u5411\u5de6\u503c\u8868\u8fbe\u5f0f\u7684\u6307\u9488\u3002
\u5de6\u503c\u8868\u8fbe\u5f0f
\u5de6\u503c\uff0c\u7b80\u5355\u6765\u8bf4\u53ef\u4ee5\u770b\u4f5c\u662f\u5728\u5185\u5b58\u4e2d\u6709\u5bf9\u5e94\u5b58\u50a8\u7a7a\u95f4\u7684\u8868\u8fbe\u5f0f\uff0c\u5982\u53d8\u91cf\u3001\u6570\u7ec4\u5143\u7d20\u3001\u7ed3\u6784\u4f53\u6210\u5458\u7b49\u3002
\u76f8\u53cd\uff0c\u82e5\u8868\u8fbe\u5f0f\u5728\u5185\u5b58\u4e2d\u6ca1\u6709\u5bf9\u5e94\u5b58\u50a8\u7a7a\u95f4\uff0c\u5219\u4e0d\u80fd\u53d6\u5740\uff0c\u6bd4\u5982 &a
\u30011+2
\u7b49\u3002
-
& * \u8868\u8fbe\u5f0f
\uff1a&
\u548c *
\u5f7c\u6b64\u62b5\u6d88\uff0c\u5747\u4e0d\u6c42\u503c\u3002\u8fd9\u4e2a\u4ec5\u4f5c\u4e86\u89e3\u3002
& \u8868\u8fbe\u5f0f [\u8868\u8fbe\u5f0f]
\uff1a\u7b49\u4ef7\u4e8e & *(\u8868\u8fbe\u5f0f + \u8868\u8fbe\u5f0f)
\u7b49\u4ef7\u4e8e \u8868\u8fbe\u5f0f + \u8868\u8fbe\u5f0f
\u3002\u8fd9\u4e2a\u4ec5\u4f5c\u4e86\u89e3\u3002
\u89e3\u5f15\u7528\u4e0e\u53d6\u5740\u64cd\u4f5c\u7684\u5e94\u7528
\u8f93\u5165\u4e00\u4e2a 64 \u4f4d\u65e0\u7b26\u53f7\u6574\u6570 x
\uff0c\u6c42 x
\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u7684 01 \u4e32\u6240\u8868\u793a\u7684 double
\u7c7b\u578b\u53d8\u91cf\u7684\u503c\u3002
Answer unsigned long long x;\nscanf(\"%llu\", &x);\nprintf(\"%lf\\n\", *((double *)&x));\n
"},{"location":"programming_lecture/lecture5/lecture5/#_9","title":"\u901a\u8fc7\u6307\u9488\u8fdb\u884c\u6210\u5458\u8bbf\u95ee","text":"\u5bf9\u4e8e\u7ed3\u6784\u4f53\u7c7b\u578b\u7684\u6307\u9488\uff0cC \u8bed\u8a00\u63d0\u4f9b\u4e86\u4e00\u4e2a\u8fd0\u7b97\u7b26 ->
\uff0c\u7528\u4e8e\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u7ed3\u6784\u4f53\u6210\u5458\u3002
struct Point { int x, y; }; // \u5b9a\u4e49\u7ed3\u6784\u4f53 Point\nstruct Point point = { 1, 2 }; // \u5b9a\u4e49\u7ed3\u6784\u4f53\u53d8\u91cf point\n\nstruct Point *p = &point; // p \u6307\u5411 point \u7ed3\u6784\u4f53\np->x = 3; // \u901a\u8fc7\u6307\u9488 p \u8bbf\u95ee\u7ed3\u6784\u4f53\u6210\u5458 x\n// \u7b49\u4ef7\u4e8e (*p).x = 3;\n
"},{"location":"programming_lecture/lecture5/lecture5/#_10","title":"\u6570\u7ec4\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362","text":"\u9690\u5f0f\u8f6c\u6362
\u6570\u7ec4\u5230\u6307\u9488\u8f6c\u6362
\u4efb\u4f55\u6570\u7ec4\u7c7b\u578b\u7684\u5de6\u503c\u8868\u8fbe\u5f0f\uff0c\u5728\u7528\u4e8e\u5f02\u4e8e\u4e0b\u5217\u8bed\u5883\u65f6
- \u4f5c\u4e3a\u53d6\u5740\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\u6570
- \u4f5c\u4e3a
sizeof
\u7684\u64cd\u4f5c\u6570 - \u4f5c\u4e3a
typeof
\u548c typeof_unqual
\u7684\u64cd\u4f5c\u6570 - \u4f5c\u4e3a\u7528\u4e8e\u6570\u7ec4\u521d\u59cb\u5316\u7684\u5b57\u7b26\u4e32\u5b57\u9762\u91cf
\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u975e\u5de6\u503c\u6307\u9488\u7684\u8f6c\u6362\u3002
\u2014\u2014 cppreference-\u9690\u5f0f\u8f6c\u6362
\u7b80\u5355\u6765\u8bf4\uff1a\u7262\u8bb0\u6570\u7ec4\u540d \u4e0d\u7b49\u4e8e \u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u7684\u6307\u9488\uff0c\u5f53\u6570\u7ec4\u540d\u88ab\u53d6\u5740\u8fd0\u7b97\u7b26 &
\u4f5c\u7528\uff0c\u6216\u8005\u4f5c\u4e3a sizeof
\u7684\u64cd\u4f5c\u6570\u65f6\uff0c\u4e0d\u4f1a\u53d1\u751f\u9690\u5f0f\u8f6c\u6362\u3002
\u8fd9\u91cc\u8981\u6ce8\u610f\u7684\u4e00\u70b9\u662f\uff0c\u5c06\u6570\u7ec4\u4f5c\u4e3a\u53c2\u6570\u4f20\u7ed9\u51fd\u6570\u65f6\uff0c\u51fd\u6570\u7684\u5f62\u53c2\u53ea\u80fd\u662f\u6307\u9488\uff0c\u800c\u4e0d\u80fd\u662f\u6570\u7ec4\uff0c\u6b64\u65f6\u6570\u7ec4\u540d\u4f1a\u53d1\u751f\u9690\u5f0f\u8f6c\u6362\u3002
\u6570\u7ec4\u7c7b\u578b\u7528\u4e8e\u51fd\u6570\u5f62\u53c2
\u5f53\u6570\u7ec4\u7c7b\u578b\u7528\u4e8e\u51fd\u6570\u5f62\u53c2\u5217\u8868\u65f6\uff0c\u5b83\u4f1a\u8f6c\u6362\u6210\u5bf9\u5e94\u7684\u6307\u9488\u7c7b\u578b\uff1aint f(int a[2])
\u3001int f(int a[])
\u3001int f(int *a)
\u58f0\u660e\u540c\u4e00\u4e2a\u51fd\u6570\u3002
\u56e0\u4e3a\u51fd\u6570\u5b9e\u9645\u53c2\u6570\u7c7b\u578b\u4e3a\u6307\u9488\u7c7b\u578b\uff0c\u4f7f\u7528\u6570\u7ec4\u5b9e\u53c2\u7684\u51fd\u6570\u8c03\u7528\u4f1a\u8fdb\u884c\u4e00\u4e2a\u6570\u7ec4\u5230\u6307\u9488\u8f6c\u6362\uff1b\u88ab\u8c03\u7528\u51fd\u6570\u65e0\u6cd5\u83b7\u5f97\u5b9e\u53c2\u6570\u7ec4\u7684\u5927\u5c0f\uff0c\u5fc5\u987b\u663e\u5f0f\u4f20\u9012\u3002
\u89c1 \u6bcf\u65e5\u4e00\u9898-29\u3002
Warning
\u53ea\u6709\u6570\u7ec4\u7c7b\u578b\u7528\u4e8e\u51fd\u6570\u5f62\u53c2\u5217\u8868\u65f6\uff0ca[]
\u548c *a
\u624d\u662f\u7b49\u4ef7\u7684\u3002
\u6bd4\u5982\u4f7f\u7528\u5b57\u7b26\u4e32\u5e38\u91cf\u521d\u59cb\u5316\u5b57\u7b26\u4e32\uff1a
\u521b\u5efa\u6307\u5411\u5b57\u7b26\u4e32\u5e38\u91cf\u7684\u6307\u9488\uff0c\u5185\u5bb9\u4e0d\u80fd\u66f4\u6539\uff0c
char *s = \"hello\"; // s \u7c7b\u578b\u4e3a char * \uff0c\u6307\u5411\u5b57\u7b26\u4e32\u5e38\u91cf\ns = \"he11o\"; // OK\n
\u521b\u5efa char \u6570\u7ec4\uff0c\u5185\u5bb9\u88ab\u5b57\u7b26\u4e32\u5e38\u91cf\u521d\u59cb\u5316\uff0c\u5185\u5bb9\u53ef\u4ee5\u66f4\u6539\uff0c
char s[] = \"hello\"; // s \u7c7b\u578b\u4e3a char [6] \uff0c\u6570\u7ec4\u5185\u5bb9\u662f \"hello\\0\" \u7684\u62f7\u8d1d\n// s[] = \"he11o\"; // wrong\n
Question
\u4e0b\u5217\u4ee3\u7801\u7684 val_x
\u548c val_y
\u7684\u7c7b\u578b\u4e00\u6837\u5417\uff1f
int a[10], *p = a;\nType1 val_x = &a;\nType2 val_y = &p;\n
Question
\u4e0b\u5217\u4ee3\u7801\u7684 size_x
\u548c size_y
\u5927\u5c0f\u4e00\u6837\u5417\uff1f
int a[10], *p = a;\nsize_t size_x = sizeof a;\nsize_t size_y = sizeof p;\n
"},{"location":"programming_lecture/lecture5/lecture5/#_11","title":"\u6307\u9488\u7684\u503c\u4e0e\u6307\u9488\u7684\u5730\u5740","text":"\u6307\u9488\u7684\u503c\uff0c\u53c8\u79f0\u4e3a\u6307\u9488\u6240\u6307\u5411\u7684\u5185\u5b58\u533a\u3002
\u5728\u8ba1\u7b97\u673a\u4e2d\uff0c\u5185\u5b58\u4e2d\u7684\u6240\u6709\u5b57\u8282\u90fd\u62e5\u6709\u4e00\u4e2a\u552f\u4e00\u7f16\u53f7\uff0c\u4e5f\u5373\u5185\u5b58\u5730\u5740\u3002\u6307\u9488\u6307\u5411\u67d0\u4e00\u6570\u636e\u7684\u5730\u5740\uff0c\u5373\u6307\u9488\u53d8\u91cf\u5b58\u50a8\u4e86\u8fd9\u4e2a\u6570\u636e\u7684\u5185\u5b58\u5730\u5740\u7684\u7f16\u53f7\u3002
\u6307\u9488\u6240\u5360\u7684\u5b57\u8282\u6570
\u73b0\u5728\u4e00\u822c\u7684\u8ba1\u7b97\u673a\u57fa\u672c\u90fd\u662f 64 \u4f4d\u7cfb\u7edf\uff0c\u4f7f\u7528 64 \u4f4d\u957f\u7684\u5185\u5b58\u5730\u5740\uff0c\u5373\u5185\u5b58\u5730\u5740\u7684\u7f16\u53f7\u662f\u4e00\u4e2a 64 \u4f4d\u6574\u6570\u3002\u5728 64 \u4f4d\u7cfb\u7edf\u4e2d\u4f7f\u7528 sizeof
\u8fd0\u7b97\u7b26\u6c42\u6307\u9488\u7684\u5927\u5c0f\u65f6\uff0c\u5f97\u5230\u7684\u7ed3\u679c\u4e3a 8\u3002
\u6ce8\u610f\uff0c\u4e00\u822c\u6765\u8bf4\u65e0\u6cd5\u9884\u6d4b\u5730\u5740\u7684\u503c\uff0c\u56e0\u4e3a\u5185\u5b58\u5730\u5740\u53d6\u51b3\u4e8e\u7cfb\u7edf\u7684\u5185\u5b58\u5206\u914d\u60c5\u51b5\u3002\u4f46\u90e8\u5206\u60c5\u51b5\u4e0b\u53ef\u4ee5\u786e\u5b9a\u5185\u5b58\u5730\u5740\u7684\u76f8\u5bf9\u4f4d\u7f6e\uff0c\u6bd4\u5982\u540c\u4e00\u6570\u7ec4\u4e2d\u5143\u7d20\u5728\u5185\u5b58\u4e2d\u8fde\u7eed\u3002
\u6b64\u5916\uff0c\u6307\u9488\u540c\u6837\u4e5f\u662f\u4e00\u4e2a\u5728\u5185\u5b58\u4e2d\u6709\u5bf9\u5e94\u5b58\u50a8\u7a7a\u95f4\u7684\u53d8\u91cf\uff0c\u4e5f\u6709\u81ea\u5df1\u7684\u5185\u5b58\u5730\u5740\u3002\u5728\u6307\u9488\u7684\u5185\u5b58\u5730\u5740\u4e2d\uff0c\u5b58\u50a8\u7684\u5185\u5bb9\u662f\u5176\u6307\u5411\u7684\u5185\u5bb9\u7684\u5185\u5b58\u5730\u5740\u3002
\u7c7b\u6bd4\u7406\u89e3
\u5047\u5982\u6709\u4e00\u4e2a\u5f88\u957f\u7684\u6570\u7ec4\uff0c\u5b58\u50a8\u4e86\u4e00\u4e9b\u6570\u636e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u4e0b\u6807\u53bb\u8bbf\u95ee\u6570\u636e\u3002\u5c06\u6570\u7ec4\u4e0b\u6807\u5f53\u4f5c\u6570\u636e\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u53ef\u4ee5\u4ece\u6570\u7ec4\u4e2d\u7684\u67d0\u4e00\u4f4d\u7f6e\u53bb\u8bbf\u95ee\u5176\u5b58\u50a8\u7684\u6570\u7ec4\u4e0b\u6807\u7684\u4f4d\u7f6e\u7684\u6570\u636e\uff0c\u8fd9\u5c31\u53ef\u4ee5\u770b\u4f5c\u662f\u7b80\u5355\u7684\u6307\u9488\u3002
\u4e0b\u6807 31 32 33 34 ... X\narr data0 data1 data2 data3 .... 32\n ^ |\n +--------------------------------+\n
Question
\u90a3\u4e48\u5c31\u6709\u540c\u5b66\u95ee\u4e86\uff1a\u65e2\u7136\u6307\u9488\u7684\u503c\u662f 64 \u4f4d\u6574\u6570\uff0c\u90a3\u80fd\u7528\u5173\u7cfb\u8fd0\u7b97\u7b26\u6bd4\u8f83\u5927\u5c0f\u5417\uff1f
\u7b54\u6848\u662f\uff1a\u90e8\u5206\u60c5\u51b5\u4e0b\u53ef\u4ee5\u3002
\u5173\u7cfb\u8fd0\u7b97\u7b26\u8fdb\u884c\u6307\u9488\u6bd4\u8f83 \u6839\u636e cppreference-\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff0c\u5f53\u8fdb\u884c\u6307\u9488\u6bd4\u8f83\u7684\u65f6\u5019\uff0c\u6709\u4ee5\u4e0b\u8981\u6c42\uff1a
\u4e24\u6307\u9488\u5fc5\u987b\u662f\u517c\u5bb9\u7c7b\u578b\u7684\u6307\u9488\u3002\u4e14\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u4e4b\u4e00\uff1a
- \u4e24\u4e2a\u6307\u9488\u6307\u5411\u540c\u4e00\u5bf9\u8c61\uff0c\u6216\u6307\u5411\u540c\u4e00\u6570\u7ec4\u7684\u5c3e\u540e\u4e00\u4f4d\u7f6e\uff0c\u5219\u76f8\u7b49\u3002
- \u4e24\u4e2a\u6307\u9488\u6307\u5411\u540c\u4e00\u6570\u7ec4\u4e2d\u7684\u4e0d\u540c\u5143\u7d20\uff0c\u5219\u6307\u5411\u6709\u8f83\u5927\u4e0b\u6807\u7684\u5143\u7d20\u7684\u6307\u9488\u6bd4\u8f83\u5927\u3002\uff08\u540c\u4e00\u6570\u7ec4\u4e2d\uff0c\u6307\u5411\u6570\u7ec4\u5c3e\u540e\u4e00\u4f4d\u7f6e\u7684\u6307\u9488\u6700\u5927\uff09
- \u4e24\u4e2a\u6307\u9488\u6307\u5411\u540c\u4e00\u7ed3\u6784\u4f53\u7684\u6210\u5458\uff0c\u5219\u6307\u5411\u7ed3\u6784\u4f53\u58f0\u660e\u4e2d\u8f83\u540e\u58f0\u660e\u7684\u6210\u5458\u7684\u6307\u9488\u66f4\u5927\u3002
- \u6307\u5411\u540c\u4e00\u8054\u5408\u4f53\u6210\u5458\u7684\u6307\u9488\u6bd4\u8f83\u76f8\u7b49\u3002\u8fd9\u4e2a\u4e0d\u505a\u8981\u6c42\u3002
\u9664\u6b64\u4e4b\u5916\uff0c\u6307\u9488\u7684\u6bd4\u8f83\u7ed3\u679c\u662f\u672a\u5b9a\u4e49\u7684\u3002
\u6307\u9488\u7684\u8ba1\u7b97
\u6d89\u53ca\u6307\u9488\u7684\u52a0\u51cf\u53ea\u6709\u4e24\u79cd\u60c5\u51b5\uff1a
-
\u6307\u9488\u7c7b\u578b \u00b1 \u6574\u6570\u7c7b\u578b p + a
\u6216 p - a
\u7ed3\u679c\u4e3a\u6307\u9488 p
\u53f3\u79fb/\u5de6\u79fb a
\u4e2a\u5355\u4f4d\uff0c\u5355\u4f4d\u7531\u6307\u9488\u7684\u7c7b\u578b\u51b3\u5b9a\u3002
\u6bd4\u5982\u8bfb\u5165\u6570\u7ec4\u65f6\u53ef\u4ee5\u4f7f\u7528\uff1ascanf(\"%d\", arr + i)
\u3002
-
\u76f8\u540c\u7c7b\u578b\u7684\u6307\u9488\u76f8\u51cf
\u7ed3\u679c\u4e3a\u4e24\u6307\u9488\u4e4b\u95f4\u5dee\u4e86\u591a\u5c11\u5355\u4f4d\u8ddd\u79bb\uff0c\u800c\u4e0d\u662f\u6307\u9488\u7684\u503c\u76f8\u51cf\u3002
\u4f8b\u9898
\u4ee5\u4e0b\u4ee3\u7801\u7684\u8f93\u51fa\u4e3a _____\u3002
int a[] = {1, 2, 3, 4, 5};\nint *p = a, *q = &a[2];\nprintf(\"%lu\\n\", q - p);\n
"},{"location":"programming_lecture/lecture5/lecture5/#_12","title":"\u4e00\u4e9b\u9898\u76ee","text":"\u9898\u76ee 1
The following code fragment will output _____.
char *week[]={\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"}, **pw=week;\nchar c1, c2;\nc1 = (*++pw)[1];\nc2 = *++pw[1];\nprintf(\"%c#%c#\", c1, c2);\n
Answer \"Mon\\0\" \"Tue\\0\" \"Wed\\0\" \"Thu\\0\" \"Fri\\0\" \"Sat\\0\" \"Sun\\0\"\n ^ ^ ^ ^ ^ ^ ^\n | | | | | | |\nweek: week[0] week[1] week[2] week[3] week[4] week[5] week[6]\n ^\n |\n pw\n
\u9898\u76ee 2
For definitions:
char s[2][3] = {\"ab\", \"cd\"}, *p = (char *)s;\n
the expression _____ is correct and its value is equivalent to the element s[1][1]
.
A. *(s + 3)
B. *s + 2
C. p[1][1]
D. *++p + 2
Answer s: \"ab\\0\" \"cd\\0\"\n ^\n |\ns(\u9690\u5f0f\u8f6c\u6362)(char *[3])\n\ns: \"ab\\0\" \"cd\\0\"\n ^\n |\n p = (char *)s\n
"},{"location":"programming_lecture/lecture5/lecture5/#_13","title":"\u94fe\u8868","text":""},{"location":"programming_lecture/lecture5/lecture5/#_14","title":"\u57fa\u7840\u77e5\u8bc6\u548c\u603b\u7ed3","text":"\u94fe\u8868\u662f\u4e00\u79cd\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u901a\u8fc7\u8282\u70b9\u7684\u5f62\u5f0f\u5b58\u50a8\u6570\u636e\u3002\u6bcf\u4e2a\u8282\u70b9\u5305\u542b\u6570\u636e\u90e8\u5206\u548c\u6307\u5411\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684\u6307\u9488\u3002\u94fe\u8868\u53ef\u4ee5\u662f\u5355\u5411\u7684\u4e5f\u53ef\u4ee5\u662f\u53cc\u5411\u7684\uff0c\u6211\u4eec\u5148\u770b\u770b\u5355\u5411\u94fe\u8868\uff1a
\u5355\u5411\u94fe\u8868\u7684\u4e00\u79cd\u5b9a\u4e49\u65b9\u5f0f
typedef struct Node {\n int data;\n struct Node* next;\n} Node;\n
\u597d\u4e86\uff0c\u6211\u4eec\u5df2\u7ecf\u628a\u94fe\u8868\u7ed9\u5b9a\u4e49\u51fa\u6765\u4e86\u3002\u4f46\u662f\u4f60\u4f1a\u597d\u5947\uff0c\u6211\u4eec\u4e0d\u662f\u53ea\u5b9a\u4e49\u51fa\u4e86\u8282\u70b9\u5417\uff1f\u600e\u4e48\u5df2\u7ecf\u5b9a\u4e49\u5b8c\u4e86\uff1f\u4e8b\u5b9e\u4e0a\uff0c\u8fd9\u51e0\u4e4e\u5c31\u5df2\u7ecf\u662f\u94fe\u8868\u7684\u5b8c\u6574\u7ed3\u6784\u4e86\u2014\u2014\u56e0\u4e3a\u94fe\u8868\u5c31\u662f\u7b80\u5355\u7684\u94fe\u8868\u8282\u70b9\u7684\u4e32\u8054\u3002
\u5927\u5bb6\u90fd\u5df2\u7ecf\u77e5\u9053\u4e86\u94fe\u8868\u7684\u7ed3\u6784\uff0c\u662f\u7c7b\u4f3c\u4e8e\u4e0b\u9762\u8fd9\u6837\u7684\uff1a
\u6240\u4ee5\uff0c\u94fe\u8868\u5176\u5b9e\u5c31\u662f\u4ee5\u4e0b\u7684\u4e1c\u897f\u7684\u7ed3\u5408\uff1a
- \u4e00\u4e2a\u6307\u5411\u5934\u7ed3\u70b9\u7684\u6307\u9488
head
\uff0c\u544a\u8bc9\u6211\u4eec\u4ece\u54ea\u91cc\u5f00\u59cb\u904d\u5386\u6574\u4e2a\u94fe\u8868\u3002 - \u5934\u8282\u70b9\u6307\u5411\u7684\u4e0b\u4e00\u4e2a\u8282\u70b9
head->next
\u3002\u6ce8\u610f\u8fd9\u4e5f\u662f\u4e00\u4e2a\u6307\u9488\u3002 - \u5934\u8282\u70b9\u6307\u5411\u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u8282\u70b9
head->next->next
\u3002 - ...
- \u6700\u540e\u4e00\u4e2a\u8282\u70b9\u3002
\u6211\u4eec\u600e\u4e48\u77e5\u9053\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u662f\u4ec0\u4e48\u5462\uff1f\u6211\u4eec\u89c4\u5b9a\uff0c\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u6307\u5411\u7684\u4f4d\u7f6e\u5c31\u662f NULL
\uff0c\u4e5f\u5c31\u662f 0
\u3002\u8fd9\u6837\uff0c\u53ea\u8981\u5224\u65ad\u8282\u70b9\u7684 .next
\u662f\u5426\u662f NULL
\uff0c\u5c31\u53ef\u4ee5\u77e5\u9053\u8fd9\u4e2a\u8282\u70b9\u662f\u4e0d\u662f\u5c3e\u8282\u70b9\u4e86\u3002\u597d\u4e86\uff0c\u6240\u4ee5\u6211\u4eec\u53ea\u9700\u8981\u82e5\u5e72\u4e2a Node
\uff0c\u7136\u540e\u5c06\u4ed6\u4eec\u4e32\u8054\u2014\u2014\u4e5f\u5c31\u662f\u901a\u8fc7 next
\u8fde\u63a5\uff0c\u5c31\u5f97\u5230\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u94fe\u8868\u3002
\u63a5\u4e0b\u6765\u8ba9\u6211\u4eec\u56de\u5fc6\u4e00\u4e0b\u94fe\u8868\u7684\u5404\u79cd\u64cd\u4f5c\u7684\u5b9e\u73b0\u5427\uff01\u4e0d\u8fc7\u5927\u5bb6\u5728\u5e73\u65f6\u505a\u9898\u7684\u65f6\u5019\u5e94\u8be5\u90fd\u611f\u89c9\u5230\u4e86\uff0c\u94fe\u8868\u6709\u5f88\u591a\u5f88\u591a\u96be\u4ee5\u7422\u78e8\u7684\u7ec6\u8282\u548c\u7279\u6b8a\u60c5\u51b5\uff01\u600e\u4e48\u529e\u5462\uff1f\u51b7\u9759\u4e0b\u6765\u603b\u7ed3\uff0c\u65e0\u975e\u5c31\u662f\u8fd9\u51e0\u79cd\uff1a
- \u7279\u6b8a\u60c5\u51b5 \\(1\\)\uff1a\u5982\u679c\u5934\u6307\u9488\u6307\u5411\u7684\u662f
NULL
\uff0c\u4e5f\u5c31\u662f\u94fe\u8868\u672c\u8eab\u5c31\u4e3a\u7a7a\u4e86\u3002 - \u7279\u6b8a\u60c5\u51b5 \\(2\\)\uff1a\u5982\u679c\u5f53\u524d\u64cd\u4f5c\u5728\u5934\u8282\u70b9\u8fdb\u884c\u3002
- \u7279\u6b8a\u60c5\u51b5 \\(3\\)\uff1a\u5982\u679c\u5f53\u524d\u64cd\u4f5c\u5728\u5c3e\u8282\u70b9\u8fdb\u884c\u3002
\u8fd9\u4e9b\u60c5\u51b5\u5982\u679c\u6ca1\u6709\u8003\u8651\u6e05\u695a\uff0c\u5f88\u53ef\u80fd\u5728\u5199\u4ee3\u7801\u7684\u8fc7\u7a0b\u4e2d\u51fa\u73b0 segmentation fault
\uff0c\u4e5f\u5c31\u662f\u6bb5\u9519\u8bef\u3002\u8fd9\u6781\u5927\u6982\u7387\u662f\u56e0\u4e3a\uff0c\u4f60\u8bbf\u95ee\u4e86 NULL
\u4f4d\u7f6e\u7684\u4e00\u4e9b\u4fe1\u606f\u3002\u6bd4\u5982\u5f53\u524d\u8282\u70b9\u6307\u9488 p
\u6307\u5411\u4e86 NULL
\uff0c\u4f46\u662f\u4f60\u5374\u8bbf\u95ee\u4e86 p->data
\u6216\u8005 p->next
\uff0c\u5c31\u4f1a\u62a5\u9519\u4e86\u3002
"},{"location":"programming_lecture/lecture5/lecture5/#_15","title":"\u5355\u5411\u94fe\u8868\u7684\u5404\u79cd\u7ecf\u5178\u64cd\u4f5c","text":"\u521b\u5efa\u4e00\u4e2a\u8282\u70b9 p
\uff0c\u5176\u6743\u503c\u4e3a w
\uff0c\u5e76\u8fd4\u56de\u8fd9\u4e2a\u8282\u70b9\u7684\u6307\u9488
\u53ea\u9700\u8981\u4f7f\u7528 malloc
\u5373\u53ef\u3002
Node *create(int w){\n Node* newNode = (Node*)malloc(sizeof(Node));\n newNode->next = NULL;\n newNode->data = w;\n return newNode;\n}\n
\u4e00\u4e2a\u7ec6\u8282
\u6ce8\u610f\uff0cmalloc
\u51fd\u6570\u5185\u90e8\u9700\u8981\u5f00\u7684\u8282\u70b9\u5927\u5c0f\u662f sizeof(Node)
\u800c\u4e0d\u662f sizeof(Node*)
\uff0c\u60f3\u60f3\u4e3a\u4ec0\u4e48\uff1f
\u5728\u94fe\u8868\u7684\u5934\u90e8/\u5c3e\u90e8\u63d2\u5165\u4e00\u4e2a\u8282\u70b9 p
\uff0c\u5e76\u8fd4\u56de\u65b0\u94fe\u8868\u7684\u5934\u90e8
\u5148\u770b\u5934\u90e8\u63d2\u5165\u3002
\u9996\u5148\uff0c\u7279\u6b8a\u60c5\u51b5 \\(1\\)\uff0c\u539f\u5148\u94fe\u8868\u662f\u7a7a\u7684\uff0c\u90a3\u80af\u5b9a\u662f\u628a head
\u8d4b\u503c\u4e3a\u65b0\u8282\u70b9\u561b\u3002
\u53d1\u73b0\u53ea\u5269\u4e0b\u7279\u6b8a\u60c5\u51b5 \\(2\\)\uff0c\u90a3 head
\u4e5f\u8981\u8d4b\u503c\u4e3a\u65b0\u8282\u70b9\uff0c\u7136\u540e\u65b0\u8282\u70b9\u8fde\u5411\u8001 head
\u3002
Node *insertAtHead(Node* head, Node* p) {\n if (!head) return p; // \u53ef\u4ee5\u53d1\u73b0\uff0c\u8fd9\u53e5\u8bdd\u4e0d\u5199\u4e5f\u6ca1\u6709\u5f71\u54cd \n p->Next = head;\n return p;\n}\n
\u4e00\u4e2a\u7ec6\u8282
\u4e3a\u4ec0\u4e48 if
\u91cc\u662f !head
\uff1f
\u7136\u540e\u662f\u5c3e\u90e8\u63d2\u5165\u3002\u9996\u5148\u8fd8\u662f\u7279\u6b8a\u60c5\u51b5 \\(1\\)\uff0c\u5904\u7406\u5b8c\u4ee5\u540e\u53ea\u5269\u4e0b\u7279\u6b8a\u60c5\u51b5 \\(3\\) \uff0c\u90a3\u4e48\u6211\u4eec\u53ea\u9700\u8981\u627e\u5230\u5c3e\u8282\u70b9\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u63d2\u5165\u4e86\uff0c\u6700\u540e\u8fd4\u56de\u7684\u4e5f\u53ea\u662f\u539f\u672c\u7684 head
\u3002
Node *insertAtEnd(Node* head, Node* p) {\n if (!head) return p;\n Node* last = head;\n while (last->next) {\n last = last->next;\n }\n last->next = p;\n return head;\n}\n
\u5220\u9664\u6743\u503c\u4e3a key
\u7684\u8282\u70b9\uff0c\u5982\u679c\u6709\u591a\u4e2a\uff0c\u5219\u5220\u9664\u6700\u9760\u8fd1\u5f00\u5934\u7684\uff0c\u6ca1\u6709\u5219\u4e0d\u5220\u9664\uff0c\u8fd4\u56de\u65b0\u94fe\u8868\u7684\u5934\u90e8
\u6700\u7e41\u7410\u6700\u590d\u6742\u7684\u4e00\u4e2a\u64cd\u4f5c\uff0c\u4e5f\u662f\u65b0\u624b\u7684\u5669\u68a6\u3002\u4e0d\u8fc7\u6309\u7167\u4e09\u6b65\u8d70\u5c31\u597d\u4e86\u3002
\u5148\u5904\u7406\u4e00\u4e0b\u7279\u6b8a\u60c5\u51b5 \\(1\\) \u3002
Node *deleteNode(Node* head, int key) {\n if (!head) return NULL;\n}\n
\u7136\u540e\u60c5\u51b5 \\(2\\) \u5462\uff0c\u5934\u7ed3\u70b9\u4f1a\u53d1\u751f\u53d8\u5316\u3002
Node *deleteNode(Node* head, int key) {\n if (!head) return NULL;\n if (head->data == key){\n node* tmp = head->next; //\u8fd9\u4e48\u505a\u662f\u56e0\u4e3a free \u4ee5\u540e\uff0chead->next \u5c31\u4e0d\u80fd\u83b7\u53d6\u4e86\u3002\n free(head);\n return tmp;\n }\n}\n
\u5269\u4e0b\u60c5\u51b5 \\(3\\) \u8fd8\u8981\u7279\u6b8a\u5224\u65ad\u3002\u6211\u4eec\u5148\u627e\u5230\u8981\u5220\u9664\u7684\u4f4d\u7f6e\u3002\u56de\u5fc6\u4e00\u4e0b\u5220\u9664\u7684\u8fc7\u7a0b\uff0c\u6211\u4eec\u9700\u8981\u8bb0\u5f55\u5f53\u524d\u9700\u8981\u88ab\u5220\u9664\u7684\u8282\u70b9\u7684\u6307\u9488 prev
\uff1a
Node *deleteNode(Node* head, int key) {\n if (!head) return NULL;\n if (head->data == key){\n node* temp = head->next; //\u8fd9\u4e48\u505a\u662f\u56e0\u4e3a free \u4ee5\u540e\uff0chead->next \u5c31\u4e0d\u80fd\u83b7\u53d6\u4e86\u3002\n free(head);\n return tmp;\n }\n node* temp = head, prev = NULL;\n while (temp && temp->data != key) {\n prev = temp;\n temp = temp->next;\n }\n if (!temp) return head;\n prev->next = temp->next; //\u4e8b\u5b9e\u4e0a\u76f4\u63a5\u5220\u9664\u5c31\u597d\u4e86\uff0c\u4e0d\u9700\u8981\u5173\u7cfb\u60c5\u51b5 3 \u4e86\uff0c\u4e0d\u8fc7\u7279\u5224\u4e00\u4e0b\u4e5f\u4e0d\u9519\u3002\n free(temp);\n return head;\n}\n
\u6ce8\u610f\uff01
\u7406\u8bba\u8003\u8bd5\u5199\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u4e00\u5b9a\u4e0d\u8981\u5fd8\u8bb0 free
\u88ab\u5220\u9664\u7684\u8282\u70b9\uff01\uff01\uff01\u5c0f\u5fc3\u6263\u5206\uff01\uff01\uff01
\u4e0a\u673a\u4e0d free
\u5012\u662f\u6ca1\u5173\u7cfb\uff08\u6307\u8fd8\u80fd\u901a\u8fc7\uff09\uff0c\u4f46\u8fd8\u662f\u5efa\u8bae\u517b\u6210\u826f\u597d\u7684\u4e60\u60ef\uff0c\u9632\u6b62\u5185\u5b58\u6cc4\u6f0f\uff01
"},{"location":"programming_lecture/lecture5/lecture5/#_16","title":"\u53cc\u5411\u94fe\u8868","text":"\u5176\u5b9e\u6ca1\u4ec0\u4e48\u53ef\u4ee5\u8bb2\u7684\uff0c\u4e5f\u5c31\u662f\u5728 struct
\u7684\u5b9a\u4e49\u4e2d\u52a0\u5165\u4e86 prev
\uff0c\u53ef\u4ee5\u8ba9\u6211\u4eec\u65b9\u4fbf\u7684\u83b7\u53d6\u4e0a\u4e00\u4e2a\u8282\u70b9\u7684\u6307\u9488\uff0c\u8fd9\u6837\u5220\u9664\u8fc7\u7a0b\u4e2d\u5c31\u4e0d\u9700\u8981\u5355\u72ec\u5f00\u53d8\u91cf\u8bb0\u5f55\u4e86\u3002
\u53cc\u5411\u94fe\u8868\u7684\u4e00\u79cd\u5b9a\u4e49\u65b9\u5f0f
typedef struct Node {\n int data;\n struct Node* prev, next;\n} Node;\n
\u7279\u522b\u7684\uff0c\u5934\u7ed3\u70b9\u7684 prev
\u662f NULL
\u3002
\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u9898\u5427~
\u9898\u76ee 3
To delete p
from a doubly linked list, we must do:
A. p->prev=p->prev->prev; p->prev->next=p;
B. p->next->prev=p; p->next=p->next->next;
C. p->prev->next=p->next; p->next->prev=p->prev;
D. p->next=p->prev->prev; p->prev=p->next->next;
Answer C.
"},{"location":"programming_lecture/lecture5/lecture5/#_17","title":"\u6808\u548c\u961f\u5217","text":"\u8fd9\u4e00\u90e8\u5206\u7684\u5185\u5bb9\u76f8\u4fe1\u5927\u5bb6\u5728\u8bfe\u4e0a\u5df2\u7ecf\u6709\u5f88\u597d\u7684\u7406\u89e3\u4e86\uff0c\u4f46\u662f\u4f1a\u51fa\u4e00\u4e9b\u548c\u94fe\u8868\u7ed3\u5408\u7684\u6709\u96be\u5ea6\u7684\u7406\u8bba\u9898\u548c\u7f16\u7a0b\u9898\uff0c\u6240\u4ee5\u7b80\u5355\u5e26\u8fc7\u4e00\u4e0b\uff1a
\u901a\u5e38\u9898\u76ee\u4f1a\u4f7f\u7528\u5355\u5411\u94fe\u8868\u6765\u5b9e\u73b0\u6808\u548c\u961f\u5217\u3002\u4e0d\u8fc7\u5f88\u591a\u9898\u76ee\u5176\u5b9e\u4f1a\u4e0d\u544a\u8bc9\u4f60\uff0c\u94fe\u8868\u54ea\u4e00\u6bb5\u8868\u793a\u6808\u9876\uff0c\u54ea\u4e00\u6bb5\u8868\u793a\u961f\u5934\uff0c\u54ea\u4e00\u6bb5\u8868\u793a\u961f\u5c3e\u3002
\u4e00\u4e2a\u95ee\u9898
\u5982\u679c\u662f\u53cc\u5411\u94fe\u8868\u5176\u5b9e\u6ca1\u6709\u8fd9\u4e48\u591a\u70e6\u607c\uff0c\u4f46\u662f\u73b0\u5728\u662f\u5355\u5411\u7684\u3002\u600e\u4e48\u5224\u65ad\u94fe\u8868\u7684\u5934\u4ee3\u8868\u6808/\u961f\u5217\u7684\u54ea\u4e2a\u90e8\u5206\u5462\uff1f
\u6808\u9876\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u6211\u4eec\u53ea\u9700\u8981\u8bb0\u5f55\u4e00\u4e0b\u94fe\u8868\u7684\u5934\u6307\u9488 head
\uff0c\u5728\u4e0a\u9762\u64cd\u4f5c\uff0c\u53ef\u4ee5\u76f4\u63a5\u5b8c\u6210\u5bf9\u6808\u7684\u6a21\u62df\uff0c\u6240\u4ee5\u94fe\u8868\u7684\u5934\u4ee3\u8868\u6808\u9876\u3002
\u90a3\u961f\u5217\u5462\uff1f\u6211\u4eec\u4e0d\u59a8\u8bd5\u4e00\u4e0b\uff0c\u5047\u8bbe\u94fe\u8868\u5934\u90e8\u4ee3\u8868\u961f\u5c3e\uff0c\u90a3\u4e48\u961f\u5217\u7684\u5165\u961f\u64cd\u4f5c\u5f88\u597d\u5b9e\u73b0\uff0c\u4f46\u662f\uff0c\u51fa\u961f\u9700\u8981\u5728\u94fe\u8868\u5c3e\u90e8\u8fdb\u884c\u64cd\u4f5c\u3002\u6709\u4e00\u4e2a\u5f88\u76f4\u89c2\u7684\u65b9\u6cd5\u5c31\u662f\u540c\u65f6\u8bb0\u5f55\u5e76\u7ef4\u62a4\u94fe\u8868\u7684\u5c3e\u6307\u9488 tail
\uff0c\u4f46\u662f\uff0c\u5220\u9664\u7684\u8bdd\uff0c\u6211\u4eec\u9700\u8981\u77e5\u9053\u5c3e\u6307\u9488\u7684\u524d\u9a71\u8282\u70b9...
\u6240\u4ee5\u4e00\u4e9b\u9898\u76ee\u7684\u5b9e\u73b0\uff0c\u9ed8\u8ba4\u4e86\u94fe\u8868\u7684\u5934\u90e8\u4ee3\u8868\u961f\u5934\u3002\u770b\u4e00\u4e0b\u8fd9\u4e2a\u9898\u76ee\uff1a
\u9898\u76ee 4
Represent a queue by a singly linked list. Given the current status of the linked list as 1->2->3
where x->y
means y
is linked after x
. Now if 4
is enqueued and then a dequeue is done, the resulting status must be:
A. 1->2->3
B. 2->3->4
C. 4->1->2
D. the solution is not unique
Answer B.
\u8fd9\u91cc\u9700\u8981\u989d\u5916\u63d0\u4e00\u4e2a\u53eb\u505a\u5faa\u73af\u961f\u5217\u7684\u4e1c\u897f\u3002\u5b83\u662f\u961f\u5217\u7684\u4e00\u79cd\u53d8\u4f53\uff0c\u901a\u5e38\u4f7f\u7528\u6570\u7ec4\u6765\u5b9e\u73b0\uff0c\u7528\u6765\u8282\u7ea6\u961f\u5217\u7684\u7a7a\u95f4\u3002 \u5faa\u73af\u961f\u5217\u662f\u628a\u987a\u5e8f\u961f\u5217\u9996\u5c3e\u76f8\u8fde\uff0c\u628a\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u8868\u4ece\u903b\u8f91\u4e0a\u770b\u6210\u4e00\u4e2a\u73af\u3002\u901a\u5e38\u7528\u4e24\u4e2a\u53d8\u91cf\u4ee3\u8868\u5f53\u524d\u5faa\u73af\u961f\u5217\u5b58\u50a8\u7684\u7a7a\u95f4\uff1a\u4e00\u4e2a\u662f\u5c3e rear
\uff0c\u4e00\u4e2a\u662f\u5934front
\u3002\u4e0d\u8fc7\u8fd9\u4e2a\u662f\u5f00\u533a\u95f4\u8fd8\u662f\u95ed\u533a\u95f4\u5462\uff0c\u8fd8\u5f97\u770b\u5177\u4f53\u5b9e\u73b0\u65b9\u5f0f\u548c\u9898\u5e72\u8981\u6c42\uff0c\u5927\u5bb6\u6700\u597d\u7ffb\u7ffb\u8001\u5e08\u7684 PPT\uff0c\u770b\u770b\u4e0a\u8bfe\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff0c\u4e07\u4e00\u9898\u76ee\u6ca1\u6709\u7ed9\u51fa\u5b9e\u73b0\u65b9\u5f0f\u5c31\u6309\u7167\u8001\u5e08\u8bb2\u7684\u4e3a\u4e3b\u5427\u3002
\u9898\u76ee 5
Suppose that an array of size 6 is used to store a circular queue, and the values of front and rear are 0 and 4, respectively. Now after 2 dequeues and 2 enqueues, what will the values of front and rear be?
A. 2 and 0
B. 2 and 2
C. 2 and 4
D. 2 and 6
Answer A.
\u5173\u4e8e\u7f16\u7a0b\u90e8\u5206\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u8fd9\u4e2a\u6bcf\u65e5\u4e00\u9898\u3002
"}]}
\ 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 \u5386\u5e74\u5377\u9898\u89e3 \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":" - \u6bcf\u4e2a\u957f\u5b66\u671f\u521d\uff0c\u6211\u4eec\u4f1a\u62db\u52df\u4f18\u79c0\u7684\u5b66\u957f\u5b66\u59d0\u4f5c\u4e3a\u8f85\u5b66\u5b66\u957f\u3002\u6240\u6709\u8f85\u5b66\u5b66\u957f\u90fd\u4f1a\u5728\u8f85\u5b66\u7fa4\u5185\u8fdb\u884c\u7b54\u7591\uff0c\u90e8\u5206\u8f85\u5b66\u5b66\u957f\u4f1a\u8fdb\u884c\u6388\u8bfe\u3002
- \u6388\u8bfe\u4e00\u822c\u4f9d\u7167\u8bfe\u7a0b\u8fdb\u5ea6\u8fdb\u884c\uff0c\u5bf9\u4e13\u9898\u7684\u77e5\u8bc6\u8fdb\u884c\u603b\u7ed3\u590d\u4e60\uff0c\u6216\u662f\u5728\u671f\u4e2d\u671f\u672b\u8003\u524d\u8fdb\u884c\u590d\u4e60\u548c\u4e60\u9898\u8bb2\u89e3\u3002\u5f00\u5c55\u6388\u8bfe\u524d\u4e00\u5468\uff0c\u8f85\u5b66\u7fa4\u5185\u4f1a\u53d1\u5e03\u6388\u8bfe\u4fe1\u606f\u548c\u62a5\u540d\u95ee\u5377\uff0c\u540c\u5b66\u4eec\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u9009\u62e9\u53c2\u52a0\u3002
- \u8f85\u5b66\u6388\u8bfe\u7684\u5f62\u5f0f\u81ea\u7531\uff0c\u4e0d\u8bba\u4f60\u662f\u5426\u586b\u5199\u95ee\u5377\uff0c\u90fd\u53ef\u4ee5\u53c2\u52a0\u6388\u8bfe\u3002\u4f60\u53ef\u4ee5\u968f\u65f6\u6765\u5230\u8bfe\u5802\uff0c\u4e5f\u53ef\u4ee5\u968f\u65f6\u79bb\u5f00\uff0c\u4f46\u8bf7\u4e0d\u8981\u6253\u6270\u5230\u5176\u4ed6\u540c\u5b66\uff0c\u5e76\u6ce8\u610f\u7ef4\u62a4\u6559\u5ba4\u73af\u5883\u536b\u751f\u3002\u53c2\u4e0e\u8f85\u5b66\u7684\u540c\u5b66\u6bcf\u6b21\u80fd\u591f\u83b7\u5f97\u53c2\u4e0e\u5ea6\u7eaa\u5b9e\u5206\u6570 0.5 \u5206\uff0c\u6bcf\u4e2a\u957f\u5b66\u671f\u6700\u591a\u901a\u8fc7\u8f85\u5b66\u7cfb\u5217\u6d3b\u52a8\u83b7\u5f97 1 \u5206\u3002
- \u6b64\u5916\uff0c\u90e8\u5206\u8bfe\u7a0b\u5f00\u8bbe\u4e86\u8f85\u5b66\u7cbe\u54c1\u8bfe\u7a0b\u3002\u6388\u8bfe\u5b66\u957f\u5b66\u59d0\u4ee5\u8bfe\u7a0b\u7ec4\u7684\u5f62\u5f0f\u7ec4\u7ec7\u8d77\u6765\uff0c\u7f16\u5199\u7cfb\u7edf\u7684\u914d\u5957\u7684\u8bb2\u4e49\uff0c\u8fdb\u884c\u8fde\u8d2f\u7684\u6388\u8bfe\uff0c\u6df1\u5ea6\u5951\u5408\u7afa\u9662\u8363\u8a89\u8bfe\u7a0b\u7684\u5185\u5bb9\u3002\u6211\u4eec\u5e0c\u671b\u80fd\u643a\u624b\u4f18\u79c0\u7684\u5b66\u957f\u5b66\u59d0\uff0c\u4e3a\u7afa\u9662\u5b66\u5b50\u6253\u9020\u9ad8\u8d28\u91cf\u7684\u8f85\u5b66\u8bfe\u7a0b\u3002
"},{"location":"#_3","title":"\u5f55\u64ad/\u56de\u653e","text":"\u81f4\u8c22\uff1a\u7afa\u53ef\u6862\u5b66\u9662\u5168\u5a92\u4f53\u5de5\u4f5c\u5ba4
\u5728\u7afa\u9662\u5168\u5a92\u4f53\u7684\u4eba\u5458\u548c\u8bbe\u5907\u652f\u6301\u4e0b\uff0c\u5927\u90e8\u5206\u8f85\u5b66\u6388\u8bfe\u90fd\u6709\u4e86\u4f18\u8d28\u7684\u5f55\u64ad\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\u5f55\u64ad\u90fd\u5c06\u4e0a\u4f20\u5230\u7afa\u9662\u5b66\u6307\u7684 Bilibili \u8d26\u53f7\u4e2d\uff0c\u70b9\u51fb\u5361\u7247\u5373\u53ef\u8df3\u8f6c\u5230 Bilibili \u9875\u9762\u3002
"},{"location":"#_4","title":"\u8d21\u732e","text":"\u5982\u679c\u60a8\u613f\u610f\u53c2\u4e0e\u8be5\u7f51\u7ad9\u7684\u5efa\u8bbe\uff0c\u8bf7\u5230 GitHub \u4e2d\u672c\u9879\u76ee\u7684\u4ed3\u5e93\u8fdb\u884c\u8d21\u732e\u3002\u5411\u4ed3\u5e93\u63d0\u4ea4\u524d\uff0c\u8bf7\u67e5\u770b\u8d21\u732e\u9875\u9762\u3002
"},{"location":"#_5","title":"\u5927\u6587\u4ef6\u5b58\u653e\u5904","text":"\u8d85\u8fc7 20MB \u7684\u5927\u6587\u4ef6\u90fd\u653e\u7f6e\u5728\u5b66\u4e1a\u6307\u5bfc\u4e2d\u5fc3\u516c\u5171\u7f51\u76d8\u7684\u5206\u4eab\u94fe\u63a5\u4e2d\uff0c\u540c\u5b66\u4eec\u53ef\u4ee5\u70b9\u51fb\u4e0b\u9762\u7684\u94fe\u63a5\u67e5\u770b\u3002\u5982\u679c\u6709\u9700\u8981\u653e\u7f6e\u7684\u5927\u6587\u4ef6\uff0c\u8bf7\u8054\u7cfb\u5b66\u4e1a\u6307\u5bfc\u4e2d\u5fc3\u7684\u540c\u5b66\u4e0a\u4f20\u3002
- \u767e\u5ea6\u7f51\u76d8-\u7afa\u9662\u8f85\u5b66\u8d44\u6599
"},{"location":"#_6","title":"\u76f8\u5173\u7f51\u7ad9","text":" - \u6d59\u6c5f\u5927\u5b66\u56fe\u7075\u73ed\u8bfe\u7a0b\u5b66\u4e60\u6307\u5357
- \u6d59\u6c5f\u5927\u5b66\u8bfe\u7a0b\u653b\u7565\u5171\u4eab\u8ba1\u5212
"},{"location":"contribute/","title":"\u8d21\u732e","text":"\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
- \u6bcf\u4e2a\u8f85\u5b66\u79d1\u76ee\u7684\u4e3b\u9875\u653e\u7f6e\u662f
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\u3002 - \u6bcf\u5e74\u7684\u8f85\u5b66\u8d44\u6599\u653e\u7f6e\u5728\u540c\u4e00\u4e2a\u6587\u4ef6\u5939\u4e2d\uff0c\u4f9d\u6b21\u547d\u540d\u4e3a
lecture1_contents.pdf
\u7b49\u3002 - \u6240\u6709\u5386\u5e74\u5377\u53ca\u5176\u7b54\u6848\u653e\u7f6e\u5728
exam
\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/2023-2024/analysis_lecture1_sequence_limits/","title":"\u7b2c\u4e00\u8bb2 \u6570\u5217\u6781\u9650","text":" - PDF \u7248
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_2","title":"\u5b9e\u6570\u5b8c\u5907\u6027\u5b9a\u7406","text":""},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_3","title":"\u8981\u6c42","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
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_4","title":"\u6982\u5ff5\u53d9\u8ff0","text":" -
\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} \\]
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_5","title":"\u5b9a\u7406\u53d9\u8ff0","text":" -
\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} \\]
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_6","title":"\u5e38\u7528\u6280\u5de7","text":" -
\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
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_7","title":"\u4f8b\u9898&\u4e60\u9898","text":" - \u7528\u786e\u754c\u539f\u7406\u8bc1\u660e\u5355\u8c03\u6709\u754c\u539f\u7406\u3001\u81f4\u5bc6\u6027\u5b9a\u7406\u3001Cauchy\u51c6\u5219\u3001\u95ed\u533a\u95f4\u5957\u5b9a\u7406\u3001\u6709\u9650\u8986\u76d6\u5b9a\u7406\u3002
- \u7528\u5355\u8c03\u6709\u754c\u5b9a\u7406\u8bc1\u660e\u95ed\u533a\u95f4\u5957\u5b9a\u7406\uff0c\u7528\u95ed\u533a\u95f4\u5957\u5b9a\u7406\u8bc1\u660e\u6709\u9650\u8986\u76d6\u5b9a\u7406\uff1b\u7528\u81f4\u5bc6\u6027\u5b9a\u7406\u8bc1\u660eCauchy\u6536\u655b\u51c6\u5219\u3002
- \\(f,g\u4e3aD\u4e0a\u6709\u754c\u51fd\u6570,\\text{pf:}\\inf\\{f(x)+g(x)\\}\\le\\inf{f(x)}+\\sup{g(x)}\\)
- \u8bbe\\(f(x)\u5728[0,1]\u4e0a\u9012\u589e,f(0)>0,f(1)<1,\u6c42\u8bc1:\\exists x_0\\in(0,1),\u4f7f\u5f97f(x_0)=x_0^2\\) (Hint:\u786e\u754c\u539f\u7406or\u533a\u95f4\u5957\u5b9a\u7406)
- \u8bbe\\(f(x)\\)\u5728\\([a,b]\\)\u4e0a\u6709\u5b9a\u4e49\u4e14\u5728\u6bcf\u4e00\u70b9\u5904\u51fd\u6570\u7684\u6781\u9650\u5b58\u5728\uff0c\u6c42\u8bc1\\(f(x)\\)\u5728\\([a,b]\\)\u4e0a\u6709\u754c (Hint:\u6709\u9650\u8986\u76d6)
- \\(\u8bbef(x)\u5728(a,b)\u5185\u6709\u5b9a\u4e49\uff0c\\forall\\xi\\in(a,b),\\exists\\delta>0,\u5f53x\\in(\\xi-\\delta,\\xi+\\delta)\\cap(a,b)\u65f6,\\)\u6709\u5f53\\(x<\\xi\\)\u65f6,\\(f(x)<f(\\xi), \u5f53x>\\xi\\)\u65f6,\\(f(x)>f(\\xi)\\).\u8bf7\u8bc1\u660e:\\(f(x)\u5728(a,b)\\)\u5185\u4e25\u683c\u9012\u589e (Hint:\u6709\u9650\u8986\u76d6)
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_8","title":"\u6570\u5217\u6781\u9650","text":""},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_9","title":"\u8981\u6c42","text":" - \u4ece\u5c0f\u6d4b\u7684\u89d2\u5ea6\u6765\u8bf4\uff0c\u6982\u5ff5\uff0c\u5b9a\u7406\u4ee5\u53ca\u5224\u65ad\u9898\u662f\u6bd4\u8f83\u91cd\u8981\uff08\u641e\u8111\u5b50\uff09\u7684\uff0c\u5f53\u7136\u4e5f\u4f1a\u6709\u8ba1\u7b97\u9898
- \u671f\u672b\u8003\u8bd5\u53ef\u80fd\u4f1a\u51fa1-2\u9053\u6c42\u6781\u9650\uff0c1\u9053\u975e\u5e38\u7b80\u5355\u7684\u6781\u9650\u8bc1\u660e\u9898\uff08\u9644\u5728\u5b9a\u7406\u53d9\u8ff0\u4e0a\uff09
- \u8ba1\u7b97\u4e5f\u9700\u8981\u638c\u63e1\uff0c\u4f46\u662f\u6280\u5de7\u6027\u5f3a\u7684\u53ef\u4ee5\u4e0d\u638c\u63e1
- \u5b66\u597d\u6570\u5217\u6781\u9650\u5bf9\u51fd\u6570\u6781\u9650\u548c\u7ea7\u6570\u90fd\u5f88\u6709\u5e2e\u52a9\uff0c\u800c\u5b66\u597d\u4e86\u51fd\u6570\u6781\u9650\u5c31\u53ef\u4ee5\u5b66\u597d\u5bfc\u6570\u548c\u79ef\u5206\uff0c\u7136\u540e\u4f60\u5c31\u5b66\u4f1a\u4e86\u6570\u52061
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_10","title":"\u6982\u5ff5\u53d9\u8ff0","text":" - \u6570\u5217\u6781\u9650\uff08\\(\\epsilon-N\\)\u8bed\u8a00\uff09
\\[ \\forall\\epsilon>0,\\exists N>0,\\forall n>N,|x_n-A|<\\epsilon\u79f0\\lim_{x\\rightarrow\\infty}x_n=A\\\\ *:|x_n-A|<f(\\epsilon),f(x)\u6ee1\u8db3\\lim _{x\\rightarrow0}f(x)=0\u5373\u53ef \\] - \u6570\u5217\u53d1\u6563
\\[ \\forall A\\in R,\\exists\\epsilon_0>0,\\forall N>0,\\exists n_N>N,|x_n-A|\\ge\\epsilon_0 \\] -
\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} \\]
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_11","title":"\u5b9a\u7406\u53d9\u8ff0","text":" -
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
\\[ \\begin{align} a_n\u6536\u655b& \\iff\\forall \\epsilon>0,\\exists N>0,\\forall m,n>N,\u5747\u6709|a_m-a_n|<\\epsilon \\\\ & \\iff \\forall \\epsilon>0,\\exists N>0,\\forall n>N,p>0,\u5747\u6709|a_{n+p}-a_n|<\\epsilon \\\\ \u5426\u5b9a\u5f62\u5f0f:a_n\u53d1\u6563& \\iff\\exists\\epsilon_0>0,\\forall N,\\exists n_0>N,p>0,|x_{n_0+p}-x_{n_0}|\\ge\\epsilon_0 \\end{align} \\]"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_12","title":"\u5e38\u7528\u6280\u5de7","text":" -
\u4e00\u4e9b\u5173\u7cfb\u94fe\uff1a
- \\(n\\rightarrow\\infty\u65f6\\)
\\[ \\log\\log n\\ll \\log n \\ll n^a\\ll b^n\\ll n!\\ll n^n\\quad(a,b>0) \\] - \\(x\\rightarrow0\u65f6\\)
\\[ \\begin{align} x \\sim &\\sin x\\sim \\tan x \\sim \\arcsin x\\sim \\arctan x \\\\ \\sim &\\ln{(1+x)} \\sim \\text{e}^x-1 \\sim \\frac{a^x-1}{\\ln a}\\sim \\frac{(1+x)^b-1}b \\quad(a>0,b\\neq0)\\\\ & 1-\\cos x \\sim \\frac12 x^2 \\end{align} \\] -
\u8bc1\u660e\u6570\u5217\u6781\u9650\u5b58\u5728\uff1a
- \u5b9a\u4e49\uff08\\(\\epsilon-N\\)\u65b9\u6cd5\uff09
\u6280\u5de7\uff1a\u653e\u5927\u6cd5(\u5e38\u7528)/\u5206\u6b65\u6cd5/\u6784\u9020\u5f62\u5f0f\u7c7b\u4f3c\u7684\u9879/\u62df\u5408\u6cd5(\u6280\u5de7\u6027\u8f83\u5f3a)
-
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
- Cauchy\u547d\u9898\u7684\u5426\u5b9a\u5f62\u5f0f
- \u5b50\u5217\u4e0d\u6536\u655b\u6216\u6536\u655b\u4e8e\u4e0d\u540c\u7684\u6570
-
\u6c42\u6570\u5217(\u51fd\u6570)\u6781\u9650\uff1a
- \u6781\u9650\u7684\u8fd0\u7b97\u6027\u8d28
\u4e00\u4e9b\u91cd\u8981\u6781\u9650\uff1a\\(\\lim\\limits_{n\\rightarrow\\infty}n^\\frac1n=1\\)\uff0c\\(\\lim\\limits_{n\\rightarrow\\infty}(1+\\frac1n)^n=e\\)
-
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
"},{"location":"analysis/2023-2024/analysis_lecture1_sequence_limits/#_13","title":"\u4f8b\u9898&\u4e60\u9898","text":" -
\u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u5b50\u5217\u7684\u547d\u9898
- \u8bbe\\(\\{a_n\\}\\)\u662f\u4e00\u4e2a\u6570\u5217\uff0c\u82e5\u5728\u4efb\u4e00\u5b50\u5217\\(\\{a_{n_k}\\}\\)\u4e2d\u5747\u5b58\u5728\u6536\u655b\u5b50\u5217\\(\\(\\{a_{n_{k_r}}\\}\\)\\),\u5219\\(\\(\\{a_n\\}\\)\\)\u5fc5\u6536\u655b
- \\(\\{a_n\\}\u5355\u8c03\u9012\u589e\uff0c\\{a_{n_k}\\}\u4e3a\u5176\u4e2d\u4e00\u4e2a\u5b50\u5217\uff0c\\lim\\limits_{k\\rightarrow\\infty}a_{n_k}=a,\u5219\\lim\\limits_{n\\rightarrow\\infty}{a_n}=a\\)
- \\(\\{a_{2k}\\}\\{a_{2p+1}\\}\\{a_{2023t+2024}\\}\u5747\u6536\u655b\uff0c\u5219\\{a_n\\}\u6536\u655b\\)
- \\(\\{a_{2k}\\}\\{a_{2t+1}\\}\\{a_{6p+5}\\}\u5747\u6536\u655b\uff0c\u5219\\{a_n\\}\u6536\u655b\\)
-
\u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u65e0\u7a77\u5c0f\u91cf\u7684\u547d\u9898
- \u65e0\u7a77\u591a\u4e2a\u65e0\u7a77\u5c0f\u91cf\u4e4b\u548c\u662f\u65e0\u7a77\u5c0f\u91cf
- \u65e0\u7a77\u591a\u4e2a\u65e0\u7a77\u5c0f\u91cf\u4e4b\u79ef\u662f\u65e0\u7a77\u5c0f\u91cf
- \u65e0\u7a77\u5c0f\u91cf\u4e0e\u6709\u754c\u91cf\u4e4b\u79ef\u4e3a\u65e0\u7a77\u5c0f\u91cf
-
\u5224\u65ad\u4e0b\u5217\u5173\u4e8e\u6570\u5217\u6781\u9650\u7684\u547d\u9898
- \u6570\u5217\\(a_n\\)\u6536\u655b\\(\\iff \\forall p\\in N,\\lim\\limits_{n\\rightarrow+\\infty}{|a_{n+p}-a_n|=0}\\)
- \\(\\lim\\limits_{n\\rightarrow\\infty}x_n=A\\iff\\forall k\\in \\text{N},\\exists N>0,\\forall n>N,|x_n-A|<\\frac1k\\)
- \\(a_n\u6536\u655b \\iff \\exists N>0,\\forall \\epsilon>0,\\forall m,n>N,\u5747\u6709|a_m-a_n|<\\epsilon\\)
-
\u91cd\u8981\u7684\u4e8c\u7ea7\u7ed3\u8bba\uff1a
\\[ Cauchy\u5b9a\u7406:\\lim_{n\\rightarrow\\infty}x_n=A,\u5219\\lim_{n\\rightarrow\\infty}\\frac{x_1+x_2+...+x_n}{n}=A \\] -
\\(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
- \\(x_n=\\cos\\frac x2\\cos\\frac x{2^2}\\cdots\\cos\\frac x{2^n}\\)
- \\(x_n=(\\frac{\\sqrt[n]a+\\sqrt[n]b}{2})^n\\)
- \\(x_n=\\frac 1{\\sqrt[n]{n!}}\\)
- \\(x_n={(n!)}^{\\frac1{n^2}}\\)
- \\(x_n=\\sqrt[6]{x^6+x^5}-\\sqrt[6]{x^6-x^5}\\)
-
(2019(?)\u5e74\u6570\u52061\u671f\u672b)
\\[ \\begin{align} & \u5bf9\u4e8e\u6570\u5217x_0=a,0<a<\\frac\\pi2,x_n=\\sin x_{n-1}(n=1,2,\\cdots). \\\\ &\\text{pf:}(1)\\lim\\limits_{n\\rightarrow\\infty}x_n=0;(2)\\lim\\limits_{n\\rightarrow\\infty}{\\sqrt\\frac n3}x_n=1 \\end{align} \\]"},{"location":"analysis/analysis1_paper/22test1_answer/","title":"22\u6570\u5206\u5c0f\u6d4b\u7b54\u6848","text":"\u9898\u76ee\u3001\u9009\u9879\u987a\u5e8f\u53c2\u8003\u5c0f\u6d4b1
- D
- AC
- B
- A
- BCD
- ABD
- B
- B
- A (\u805a\u70b9\u5e94\u8be5\u4e0d\u8981\u6c42\uff0c\u53ef\u4ee5\u5ffd\u7565)
- C
"},{"location":"calculus/","title":"\u5fae\u79ef\u5206\u8f85\u5b66","text":"\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u5fae\u79ef\u5206\u7248\u5757 \ud83e\udd17\u3002
"},{"location":"calculus/#2023-2024","title":"2023-2024 \u5b66\u5e74 \u8f85\u5b66\u8d44\u6599","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad 1 Oct.22 \u6781\u9650\u4e0e\u51fd\u6570\u7684\u8fde\u7eed\u6027 \u6df7\u5408 2106 \u5f20\u5fd7\u5fc3 \u8bb2\u4e49 \u7b54\u6848 Bilibili 2 Nov.5 \u671f\u4e2d\u590d\u4e60 \u6c42\u5316 2201 \u5218\u5b50\u6db5 \u8bb2\u4e49\u7b54\u6848 Bilibili 3 Dec.3 \u5fae\u5206\u4e2d\u503c\u5b9a\u7406\u548c\u4e0d\u5b9a\u79ef\u5206 \u5f3a\u533b 2101 \u5362\u601d\u7426 \u8bb2\u4e49 Bilibili"},{"location":"chemistry/","title":"\u666e\u901a\u5316\u5b66\u8f85\u5b66","text":"\u6b22\u8fce\u6765\u5230\u7afa\u9662\u8f85\u5b66\u666e\u901a\u5316\u5b66\u7248\u5757\ud83e\udd17\u3002
"},{"location":"chemistry/#_2","title":"\u8f85\u5b66\u8d44\u6599\u5f52\u6863","text":""},{"location":"chemistry/#2023-2024","title":"2023-2024 \u5b66\u5e74 \u79cb\u51ac\u5b66\u671f","text":"\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2 \u8bb2\u4e49 \u5f55\u64ad 3 Dec.12 \u7535\u5316\u5b66\u4e0e\u7269\u8d28\u7ed3\u6784 \u6df7\u5408 2102 \u674e\u822a\u5947 \u8bb2\u4e49 Bilibili"},{"location":"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":" - \u5434\u4e00\u822a \u56fe\u70752001
- \u6885\u654f\u70ab \u56fe\u70752201
- \u6f58\u90b9\u7eac \u5f3a\u72692101
- \u859b\u8fb0\u7acb \u56fe\u70752203
"},{"location":"lalu/#_4","title":"\u8bfe\u7a0b\u5f55\u64ad","text":"W \u4ee3\u8868\u9002\u914d\u5434\u5fd7\u7965\u73ed\uff0cT \u4ee3\u8868\u9002\u914d\u8c08\u4e4b\u5955\u73ed\uff0cH \u4ee3\u8868\u5408\u73ed\u4e0a\u8bfe\u3002
\u8282\u6b21 \u65f6\u95f4 \u5185\u5bb9 \u4e3b\u8bb2\u4eba \u5f55\u64ad\u5730\u5740 \u8bb2\u4e49 W1 Oct.29 \u5f15\u5165\uff1a\u7ebf\u6027\u7a7a\u95f4 \u6885\u654f\u70ab Bilibili LALU T1 Oct.29 \u5f15\u5165\uff1a\u7ebf\u6027\u7a7a\u95f4 \u5434\u4e00\u822a Bilibili LALU H2 Nov.18 \u7ebf\u6027\u6620\u5c04\u53ca\u5176\u77e9\u9635\u8868\u793a \u5434\u4e00\u822a Bilibili LALU H3 Dec.3 \u77e9\u9635\u7684\u79e9\u4e0e\u5206\u5757\u77e9\u9635 \u6f58\u90b9\u7eac Bilibili \u8bb2\u4e49 H4 Dec.16 \u884c\u5217\u5f0f\u548c\u7ebf\u6027\u65b9\u7a0b\u7ec4 \u859b\u8fb0\u7acb Bilibili LALU H5 Dec.30 \u671f\u672b\u590d\u4e60 \u5434\u4e00\u822a Bilibili PPT"},{"location":"lalu/#_5","title":"\u8bfe\u7a0b\u5b89\u6392","text":" - \u7b2c\u4e00\u8bb2 \u5f15\u5165 \u7ebf\u6027\u7a7a\u95f4
- \u9884\u8ba1\u7b2c 6 \u5468\uff0c\u5206\u4e24\u4e2a\u6559\u5b66\u73ed\u5f00\u8bfe\uff0c\u5434\u5fd7\u7965\u73ed\u4e0a\u5b8c\u5185\u79ef\uff0c\u8c08\u4e4b\u5955\u73ed\u4e0d\u4e0a\u5185\u79ef\uff08\u6216\u5434\u5fd7\u7965\u7b2c 5 \u5468\uff0c\u8c08\u4e4b\u5955\u7b2c 6 \u5468\uff09
- \u8bb2\u4e49 1-2 \u8bb2\u91cd\u70b9\u5728\u4e8e\u4f20\u8fbe\u4e00\u4e9b\u57fa\u672c\u601d\u60f3\uff0c\u4f4e\u8d77\u70b9\u5f15\u5165\u4f46\u9ad8\u843d\u70b9
- \u8bb2\u4e49\u7b2c 3 \u8bb2\u300a\u6709\u9650\u7ef4\u7ebf\u6027\u7a7a\u95f4\u300b\u4e00\u8bb2\u5efa\u8bae\u6309\u7167\u601d\u7ef4\u5bfc\u56fe\u8fdb\u884c\u5b8c\u6574\u4ecb\u7ecd
- \u7b2c\u4e8c\u8bb2 \u7ebf\u6027\u6620\u5c04 \u671f\u4e2d\u590d\u4e60
- \u9884\u8ba1\u7b2c 8 \u5468\uff0c\u5206\u4e24\u4e2a\u6559\u5b66\u73ed\u5f00\u8bfe\uff0c\u5434\u5fd7\u7965\u73ed\u4e0a\u5b8c\u77e9\u9635\u4e58\u6cd5\uff08\u77e9\u9635\u90e8\u5206\u53ef\u4ee5\u7565\u8bb2\uff0c\u4e4b\u540e\u6709\u4e13\u9898\uff09\uff0c\u8c08\u4e4b\u5955\u73ed\u4e0a\u5230\u7ebf\u6027\u6620\u5c04\u7ed3\u675f
- \u5efa\u7acb\u5bf9\u7ebf\u6027\u7a7a\u95f4\u4e0e\u7ebf\u6027\u6620\u5c04\u7684\u6574\u4f53\u8ba4\u8bc6\uff0c\u7406\u89e3\u4e24\u4e2a\u7ef4\u6570\u516c\u5f0f\uff0c\u7406\u89e3\u540c\u6784
- \u590d\u4e60\u90e8\u5206\u5bf9\u7279\u5b9a\u7684\u9898\u578b\u8fdb\u884c\u8bb2\u89e3\uff1a\u65b9\u7a0b\u7ec4\uff08\u542b\u53c2\uff09\uff0c\u6781\u5927\u7ebf\u6027\u65e0\u5173\u7ec4\uff0c\u76f4\u548c\u8bc1\u660e\uff0c\u50cf\u7a7a\u95f4\u6838\u7a7a\u95f4\u8bc1\u660e\u7b49\uff08\u7ed3\u5408\u5386\u5e74\u5377\u548c\u8bb2\u4e49\uff09
- \u7b2c\u4e09\u8bb2 \u77e9\u9635
- \u9884\u8ba1\u7b2c 11 \u5468\uff0c\u53ef\u4ee5\u5408\u73ed\u6559\u5b66\uff08\u6216\u5434\u5fd7\u7965\u7b2c 10 \u5468\uff0c\u8c08\u4e4b\u5955\u7b2c 11 \u5468\uff09
- \u91cd\u70b9\u5728\u4e09\u4e2a\u5185\u5bb9\uff1a\u4e00\u4e2a\u662f\u7ebf\u6027\u6620\u5c04\u77e9\u9635\u8868\u793a\uff0c\u4e00\u4e2a\u662f\u77e9\u9635\u7684\u79e9\u7684\u6574\u4f53\u8ba4\u8bc6\uff0c\u6700\u540e\u662f\u4e00\u4e9b\u4e0a\u8bfe\u4e0d\u592a\u8bb2\u7684\u6280\u5de7
- \u7b2c\u56db\u8bb2 \u884c\u5217\u5f0f \u7ebf\u6027\u65b9\u7a0b\u7ec4
- \u9884\u8ba1\u7b2c 13 \u5468\uff0c\u53ef\u4ee5\u5408\u73ed\u6559\u5b66
- \u884c\u5217\u5f0f\u91cd\u70b9\u5728\u7075\u6d3b\u8fd0\u7528\u4e00\u4e9b\u6027\u8d28\uff0c\u884c\u5217\u5f0f\u8ba1\u7b97\u89c6\u60c5\u51b5\u7ebf\u4e0b\u6388\u8bfe\u53ef\u4ee5\u629b\u5f03\uff08\u51c6\u5907\u7ebf\u4e0a\u8d44\u6599\u66ff\u4ee3\uff09\uff0c\u7ebf\u6027\u65b9\u7a0b\u7ec4\u91cd\u70b9\u5728\u4f53\u73b0\u300a\u671d\u82b1\u5915\u62fe\u300b\u7684\u6838\u5fc3\u601d\u60f3\uff0c\u7ebf\u6027\u65b9\u7a0b\u7ec4\u7406\u8bba\u610f\u5c3d
- \u7b2c\u4e94\u8bb2 \u7279\u5f81\u503c\u4e0e\u77e9\u9635\u6807\u51c6\u5f62 \u671f\u672b\u590d\u4e60
- \u9884\u8ba1\u7b2c 15 \u5468\uff0c\u53ef\u4ee5\u5408\u73ed\u6559\u5b66\uff0c\u4e5f\u53ef\u4ee5\u6309\u96be\u5ea6\u5206\u5c42\u6559\u5b66
- \u7279\u5f81\u503c\u4e0e\u77e9\u9635\u6807\u51c6\u5f62\u90e8\u5206\u6839\u636e\u73ed\u7ea7\u6388\u8bfe\u8fdb\u5ea6\u786e\u5b9a\u5185\u5bb9\uff0c\u5982\u679c\u65f6\u95f4\u6709\u9650\u6216\u6559\u5b66\u73ed\u6ca1\u6709\u4e0a\u5b8c\u6b63\u8bfe\uff0c\u90e8\u5206\u5185\u5bb9\u79fb\u81f3\u7ebf\u4e0a\u51c6\u5907\u89c6\u9891
- \u671f\u672b\u590d\u4e60\u90e8\u5206\u6574\u7406\u672c\u5b66\u671f\u5b8c\u6574\u601d\u8def\uff0c\u7ed3\u5408\u5386\u5e74\u5377\u548c\u8bb2\u4e49\u8bb2\u89e3\u6700\u6838\u5fc3\u7684\u9898\u578b
"},{"location":"lalu/#_6","title":"\u8bfe\u7a0b\u8bb2\u4e49","text":"\u8bb2\u4e49\uff08v0.3\uff09\u7b54\u6848\uff08v0.3\uff09 LALU \u8bfe\u7a0b\u7684\u8bb2\u4e49\u5b58\u653e\u5728\u4e0b\u9762\u7684\u4ed3\u5e93\u4e2d\uff0c\u4f60\u53ef\u4ee5\u70b9\u51fb\u56fe\u7247\u8df3\u8f6c\u5230\u4ed3\u5e93\u9875\u9762\u3002\u6b22\u8fce\u63d0\u51fa issue \u548c pull request\u3002
\u70b9\u51fb\u4e0b\u9762\u7684\u94fe\u63a5\u53ef\u4ee5\u4e0b\u8f7d\u8bb2\u4e49\u7684\u6700\u65b0 Release \u7248\u672c\uff1a
- \u70b9\u51fb\u4e0b\u8f7d\u8bb2\u4e49
- \u70b9\u51fb\u4e0b\u8f7d\u8bb2\u4e49\u7b54\u6848
"},{"location":"other/","title":"\u5176\u4ed6\u8d44\u6e90","text":""},{"location":"other/#_2","title":"\u6982\u7387\u8bba\u4e0e\u6570\u7406\u7edf\u8ba1","text":""},{"location":"other/#_3","title":"\u5c0f\u6d4b\u9898\u5e93","text":"\u5b66\u671f \u8bd5\u5377 23\u79cb\u51ac \u5c0f\u6d4b\u4e00(1)\u5c0f\u6d4b\u4e8c(1)/\u5c0f\u6d4b\u4e8c(2)/\u5c0f\u6d4b\u4e8c(3)\u5c0f\u6d4b\u4e09(1)/\u5c0f\u6d4b\u4e09(2) 23\u6625\u590f \u5c0f\u6d4b\u4e00(1)"},{"location":"physics/","title":"\u666e\u7269\u8f85\u5b66","text":"\u6b22\u8fce\u6765\u5230\u7afa\u9662\u666e\u7269\u8f85\u5b66\u7248\u5757\ud83e\udd17\u3002\u4f60\u53ef\u4ee5\u5728\u5de6\u4fa7\u5bfc\u822a\u680f\u4e2d\u8be6\u7ec6\u6d4f\u89c8\u672c\u6a21\u5757\u7684\u5185\u5bb9\u3002
"},{"location":"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
- \u6307\u9488\u6982\u89c8
- \u51fd\u6570\u6307\u9488\u8ba4\u8bfb
"},{"location":"programming/#faq","title":"FAQ","text":"\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":" - CPPReference\uff1aC/C++ \u53c2\u8003\u624b\u518c\uff0c\u53ef\u4ee5\u67e5\u627e C/C++ \u8bed\u6cd5\u548c\u6807\u51c6\u5e93\u7684\u7528\u6cd5\u7b49\u3002
"},{"location":"programming/#_9","title":"\u5b66\u957f\u5b66\u59d0\u7684\u7b14\u8bb0\u672c","text":"\u5f88\u591a\u5b66\u957f\u5b66\u59d0\u90fd\u5728\u81ea\u5df1\u7684\u535a\u5ba2/\u7b14\u8bb0\u672c\u4e2d\u5199\u4e86\u4e00\u4e9b\u5173\u4e8e\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u5185\u5bb9\uff0c\u8fd9\u91cc\u5217\u51fa\u4e00\u4e9b\u94fe\u63a5\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\u3002
- \u56fe\u7075\u73ed\u5b66\u4e60\u6307\u5357\uff1a\u7a0b\u5e8f\u8bbe\u8ba1\u4e0e\u7b97\u6cd5\u57fa\u7840
- TimeMachine\uff1aC-review
- \u9e64\u7fd4\u4e07\u91cc\uff1aC \u8bed\u8a00\u6742\u9879
- Isshiki\u4fee\uff1aC\u5c0f\u7a0b \u7410\u788e\u77e5\u8bc6\u70b9\u6574\u7406
- \u6e90\u8679\u7ffc\uff1aZJU\u79cb\u7a0b\u8bbe\u5b66\u4e60\u7b14\u8bb0
"},{"location":"programming/faq/","title":"\u5e38\u89c1\u95ee\u9898","text":"\u8fd9\u91cc\u5206\u6a21\u5757\u6c47\u603b\u4e86\u7a0b\u8bbe\u8f85\u5b66\u7fa4\u4e2d\u7684\u5e38\u89c1\u95ee\u9898\u53ca\u5176\u89e3\u7b54\u3002
"},{"location":"programming/faq/#_2","title":"\u57fa\u672c\u6570\u636e\u7c7b\u578b\u3001\u8fd0\u7b97\u7b26\u3001\u8868\u8fbe\u5f0f\u548c\u8bed\u53e5","text":"\u6709\u5e03\u5c14\u7c7b\u578b\u5417\uff1f Author\uff1a\u6731\u5b9d\u6797
\u5e03\u5c14\u7c7b\u578b\u7684\u5386\u53f2\uff1a
- \u6700\u65e9\u7684 C \u8bed\u8a00\u89c4\u8303\u4e2d\u6ca1\u6709\u5e03\u5c14\u7c7b\u578b\u3002
- C99 \u5f15\u5165\u4e86
_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\u3002 bool
\u5c55\u5f00\u6210 _Bool
\u3002 true
\u548c false
\u5206\u522b\u5c55\u5f00\u6210 int
\u7c7b\u578b\u7684 1
\u548c 0
\u3002
- C23 \u6b63\u5f0f\u4f7f\u7528
bool
\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
- \u5230
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\u3002
\u6d6e\u70b9\u6570\u662f\u5982\u4f55\u5b58\u50a8\u7684\uff1f\u4e3a\u4ec0\u4e48\u5b83\u4e0d\u7cbe\u786e\uff1f Author\uff1a\u6731\u5b9d\u6797
\u4e0b\u9762\u7684\u5185\u5bb9\u6765\u81ea\u300a\u8ba1\u7b97\u673a\u79d1\u5b66\u5bfc\u8bba\u300b\uff0c\u8bf7\u5b8c\u6574\u9605\u8bfb\u4ee5\u4e86\u89e3\u6d6e\u70b9\u6570\u7684\u5b58\u50a8\u65b9\u5f0f\u3002
\u5982\u679c\u4f60\u8bfb\u5b8c\u4e86\u4e0a\u9762\u7684\u5185\u5bb9\uff0c\u4f60\u5e94\u8be5\u80fd\u7406\u89e3\u6d6e\u70b9\u6570\u5b58\u50a8\u4e0d\u7cbe\u786e\u7684\u539f\u56e0\uff1a
- \u6d6e\u70b9\u6570\u7684\u5c3e\u6570\u90e8\u5206\u957f\u5ea6\u6709\u9650\uff0c\u65e0\u6cd5\u5b58\u50a8\u65e0\u9650\u7684\u5c0f\u6570\u3002
\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/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/#10-i-love-pointer","title":"\u300c10\u300d I Love pointer","text":"What is the output of the following program on a 64-bit system?
char str[3][10]={\"\",\"ILoveCKC\",\"ILoveZJU\"};\n printf(\"%lu#%lu\\n\",strlen(str[0]),sizeof(str[0]));\n printf(\"%lu#%lu\\n\",strlen(str),sizeof(str));\n printf(\"%d#%c\\n\",str[1][-10],str[1][10]); // Don't write this in your own code.\n printf(\"%s\\n\",(**str == (*(str + 1) + 8)[1] ? \"True\" : \"False\"));\n printf(\"%s\",&str[1][9] == &((*(str + 1) + 8)[1]) ? \"True\" : \"False\");\n
Answer 0#10\n 0#30\n 0#I\n True\n True\n
strlen(str[0])
returns the length of the string pointed to by str[0]
, which is 0. sizeof(str[0])
returns the size of the array str[0]
, which is 10. strlen(str)
returns the length of the string pointed to by str
, which is 0. sizeof(str)
returns the size of the array str
, which is 30. In fact, str[0]
's value is same as str
's value. str[1][-10]
is equivalent to *(str[1] - 10)
which is equivalent to **(str + 1 * 10 - 10)
which is equivalent to ** str
. So str[1][-10]
's value is '\\0'
. str[1][10]
is equivalent to *(str[1] + 10)
which is equivalent to **(str + 1 * 10 + 10)
which is equivalent to ** (str + 20)
So str[1][10]
's value is 'I'
. (*(str + 1) + 8)[1]
is the same as str[1][9]
. So **str == (*(str + 1) + 8)[1]
is true.
\u4f9b\u9898\u4eba\uff1a\u80e1\u80b2\u73ae
"},{"location":"programming/daily/2023/#9-sizeof-all-in-one","title":"\u300c9\u300d sizeof
All in One","text":"What is the output of the following program on a 64-bit system?
char str[][3] = {'L', 'o', 'v', 'e', 'C', 'K', 'C'};\nprintf(\"%d \", (int)sizeof(str));\nprintf(\"%d \", (int)sizeof(&str));\nprintf(\"%d \", (int)sizeof(*str));\nprintf(\"%d \", (int)sizeof(str + 1));\nprintf(\"%d \", (int)sizeof(*str + 1));\nprintf(\"%d \", (int)sizeof(*(str + 1)));\nprintf(\"%d\", (int)sizeof(*(*(str + 1) + 1)));\n
Answer 9 8 3 8 8 3 1
.
This is a comprehensive problem combining sizeof
and pointer.
- When the object is an array name, the return value is the total size of the whole array. At initialization, the third row of the array will be filled to a 1-D array of length 3 automatically:
char str[][3] = {{'L', 'o', 'v'}, {'e', 'C', 'K'}, {'C', '\\0', '\\0'}};
. Therefore the value of sizeof(str)
equals to 3 * 3 * 1 = 9 since sizeof(char) = 3
. - In the expression
&str
, &
represents the address-of operator and the return value is the address of the entire array. That, of course, can be regarded as a pointer and hence sizeof(&str)
equals 8 (Bytes), the size of a pointer on a 64-bit system. - Now let's focus on
str
. We know that str
is an array of char [3]
. In the view of pointer, str
is also a pointer to the first element (Note that the element here is an array of length 3). Hence *str
is equivalent to str[0]
which is an 1D array of length 3. So the output of sizeof(*str)
is 3 * 1 = 3. - In the previous discussion we know that
str
is a pointer to array of length 3 (char (*)[3]
actually), so str + 1
is also a pointer and the output is 8. *str
(equivalent to str[0]
), will be converted to int *
when added by 1. Therefore *str + 1
is a pointer to str[0][1]
and 8 will be output again. - From discussion 3 and 4 it's not difficult to find
*(str + 1)
an array of length 3 (str[1]
), so 3 is the answer. *(*(str + 1) + 1)
is classical equivalence of str[1][1]
. Therefore sizeof(*(*(str + 1) + 1))
equals to sizeof(char)
, namely 1.
\u4f9b\u9898\u4eba\uff1a\u5f90\u82e5\u79ba
"},{"location":"programming/daily/2023/#8-j-lost","title":"\u300c8\u300d J lost","text":"Given the following program:
void xqc(char c[], int i);\n\nint main(void) {\n char c[] = \"I am a Man of Fortune\";\n char d[] = \"and I must seek my Fortune\";\n\n xqc(c + 1, ~1694);\n xqc(d - ~3, -65);\n printf(\"%s, %s\\n\", c, d);\n}\n\nvoid xqc(char c[], int i) {\n c = c - 1;\n c[0] = ' ';\n c[1] = (i & 1) + 'I';\n}\n
Which of the following is correct?
A. This program fails to compile, because you cannot assign to an array in line 13.
B. Because of the call-by-value, function xqc
cannot modify the character arrays in function main
.
C. Change 1694
in line 7 to 1994
, and the result of the program is the same.
D. This program outputs I am a Man of Fortune, and J must seek my Fortune
.
Answer C.
A: Inside function xqc
, c
is a pointer type char *
rather than an array type, because when an array type is used in a function parameter list, it actually is the corresponding pointer type. Therefore, the assignment in line 13 is valid, and it means \"to move the pointer c
one position backward\".
B: The function xqc
can modify the character arrays in function main
, because it takes the address of the character arrays as parameters. The function xqc
can modify the contents of the character arrays through the pointers.
C: The ~
operator is the bitwise NOT operator. The ~1694
is equivalent to -1695
. The ~3
is equivalent to -4
. Therefore, the calls to function xqc
are equivalent to:
xqc(c + 1, -1695);\nxqc(d - -4, -65);\n
And i & 1
gets the last bit of i
. Both -1695
and -65
are odd numbers, so i & 1
is 1
, and the character 1 + 'I'
, which is 'J'
, is assigned. Changing 1694
to 1994
does not change the result of the program, because ~1994
is -1995
, and -1995
is also an odd number.
D: This program outputs \u00a0Jam a Man of Fortune, and J must seek my Fortune
.
Tip
You don't need to calculate the exact value of ~1694
. All you need to know is that the last bit of 1694
is 0 (since it is an even number), and the bitwise NOT operator will reverse that last bit. Therefore, ~1694
is an odd number, and i & 1
is 1
. Ditto for ~1994
.
\u4f9b\u9898\u4eba\uff1a\u674e\u82f1\u7426
"},{"location":"programming/daily/2023/#7-the-difference-between-strlen-and-sizeof","title":"\u300c7\u300d The difference between strlen
and sizeof
.","text":"#include <stdio.h>\n#include <string.h>\nint main()\n{\n char arr1[] = \"abcd\";\n char arr2[] = {'a', 'b', 'c', 'd'};\n printf(\"%d\\n\", sizeof(arr1));\n printf(\"%d\\n\", sizeof(arr2));\n printf(\"%d\\n\", strlen(arr1));\n printf(\"%d\\n\", strlen(arr2));\n return 0;\n}\n
What are the results?
A. 4, 4, 4, 4 B. 5, 4, 4, 4 C. 4, 4, 4, indeterminable D. 5, 4, 4, indeterminable Answer D.
arr1
has \\0
at the end, but arr2
doesn't.
The sizeof
operator returns the size of its operand in bytes. In this case, the size of arr1
is 5, because it contains 4 characters and a null character \\0
. The size of arr2
is 4, because it contains just 4 characters. The \\0
is absent in arr2
.
The strlen
function returns the length of the string, that is, the number of characters in the string before the null character \\0
. In this case, the length of arr1
is 4, because it contains 4 characters before the null character \\0
. But the length of arr2
is indeterminable, because it does not contain a null character \\0
. The strlen
function will continue to read memory until it finds a null character \\0
, resulting totally random result. If there is no null character \\0
in the memory, the behavior is undefined.
\u4f9b\u9898\u4eba\uff1a\u534e\u5c55\u8f89\uff0c\u674e\u82f1\u7426
"},{"location":"programming/daily/2023/#6-stack-and-queue-adapted-from-fds-mid-term-exam","title":"\u300c6\u300d Stack and Queue (adapted from FDS mid-term exam)","text":"Given an empty stack S
and an empty queue Q
. Push elements {1, 2, 3, 4, 5, 6, 7}
one by one onto S
. If each element that is popped from S
is enqueued onto Q
immediately, and if the dequeue sequence is {3, 2, 4, 6, 7, 5, 1}
, then the minimum size of S
should be:
A. 5 B. 4 C. 3 D. 7 Answer C.
Stack is LIFO (Last In, First Out), queue is FIFO (First In, First Out). So dequeue sequence of queue is also the enqueue sequence. If enqueue sequence of Q is {3, 2, 4, 6, 7, 5, 1}, all operation of stack S must be the following:
- Push 1 and 2 and 3 into stack sequentially. Stack S now contains 3 nodes.
- Pop 3, stack contains 2 nodes
- Pop 2, stack contains 1 node
- Push 4, stack contains 2 nodes
- Pop 4, stack contains 1 node
- Push 5, stack contains 2 nodes
- Push 6, stack contains 3 nodes
- Pop 6, stack contains 2 nodes
- Push 7, stack contains 3 nodes
- Pop 7, stack contains 2 nodes
- Pop 5, stack contains 1 node
- Pop 1, stack is empty
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
.
Answer argv
is an array of pointers to strings, and argc
is the number of strings in argv
. The argv
array contains the following strings:
argv[0] = \"./a.out\"\nargv[1] = \"this\"\nargv[2] = \"is\"\nargv[3] = \"a\"\nargv[4] = \"test\"\n
The argc
is 5, because there are 5 strings in argv
.
The argv
array is terminated by a null pointer, so argv[5]
is a null pointer.
For more information about argv
and argc
, see cppreference-argc, argv.
\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797
"},{"location":"programming/daily/2023/#3-sizeof-struct","title":"\u300c3\u300d sizeof
struct
","text":"Consider the following code fragment:
struct A {\n char a[10];\n int b;\n\n};\ntypedef struct A A;\n\nstruct B {\n char *a;\n int b;\n};\ntypedef struct B* B;\n
What is the value of sizeof(A)
and sizeof(B)
?
Answer sizeof(A)
is 16, and sizeof(B)
is 8 (on a 64-bit modern system).
The sizeof
operator returns the size of its operand in bytes. The size of a structure type is as large as the sum of the sizes of its members.
You may think the size of A
is 14, because the size of char[10]
is 10, and the size of int
is 4. However, to improve performance of memory access, C standard allows the compiler to add padding bytes after each member of a structure, and the padding strategy is implementation specific. A common strategy is to align each member to the size of its type, that is to say, make their memory address to be a multiple of the size of the member. For example, on a 64-bit system, the address of a 4-byte integer must be a multiple of 4.
Therefore, The size of A
is 16. The compiler will add 2 padding bytes after char[10]
, to make the address of int
a multiple of 4 in struct A
.
The size of B
is 8, because B
is a pointer and the size of pointer is 8. The size of type to which B
points does not affect the size of B
. Notice that type B
is not equivalent to type struct B
.
For more information about sizeof
operator, see cppreference-sizeof.
\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797\u3001\u5b59\u5146\u6c5f
"},{"location":"programming/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:
- Do not use the
printf
series of formatting output functions. - The minimum field width for output is
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.
Answer C
.
The strcat
function appends a copy of the string pointed to by s4
to the end of the string pointed to by s3
. The s3
and s4
pointers point to the third character of s1
and the fourth character of s2
, respectively. Therefore, the strcat
function appends the string \"ld\"
to the end of the string \"Hellold\"
, resulting in \"Helloldld\"
, and the printf
function prints \"Hellold, world; llold, ld.\"
.
When the strcat
function appends the string \"ld\"
after \"Hello\", it overwrites the null character '\\0'
at the end of the string \"Hello\"
and write a new null character '\\0'
at the end of the string \"Helloldld\"
. Therefore, the character w
and <
after the null character '\\0'
in s1
are not printed.
\u4f9b\u9898\u4eba\uff1a\u90d1\u4fca\u8fbe
"},{"location":"programming/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:
- Create a new node and set its
data
to data
. - Insert the new node between the dummy node and the first node of the list.
If you want to iterate over the list, you should start from the first node of the list, which is list->next
.
\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797
"},{"location":"programming/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 Love scanf
!","text":"After entering the following inputs, does the program operate normally? If it does, what should be the output?
int a;\nchar c1, c2;\nchar s[7];\nscanf(\"%d%c %c%s\\n\", &a, &c1, &c2, s);\nprintf(\"%d#%c#%c#%s\", a, c1, c2, s);\n
#input: there is no space after the last character\n20231127\n ckc-agc\ndaily_problem\n
Answer The program operates normally and the output is:
20231127#\n#c#kc-agc\n
The scanf
function reads input from the standard input stream, which is usually the keyboard. The format string of scanf
is \"%d%c %c%s\\n\"
. The first %d
matches the integer 20231127
, the second %c
matches the character '\\n'
because %c
won't miss any character including ' '
and '\\n'
. The space in formatting string will ignore every blank character, so the third %c
matches the character 'c'
, and the fourth %s
matches the string \"kc-agc\"
, whose length is 7. When you print \\n
after line2, scanf
will not stop, because '\\n'
in formatting string will ignore every blank character. So until you enter a non-blank character and use enter to send it to the program from buffer, scanf
will stop.
\u4f9b\u9898\u4eba\uff1a\u80e1\u80b2\u73ae
"},{"location":"programming/daily/2023/#26-broken-strcpy","title":"\u300c26\u300d Broken strcpy()
","text":"Does this strcpy()
implementation do its job?
void my_strcpy(char *s, const char *t) {\n do {\n *s++ = *t++;\n } while (*t);\n}\n
Answer No, it's broken. This implementation does not terminate the string pointed to by s
. To correctly copy a string, the character used in assignment must be the same character used in loop condition.
What does that mean? Suppose t = \"Hello\"
, then:
*t
is 'H'
, and is assigned to *s
. s
and t
increment. *t
, now being 'e'
, is used to evaluate the while
condition. - ... this process repeats until
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. - Now we have a memory out-of-bounds. Accessing
*t
is undefined behavior. - And it keeps copying garbage values until some arbitrary
'\\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
Answer A
.
The function my_strcat
is supposed to concatenate s1
and s2
and store the result in s3
. However, the function does not work as expected. The problem lies in the line s3 = malloc(len1 + len2 + 1);
. The function my_strcat
takes s3
as a parameter, which is a pointer to a char
array. When the function is called, the value of s3
is copied to the function's local variable s3
. Therefore, the malloc
function allocates memory for the local variable s3
, not the original s3
in main
. The memory allocated for the local variable s3
is not used after the function returns, so it is a memory leak. The original s3
in main
is not modified, so it is still an empty string.
You may think that the problem can be solved by simply deleting the line s3 = malloc(len1 + len2 + 1);
. However, this will cause another problem. s3
is initialized as an empty string, which means that it is a pointer to a char
array with only one element, the null character \\0
. The memory allocated for s3
is not enough to store the concatenated string. Therefore, this will cause a buffer overflow.
\u4f9b\u9898\u4eba\uff1a\u6885\u654f\u70ab
"},{"location":"programming/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\u300d typedef
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:
- Suffix increacement and decreacement:
a++
- Logical NOT:
!
- Prefix increacement and decreacement:
--a
- Subtraction:
-
- Bitwise left shift:
<<
- Comparison:
<
, >
- Logical OR:
||
- Ternary conditional:
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. - Since
x
has the value of 2 and y
has the value of 1, the output will be 2.
\u4f9b\u9898\u4eba\uff1a\u5f90\u82e5\u79ba
"},{"location":"programming/daily/2023/#27-or-in-switch","title":"\u300c27\u300d Or in switch
","text":"What will happen when compiling and executing the following code fragment with input 5
?
char ch;\nscanf(\"%c\", &ch);\nswitch (ch) {\n case 0 || 2 || 4 || 6 || 8:\n printf(\"even digit \");\n case 1 || 3 || 5 || 7 || 9:\n printf(\"odd digit \");\n default:\n printf(\"not a digit \");\n}\n
A. It will print odd digit
.
B. It will print odd digit not a digit
.
C. It will print not a digit
.
D. It cannot be compiled.
Answer D
.
The compiler will tell you that case label value has already appeared in this switch
. There are many problems in this code fragment, and the most important one is that 0 || 2 || 4 || 6 || 8
will not behave as expected in case
statement. It will be evaluated as 1
because 0 || 2 || 4 || 6 || 8
is equivalent to ((((0 || 2) || 4) || 6) || 8)
. The result of 0 || 2
is 1
, so the result of 0 || 2 || 4
is 1
, and so on. Therefore, the case
statement will be evaluated as case 1
. The same problem exists in case 1 || 3 || 5 || 7 || 9
, which will also be evaluated as case 1
. The correct way to write this code fragment is:
char ch;\nscanf(\"%c\", &ch);\nswitch (ch) {\n case '0': case '2': case '4': case '6': case '8':\n printf(\"even digit \"); break;\n case '1': case '3': case '5': case '7': case '9':\n printf(\"odd digit \"); break;\n default:\n printf(\"not a digit \");\n}\n
For more information about switch
statement, see cppreference-Switch statement.
\u4f9b\u9898\u4eba\uff1a\u90d1\u4fca\u8fbe
"},{"location":"programming/daily/2023/#26-bitwize-operator","title":"\u300c26\u300d Bitwize Operator","text":"Which of the following options can achieve a swapping effect for pair(*,*)
? Note that ^
represents XOR
operation. For binary numbers, 0 XOR 0 = 0
, 0 XOR 1 = 1
, 1 XOR 0 = 1
, 1 XOR 1 = 0
.
A. (x, y)
: x ^= y ^= x ^= y;
B. (a[x], a[y])
: a[x] ^= a[y] ^= a[x] ^= a[y];
C. (x, y)
: x -= y += x -= y;
D. (a[x], a[y])
: a[x] -= a[y] += a[x] -= a[y];
Answer A
.
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 Nested switch
, Confusing default
and break
","text":"After executing the following code fragment, the output should be __.
int x = 1, y = 1;\nswitch (x) {\n case 1:\n switch (y) {\n default:\n printf(\"three \");\n case 1:\n printf(\"one \");\n case 2:\n printf(\"two \");\n break;\n }\n case 2: case 3:\n printf(\"four \");\n break;\n default:\n printf(\"five \");\n}\n
Answer one two four
The syntax of switch
statement is:
switch (expression) {\n case constant-expression:\n statements\n case constant-expression:\n statements\n default:\n statements\n}\n
The expression
must have an integral or enumerated type, or be of a class type in which the class has a single conversion function to an integral or enumerated type. The constant-expression
for each case
must be a constant expression of the same type as the expression, and no two of the constant expressions associated with the same switch
statement shall have the same value after conversion.
The switch
statement evaluates expression
, then looks for the case
constant-expression whose value is equal to the value of expression
(after conversion). If such a case
is found, the statements following that case
are executed until a break
statement is encountered. If no case
is found whose value is equal to the value of the expression, and if there is a default
label, the statements following the default
label are executed. Otherwise, the statements of the switch
statement are skipped.
If some case
labels are not followed by break
statements, the execution of the switch
statement falls through to the next case
label. You can use this behavior to execute multiple statements for a particular case
label or to execute statements for more than one case
label.
\u4f9b\u9898\u4eba\uff1a\u6731\u5b9d\u6797
"},{"location":"programming/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
).
- The result of the postfix forms is the value of
x
. - The result of the prefix forms is the value of
x + 1
for ++x
(or x - 1
for --x
).
For more information, see cppreference-Increment/decrement operators
-
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.
- To compare two strings, you should use
strcmp
function in <string.h>
header file. Learn how to use the function by yourself. - In the code snippet above,
a
, b
and c
are all arrays of char
, so a > b
and a > c
are actually comparing the addresses of these arrays. You may think that the array declared later has a larger address, but this is not always true. It depends on the design of the architecture that the stack grows towards higher memory addresses or towards lower memory addresses. So the output of this program is unpredictable. For more information on this, see StackOverflow: Is the order of memory addresses of successively declared variables always descending?
\u4f9b\u9898\u4eba\uff1a\u6768\u7433\u73a5
"},{"location":"programming/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 Bad if
-else
","text":"After executing the following code fragment, the output is __.
int x = 0;\nint y = -2;\nif(x > 0) y = 1;\nelse if(x < 0) y = -1;\nelse if(x = 0) y = 0;\nprintf(\"%d\", y);\n
A. 1 B. 0 C. -1 D. -2 Answer D
.
Notice that the condition of if
in line 5 is x = 0
, not x == 0
. The former means \"0 is assigned to x\", and then the if sentence won't be executed since it is equivalent to if(0)
. Thus the value of y
is its initial value, -2.
\u4f9b\u9898\u4eba\uff1a\u6885\u654f\u70ab
"},{"location":"programming/daily/2023/#17-character","title":"\u300c17\u300d Character","text":"Given: char c = '@';
, the value of expression 'A' <= c <= 'Z'
is __.
Answer 1
.
To solve this problem you do not need to remember ASCII code. This problem is about operator precedence. The expression 'A' <= c <= 'Z'
is equivalent to (('A' <= c) <= 'Z')
. No matter what the value of c
is, the expression ('A' <= c)
will be evaluated to 1
or 0
, which is less than 'Z'
. Therefore, the value of the expression 'A' <= c <= 'Z'
is 1
.
But in other problems you may need to remember some key ASCII codes:
Character ASCII Code '0'
48
'A'
65
'a'
97
Upper case is prior to lower case. The difference between 'A'
and 'a'
is 32
. So if you want to convert a lowercase letter to uppercase, you can use c - 32
. Or an easier way: c - 'a' + 'A'
.
\u6765\u81ea\uff1aC \u5927 13 \u5e74\u671f\u672b
"},{"location":"programming/daily/2023/#16-overflow","title":"\u300c16\u300d Overflow","text":"For code below:
unsigned short sht = 0;\nsht--;\n
What will be the value of sht
after the execution?
A. -1 B. 65535 C. 32767 D. 65536 Answer B.
Remember that unsigned short
is an unsigned integer type, so it will not be negative. Instead, it will be the largest value of unsigned short
type. The largest value of unsigned short
type is 65535
, because unsigned short
is 16-bit long.
\u6765\u81ea\uff1aC \u5927 13 \u5e74\u671f\u672b
"},{"location":"programming/exam/exam/","title":"\u5386\u5e74\u5377\u7ecf\u5178\u9898\u76ee\u89e3\u6790","text":""},{"location":"programming/exam/exam/#_2","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u57fa\u7840\u5e38\u95ee\u9898\u76ee\u96c6\u53ca\u89e3\u6790","text":"Info
\u672c\u7bc7\u7b14\u8bb0\u6765\u81ea []
\u8fd9\u91cc\u662f\u4f5c\u4e3a 2022 \u5e74\u7afa\u9662\u56e2\u59d4\u5b66\u7814\u90e8\u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66\u7b54\u7591\u5b66\u957f\u65f6\u6574\u5408\u7684\u7fa4\u91cc\u7ecf\u5e38\u95ee\u5230\u7684\u4e00\u4e9b\u95ee\u9898\uff0c\u5305\u62ec\u89e3\u6790\uff0c\u4e5f\u6709\u4e00\u4e9b\u76f8\u5173\u77e5\u8bc6\u70b9\u7684\u6574\u7406\u3002\u5927\u90e8\u5206\u9898\u76ee\u662f 13-18 \u7684\u671f\u672b\u771f\u9898\uff0c\u5c0f\u90e8\u5206\u4e2d\u6587\u9898\u76ee\u662f\u7fa4\u91cc\u6211\u4e0d\u6e05\u695a\u6765\u6e90\u7684 PTA \u4e0a\u7684\u9898\u76ee\u6216\u8005\u6211\u81ea\u5df1\u7f16\u7684\u5c0f\u9898\u3002\u4e00\u5171\u4e94\u5341\u9053\u9898\uff0c\u5df2\u7ecf\u6309\u7167\u8003\u70b9/\u6613\u9519\u70b9\u5206\u5f00\u4e86\u3002
"},{"location":"programming/exam/exam/#_3","title":"\u6807\u8bc6\u7b26/\u5173\u952e\u5b57","text":"\u8fd9\u7c7b\u9898\u76ee\u4e00\u822c\u662f\u95ee\u54ea\u4e9b\u662f\u5408\u6cd5\u7684\u6807\u8bc6\u7b26\u3001\u54ea\u4e9b\u662f\u5173\u952e\u5b57\u3002\u5bf9\u4e8e\u6807\u8bc6\u7b26\uff0c\u53ea\u9700\u8981\u8003\u8651 int <identifier>;
\u662f\u5426\u5408\u6cd5\uff0c\u5982\u679c\u5408\u6cd5\uff0c\u90a3 <identifier>
\u5c31\u662f\u5408\u6cd5\u7684\u6807\u8bc6\u7b26\uff08\u6216\u8005\u8003\u8651\u662f\u4e0d\u662f\u5173\u952e\u5b57\uff0c\u5982\u679c\u662f\u5173\u952e\u5b57\uff0c\u90a3\u80af\u5b9a\u4e0d\u662f\u5408\u6cd5\u7684\u6807\u8bc6\u7b26\uff09\u3002\u81f3\u4e8e\u5173\u952e\u5b57\uff0c\u53ef\u4ee5\u770b cppreference\u3002
-
(C13A) Which one below is NOT a keyword of the C programming language? _____ A. define B. if C. typedef D. while
define
\u4e0d\u662f\u5173\u952e\u5b57\uff0c\u662f\u9884\u5904\u7406\u6307\u4ee4\uff0c\u4f60\u751a\u81f3\u53ef\u4ee5 int define;
\u800c if
\u3001typedef
\u3001while
\u663e\u7136\u90fd\u662f\u5173\u952e\u5b57\u3002
-
(C14A) Which one below is NOT a valid identifier in the C programming language? _____ A. printf B. _ever C. \"char\" D. true
\u663e\u7136\u9009\u62e9 C\uff0c\u56e0\u4e3a int \"char\";
\u80af\u5b9a\u662f\u975e\u6cd5\u7684\uff0c\u6807\u8bc6\u7b26\u5fc5\u987b\u4ee5\u5b57\u6bcd\u6216\u4e0b\u5212\u7ebf\u5f00\u5934\u3002\u5bf9\u4e8e A\uff0cprintf \u53ea\u662f\u4e00\u4e2a\u51fd\u6570\u540d\uff0c\u4e0d\u662f\u5173\u952e\u5b57\uff0c\u6240\u4ee5\u662f\u5408\u6cd5\u7684\u3002\u5bf9\u4e8e D\uff0cC \u8bed\u8a00\u4e2d true \u5e76\u4e0d\u662f\u5173\u952e\u5b57\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u3002
"},{"location":"programming/exam/exam/#_4","title":"\"\u52a0\u62ec\u53f7\"\u95ee\u9898","text":"\u5373\u6307\u8868\u8fbe\u5f0f\u4e2d\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u7b49\u95ee\u9898\uff0c\u4f8b\u5982\u7ed9\u4e00\u4e2a\u590d\u6742\u7684\u6ca1\u6709\u62ec\u53f7\u7684\u8868\u8fbe\u5f0f\uff0c\u8fd9\u65f6\u4e25\u683c\u6309\u7167\u4f18\u5148\u7ea7\u89c4\u5219\u7ed9\u8868\u8fbe\u5f0f\u5404\u4e2a\u90e8\u5206\u52a0\u4e0a\u62ec\u53f7\uff0c\u7ed3\u679c\u5c31\u6e05\u6670\u4e86\u3002
\u5173\u4e8e\u4f18\u5148\u7ea7\u7684\u9898\u76ee\u8fd9\u91cc\u5c31\u4e0d\u5217\u4e86\uff0c\u53ef\u4ee5\u53bb\u67e5\u9605\u4fee\u4f6c\u7684 note\uff0c\u91cc\u9762\u5199\u7684\u5f88\u6e05\u6670\u4e86\u3002
\u8fd9\u91cc\u7ed9\u51fa\u4e24\u9053\u548c\u4e09\u76ee\u8fd0\u7b97\u7b26 ?: \u6709\u5173\u7684\u9898\u76ee\u3002
-
(C18A) Given: int a=1,b=2,c=3,d=4;
, the value of the expression a<b?a:c<d?c:d
is _____.
\u5bf9\u4e8e\u4e09\u76ee\u8fd0\u7b97\u7b26\uff0c\u4f60\u9700\u8981\u77e5\u9053\u4e00\u4e2a ? \u80af\u5b9a\u8981\u548c\u540e\u9762\u7684\u4e00\u4e2a : \u8fdb\u884c\u914d\u5bf9 \u90a3\u4e48 c<d?c:d
\u8fd9\u90e8\u5206\u4e00\u5b9a\u662f\u4e00\u4f53\u7684\uff0c\u53ef\u4ee5\u7ed9\u5b83\u5de6\u53f3\u52a0\u4e0a\u62ec\u53f7\uff0c\u5c31\u53d8\u6210\u4e86 a<b?a:(c<d?c:d)
\uff0c\u5c31\u5df2\u7ecf\u5f88\u6e05\u6670\u4e86\u3002 \u6240\u4ee5\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u7684\u503c\uff1aa<b \u6210\u7acb\uff0c\u9009\u62e9\u7b2c\u4e00\u4e2a\u7ed3\u679c\u4e5f\u5c31\u662f a\uff0c\u7b54\u6848\u662f 1
-
\u82e5\u5b9a\u4e49 int a=1,b=2,c=3,d=4
\u90a3\u4e48\u8868\u8fbe\u5f0f (a>b?c>a?c-3:c-1:b==c?d-a:d-c)
\u7684\u503c\u4e3a _____.
\u548c\u4e0a\u9762\u540c\u7406\uff0c\u4e0d\u8fc7\u6709\u4e9b\u590d\u6742\u3002\u4f46\u662f\u8fd9\u4e2a\u4e09\u76ee\u8fd0\u7b97\u7b26\u7684\u914d\u5bf9\u8fc7\u7a0b\u6211\u4eec\u53ef\u4ee5\u7c7b\u6bd4\u4e3a\u62ec\u53f7\u5339\u914d\u3002\u5c06 ? \u89c6\u4e3a\u5de6\u62ec\u53f7 (\uff0c: \u89c6\u4e3a\u53f3\u62ec\u53f7 )\uff0c\u90a3\u4e48\u4e00\u4e2a ? \u5e94\u8be5\u548c\u54ea\u4e2a : \u914d\u5bf9\u5c31\u6e05\u6670\u4e86\u3002
(a>b?c>a?c-3:c-1:b==c?d-a:d-c)\n ( ( ) ) ( )\n | +---+ | +---+\n +-----------+\n
\u77e5\u9053\u4e86 ? \u548c : \u914d\u5bf9\u5173\u7cfb\u4e4b\u540e\u5c31\u80fd\u6b63\u786e\u5212\u5206\u7ed3\u6784\u4e86\uff1a a>b? (c>a?c-3:c-1) : (b==c?d-a:d-c)\n
\u6240\u4ee5 a>b \u4e0d\u6210\u7acb\uff0c\u9009\u62e9\u540e\u8005\uff0cb==c \u4e0d\u6210\u7acb\uff0c\u518d\u9009\u62e9\u540e\u8005\uff0c\u7b54\u6848\u662f d-c=1
"},{"location":"programming/exam/exam/#_5","title":"\u6570\u636e\u7c7b\u578b\u53ca\u5b57\u9762\u91cf","text":"\u51e0\u4e2a\u5e38\u89c1\u7684\u6570\u636e\u7c7b\u578b\u4e00\u5b9a\u8981\u77e5\u9053\u5b83\u4eec\u5360\u51e0\u4e2a\u5b57\u8282\u7684\u5927\u5c0f\u3002\u5e76\u4e14\u5728\u8868\u8fbe\u5f0f\u4e2d\u4e5f\u8981\u65f6\u523b\u6ce8\u610f\u5e38\u91cf\u7684\u7c7b\u578b\uff08\u5982\u7b2c\u4e5d\u9898\uff09\u3002
\u5b57\u9762\u91cf\u5373\u4e00\u4e2a\u503c\u7684\u8868\u793a\u65b9\u6cd5\uff1a
- \u6574\u578b\uff1a123 \u8868\u793a\u5341\u8fdb\u5236 123\uff1b0123 \u662f\u516b\u8fdb\u5236\u7684\u8868\u793a\u65b9\u6cd5\uff08\u5f00\u5934\u4e00\u5b9a\u52a0 0\uff0c0123 \u7b49\u4ef7\u4e8e 83\uff09\uff0c0x123 \u662f\u5341\u516d\u8fdb\u5236\u7684\u8868\u793a\u65b9\u6cd5\uff08\u5f00\u5934\u4e00\u5b9a\u52a0 0x\uff0c0x123 \u7b49\u4ef7\u4e8e 291\uff09
- \u5b57\u7b26\u578b\uff1a
- \u8bb0\u4f4f\u4e00\u4e2a\u5b57\u7b26\u7c7b\u578b\u5b9e\u9645\u4e0a\u5c31\u76f8\u5f53\u4e8e\u4e00\u4e2a\u5b57\u8282\u7684\u6574\u578b\uff0c\u6240\u4ee5\u53ef\u4ee5\u901a\u8fc7\u6570\u503c\u6765\u8868\u793a\uff1achar c = 65; \u5c31\u76f8\u5f53\u4e8e char c = 'A';
- \u540c\u65f6 \u5728\u5f15\u53f7\u91cc\u6709\u8f6c\u4e49\u7684\u6548\u679c\uff0c\u6bd4\u5982 '\\n' '\\t' \u90fd\u4ee3\u8868\u4e00\u4e2a\u5b57\u7b26\uff0c\u800c '\\\\' \u624d\u4f1a\u8868\u793a\u4e00\u4e2a \u5b57\u7b26\uff1b
- \u518d\u8fdb\u4e00\u6b65\uff0c \u540e\u9762\u53ef\u4ee5\u63a5\u6700\u591a\u4e09\u4e2a\u6570\u5b57\u6765\u4f7f\u7528\u516b\u8fdb\u5236\u8868\u793a\u4e00\u4e2a\u5b57\u8282\uff0c\u4e14\u9047\u5230 0-7 \u8303\u56f4\u4e4b\u5916\u7684\u6570\u5b57\u4f1a\u7ed3\u675f\u5f53\u524d\u5b57\u8282\uff0c\u6bd4\u5982 '\\101' \u4e5f\u8868\u793a 'A'\uff0c\u800c '\\08' \u56e0\u4e3a 8 \u8d85\u8fc7\u4e86\u516b\u8fdb\u5236\u8303\u56f4\uff0c\u6240\u4ee5\u8fd9\u662f\u4e24\u4e2a\u5b57\u7b26\u653e\u5230\u4e86\u4e00\u4e2a\u5355\u5f15\u53f7\u91cc\uff0c\u4e0d\u662f\u6b63\u786e\u7684\u7528\u6cd5\uff0c\u5982\u679c\u5199\u6210\u5b57\u7b26\u4e32\uff0c\u5219 \"\\08\" \u8868\u793a\u4e24\u4e2a\u5b57\u7b26\uff1b
- \\x \u540e\u9762\u63a5 0-9A-F \u5b57\u7b26\u901a\u8fc7\u5341\u516d\u8fdb\u5236\u6765\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\u3002\u4e0d\u8fc7\u5e76\u4e0d\u4f1a\u6709\u957f\u5ea6\u9650\u5236\uff0c\u6bd4\u5982 '\\x00000041' \u4e5f\u662f\u4e00\u4e2a\u5b57\u7b26\uff0c\u540c\u6837\u9047\u5230\u8303\u56f4\u5916\u7684\u5b57\u7b26\u5c31\u7ed3\u675f\u3002
-
(C13A) For code below:
unsigned short sht = 0;\nsht--;\n
What will be the value of sht
after the execution? _____ A. -1 B. 65535 C. 32767 D. 65536 sht \u662f unsigned short \u7c7b\u578b\uff0c\u662f\u4e24\u4e2a\u5b57\u8282\u7684\uff0c\u6240\u4ee5\u8303\u56f4\u4e3a 0-65535\u3002 \u65e0\u7b26\u53f7\u6574\u578b\u4ece 0 \u51cf\u53bb 1 \u4f1a\u4e0b\u6ea2\u5230\u6700\u5927\u503c\uff0c\u5bf9\u4e8e\u6b64\u9898\u4e5f\u5c31\u662f 65535\uff0c\u9009 B
-
(C13A) Which literal below is 124 in decimal(\u5341\u8fdb\u5236)? _____ A. 0124 B. 124d C. 0x124 D. 0174
\u6839\u636e\u524d\u9762\u8bf4\u5230\u7684\uff0cA. 0124 \u662f\u516b\u8fdb\u5236\u8868\u793a\u6cd5\uff0c\u5b83\u7b49\u4e8e\u5341\u8fdb\u5236\u7684 84\uff1bB. 124d \u6ca1\u6709\u8fd9\u79cd\u8868\u793a\u65b9\u6cd5\uff0c\u662f\u8bed\u6cd5\u9519\u8bef\u7684\uff1bC. 0x124 \u662f\u5341\u516d\u8fdb\u5236\u8868\u793a\u6cd5\uff0c\u7b49\u4e8e\u5341\u8fdb\u5236\u7684 292\uff1bD. 0174 \u516b\u8fdb\u5236\uff0c\u7b49\u4e8e\u5341\u8fdb\u5236 124\uff0c\u9009 D
-
(C16A) In the following notations, _____ can express a character constant(\u5b57\u7b26\u5e38\u91cf) correctly. A. '\\x100' B. 125 C. '\\08' D. '\\'
A. '\\x100' \u662f\u5341\u516d\u8fdb\u5236\u8868\u793a\u6cd5\uff0c\u4f46\u662f\u8d85\u51fa\u4e86\u4e00\u4e2a\u5b57\u8282\u7684\u8303\u56f4\uff0c\u662f\u8bed\u6cd5\u9519\u8bef\u7684\uff1bB. 125 \u901a\u8fc7\u4e00\u4e2a\u6574\u6570\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\uff0c\u800c\u4e14\u5728 ASCII \u7801\u8303\u56f4\u5185\uff0c\u80af\u5b9a\u662f\u5408\u6cd5\u7684\uff08\u5b9e\u9645\u4e0a\u8868\u793a\u7684\u5c31\u662f\u5b57\u7b26 '}'\uff09\uff1bC. '\\08' \u524d\u9762\u8bf4\u8fc7\u4e86\uff0c\\0 8 \u662f\u4e24\u4e2a\u5b57\u7b26\uff0c\u6324\u5230\u4e86\u4e00\u4e2a\u5355\u5f15\u53f7\u91cc\uff0c\u662f\u9519\u8bef\u7684\u7528\u6cd5\uff1bD. '\\' \u4e2d \u4f1a\u5c06 ' \u8f6c\u4e49\uff0c\u6240\u4ee5\u76f8\u5f53\u4e8e\u8fd9\u4e2a\u5355\u5f15\u53f7\u6ca1\u6709\u95ed\u5408\uff0c\u662f\u8bed\u6cd5\u9519\u8bef\u7684\u3002\u6240\u4ee5\u9009 B\u3002
-
(C17A) In the following notations, _____ can NOT express a single-character constant(\u5355\u5b57\u7b26\u5e38\u91cf) correctly. A. '%c' B. 127 C. '\\077' D. 55
A. '%c' \u540c\u6837\u662f\u4e24\u4e2a\u5b57\u7b26\u6324\u5230\u4e86\u4e00\u4e2a\u5355\u5f15\u53f7\u91cc\uff0c\u662f\u9519\u8bef\u7528\u6cd5\uff1bBCD \u90fd\u53ef\u4ee5\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\uff0c\u6240\u4ee5\u9009 A
-
\u4ee5\u4e0b\u8868\u8fbe\u5f0f\u54ea\u4e2a\u662f\u4e0d\u6b63\u786e\u7684 _____. A. 0.5%2 B. 3&(0.5+0.5) C. 4.6<<2 D. 2==(3/2)
\u8981\u6ce8\u610f\u8fd0\u7b97\u7b26\u4e24\u4fa7\u7684\u6570\u636e\u7c7b\u578b\uff0c\u53ea\u6709 D \u7684 == \u4e24\u4fa7\u90fd\u662f int\uff0c\u662f\u5408\u6cd5\u7684\u3002\u800c ABC \u7684\u64cd\u4f5c\u6570\u90fd\u51fa\u73b0\u4e86 double \u7c7b\u578b\uff0c% & << \u8fd0\u7b97\u7b26\u4e0d\u80fd\u7528\u5728 double \u4e0a\uff0c\u8bed\u6cd5\u9519\u8bef\u3002
"},{"location":"programming/exam/exam/#_6","title":"\u6570\u7ec4\u4e0e\u6307\u9488","text":"\u6307\u9488\u662f C \u8bed\u8a00\u7684\u7075\u9b42\uff0c\u4e5f\u662f\u8003\u8bd5\u5e38\u8003\u6613\u9519\u7684\u77e5\u8bc6\u70b9\uff0c\u7279\u522b\u662f\u548c\u6570\u7ec4\u4e00\u8d77\u51fa\u73b0\u65f6\u3002
\u51e0\u4e2a\u9700\u8981\u8bb0\u4f4f\u7684\u77e5\u8bc6\u70b9\uff1aa[b] \u548c *(a+b) \u5728\u4f7f\u7528\u65f6\u5b8c\u5168\u7b49\u4ef7\uff1b\u4e8c\u7ef4\u6570\u7ec4\u65e0\u6cd5\u9000\u5316\u4e3a\u4e8c\u7ea7\u6307\u9488\uff1b\u6570\u7ec4\u540d\u4e0d\u80fd\u88ab\u91cd\u65b0\u8d4b\u503c\u3002
-
(C13A) Given the declaration: int a[10], *p=a;
\uff0cthe expression _____ is NOT correct. A. a[9] B. p[5] C. *p++ D. a++
a \u662f\u4e00\u4e2a\u6570\u7ec4\uff0cp \u662f\u4e00\u4e2a\u6307\u9488\uff0c\u5c06 a \u8d4b\u503c\u7ed9 p \u65f6\u5373\u5c06 a \u7684\u9996\u5730\u5740\u8d4b\u503c\u7ed9 p\u3002 a[9] \u80af\u5b9a\u662f\u5408\u6cd5\u7684\uff0c\u56e0\u4e3a p[5] \u7b49\u4ef7\u4e8e *(p+5)\uff0c\u4e5f\u662f\u5408\u6cd5\u7684\uff0c*p++ \u53d6\u4e86\u5f53\u524d p \u6307\u5411\u7684\u503c\uff0c\u5e76\u5c06 p \u6307\u9488 ++\uff0c\u662f\u5408\u6cd5\u7684\u3002 \u800c D. a++ \u4e2d\u5305\u542b\u4e86\u5bf9 a \u7684\u91cd\u65b0\u8d4b\u503c\uff08\u5c06 a+1 \u8d4b\u503c\u7ed9 a\uff09\uff0c\u7531\u4e8e\u6570\u7ec4\u540d\u4e0d\u80fd\u88ab\u8d4b\u503c\uff0c\u6240\u4ee5\u662f\u9519\u8bef\u7684\uff0c\u9009 D\u3002
-
(C13A) Given the declaration: int a[3][3]={1,2,3,4,5,6,7,8,9};
, the value of a[-1][5]
is _____.
\u9996\u5148\u6765\u770b a[-1]\uff0c\u5373 (a-1)\uff0ca-1 \u4f1a\u4ee5\u4e09\u4e2a int \u4e3a\u5355\u4f4d\u5411\u5de6\u79fb\u52a8\uff0c\u5373 (a-1) \u662f\u4e00\u4e2a\u6307\u5411\u5982\u4e0b\u4f4d\u7f6e\u7684\u6307\u9488\uff1a
0 0 0 1 2 3 4 5 6 7 8 9\n ^\n |\n*(a-1) = p\n
\u73b0\u5728\u6211\u4eec\u5c06 a[-1] \u4e5f\u5c31\u662f *(a-1) \u89c6\u4e3a p\uff0c\u90a3\u6211\u4eec\u8981\u627e\u7684\u7ed3\u679c\u5c31\u662f p[5]\uff0c\u6b64\u65f6 p \u662f\u4e00\u4e2a\u6307\u5411 int \u7c7b\u578b\u7684\u6307\u9488\uff0c*(p+5) \u5c31\u76f8\u5f53\u4e8e\u627e\u5230\u5b83\u6307\u5411\u7684\u4f4d\u7f6e\u53f3\u4fa7\u7b2c 5 \u4e2a int \u7684\u503c\uff0c\u4e5f\u5c31\u662f 3\u3002 -
(C14A) Given the declaration: int a[3][2]={1,2,3,4,5,6};
what is the value of expression (a[1]+1)[0]
? _____.
\u540c\u4e0a\u9898\u4e00\u6837\u5206\u6790\u5373\u53ef\uff0c\u65f6\u523b\u8bb0\u5f97 a[b] \u7b49\u4ef7\u4e8e *(a+b)\u3002\u4ee5\u4e0b\u662f\u8d3a\u8001\u5e08\u66fe\u7ecf\u7684\u56fe\uff1a
a -> {\na[0] -> {1, 2}\na[1] -> {3, 4}\n ^\n +--- a[1] + 1\na[2] -> {5, 6}\n }\n
\u6240\u4ee5 (a[1]+1)[0] \u5c31\u662f *(a[1]+1) = 4 -
(C15A/C16A) For the declarations: char *s, str[10];
, statement _____ is completely correct. A. strcpy(s, \"hello\"); B. str=\"hello\"+1 C. s=*&(str+1) D. s=str+1
\u8fd9\u91cc\u6d89\u53ca\u5230\u4e86\u4e00\u4e2a\u91ce\u6307\u9488\u7684\u95ee\u9898\uff0c\u4e0b\u9762\u4f1a\u4e13\u95e8\u6709\u4e00\u4e2a\u90e8\u5206
A. \u5c06 \"hello\" \u62f7\u8d1d\u5230 s \u6307\u5411\u7684\u7a7a\u95f4\u3002\u4f46\u662f s \u6307\u5411\u4ec0\u4e48\u5462\uff1f\u4f60\u5e76\u4e0d\u6e05\u695a\uff0c\u4e5f\u5c31\u662f\u8bf4 s \u662f\u4e00\u4e2a\u91ce\u6307\u9488\uff0c\u4f60\u4e0d\u6e05\u695a\u5b83\u6307\u5411\u54ea\u91cc\uff0c\u4e5f\u5c31\u81ea\u7136\u4e0d\u80fd\u5411\u5b83\u6307\u5411\u7684\u7a7a\u95f4\u4e2d\u5199\u5165\u6570\u636e B. str \u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u540d\u4e0d\u80fd\u88ab\u8d4b\u503c\uff0c\u6240\u4ee5\u662f\u9519\u7684 C. str+1 \u4e0d\u80fd\u88ab\u53d6\u5730\u5740\uff0c\u56e0\u4e3a\u8fd9\u662f\u8ba1\u7b97\u8fc7\u7a0b\u4e2d\u7684\u4e00\u4e2a\u6570\uff0c\u800c\u4e0d\u662f\u5b9e\u9645\u5b58\u5728\u5185\u5b58\u4e2d\u7684\u6570\uff0c\u6240\u4ee5\u662f\u9519\u7684 D. str+1 \u8868\u793a\u7684\u5c31\u662f str \u6570\u7ec4\u4e2d\u7b2c\u4e8c\u4e2a\u5143\u7d20\u7684\u5730\u5740\uff0c\u5c06\u5176\u8d4b\u503c\u7ed9 s\uff0c\u662f\u6b63\u786e\u7684
-
(C16A) Given: double a[]={1, 2, 3, 4, 5};
, the value of expression (int)&a[3] - (int)&a[0]
is _____
\u7531\u4e8e\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u90fd\u662f\u8fde\u7eed\u5b58\u50a8\u7684\uff0c\u6240\u4ee5 a[3] \u7684\u5730\u5740\u51cf\u53bb a[0] \u7684\u5730\u5740\u5c31\u662f a[3] \u4e0e a[0] \u4e4b\u95f4\u7684\u8ddd\u79bb\uff0c\u4e5f\u5c31\u662f 3 \u4e2a double \u7c7b\u578b\u7684\u5927\u5c0f\uff0c\u5373 3 * sizeof(double) = 24
\u8fd9\u91cc\u9700\u8981\u548c 17 \u9898\u8fdb\u884c\u4e00\u4e0b\u5bf9\u6bd4\uff0c17 \u9898\u91cc\u6211\u4eec\u518d\u8be6\u7ec6\u8bf4\u660e
-
(C17A) The following code fragment will output _____.
char *week[]={\"Mon\", \"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\",\"Sun\"}, **pw=week;\nchar c1, c2;\nc1 = (*++pw)[1];\nc2 = *++pw[1];\nprintf(\"%c#%c#\", c1, c2);\n
\u9996\u5148 c1 = (*++pw)[1]\uff0c++pw \u4f7f pw \u6307\u5411\u4e86 week[1]\uff0c\u7136\u540e (*++pw) \u5c31\u662f week[1]\uff0c\u518d [1] \u5c31\u662f week[1][1] \u4e5f\u5c31\u662f 'u' \u7136\u540e c2 = *++pw[1]\uff0c\u8fd9\u91cc\u7684\u7406\u89e3\u65b9\u5f0f\u4e00\u5b9a\u662f\u5bf9 pw[1] \u8fdb\u884c ++\uff0cpw[1] \u6b64\u65f6\u662f week[2]\uff0c\u7136\u540e\u5c06\u5176\u81ea\u589e\u5f97\u5230\u6307\u5411 week[2][1] \u7684\u6307\u9488\uff0c\u518d\u89e3\u5f15\u7528\u5f97\u5230 'e'
-
(C17A) For the declaration: int a[3][4]={{0,1,2},{4,5,6},{7,8}};
, the value of the element of a[1][-2]
is _____.
\u548c 11\u300112 \u9898\u7c7b\u4f3c\u5206\u6790\u5373\u53ef
a -> {\n a[0] -> {0, 1, 2, 0}\n ^\n +---- a[1][-2]\n a[1] -> {4, 5, 6, 0}\n a[2] -> {7, 8, 0, 0}\n}\n
-
\u4ee5\u4e0b\u4ee3\u7801\u7684\u8f93\u51fa\u4e3a _____.
int a[] = {1, 2, 3, 4, 5};\nint *p = a, *q = &a[2];\nprintf(\"%lu\", q-p);\n
\u9996\u5148\u8fd9\u9053\u9898\u7684\u8f93\u51fa\u662f 2 \u800c\u4e0d\u662f 2*sizeof(int)=8\uff0c\u56e0\u4e3a q\u3001p \u6307\u9488\u76f8\u51cf\u7684\u610f\u4e49\u5b9e\u9645\u4e0a\u662f\u8ba1\u7b97\u4e24\u4e2a\u6307\u9488\u5dee\u4e86\u51e0\u4e2a\u201c\u5355\u4f4d\u201d\u7684\u8ddd\u79bb\uff0c\u8fd9\u91cc\u4e00\u4e2a\u5355\u4f4d\u5c31\u662f\u4e00\u4e2a int \u7684\u957f\u5ea6\uff0c\u5b83\u4eec\u5dee\u4e86\u4e24\u4e2a int\uff0c\u6240\u4ee5\u662f 2
\u6307\u9488\u76f8\u51cf\u5e76\u4e0d\u662f\u5c06\u5176\u503c\uff08\u4e5f\u5c31\u662f\u5730\u5740\uff09\u76f8\u51cf\uff0c\u5982\u679c\u8fd9\u662f\u9884\u671f\u884c\u4e3a\uff0c\u90a3\u4e48\u5e94\u8be5\u4f7f\u7528\u4ee5\u4e0b\u4e24\u79cd\u5199\u6cd5\uff1a
printf(\"%d\", (int)q - (int)p); // \u5373 14 \u9898\u4e2d\u5199\u6cd5\nprintf(\"%d\", (char*)q - (char*)p); // \u8f6c\u4e3a char* \u7c7b\u578b\u6307\u9488\uff0c\u5355\u4f4d\u5c31\u662f\u4e00\u4e2a\u5b57\u8282\uff0c\u548c\u5730\u5740\u76f8\u51cf\u6548\u679c\u76f8\u540c\n
-
\u4ee5\u4e0b\u54ea\u4e2a\u5b9a\u4e49\u4e2d p \u4e0d\u662f\u6307\u9488 _____. A. char **p; B. char (*p)[10]; C. char *p[6]; D. \u524d\u4e09\u9879\u4e2d p \u90fd\u662f\u6307\u9488
\u8be6\u7ec6\u5206\u6790\u53ef\u4ee5\u770b\u8d3a\u8001\u5e08\u300a\u6d45\u8c08 C \u8bed\u8a00\u7684\u6570\u636e\u7c7b\u578b\u300b\u4e2d\u63cf\u8ff0\u7684 Clockwise/Spiral Rule
A \u4e2d p \u663e\u7136\u662f\u4e00\u4e2a\u4e8c\u7ea7\u6307\u9488\uff0cB \u4e2d p \u662f\u4e00\u4e2a\u6307\u5411\u957f\u5ea6\u4e3a 10 \u7684\u6570\u7ec4\u7684\u6307\u9488\uff0cC \u4e2d p \u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a 6 \u7684\u6307\u9488\u6570\u7ec4\uff08\u5373\u4e00\u4e2a\u6570\u7ec4\uff0c\u5185\u90e8\u5143\u7d20\u662f\u6307\u9488\uff09
\u8fd8\u6709\u4e00\u70b9\u8981\u6ce8\u610f\uff0c\u6570\u7ec4\u548c\u6307\u9488\u662f\u4e24\u79cd\u7c7b\u578b
-
\u5bf9\u4e8e\u51fd\u6570\u58f0\u660e void f(char **p)
\uff0c\u4ee5\u4e0b\u54ea\u4e2a var \u7684\u5b9a\u4e49\u4f1a\u4f7f f(var) \u8bed\u6cd5\u9519\u8bef _____. A. char var[10][10]; B. char *var[10]; C. void *var = NULL; D. char *v=NULL, **var=&v;
BD \u4e00\u822c\u6ca1\u4ec0\u4e48\u95ee\u9898\uff0c\u5927\u90e8\u5206\u540c\u5b66\u4e0d\u7406\u89e3 A \u548c C
A. \u4e8c\u7ef4\u6570\u7ec4\u4e0d\u80fd\u9000\u5316\u4e3a\u4e8c\u7ea7\u6307\u9488\uff0c\u6240\u4ee5\u80af\u5b9a\u662f\u9519\u7684 C. \u5728 C \u8bed\u8a00\u4e2d\uff0cvoid* \u8868\u793a\u300c\u6307\u5411\u4efb\u610f\u7c7b\u578b\u7684\u6307\u9488\u300d\uff0c\u800c\u8fd9\u4e2a\u300c\u4efb\u610f\u7c7b\u578b\u300d\u4e5f\u53ef\u4ee5\u662f char*\uff08\u5373\u6307\u5411 char \u7684\u6307\u9488\uff09\uff0c\u6240\u4ee5\u5b83\u53ef\u4ee5\u4ee3\u8868\u300c\u6307\u5411\u6307\u5411 char \u7684\u6307\u9488\u7684\u6307\u9488\u300d\uff08char**\uff09\uff0c\u6240\u4ee5\u662f\u5bf9\u7684
-
\u5bf9\u4e8e\u5b9a\u4e49 char s[2][3] = {\"ab\", \"cd\"}, *p=(char*)s
\uff0c\u4ee5\u4e0b\u54ea\u4e2a\u8868\u8fbe\u5f0f\u662f\u6b63\u786e\u7684\u4e14\u503c\u7b49\u4e8e s[1][1] _____. A. *(s+3) B. *s+2 C. p[1][1] D. *++p+2
s -> {\n s[0] -> {'a', 'b', '\\0'}\n s[1] -> {'c', 'd', '\\0'}\n}\n
A. *(s+3) \u7b49\u4ef7\u4e8e s[3]\uff0c\u9996\u5148\u7c7b\u578b\u4e0a\u5b83\u5c31\u4e0d\u5bf9 B. \u540c\u6837 *s+2 \u4e5f\u662f\u6307\u9488\uff0c\u7c7b\u578b\u4e0a\u5c31\u80af\u5b9a\u4e0d\u5bf9 C. p \u6b64\u65f6\u662f char* \u7c7b\u578b\uff0c\u4e0d\u80fd\u8fdb\u884c\u4e24\u6b21\u89e3\u5f15\u7528\uff0c\u8bed\u6cd5\u9519\u8bef D. ++p \u5c06 p \u6307\u5230\u4e86 'b' \u5934\u4e0a\uff0c\u89e3\u5f15\u7528\u5f97\u5230 'b' \u518d\u52a0\u4e8c\u5f97\u5230 'd' \u7b49\u4e8e s[1][1]\uff0c\u9009 D
"},{"location":"programming/exam/exam/#_7","title":"\u5b57\u7b26\u4e32\u76f8\u5173","text":"\u5b57\u7b26\u4e32\u4e5f\u662f\u4e00\u4e2a\u5f88\u5bb9\u6613\u51fa\u9519\u7684\u8003\u70b9\uff0c\u6211\u63a8\u8350\u7684\u7406\u89e3\u65b9\u5f0f\u662f\uff1aC \u8bed\u8a00\u4e2d\u4e0d\u5b58\u5728\u5b57\u7b26\u4e32\uff0c\u53ea\u6709\u5b57\u7b26\u6570\u7ec4\uff0c\u800c\u5b57\u7b26\u4e32\u662f\u4e00\u79cd\u5bf9\u4e8e\u5b57\u7b26\u6570\u7ec4\u7684\u4eba\u4e3a\u7406\u89e3\u65b9\u5f0f\uff0c\u5373\u4ece\u5f00\u5934\u76f4\u5230\u7b2c\u4e00\u4e2a '\\0' \u6807\u5fd7\u4e86\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u6240\u4ee5 \"abc\" \u548c {'a', 'b', 'c', '\\0'} \u662f\u7b49\u4ef7\u7684\u3002
\u53e6\u4e00\u4e2a\u9700\u8981\u7262\u8bb0\u7684\u77e5\u8bc6\u70b9\u662f\uff0c\u5f53\u7a0b\u5e8f\u4e2d\u51fa\u73b0\u5b57\u7b26\u4e32\u5e38\u91cf\u7684\u65f6\u5019\uff0c\u8981\u5c06\u5176\u89c6\u4e3a\u6307\u5411\u8be5\u5b57\u7b26\u4e32\u7684\u9996\u5b57\u7b26\u7684\u6307\u9488\u6765\u5904\u7406\u3002\u800c\u4e14\u5728\u521d\u59cb\u5316\u5b57\u7b26\u6570\u7ec4\u65f6\u9664\u5916\uff08char s[] = \"abc\"; \u5e76\u4e0d\u662f\u628a \"abc\" \u9996\u5b57\u7b26\u5730\u5740\u8d4b\u503c\u7ed9\u4e86 s\uff09\u3002
\u5bf9\u4e8e char *s = \"abc\" \u548c char s[] = \"abc\" \u6211\u4eec\u5728\u7b2c 31 \u9898\u4e2d\u518d\u8be6\u7ec6\u8fdb\u884c\u533a\u5206\u3002
-
(C13A) Given: char format[] = \"No.%d%c\"
; the statement printf(format, 3, *(\"xyz\"+2));
will print out _____.
\"xyz\" \u8fd9\u91cc\u5f53\u4f5c\u6307\u5411 'x' \u7684\u6307\u9488\uff0c\u52a0 2 \u5219\u6307\u5230\u4e86 'z'\uff0c\u89e3\u5f15\u7528\u5c31\u5f97\u5230\u4e86 'z' \u8fd9\u4e2a\u5b57\u7b26\u3002\u6240\u4ee5\u8f93\u51fa\u4e3a No.3z
-
(C14A/C15A) Given the following code fragment, the loop condition str[i]!='\\0'
could be replaced by which choice? _____.
char str[20]=\"hello, world\";\nfor (i = 0; str[i] != '\\0'; i++) putchar(str[i]);\n
A. str[i] B. i < 20 C. !(str[i] = '\\0') D. i <= 20 \u8fd8\u8981\u8bb0\u4f4f\u7684\u4e00\u70b9\u662f\uff0c'\\0' \u5c31\u662f 0\uff0c\u6240\u4ee5\u8fd9\u9898\u91cc str[i] != '\\0' \u548c A \u662f\u5b8c\u5168\u7b49\u4ef7\u7684\u3002\uff08C \u5dee\u4e86\u4e00\u4e2a\u7b49\u53f7\uff09 B \u9519\u8bef\u7684\u539f\u56e0\u662f\uff0c'\\0' \u4e5f\u662f\u5b57\u7b26\uff0c\u8fd9\u6837\u5c31\u4e00\u5b9a\u4f1a\u8f93\u51fa 20 \u4e2a\u5b57\u7b26\u6765\uff0c\u5373\u4f7f\u5b9e\u9645\u4e0a\u4f60\u770b\u4e0d\u89c1 '\\0' \u8fd9\u4e2a\u5b57\u7b26\uff0c\u4f46\u5b83\u4eec\u786e\u5b9e\u88ab\u8f93\u51fa\u4e86
-
(C14A) The value of expression !*(\"2015-01-28\"+5)
is _____
\u5b57\u7b26\u4e32\u5e38\u91cf\u51fa\u73b0\u5728\u7a0b\u5e8f\u91cc\u5f53\u4f5c\u6307\u5411\u9996\u5b57\u7b26\u7684\u6307\u9488\u5904\u7406\uff0c\u6240\u4ee5 \"2015-01-28\"+5 \u5373\u8868\u793a\u6307\u5411 '0' \u4f4d\u7f6e\u7684\u6307\u9488\uff0c\u89e3\u5f15\u7528\u5f97\u5230 '0'\u3002\u6240\u4ee5\u8fd9\u9898\u5316\u4e3a\u4e86 !'0' \u7684\u503c\u3002
\u4e00\u5b9a\u8981\u533a\u5206\u6e05\u695a '0' \u548c '\\0'\uff0c'0'==48 \u800c '\\0'==0\uff0c\u6240\u4ee5 !'0' \u662f !48 \u5373 0
-
(C14A) The output of the code below is _____.
char x[] = \"hello,world\\012345\";\nprintf(\"%d#%d#\"\uff0csizeof(x)\uff0cstrlen(x));\n
\u590d\u4e60\u4e00\u4e0b\u524d\u9762\u8bf4\u8fc7\u7684\u5b57\u7b26\u5b57\u9762\u91cf\u7684\u8868\u793a
\u8fd9\u91cc x \u5c31\u76f8\u5f53\u4e8e 'h', 'e', 'l', 'l', 'o', ',', 'w', 'o', 'r', 'l', 'd', '\\012', '3', '4', '5', '\\0'\uff0c\u6240\u4ee5 sizeof(x) \u8ba1\u7b97\u5360\u4e86\u591a\u5c11\u7a7a\u95f4\uff0c\u4e00\u5171 16 \u4e2a\u5b57\u8282\uff0c\u7ed3\u679c\u4e3a 16\u3002\u800c strlen(x) \u8ba1\u7b97\u7b2c\u4e00\u4e2a '\\0' \u524d\u6709\u51e0\u4e2a\u5b57\u7b26\uff0c\u8fd9\u91cc\u6709 15 \u4e2a\uff08'\\012' \u4e2d\u7684 \\0 \u5e76\u4e0d\u7b97 '\\0'\uff09\uff0c \u7ed3\u679c\u4e3a 15\u3002
-
(C17A) The value of expression !\"01-21-2018\"[7]
is _____
\u540c 23 \u9898\uff0c\u8fd9\u91cc \"01-21-2018\"[7] \u6307\u5411\u4e86 '0'\uff0c!'0' \u4e3a 0
-
(C17A) Given: char s[]=\"123\\029\\08\";
, then sizeof(s)
and strlen(s)
will be _____ respectively.
\u540c 24 \u9898\uff0c\u8fd9\u91cc s \u5b57\u7b26\u6570\u7ec4\u76f8\u5f53\u4e8e '1', '2', '3', '\\02', '9', '\\0', '8', '\\0'\uff0c\u4e00\u5171 8 \u4e2a\uff0c\u6240\u4ee5 sizeof(s) \u4e3a 8\u3002\u7b2c\u4e00\u4e2a '\\0' \u524d\u6709 5 \u4e2a\uff0c\u6240\u4ee5 strlen(s) \u4e3a 5\u3002
-
(C17A) The value of expression strcmp(\"abcabc\",\"aabbcc\"+1) < 0
is _____.
strcmp(s1, s2) \u5f53 s1 < s2 \u65f6\u8fd4\u56de\u4e00\u4e2a\u8d1f\u6570\uff0c\u5f53 s1 > s2 \u65f6\u8fd4\u56de\u4e00\u4e2a\u6b63\u6570\uff0c\u5f53 s1 == s2 \u65f6\u8fd4\u56de 0\u3002\u6240\u4ee5\u8fd9\u9898\u76f8\u5f53\u4e8e\u6bd4\u8f83 \"abcabc\" \u548c \"abbcc\"\uff0c\"abcabc\" > \"abbcc\"\uff0c\u6240\u4ee5\u8fd4\u56de\u4e00\u4e2a\u6b63\u6570\uff0c\u7ed3\u679c\u4e3a 0
\u5177\u4f53\u5b57\u7b26\u4e32\u6bd4\u8f83\u5927\u5c0f\u7684\u65b9\u5f0f\u79f0\u4e3a\u201c\u5b57\u5178\u5e8f\u201d\uff0c\u4e5f\u5c31\u662f\u8bf4\u5047\u8bbe\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u5728\u82f1\u6587\u8bcd\u5178\u4e2d\uff0c\u90a3\u4e48\u5b83\u4eec\u7684\u5927\u5c0f\u5173\u7cfb\u5c31\u662f\u5728\u8bcd\u5178\u4e2d\u51fa\u73b0\u7684\u5148\u540e\u5173\u7cfb\uff08\u5148\u51fa\u73b0\u7684\u5c0f\uff09
-
(C18A) The value of expression !(\"01/24/2019\"+5)[5]
is _____.
\u540c 23 \u9898\uff0c\u8fd9\u91cc\u76f8\u5f53\u4e8e !*(\"01/24/2019\"+10)\u3002\u5176\u4e2d\u5b57\u7b26\u4e32\u52a0 10 \u540e\u6307\u5411\u4e86\u7ed3\u5c3e\u9690\u85cf\u7684 '\\0'\uff0c\u800c '\\0' \u5c31\u662f 0\uff0c\u6240\u4ee5\u53d6\u53cd\u4e3a 1
-
\u4ee5\u4e0b\u4ee3\u7801\u6bb5\u7684\u8f93\u51fa\u4e3a _____.
char c[] = \"I\\t\\r\\\\\\0will\\n\";\nprintf(\"%d\", strlen(c));\n
\u540c 24 \u9898\uff0c\u8fd9\u91cc c \u5b57\u7b26\u6570\u7ec4\u76f8\u5f53\u4e8e 'I', '\\t', '\\r', '\\', '\\0', 'w', 'i', 'l', 'l', '\\n', '\\0'\uff0c\u7b2c\u4e00\u4e2a '\\0' \u524d\u6709 4 \u4e2a\uff0c\u6240\u4ee5 strlen\u00a9 \u4e3a 4\u3002
-
\u4ee5\u4e0b\u4ee3\u7801\u6bb5\u7684\u8f93\u51fa\u4e3a _____.
char a[] = \"abc\";\nchar b[] = {'a', 'b', 'c'};\nprintf(\"%d#%d#\", sizeof(a), sizeof(b));\n
\"abc\" \u53ef\u4ee5\u5f53\u4f5c {'a', 'b', 'c', '\\0'}\uff0c\u6240\u4ee5 sizeof(a) \u4e3a 4\uff0csizeof(b) \u4e3a 3\u3002
-
\u4ee5\u4e0b\u4ee3\u7801\u662f\u5426\u5b58\u5728\u9519\u8bef\uff0c\u5982\u679c\u6709\u8bf7\u6307\u51fa\u54ea\u91cc\u6709\u95ee\u9898 _____.
char *a = \"hello\";\nchar b[] = \"hello\";\na[0] = 'H';\nb[0] = 'H';\n
\u8fd9\u91cc\u6211\u4eec\u8981\u533a\u5206\u7684\u662f a \u548c b\u3002a \u5c31\u662f\u4e00\u4e2a\u5b57\u7b26\u6307\u9488\uff0c\u5b83\u6307\u5411\u4e86 \"hello\" \u7684\u5f00\u5934\uff0c\u800c\u8fd9\u4e2a \"hello\" \u5b58\u5728\u4e8e\u9759\u6001\u5b58\u50a8\u533a\u4e2d\uff0c\u662f\u53ea\u8bfb\u7684\uff0c\u4e0d\u80fd\u8fdb\u884c\u4fee\u6539\uff0c\u6240\u4ee5 a[0] = 'H' \u4f1a\u5728\u8fd0\u884c\u65f6\u4ea7\u751f\u9519\u8bef\uff08\u53ef\u4ee5\u901a\u8fc7\u7f16\u8bd1\uff0c\u4f46\u662f\u8fd0\u884c\u4f1a\u62a5\u9519\uff09 \u800c b \u662f\u4e00\u4e2a\u5b57\u7b26\u6570\u7ec4\uff0c\u5b83\u81ea\u5e26\u4e86\u6808\u4e0a\u7a7a\u95f4\uff0c\u5728\u521d\u59cb\u5316\u8d4b\u503c\u7684\u65f6\u5019 \"hello\" \u4f1a\u88ab\u590d\u5236\u5230 b \u7684\u7a7a\u95f4\u4e2d\uff0c\u6240\u4ee5 b[0] = 'H' \u662f\u5408\u6cd5\u7684\u3002
"},{"location":"programming/exam/exam/#_8","title":"\u91ce\u6307\u9488\u76f8\u5173","text":"13 \u9898\u4e2d\u51fa\u73b0\u4e86\u4e00\u4e2a\u91ce\u6307\u9488\uff0c\u5373\u6ca1\u6709\u88ab\u8d4b\u503c\uff0c\u4e0d\u77e5\u9053\u6307\u5411\u4ec0\u4e48\u7684\u6307\u9488\u3002\u8fd9\u6837\u7684\u6307\u9488\u4e0d\u80fd\u8fdb\u884c\u89e3\u5f15\u7528\uff08\u4f1a\u62a5\u9519\uff09\uff0c\u56e0\u4e3a\u5b83\u968f\u673a\u6307\u5411\u7684\u4f4d\u7f6e\u5927\u6982\u7387\u662f\u4f60\u4e0d\u53ef\u7528\u7684\u7a7a\u95f4\u3002
\u8981\u6e05\u695a\u7684\u662f\uff0c\u58f0\u660e\u4e00\u4e2a\u6307\u9488\u53ea\u4f1a\u5206\u914d\u4e00\u4e2a\u7ed9\u6307\u9488\u53d8\u91cf\u7684\u7a7a\u95f4\uff08\u8fd9\u90e8\u5206\u7a7a\u95f4\u7528\u6765\u5b58\u50a8\u5b83\u6307\u5411\u7684\u4f4d\u7f6e\u7684\u5730\u5740\u503c\uff09\uff0c\u800c\u4e0d\u4f1a\u5206\u914d\u6307\u5411\u7684\u7a7a\u95f4\u3002\u4f7f\u4e00\u4e2a\u6307\u9488\u53ef\u7528\u53ef\u4ee5\u5c06\u5176\u5b83\u53d8\u91cf\u53d6\u5730\u5740\u8d4b\u503c\u7ed9\u5b83\uff0c\u8fd9\u6837\u5b83\u6307\u5411\u7684\u4f4d\u7f6e\u5c31\u662f\u6709\u6548\u7684\u3002\u6216\u8005\u901a\u8fc7 malloc \u6765\u65b0\u5206\u914d\u4e00\u5757\u5806\u4e0a\u7684\u5185\u5b58\uff0cmalloc \u7684\u8fd4\u56de\u503c\u5c31\u662f\u8fd9\u5757\u5185\u5b58\u7684\u9996\u5730\u5740\uff0c\u4e5f\u662f\u4f60\u53ef\u7528\u7684\u3002
-
(C13A) In the following code fragments, item _ is correct. A. int *p; scanf(\"%d\", &p); B. int *p; scanf(\"%d\", p); C. int k, *p=&k; scanf(\"%d\", p); D. int k, *p; *p=&k; scanf(\"%d\", p);
A. \u8fd9\u91cc\u5b9e\u9645\u4e0a\u662f\u8bfb\u5165\u4e86\u6570\u636e\u5199\u5230\u4e86 p \u6307\u9488\u7684\u7a7a\u95f4\u4e0a\uff08\u5373\u901a\u8fc7\u8f93\u5165\u6765\u7ed9\u6307\u9488\u8d4b\u503c\uff09\uff0c\u662f\u9519\u8bef\u7684\u64cd\u4f5c\uff1b B. \u8fd9\u91cc\u8bfb\u5165\u6570\u636e\u5199\u5230\u4e86 p \u6307\u5411\u7684\u7a7a\u95f4\u4e2d\uff0c\u800c p \u662f\u4e00\u4e2a\u91ce\u6307\u9488\uff0c\u4e0d\u80fd\u5411\u5b83\u6307\u5411\u7684\u7a7a\u95f4\u5199\u5165\u6570\u636e\uff0c\u662f\u9519\u8bef\u7684\uff1b C. \u8fd9\u91cc\u5c06 k \u7684\u5730\u5740\u8d4b\u503c\u7ed9\u4e86 p\uff0c\u6240\u4ee5\u8bfb\u5165\u4f1a\u5199\u5230 k \u4e2d\uff0c\u662f\u6b63\u786e\u7684\uff0c\u9009 C\uff1b D. \u8fd9\u91cc *p=&k \u4e00\u53e5\u5b9e\u9645\u4e0a\u662f\u5c06 k \u7684\u5730\u5740\u5199\u5165 p \u6307\u5411\u7684\u7a7a\u95f4\u4e2d\uff0c\u540c\u7406\uff0cp \u662f\u91ce\u6307\u9488\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u662f\u9519\u8bef\u7684\u3002
Note
\u8fd9\u91cc\u591a\u8bf4\u4e00\u5634 scanf \u7684\u4f5c\u7528\uff0cscanf \u8981\u8bfb\u53d6\u6570\u636e\u5199\u5230\u5185\u5b58\u4e2d\uff0c\u6240\u4ee5\u53c2\u6570\u4e3a\u6307\u9488\u3002 \u4f8b\u5982 int n; scanf(\"%d\", &n); \"%d\" \u544a\u8bc9 scanf \u6211\u8981\u8bfb\u53d6\u4e00\u4e2a\u6574\u578b \u8bfb\u5230\u54ea\u91cc\u2014\u2014\u2014\u2014\u8bfb\u5230\u53d8\u91cf n \u7684\u5185\u5b58\u7a7a\u95f4\u4e2d n \u5b58\u5728\u54ea\u91cc\u2014\u2014\u2014\u2014n \u7684\u5730\u5740 \u600e\u4e48\u5f97\u5230 n \u7684\u5730\u5740\u2014\u2014\u2014\u2014\u901a\u8fc7 & \u53d6\u5730\u5740
-
\u5047\u8bbe scanf
\u8bed\u53e5\u6267\u884c\u65f6\u8f93\u5165 ABCDE<\u56de\u8f66>
\uff0c\u80fd\u4f7f puts(s)
\u8bed\u53e5\u6b63\u786e\u8f93\u51fa ABCDE
\u7684\u7a0b\u5e8f\u6bb5\u662f _____. A. char s[5] = {\"ABCDE\"}; puts(s); B. char s[5] = {'A', 'B', 'C', 'D', 'E'}; puts(s); C. char *s; scanf(\"%s\", s); puts(s); D. char *s; s=\"ABCDE\"; puts(s);
A. s \u7684\u5927\u5c0f\u53ea\u6709 5 \u4e2a\u5b57\u8282\uff0c\u653e\u4e0d\u4e0b\u6700\u540e\u7684 '\\0'\uff0c\u6240\u4ee5 puts \u53ef\u80fd\u51fa\u9519 B. \u7ed3\u5c3e\u6ca1\u6709 '\\0'\uff0cputs \u53ef\u80fd\u51fa\u9519 C. \u5411\u91ce\u6307\u9488 s \u5199\u5165\u4e86\u6570\u636e\uff0c\u4e00\u5b9a\u51fa\u9519 D. \u5c06\u9759\u6001\u5b58\u50a8\u533a\u4e2d \"ABCDE\" \u7684\u9996\u5730\u5740\u7ed9\u4e86 s\uff0c\u7136\u540e\u8f93\u51fa\uff0c\u5b8c\u5168\u6b63\u786e\uff0c\u9009 D
"},{"location":"programming/exam/exam/#_9","title":"\"\u5947\u602a\"\u7684\u8868\u8fbe\u5f0f/\u8bed\u53e5","text":"\u4e00\u4e9b\u5b8c\u5168\u8bed\u6cd5\u6b63\u786e\uff0c\u4f46\u662f\u53ef\u80fd\u4f1a\u6df7\u6dc6\u89c6\u542c\u8ba9\u4f60\u7406\u89e3\u9519\u8bef\u7684\u8868\u8fbe\u5f0f/\u8bed\u53e5\u3002
-
(C13A) Given: char c='@'
;, the value of expression 'A' <= c <= 'Z'
is _____.
\u4e00\u4e2a\u7ecf\u5178\u95ee\u9898\uff0c'A' <= c <= 'Z' \u5e76\u4e0d\u662f\u5224\u65ad c \u5728\u4e0d\u5728 A-Z \u8303\u56f4\u5185\uff0c\u800c\u662f\u7b49\u4ef7\u4e8e ('A' <= c) <= 'Z'\u3002\u5176\u4e2d 'A' <= c \u4e00\u5b9a\u662f 0 \u6216 1\uff0c\u65e0\u8bba\u5982\u4f55\u90fd\u5c0f\u4e8e 'Z'\uff0c\u6240\u4ee5\u7ed3\u679c\u4e3a 1\u3002
-
(C13A) After executing the code below, the value of y is _____.
int x = 0, y = 0, z = 0;\nz = (x==1) && (y=2);\n
\u8fd9\u91cc\u6d89\u53ca\u5230\u4e86 || \u548c && \u7684\u201c\u77ed\u8def\u201d\u6027\u8d28\uff1a\u5f53 && \u5de6\u8fb9\u4e3a\u5047\u65f6\uff0c\u6574\u4f53\u4ee5\u5b9a\u4f4d\u5047\uff0c\u5219\u53f3\u8fb9\u4e0d\u518d\u8ba1\u7b97\uff1b\u5f53 || \u5de6\u8fb9\u4e3a\u771f\u65f6\uff0c\u6574\u4f53\u4e00\u5b9a\u4e3a\u771f\uff0c\u5219\u53f3\u8fb9\u4e0d\u518d\u8ba1\u7b97\u3002
\u8fd9\u91cc x==1 \u5df2\u7ecf\u4e3a\u5047\uff0c\u6240\u4ee5\u53f3\u4fa7\u7684 y=2 \u4e0d\u518d\u6267\u884c\uff0cy \u4ecd\u7136\u4e3a 0\u3002
-
(C17A) After executing the following code fragment, the output is _____.
int i, b; i = b = 1;\nswitch (i) {\n case 0: b += 1;\n case 1: b += 2;\n case 3: switch (b) {\n case 3: i++;\n default: break;\n }\n i += 1;\n}\nprintf(\"%d#%d#\", i, b);\n
case \u53ea\u89c4\u5b9a\u4e86\u8d77\u70b9\uff0c\u800c\u4f55\u65f6\u9000\u51fa switch \u5757\u5219\u7531 break \u51b3\u5b9a\uff0c\u53ea\u8981\u6ca1\u6709\u9047\u5230 break\uff0c\u5219\u4e00\u76f4\u5411\u4e0b\u6267\u884c\uff08\u5373\u4f7f\u78b0\u5230\u4e86\u4e0b\u4e00\u4e2a case\uff09
\u8fd9\u9898\u91cc i \u4e3a 1\uff0c\u8fdb\u5165\u4e86 case 1 \u4e2d\uff0cb \u53d8\u4e3a\u4e86 3\uff0c\u7d27\u63a5\u7740\u56e0\u4e3a\u6ca1\u6709 break \u8fd8\u4f1a\u8fdb\u5165\u5230 case 3 \u4e2d\uff0c\u6b64\u65f6 b \u4e3a 3 \u8fdb\u5165\u4e86 case 3 \u6267\u884c\u4e86 i++\uff0c\u7136\u540e\u8fdb\u5165 default \u6267\u884c\u4e86 break\uff0c\u9000\u51fa\u540e\u53c8\u6267\u884c\u4e86 i+=1\uff0c\u6240\u4ee5\u6700\u7ec8 i \u548c b \u90fd\u4e3a 3\u3002
-
\u4e0b\u5217\u4ee3\u7801\u6267\u884c\u540e m \u548c n \u7684\u503c\u5206\u522b\u4e3a _____.
int a=1, b=2, c=3, d=4, m=1, n=2, v;\nv = (m=a>b) && (n=c>d);\n
\u540c 35 \u9898\uff0c(m=a>b) \u5df2\u7ecf\u4e3a\u5047\uff08\u5c06 a>b \u5373 0 \u8d4b\u503c\u7ed9 m\uff0c\u7136\u540e\u5224\u65ad m \u662f\u5426\u4e3a 0\uff0c\u662f 0\uff0c\u90a3\u4e48\u6574\u4f53\u5c31\u662f\u5047\uff09\uff0c\u53f3\u4fa7\u7684 (n=c>d) \u4e0d\u518d\u6267\u884c\uff0c\u6240\u4ee5\u6700\u7ec8 m=0, n=2\u3002
-
\u4ee5\u4e0b\u4ee3\u7801\u8bed\u6cd5\u6b63\u786e\u7684\u662f _____. A. for ( ); B. do { } while ( ); C. while ( ) ; D. for ( ; ; ) ;
while \u540e\u7684\u62ec\u53f7\u4e2d\u5fc5\u987b\u6709\u6761\u4ef6\u8868\u8fbe\u5f0f\uff0c\u6240\u4ee5 BC \u9519\u8bef\uff1bfor \u540e\u9762\u7684\u62ec\u53f7\u4e2d\u5fc5\u987b\u6709\u4e24\u4e2a\u5206\u53f7\u5206\u5272\u7684\u4e09\u4e2a\u8bed\u53e5\uff0c\u6240\u4ee5 A \u9519\u8bef\u3002 D \u662f\u6b63\u786e\u7684\uff0cfor( ; ; ) \u5c31\u8868\u793a\u6b7b\u5faa\u73af\uff0c\u800c\u540e\u9762\u7684 ; \u8868\u793a\u5faa\u73af\u4f53\u4e3a\u7a7a\uff0c\u8bed\u6cd5\u5b8c\u5168\u6b63\u786e\uff0c\u662f\u4e00\u4e2a\u5f7b\u5e95\u7684\u6b7b\u5faa\u73af\u3002
-
\u6709\u5b9a\u4e49 int a = 1;
\uff0c\u5219\u8868\u8fbe\u5f0f (a=4*5,a*2),a+6
\u7684\u503c\u4e3a _____.
\u8fd9\u91cc\u7684\u8003\u70b9\u662f\u300c\u9017\u53f7\u8868\u8fbe\u5f0f\u300d\uff0c\u9017\u53f7\u8868\u8fbe\u5f0f\u5728\u6267\u884c\u65f6\u4ece\u5de6\u5230\u53f3\u4f9d\u6b21\u6267\u884c\u9017\u53f7\u5206\u5272\u7684\u5404\u4e2a\u90e8\u5206\uff0c\u7136\u540e\u8868\u8fbe\u5f0f\u6700\u7ec8\u7684\u503c\u4e3a\u6700\u53f3\u4fa7\u7684\u503c\u3002 \u8fd9\u91cc\u5148\u6267\u884c\u4e86 a=4*5\uff0c\u7136\u540e\u6267\u884c\u4e86 a*2\uff08\u6ca1\u6709\u4efb\u4f55\u6548\u679c\uff09\uff0c\u6700\u7ec8\u7684\u503c\u4e3a a+6 = 20+6 = 26\u3002
-
\u5b9a\u4e49 int a[][3] = {{1, 2, 3}, (4, 5, 6)}
\u662f\u5426\u6b63\u786e _\uff0c\u5982\u679c\u6b63\u786e\uff0c\u90a3\u4e48 a[1][0]
\u7684\u503c\u4e3a ___.
\u8fd9\u91cc\u4e5f\u662f\u4e00\u4e2a\u9017\u53f7\u8868\u8fbe\u5f0f\u7684\u5e94\u7528\uff0c\u4e0d\u8fc7 (4, 5, 6) \u51fa\u73b0\u5728\u8fd9\u91cc\u5f88\u5bb9\u6613\u6df7\u6dc6\u8ba9\u4eba\u4ee5\u4e3a\u662f\u4e00\u4e2a\u6570\u7ec4\u3002\u5176\u5b9e\u8fd9\u9053\u9898\u7684\u5b9a\u4e49\u76f8\u5f53\u4e8e int a[][3] = {{1, 2, 3}, 6}
\uff0c\u6240\u4ee5 a[1][0] \u503c\u4e3a 6\u3002
"},{"location":"programming/exam/exam/#sizeof","title":"sizeof \u95ee\u9898","text":"sizeof \u662f C \u8bed\u8a00\u4e2d\u7684\u4e00\u4e2a\u8fd0\u7b97\u7b26\uff0c\u800c\u4e0d\u662f\u51fd\u6570\uff0c\u5b83\u7684\u4f5c\u7528\u662f\u67e5\u8be2\u5360\u636e\u7684\u7a7a\u95f4\u5b57\u8282\u6570\u3002\u4f8b\u5982 sizeof(int) \u8ba1\u7b97\u4e00\u4e2a int \u5360\u7684\u5b57\u8282\u6570\uff0c\u4e5f\u5c31\u662f 4\uff1bint a[2]; sizeof(a) \u8ba1\u7b97 a \u8fd9\u4e2a\u6570\u7ec4\u5360\u7684\u5b57\u8282\u6570\uff0c\u4e5f\u5c31\u662f 2 \u4e2a int\uff0c\u5373 2*4=8\u3002
-
(C18A) Given: short s[][5]={301,302,303,304,305,306,307,308,309,0};
, the values of sizeof(s)
and strlen((char *)s)
will be _____ respectively.
\u4e00\u4e2a short \u5360\u4e24\u4e2a\u5b57\u8282\uff0c301 \u7684\u5b58\u50a8\u65b9\u5f0f\u662f\u5b58\u50a8 0x2d 0x01 \u4e24\u4e2a\u5b57\u8282\uff08\u5c0f\u7aef\u5e8f\uff09\uff0c\u6240\u4ee5 s \u6570\u7ec4\u5728\u5185\u5b58\u4e2d\u4e3a\uff1a
2d 01 2e 01 2f 01 30 01 31 01 32 01 33 01 34 01 35 01 00 00 \n
\u4e00\u5171 20 \u4e2a\u5b57\u8282\uff0c\u6240\u4ee5 sizeof(s) = 20\uff0c\u800c strlen((char *)s) = 18\uff08\u7b2c\u4e00\u4e2a 00 \u524d\u7684\u5b57\u8282\u6570\uff09 -
\u4ee5\u4e0b\u4ee3\u7801\u7684\u8f93\u51fa\u4e3a _____.
char c[100] = \"1234\";\nprintf(\"%d#%d#\", sizeof(c), strlen(c));\n
sizeof\u00a9 = 100\uff0cstrlen\u00a9 = 4\uff0c\u4e0d\u591a\u89e3\u91ca
-
\u4ee5\u4e0b\u4ee3\u7801\u7684\u8f93\u51fa\u4e3a _____.
void func(int a[5]) {\n printf(\"%d\", sizeof(a));\n}\nint main() {\n int a[5] = {0};\n printf(\"%d\\n\", sizeof(a));\n func(a);\n}\n
\u8fd9\u91cc\u9996\u5148\u8f93\u51fa\u6570\u7ec4 a \u5360\u7684\u5b57\u8282\u6570\uff0c\u4e5f\u5c31\u662f 4*5=20\u3002\u7136\u540e\u5c06 a \u4f20\u5165 func \u51fd\u6570\u540e\uff0ca \u9000\u5316\u4e3a\u4e86\u6307\u9488\uff08\u5373\u4f7f\u51fd\u6570\u524d\u9762\u91cc\u7c7b\u578b\u8fd8\u662f int[5]\uff09\uff0c\u5728 func \u51fd\u6570\u4e2d\u8ba1\u7b97 sizeof(a) \u7684\u8bdd\u8f93\u51fa\u7684\u5c31\u662f\u6307\u9488\u5360\u7684\u5927\u5c0f\uff0c\u8fd9\u4e2a\u503c\u662f\u4e0d\u4e00\u5b9a\u7684\uff0c\u5728 32 \u4f4d\u67b6\u6784\u4e2d\u662f 4\uff0c\u5728 64 \u4f4d\u67b6\u6784\u4e2d\u662f 8\u3002
"},{"location":"programming/exam/exam/#_10","title":"\u5173\u4e8e\u8f93\u5165\u8f93\u51fa","text":"\u683c\u5f0f\u5316\u8f93\u5165\u8f93\u51fa\uff08printf\uff0cscanf\uff09\u8fd8\u6709\u4e24\u79cd\u53d8\u4f53\uff1asprintf\uff0csscanf \u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\u5b57\u7b26\u4e32\uff08char\uff09\uff0c\u4f1a\u8f93\u51fa\u5230\u5b57\u7b26\u4e32\u4e2d/\u4ece\u5b57\u7b26\u4e32\u4e2d\u8bfb\u53d6\u8f93\u5165\uff1bfprintf\uff0cfscanf \u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\u6587\u4ef6\u6307\u9488\uff08FILE\uff09\uff0c\u4f1a\u8f93\u51fa\u5230\u6587\u4ef6\u4e2d/\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u8f93\u5165\u3002\u800c printf scanf \u5219\u662f\u8f93\u51fa\u5230\u6807\u51c6\u8f93\u51fa/\u4ece\u6807\u51c6\u8f93\u5165\u8bfb\u53d6\u8f93\u5165\u3002stdin stdout \u662f\u4e24\u4e2a\u7279\u6b8a\u7684\u6587\u4ef6\uff0c\u6240\u4ee5 printf scanf \u5206\u522b\u7b49\u4ef7\u4e8e fprintf(stdout, ...) \u548c fscanf(stdin, ...)\u3002
\u5173\u4e8e scanf \u7684\u8fd4\u56de\u503c\uff0c\u5b83\u8fd4\u56de\u6b63\u5e38\u8bfb\u53d6\u7684\u53d8\u91cf\u4e2a\u6570\uff0c\u5982\u679c\u9047\u5230\u4e86\u6587\u4ef6\u7ed3\u5c3e\uff0c\u5219\u8fd4\u56de EOF \u5373 -1\u3002
-
(C16A) For the code below:
int a, b; char c;\nscanf(\"%d%c%d\",&a,&c,&b);\n
If let a=1,b=2,c='+'
, the input _____ is NOT correct. A. 1+2<ENTER> B. <BLANK><ENTER>1+<ENTER>2<ENTER> C. <ENTER>1<ENTER>+<BLANK>2<ENTER> D. <BLANK><BLANK>1+<BLANK><BLANK>2<ENTER> \u9700\u8981\u6ce8\u610f\u7684\u662f %d \u4f1a\u5ffd\u7565\u6570\u5b57\u5de6\u8fb9\u7684\u7a7a\u767d\u5b57\u7b26\uff08\u5305\u62ec\u7a7a\u683c\u3001\u6362\u884c\u7b49\uff09\uff0c\u800c %c \u4f1a\u7acb\u5373\u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26\u3002 A. \u5b8c\u5168\u6b63\u786e\uff0c\u6ca1\u4ec0\u4e48\u597d\u8bf4\u7684 B. 1 \u524d\u9762\u7684\u7a7a\u767d\u548c\u6362\u884c\u5ffd\u7565\u4e86\uff0c%c \u8bfb\u4e86 '+'\uff0c\u63a5\u4e0b\u6765 %d \u5ffd\u7565\u4e86\u6362\u884c\u8bfb\u4e86 2 C. 1 \u524d\u9762\u6362\u884c\u5ffd\u7565\u4e86\uff0c\u63a5\u4e0b\u6765 %c \u7acb\u5373\u8bfb\u5230\u4e86\u4e00\u4e2a '\\n'\uff0c\u7136\u540e\u51fa\u73b0\u4e86 '+' \u5bfc\u81f4\u540e\u9762 %d \u8bfb\u53d6\u5931\u8d25\uff08\u5982\u679c\u8fd9\u65f6\u68c0\u67e5 scanf \u7684\u8fd4\u56de\u503c\uff0c\u5e94\u8be5\u662f 2 \u800c\u4e0d\u662f 3\uff09 D. \u4e0e B \u540c\u7406\u662f\u6b63\u786e\u7684
-
(C18A) The statement printf(\"%%d%d\", 012);
will print out _____.
\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u4e2d\uff0c%% \u8868\u793a\u8f93\u51fa\u4e00\u4e2a %\uff0c\u63a5\u4e0b\u6765 d \u5b57\u7b26\u539f\u6837\u8f93\u51fa\uff0c\u7136\u540e %d \u8f93\u51fa 012\uff08\u516b\u8fdb\u5236\uff0c\u8f6c\u4e3a\u5341\u8fdb\u5236\u4e3a 10\uff09\uff0c\u6240\u4ee5\u8f93\u51fa\u4e3a %d10
-
\u4ee5\u4e0b\u4ee3\u7801\u7684\u8f93\u51fa\u4e3a _____.
int x = -1;\nprintf(\"%d\", (unsigned int)x);\n
unsigned int \u7684\u8f6c\u6362\u5e76\u4e0d\u4f1a\u6539\u53d8 x \u7684\u4e8c\u8fdb\u5236\u503c\uff08\u800c\u662f\u4ee5\u65e0\u7b26\u53f7\u7684\u65b9\u5f0f\u6765\u7406\u89e3\u8fd9\u6bb5\u6570\u636e\uff09\uff0c\u800c\u5bf9\u4e8e printf \u6765\u8bf4\uff0c\u5b83\u8981\u8f93\u51fa\u7684\u662f\u4e00\u4e2a %d\uff0c\u5373\u6709\u7b26\u53f7\u6570\uff08\u65e0\u7b26\u53f7\u7528 %u\uff09\uff0c\u6240\u4ee5\u8f93\u51fa\u65f6\u8fd8\u662f\u4f1a\u5f53\u4f5c\u6709\u7b26\u53f7\u6574\u578b\u6765\u7406\u89e3\uff0c\u5373\u8f93\u51fa -1\u3002
-
\u4ee5\u4e0b\u4ee3\u7801\u7684\u8f93\u51fa\u4e3a _____.
char str[100] = \"ZhejiangU 1 3 5\", s[10];\nint n;\nsscanf(str, \"%s %*d %d %*d\", s, &n);\nprintf(\"%s\", &s[n]);\n
%*d \u8868\u793a\u8bfb\u53d6\u4e00\u4e2a\u6574\u578b\uff0c\u4f46\u662f\u76f4\u63a5\u5ffd\u7565\uff0c\u4e0d\u5b58\u5230\u53d8\u91cf\u4e2d\u3002 \u6240\u4ee5 sscanf \u8bfb\u53d6\u5230\u7684 n \u662f\u7b2c\u4e8c\u4e2a\u6570\u5b57\u4e5f\u5c31\u662f 3\uff0c\u7136\u540e\u8f93\u51fa s[3] \u5f00\u59cb\u7684\u5b57\u7b26\u4e32\uff0c\u5373 jiangU\u3002
"},{"location":"programming/exam/exam/#_11","title":"\u4e00\u4e9b\u602a\u9898","text":"\u4e00\u4e9b\u6ca1\u4ec0\u4e48\u610f\u4e49\u7684\u602a\u9898\uff0c\u4e0d\u8981\u6df1\u7a76\uff0c\u9009\u62e9\u4e00\u4e2a\u6700\u6b63\u786e\u3001\u6ca1\u6709\u4e89\u8bae\u7684\u5c31\u53ef\u4ee5\u4e86\u3002
-
(C15A) In the following expressions, _____ is meanless(\u65e0\u610f\u4e49) A. \"hello,world\"-\"hello\" B. 'w'-'h' C. \"hello\"+10/4 D. 'a'+3/2
A \u5b57\u7b26\u4e32\u5e38\u91cf\u76f8\u51cf\u76f8\u5f53\u4e8e\u4e24\u4e2a\u5b57\u7b26\u4e32\u9996\u5730\u5740\u76f8\u51cf\uff0c\u6ca1\u6709\u610f\u4e49 BCD \u90fd\u80fd\u8bf4\u51fa\u70b9\u610f\u4e49\u6765\uff0c\u6240\u4ee5\u6700\u4f18\u9009 A\u3002
-
(C18A) Which of the following expressions is meaningful(\u6709\u610f\u4e49\u7684)? _____ A. \"hello\"*2 B. 'w'*'h' C. \"hello\"[1] D. \"hello\"-'h'
\u540c\u6837\uff0cA \u5b57\u7b26\u4e32\u9996\u5730\u5740\u4e58\u4ee5 2 \u6ca1\u6709\u610f\u4e49\uff0cB \u4e24\u4e2a\u5b57\u7b26\u4e32 ASCII \u7801\u76f8\u4e58\u4e5f\u6ca1\u5565\u5927\u610f\u4e49\u3002D \u5b57\u7b26\u4e32\u9996\u5730\u5740\u51cf 'h' \u4e5f\u5c31\u662f 104\uff0c\u4e5f\u6ca1\u5565\u610f\u4e49\u3002 C \"hello\"[1] \u8868\u793a *(\"hello\"+1) \u5373 'e'\uff0c\u8fd8\u7b97\u6709\u70b9\u610f\u4e49\uff0c\u6700\u4f18\u9009 C
-
(C17A) Which of the following is correct\uff1f _____.
int main() {\n int n[10];\n ...\n fun(n);\n ...\n}\nint fun(int a[]) {\n ...\n}\n
A. Within the function fun, a is an initial address of an array, whose value cannot be changed. B. Within the function main, the reference such as &n is invalid. C. Because of call-by-value, the elements of the array n cannot be changed within the fun. D. Within the function fun, the reference such as &a is invalid. AC \u80af\u5b9a\u662f\u9519\u7684\uff0cA. fun \u51fd\u6570\u91cc a \u662f\u4e00\u4e2a\u5c40\u90e8\u6307\u9488\u53d8\u91cf\uff08\u6570\u7ec4\u9000\u5316\u4e86\uff09\uff0c\u5b83\u7684\u503c\u53ef\u4ee5\u6539\u53d8\uff1bC. main \u51fd\u6570\u628a n \u7684\u5730\u5740\u4f20\u7ed9\u4e86 fun \u51fd\u6570\u4f5c\u4e3a a \u7684\u503c\uff0c\u6240\u4ee5\u53ef\u4ee5\u901a\u8fc7 a \u6307\u9488\u6765\u8bbf\u95ee n \u6570\u7ec4\u5904\u7684\u5185\u5b58\uff0c\u53ef\u4ee5\u6539\u53d8 n \u6570\u7ec4\u7684\u5143\u7d20\u3002
BD \u5c31\u6bd4\u8f83\u602a\u4e86\uff0c\u6211\u7684\u7406\u89e3\u65b9\u5f0f\u662f \"Within the function\" \u4ee3\u8868\u4e86\u51fd\u6570\u7ea7\u4f5c\u7528\u57df\uff0c\u800c main \u51fd\u6570\u91cc n \u7684\u4f5c\u7528\u57df\u4e0d\u662f\u201c\u51fd\u6570\u7ea7\u201d\u7684\uff0c\u800c\u662f\u5728 int n[10]; \u4e00\u53e5\u4ee5\u4e0b\uff0cmain \u51fd\u6570\u5927\u62ec\u53f7\u4e4b\u4e0a\u3002\u800c fun \u4e2d a \u5728\u6574\u4e2a\u51fd\u6570\u5185\u90fd\u53ef\u4ee5\u4f7f\u7528\u3002\u8fd9\u662f\u4e8c\u8005\u7684\u6700\u5927\u533a\u522b\uff0c\u786c\u8981\u9009\u4e00\u4e2a\u80af\u5b9a\u9009 B\u3002
"},{"location":"programming/exam/exam/#_12","title":"\u7a0b\u5e8f\u8bbe\u8ba1\u4e13\u9898\u5386\u5e74\u5377\u7ecf\u5178\u9898\u76ee\u89e3\u6790","text":"\u56fe\u5f62\u5e93\u76f8\u5173\u5185\u5bb9\u5df2\u4e0d\u518d\u51fa\u73b0\u5728\u8bfe\u7a0b\u4e2d
\u76ee\u524d\uff0c\u8bfe\u6539\u5df2\u7ecf\u5220\u53bb\u4e86\u56fe\u5f62\u5e93\u76f8\u5173\u5185\u5bb9\uff0c\u8fd9\u90e8\u5206\u5185\u5bb9\u4e0d\u4f1a\u518d\u51fa\u73b0\u5728\u6559\u5b66\u548c\u8003\u8bd5\u4e2d\uff0c\u6211\u4eec\u4e5f\u4f1a\u9010\u6b65\u5c06\u5176\u79fb\u9664\u3002
"},{"location":"programming/exam/exam/#_13","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)
"},{"location":"programming/exam/exam/#_14","title":"\u540e\u7f00\u8868\u8fbe\u5f0f","text":"\u8fd9\u4e1c\u897f\u524d\u4e24\u4e09\u5e74\u90fd\u8003\u4e86\uff0c\u9700\u8981\u4e86\u89e3\u4e00\u4e0b\u3002\u5173\u4e8e\u8868\u8fbe\u5f0f\u6811\u7684\u76f8\u5173\u5185\u5bb9\u8bf7\u53c2\u89c1\uff1a
- \u8868\u8fbe\u5f0f\u6c42\u503c - OI Wiki (oi-wiki.org)
- \u6811\u57fa\u7840 - OI Wiki (oi-wiki.org)
\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
- \u4e2d\u7f00\u8868\u8fbe\u5f0f\uff1a\u5bf9\u8fd9\u68f5\u6811\u8fdb\u884c\u4e2d\u5e8f\u904d\u5386\uff0c\u5373\u5de6\u3001\u6839\u3001\u53f3
- a+b*(c-d)-(e/f)
- \u524d\u7f00\u8868\u8fbe\u5f0f\uff1a\u5bf9\u8fd9\u68f5\u6811\u8fdb\u884c\u5148\u5e8f\u904d\u5386\uff0c\u5373\u6839\u3001\u5de6\u3001\u53f3
- -+a*b-cd/ef
- \u540e\u7f00\u8868\u8fbe\u5f0f\uff1a\u5bf9\u8fd9\u68f5\u6811\u8fdb\u884c\u540e\u5e8f\u904d\u5386\uff0c\u5373\u5de6\u3001\u53f3\u3001\u6839\u3002\u6ce8\u610f\u5230\u5de6\u53f3\u5b50\u8282\u70b9\u90fd\u6bd4\u6839\u5148\u904d\u5386\uff0c\u6240\u4ee5\u53ef\u4ee5\u4e00\u8def\u5f80\u4e0b\u627e\u5230\u6700\u6df1\u7684\u5b50\u8282\u70b9\uff0c\u7136\u540e\u5411\u4e0a\u89e3\u6790\u3002
- abcd-*+ef/-
\u503c\u5f97\u4e00\u63d0\u7684\u662f\u540e\u7f00\u8868\u8fbe\u5f0f\u5177\u6709\u51e0\u4e2a\u65b9\u4fbf\u7684\u6027\u8d28\uff1a
- \u8ba1\u7b97\u540e\u7f00\u8868\u8fbe\u5f0f\uff0c\u53ea\u9700\u8981\u7ef4\u62a4\u4e00\u4e2a\u6570\u5b57\u6808\uff0c\u6bcf\u6b21\u9047\u5230\u4e00\u4e2a\u8fd0\u7b97\u7b26\uff0c\u5c31\u53d6\u51fa\u4e24\u4e2a\u6808\u9876\u5143\u7d20\uff0c\u5c06\u8fd0\u7b97\u7ed3\u679c\u91cd\u65b0\u538b\u5165\u6808\u4e2d\u3002
- \u540e\u7f00\u8868\u8fbe\u5f0f\u4e0e\u8868\u8fbe\u5f0f\u6811\u4e00\u4e00\u5bf9\u5e94\u3002\u540e\u7f00\u8868\u8fbe\u5f0f\u4e0d\u9700\u8981\u62ec\u53f7\u8868\u793a\uff0c\u5b83\u7684\u8fd0\u7b97\u987a\u5e8f\u662f\u552f\u4e00\u786e\u5b9a\u7684\u3002
"},{"location":"programming/exam/exam/#2020-2021","title":"2020-2021 \u5e74\u5377","text":" - \u9009\u62e9\u9898 1
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
- A\uff1a
char *
- B\uff1a\u8be5\u8868\u8fbe\u5f0f\u5b9e\u9645\u4e3a
&(t->name[0])
\uff0c\u5373 char *
\u7c7b\u578b\u3002 - C\uff1a
char *
- D\uff1a
*(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
- \u9009\u62e9\u9898 3 \u6307\u9488\u7c7b\u578b
\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
- A\uff1a
p
\u662f\u51fd\u6570\u540d - B\uff1a
p
\u662f\u51fd\u6570\u540d - C\uff1a
p
\u662f\u6307\u5411 int[5]
\u7684\u6307\u9488 - D\uff1a
p
\u662f\u4e00\u4e2a\u6570\u7ec4
- \u9009\u62e9\u9898 4 \u5b58\u50a8\u7c7b\u522b\u9650\u5b9a\u7b26
C \u8bed\u8a00\u4e2d\u4e00\u5171\u6709 5 \u4e2a\u5b58\u50a8\u7c7b\u522b\u9650\u5b9a\u7b26\uff0c\u8bf7\u56de\u5fc6\u5b83\u4eec\u7684\u4f5c\u7528\uff1a
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\u3002 register
\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\u3002 extern
\uff1a\u7528\u4e8e\u5168\u5c40\u53d8\u91cf\uff0c\u8868\u793a\u53d8\u91cf\u5728\u5176\u4ed6\u6587\u4ef6\u4e2d\u5b9a\u4e49\u3002 -
static
\uff1a
- \u7528\u4e8e\u5c40\u90e8\u53d8\u91cf\uff0c\u8868\u793a\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u4e0e\u7a0b\u5e8f\u8fd0\u884c\u76f8\u540c\u3002
- \u7528\u4e8e\u5168\u5c40\u53d8\u91cf\uff0c\u8868\u793a\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u4ec5\u9650\u4e8e\u5f53\u524d\u6587\u4ef6\u3002
-
_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
- \u9009\u62e9\u9898 5 \u51fd\u6570\u6307\u9488
\u89c1 2019 \u5e74\u9009\u62e9\u9898 6
- \u9009\u62e9\u9898 8 \u6570\u636e\u7ed3\u6784\u7684\u4f7f\u7528
\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
- \u7b80\u7b54\u9898 1.1 \u540e\u7f00\u8868\u8fbe\u5f0f
\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
- \u7b80\u7b54\u9898 5 \u6392\u5e8f\u7b97\u6cd5\u6700\u4f18\u60c5\u51b5
\u89c1\u5e38\u89c1\u95ee\u9898-\u7b97\u6cd5\u590d\u6742\u5ea6
\u5f15\u7528\u4e00\u4e0b ztgg \u7684\u89e3\u91ca\uff1a
- \u5e73\u5747\u60c5\u51b5\u4e0b\uff0c\u63d2\u5165\u5143\u7d20\u5bfc\u81f4\u7684\u79fb\u52a8\u4f9d\u65e7\u662f \\(O(n)\\) \u7684\uff0c\u5e76\u6ca1\u6709\u4f18\u5316\uff0c\u6240\u4ee5\u603b\u590d\u6742\u5ea6\u8fd8\u662f \\(O(n^2)\\)\u3002\uff08\u6279\u6ce8\uff1a\u4ea4\u6362\u7684\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\)\uff0c\u6bd4\u8f83\u7684\u590d\u6742\u5ea6\u4e3a \\(O(n\\log n)\\)\uff0c\u524d\u8005\u8f83\u5927\uff0c\u5360\u636e\u4e3b\u5bfc\u5730\u4f4d\uff09\u3002
- \u6700\u4f73\u60c5\u51b5\u5e94\u8be5\u662f\u63d2\u5165\u5143\u7d20\u65f6\uff0c\u4e0d\u9700\u8981\u79fb\u52a8\u539f\u6765\u7684\u5143\u7d20\uff0c\u4e5f\u5c31\u662f\u6570\u7ec4\u5df2\u7ecf\u6392\u597d\u5e8f\u4e86\u3002\u8fd9\u4e2a\u60c5\u51b5\u4e0b\uff0c\u6bcf\u6b21\u63d2\u5165\u53ea\u6709\u4e8c\u5206\u67e5\u627e\u7684\u4ee3\u4ef7\uff0c\u5373\u4e3a \\(O(n\\log n)\\)\u3002
- \u7b80\u7b54\u9898 6 \u961f\u5217\u64cd\u4f5c
\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
- \u7a0b\u5e8f\u586b\u7a7a 3
\u8fd9\u51e0\u4e2a\u7a7a\u90fd\u9700\u8981\u82b1\u4e00\u4f1a\u513f\u65f6\u95f4\u6765\u63a8\u65ad\u7684\uff1a
InitGraphics()
\u4e00\u5b9a\u8981\u8bb0\u5f97 - \u8bb0\u4f4f\u51e0\u79cd\u56de\u8c03\u51fd\u6570\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c
void registerTimerEvent(TimerEventCallback callback)
\u4e0e void startTimer(int id,int timeinterval)
\u914d\u5bf9\u4f7f\u7528\uff0c\u5b83\u4eec\u5404\u81ea\u7684\u53c2\u6570\u610f\u4e49\u3002 - \u8ba1\u65f6\u5668\u56de\u8c03\u51fd\u6570\u600e\u4e48\u5199\uff1f\u53c2\u6570
timerID
\u662f\u7528\u6765\u505a\u4ec0\u4e48\u7684\uff1f - \u7b2c 14 \u7a7a\u53ef\u80fd\u4e0d\u5bb9\u6613\u60f3\u5230\uff0c\u53cd\u6b63\u8bb0\u4f4f\u5728\u6bcf\u6b21\u753b\u70b9\u4ec0\u4e48\u4e1c\u897f\u4e4b\u524d\uff0c\u90fd\u8981\u68c0\u67e5\u753b\u7b14\u4f4d\u7f6e\u662f\u5426\u6b63\u786e\uff0c\u8fd9\u5728\u7ed8\u5236\u5206\u5f62\u56fe\u5f62\u65f6\u4e5f\u5f88\u91cd\u8981\u3002
- \u7b97\u6cd5\u8bbe\u8ba1 1 \u94fe\u8868\u5faa\u73af\u68c0\u6d4b
\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
- \u7b97\u6cd5\u8bbe\u8ba1 2 \u6709\u5e8f\u6570\u7ec4\u539f\u5730\u53bb\u91cd
\u770b\u5230\u8fd9\u9053\u9898\u4f60\u6709\u6ca1\u6709\u60f3\u8d77\u5b57\u7b26\u4e32\u53bb\u7a7a\u683c\u7684\u4e00\u4e2a\u4f8b\u7a0b\uff1f
char *a;\nfor(int i = 0, j = 0; i < length; i++){\n if(a[i] != ' ')\n a[j++] = a[i];\n}\n
\u6709\u5e8f\u6570\u7ec4\u53bb\u91cd\u4e0e\u8fd9\u4e2a\u7b97\u6cd5\u4e5f\u6709\u4e9b\u7c7b\u4f3c\uff0c\u53ea\u662f\u6bd4\u8f83\u6761\u4ef6\u6362\u6210 a[i]!=a[j]
\u4e86\u800c\u5df2\u3002
"},{"location":"programming/exam/exam/#2019-2020","title":"2019-2020 \u5e74\u5377","text":" - \u9009\u62e9\u9898 1 \u9012\u5f52\u51fd\u6570
- D \u9879 \u8c03\u7528\u6808\u4f4d\u4e8e\u5806\u6808\u6bb5\uff08Stack Segment\uff09\uff0c\u5728\u8fd0\u884c\u65f6\u521b\u5efa\uff0c\u4e5f\u6709\u81ea\u5df1\u7684\u5927\u5c0f\uff0c\u4e0d\u80fd\u8d8a\u754c\u8bbf\u95ee\u3002\u8d8a\u754c\u9020\u6210\u6bb5\u9519\u8bef\uff08Segmentation Fault\uff09\u3002\u6bcf\u6b21\u9012\u5f52\u8c03\u7528\u6dfb\u52a0\u6808\u5e27\uff0c\u9020\u6210\u7684\u8d8a\u754c\u79f0\u4e3a\u6808\u6ea2\u51fa\uff08Stack Overflow\uff09\u3002\u5806\u6808\u6bb5\u4e2d\u4fdd\u5b58\u7740\u51fd\u6570\u8c03\u7528\u5173\u7cfb\u548c\u5c40\u90e8\u53d8\u91cf\u3002\u5c40\u90e8\u53d8\u91cf\u8fc7\u5927\u4e5f\u53ef\u80fd\u9020\u6210\u6808\u6ea2\u51fa\u3002
- \u9009\u62e9\u9898 2 \u65f6\u95f4\u590d\u6742\u5ea6\u5206\u6790
- \u9009\u62e9\u9898 6 \u51fd\u6570\u6307\u9488
\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. [...]
- \u51fd\u6570\u6307\u9488\uff1a\u6307\u5411\u51fd\u6570\u7684\u6307\u9488\u4e2d\u50a8\u5b58\u7740\u51fd\u6570\u4ee3\u7801\u7684\u8d77\u59cb\u5904\u5730\u5740\uff0c\u8981\u6307\u660e\u51fd\u6570\u7684\u7c7b\u578b\uff0c\u8981\u6307\u660e\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u548c\u5f62\u53c2\u7c7b\u578b\u3002\u628a\u51fd\u6570\u540d\u66ff\u6362\u6210
(*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
- \u7b2c\u4e00\u79cd\u5f62\u5f0f\uff0c\u5148\u89e3\u5f15\u7528\u51fd\u6570\u6307\u9488\u518d\u8c03\u7528\u8be5\u51fd\u6570\uff0c\u8fd9\u4e2a\u601d\u8def\u5f88\u76f4\u63a5\u3002
- \u7b2c\u4e8c\u79cd\u5f62\u5f0f\uff0c\u6765\u6e90\u662f\u4e0a\u9762\u7684\u8d4b\u503c\u8bed\u53e5\uff0c\u5728\u4e0a\u9762\u7684\u8d4b\u503c\u8bed\u5883\u4e0b\uff0c\u6307\u9488\u548c\u51fd\u6570\u540d\u53ef\u4ee5\u4e92\u6362\u4f7f\u7528\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.
- \u9009\u62e9\u9898 7 \u51fd\u6570\u6307\u9488
\u540c\u6837\u4f9d\u636e\u4e0a\u9762\u7684\u8bb2\u89e3\u80fd\u591f\u9009\u51fa\u6b63\u786e\u7b54\u6848
- \u9009\u62e9\u9898 8 \u51fd\u6570\u53c2\u6570
\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
- \u9009\u62e9\u9898 9 \u56fe\u5f62\u5e93
\u8bf7 WK \u73ed\u540c\u5b66\u4e00\u5b9a\u8981\u53bb\u770b\u8f85\u5b66\u7fa4\u91cc\u5176\u4ed6\u8001\u5e08\u7684\u56fe\u5f62\u5e93\u8bfe\u4ef6
- \u9009\u62e9\u9898 10 \u8fd8\u662f\u51fd\u6570\u6307\u9488
- \u7b2c\u4e00\u884c\uff1a
F
\u5b9a\u4e49\u4e3a int (int)
\u7c7b\u578b\u7684\u51fd\u6570\u3002 - \u7b2c\u4e8c\u884c\uff1a\u58f0\u660e\u4e24\u4e2a\u7c7b\u578b\u4e3a
F
\u7684\u51fd\u6570 g
\u548c h
\u3002\u5176\u5b9e\u5c31\u662f int g(int a)
\u548c int h(int a)
\u3002 - \u7b2c\u4e09\u884c\uff1a\u58f0\u660e\u4e00\u4e2a\u6570\u7ec4
p
\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\u3002 - \u8ba9\u6211\u4eec\u4ece\u5185\u5f80\u5916\u8bfb\u8fd9\u4e2a\u58f0\u660e\uff1a
p
\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\u3002 - \u7528
g
\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
- C \u9879\uff1a\u663e\u7136\u7c7b\u578b\u5339\u914d\u3002
- D \u9879\uff1a\u5bf9\u51fd\u6570\u53d6\u5730\u5740\uff0c\u5f97\u5230
int (*)(int)
\uff0c\u4e0e int (**)(int)
\u7c7b\u578b\u4e0d\u5339\u914d\u3002
- \u7b80\u7b54\u9898 1
\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
- \u7b80\u7b54\u9898 3
\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
- \u7b80\u7b54\u9898 4
\u8ba9\u6211\u4eec\u770b main()
\u51fd\u6570\u7684\u7b2c\u4e00\u884c\u7684\u8868\u8fbe\u5f0f\uff1a
- \u5916\u5c42\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\u3002 - \u5185\u5c42\uff1a
h(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\u3002 - \u5185\u5c42\u8c03\u7528\u540e\uff0c\u5916\u5c42\u5c31\u76f8\u5f53\u4e8e
h(100)
\u4e86\uff0c\u56e0\u4e3a h
\u672c\u6765\u5c31\u662f H
\u7c7b\u578b\u7684\u51fd\u6570\u3002
- \u7a0b\u5e8f\u586b\u7a7a 3
geblib.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*)
- \u5b8f\u5c55\u5f00\u4e3a
((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\u3002 - \u8fd9\u4e2a\u8c03\u7528\u5c31\u8fd4\u56de\u4e86\u4e00\u4e2a
char*
\u7684\u6307\u9488\u3002
-
FreeBlock()
\u51fd\u6570\uff1a
- \u539f\u578b\uff1a
void FreeBlock(void *ptr)
- \u4e0e
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
- \u7b97\u6cd5\u8bbe\u8ba1 1 \u5206\u5f62
\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
- \u57fa\u51c6\u60c5\u5f62\uff1a\u957f\u5ea6\u7f29\u5c0f\u5230\u67d0\u503c\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
- \u7b97\u6cd5\u8bbe\u8ba1 2 \u5217\u8868\u53d8\u5e8f
\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/exam/exam/#2018-2019","title":"2018-2019 \u5e74\u5377","text":" - \u9009\u62e9\u9898 4 \u9012\u5f52\u8ba1\u7b97
\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
- \u9009\u62e9\u9898 6 \u7b97\u6cd5\u590d\u6742\u5ea6\u5206\u6790
\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
- \u9009\u62e9\u9898 9 \u9012\u589e\u8fd0\u7b97\u7b26
\u524d\u7f00\u9012\u589e\u8fd0\u7b97\u7b26\u5148\u9012\u589e\u518d\u4f7f\u7528\u3002
- \u7b80\u7b54\u9898 1.2
\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
- \u7b80\u7b54\u9898 2 \u6570\u636e\u4e0e\u5b57\u8282
\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
- \u7b80\u7b54\u9898 3 \u94fe\u8868\u64cd\u4f5c
\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
- \u7b80\u7b54\u9898 4 \u94fe\u8868\u64cd\u4f5c
\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
- \u7b80\u7b54\u9898 5 \u53cc\u5411\u6808
\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
- \u5148\u770b
main()
\u4e2d\u7684 Push()
\uff0c\u8fd9\u600e\u4e48\u6bd4\u5e73\u5e38\u7684 Push()
\u591a\u4e00\u4e2a\u53c2\u6570\u5462\uff1f - \u518d\u770b\u7c7b\u578b\u5b9a\u4e49\uff0c\u600e\u4e48\u6709\u4e24\u4e2a
Top
\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\u3002 Push()
\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
- \u7b80\u7b54\u9898 6 \u4e0d\u77e5\u9053\u662f\u4ec0\u4e48
\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
- \u7a0b\u5e8f\u586b\u7a7a 2 \u5faa\u73af\u961f\u5217\u5b9e\u73b0
\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
- \u7a0b\u5e8f\u586b\u7a7a 3 \u56fe\u5f62\u5e93
\u53c2\u89c1\u5e38\u89c1\u95ee\u9898-\u56fe\u5f62\u5e93-\u8ba1\u65f6\u5668
- \u7b97\u6cd5\u8bbe\u8ba1 1 \u5bfb\u627e\u7b2c\u4e00\u4e2a\u516c\u5171\u8282\u70b9
\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
- \u7b97\u6cd5\u8bbe\u8ba1 2 \u4e8c\u5206\u63d2\u5165\u6392\u5e8f
\u8fd9\u9898\u7b80\u5355\uff0c\u4e0d\u4f5c\u89e3\u6790\u3002\u53c2\u7b54\u4e2d\u6f0f\u4e86\u68c0\u67e5 minPos == rh
\u7684\u60c5\u51b5\uff0c\u60f3\u60f3\u8fd9\u6837\u4f1a\u9020\u6210\u4ec0\u4e48\u540e\u679c\uff1f
"},{"location":"programming/exam/exam/#2017-2018","title":"2017-2018 \u5e74\u5377","text":" - \u9009\u62e9\u9898 1 \u6570\u636e\u7c7b\u578b\u4e0e\u6307\u9488\u64cd\u4f5c
- C \u9879\uff1a
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 - D \u9879\uff1a\u6bcf\u6b21
*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
- \u9009\u62e9\u9898 7 \u5192\u6ce1\u6392\u5e8f
\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
- \u5982\u679c\u5728\u4e0a\u4e00\u8f6e\u7684 Bubble \u4e2d\uff0c\u6ca1\u6709\u53d1\u751f\u4efb\u4f55\u4ea4\u6362\uff0c\u5219\u8bf4\u660e\u8fd9\u4e2a\u5e8f\u5217\u4e5f\u662f\u6709\u5e8f\u7684\uff0c\u4e0d\u518d\u9700\u8981\u540e\u7eed\u64cd\u4f5c\u4e86\u3002
\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
- \u9009\u62e9\u9898 9 \u5b58\u50a8\u7c7b\u522b\u9650\u5b9a\u7b26
- D \u9879\uff1a
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
- \u7b80\u7b54\u9898 1.(2) \u5199\u51fd\u6570\u58f0\u660e
\u5148\u60f3\u60f3\u81ea\u5df1\u4f1a\u600e\u4e48\u8c03\u7528\u8fd9\u4e2a fun
\u51fd\u6570\u624d\u80fd\u5f97\u5230 void
\u7c7b\u578b\uff1a
- \u7b2c\u4e00\u6b65\uff0c\u8c03\u7528\u51fd\u6570\u83b7\u53d6\u8fd4\u56de\u503c\uff1a
fun(int)
\u3002 - \u7b2c\u4e8c\u6b65\uff0c\u89e3\u5f15\u7528\u8fd4\u56de\u503c\uff0c\u83b7\u5f97\u51fd\u6570\uff0c\u8c03\u7528\u8be5\u51fd\u6570\uff1a
(*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
- \u7b80\u7b54\u9898 5 \u6700\u5927\u5b50\u5217\u548c
\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
- \u7b80\u7b54\u9898 6 \u4f8f\u5112\u6392\u5e8f
\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
- \u7a0b\u5e8f\u586b\u7a7a 2 \u591a\u9879\u5f0f\u8ba1\u7b97
\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
- \\((((3x)x^2)+2x)x + 1\\)
\u8fd9\u6837\u505a\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u51cf\u5c11\u4e86\u8ba1\u7b97\u4e58\u79ef\u7684\u6b21\u6570\u3002
\u540c\u6837\u6ce8\u610f ->
\u8fd0\u7b97\u7b26\u7684\u4f7f\u7528\u3002
"},{"location":"programming/exam/exam/#2016-2017","title":"2016-2017 \u5e74\u5377","text":" - \u9009\u62e9\u9898 1 \u5012\u5e8f\u6808
\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\u7b54\u9898 1.(2) \u5199\u51fd\u6570\u6307\u9488
\u7b80\u5355\u51fd\u6570\u6307\u9488\uff0c\u76f4\u63a5\u8fd9\u6837\u8bb0\uff1atypedef \u8fd4\u56de\u7c7b\u578b (*\u65b0\u540d\u5b57)(\u53c2\u6570\u5217\u8868)
- \u7b80\u7b54\u9898 3 \u5947\u5076\u6392\u5e8f
\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
- \u7b80\u7b54\u9898 4 \u94fe\u8868\u64cd\u4f5c
\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
- \u7b80\u7b54\u9898 5 \u56e0\u6570\u5206\u89e3
\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
- \u7a0b\u5e8f\u586b\u7a7a 1 \u8ba1\u6570\u6392\u5e8f
\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\u3002 output_array[count[input_array[i]]] = input_array[i]
\u6211\u4eec\u6765\u62c6\u89e3\u4e00\u4e0b\uff1a intput_array[i]
\u5c31\u662f\u7b2c i
\u4e2a\u5143\u7d20 - \u628a\u5b83\u653e\u5230
count[]
\u5c31\u80fd\u67e5\u5230\u8fd9\u4e2a\u6570\u5e94\u8be5\u653e\u7f6e\u7684\u8d77\u59cb\u4f4d\u7f6e\u3002 - \u6240\u4ee5\u7b2c 4 \u7a7a\u5f53\u7136\u8981\u9012\u589e\u5566\u3002
- \u7a0b\u5e8f\u586b\u7a7a 3 \u5dee\u96c6
\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/exam/exam/#2015-2016","title":"2015-2016 \u5e74\u5377","text":" - \u9009\u62e9\u9898 5 \u5b8f\u7684\u5c55\u5f00
\u5b8f\u5c55\u5f00\u53ea\u662f\u7b80\u5355\u7684\u6587\u672c\u66ff\u6362\u3002
- \u5148\u5c55\u5f00
DD
\u5f97\u5230 SQ(2*3) - SQ(2+3)
\uff0c\u5f97\u5230 2 * 3 * 2 * 3 - 2 + 3 * 2 + 3
- \u5148\u5c55\u5f00
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/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
- \u4f5c\u4e3a\u53d6\u5740\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\u6570
- \u4f5c\u4e3a
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\u7b26 C \u6807\u51c6\u5b9a\u4e49\uff0c\u6807\u8bc6\u7b26\u662f\u6570\u5b57\u3001\u4e0b\u5212\u7ebf\u3001\u5c0f\u5199\u53ca\u5927\u5199\u62c9\u4e01\u5b57\u6bcd\u7684\u4efb\u610f\u957f\u5ea6\u5e8f\u5217\uff08\u4e0d\u8ba8\u8bba Unicode \u5b57\u7b26\uff09\u3002\u5408\u6cd5\u7684\u6807\u8bc6\u7b26\u5fc5\u987b\u4ee5\u975e\u6570\u5b57\u5b57\u7b26\u5f00\u59cb\uff0c\u4ee5\u533a\u522b\u4e8e\u6574\u6570\u5e38\u91cf\u6216\u6d6e\u70b9\u5e38\u91cf\u3002
\u6807\u8bc6\u7b26\u80fd\u6307\u4ee3\u4e0b\u5217\u7c7b\u578b\u7684\u5b9e\u4f53\uff1a
- \u5bf9\u8c61
- \u51fd\u6570
- \u6807\u7b7e\uff08struct\u3001union \u6216\u679a\u4e3e\uff09
- \u7ed3\u6784\u4f53\u6216\u8054\u5408\u4f53\u6210\u5458
- \u679a\u4e3e\u5e38\u91cf
- typedef \u540d
- \u6807\u53f7\u540d
- \u5b8f\u540d
- \u5b8f\u5f62\u53c2\u540d
\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
\u6b63\u786e\u6dfb\u52a0\u9650\u5b9a\u4e0e\u5b58\u50a8\u7c7b\u578b\u8bf4\u660e \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u53ea\u6709\u51fa\u73b0\u5728 *
\u4e0e\u6807\u8bc6\u7b26\u4e4b\u95f4\u7684\u9650\u5b9a\u624d\u4f1a\u88ab\u8d4b\u4e88\u6307\u9488\u7c7b\u578b\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 char * const p;
\u58f0\u660e\u4e86\u4e00\u4e2a\u7c7b\u578b\u4e3a char *
\u7684\u3001\u503c\u4e0d\u53ef\u53d8\u7684\u6307\u9488 p
\uff0c\u5b83\u6307\u5411\u7684\u5bf9\u8c61\u7c7b\u578b\u4e3a char
\uff0c\u503c\u53ef\u901a\u8fc7\u6307\u9488 p
\u6539\u53d8\uff1b\u800c\u8bed\u53e5 const char * p;
\u58f0\u660e\u4e86\u4e00\u4e2a\u7c7b\u578b\u4e3a const char *
\u7684\u3001\u503c\u53ef\u53d8\u7684\u6307\u9488 p
\uff0c\u5b83\u6307\u5411\u7684\u5bf9\u8c61\u7c7b\u578b\u4e3a const char
\uff0c\u503c\u4e0d\u53ef\u901a\u8fc7\u6307\u9488 p
\u6539\u53d8\u3002
\u53e6\u5916\uff0c\u5b58\u50a8\u7c7b\u578b\u8bf4\u660e\u7b26\u5e76\u6ca1\u6709\u7c7b\u4f3c\u7684\u8bed\u4e49\uff0c\u5b83\u5fc5\u987b\u7f6e\u4e8e *
\u4e4b\u524d\u3002\u4ece\u8bed\u6cd5\u4e0a\u8bf4\uff0c\u5b83\u4eec\u5c5e\u4e8e\u8bf4\u660e\u7b26\u800c\u975e\u9650\u5b9a\u7b26\uff0c\u4e0d\u5e94\u7f6e\u4e8e *
\u4e0e\u6807\u8bc6\u7b26\u4e4b\u95f4\uff1b\u4ece\u8bed\u4e49\u4e0a\u6765\u8bf4\uff0c\u8bb0\u5f55\u88ab\u5f15\u7528\u5bf9\u8c61\u7c7b\u578b\u7684\u76ee\u7684\u662f\u4ece\u76ee\u6807\u5185\u5b58\u5730\u5740\u6b63\u786e\u8bfb\u53d6\u6570\u636e\uff0c\u800c\u4e86\u89e3\u6307\u5411\u5bf9\u8c61\u7684\u5b58\u50a8\u7c7b\u578b\u5bf9\u8fd9\u4e00\u76ee\u7684\u6beb\u65e0\u5e2e\u52a9\u3002
\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u58f0\u660e\u4e2d *
\u53ea\u5bf9\u76f4\u63a5\u7ed3\u5408\u7684\u6807\u8bc6\u7b26\u751f\u6548\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5982\u679c\u901a\u8fc7\u8bed\u53e5 int * a, b;
\u58f0\u660e\u53d8\u91cf a
\u4e0e b
\uff0c\u90a3\u4e48\u53ea\u6709 a
\u4f1a\u88ab\u8ba4\u5b9a\u4e3a\u6307\u9488\u7c7b\u578b\u3002
\u5728\u58f0\u660e\u6307\u5411\u67d0\u4e9b\u7c7b\u578b\u5bf9\u8c61\u7684\u6307\u9488\u65f6\uff0c\u53ef\u901a\u8fc7\u62ec\u53f7\u4f7f *
\u4f18\u5148\u4e0e\u6807\u8bc6\u7b26\u7ed3\u5408\uff0c\u4ee5\u907f\u514d\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u5dee\u5f02\u5bfc\u81f4\u7684\u6b67\u4e49\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 int *arr[3];
\u58f0\u660e\u4e86\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int *
\u4e14\u957f\u5ea6\u4e3a 3 \u7684\u6570\u7ec4 arr
\uff1b\u8bed\u53e5 int (*ptr)[3];
\u5219\u58f0\u660e\u4e86\u4e00\u4e2a\u6307\u9488 ptr
\uff0c\u5b83\u6307\u5411\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int
\u4e14\u957f\u5ea6\u4e3a 3 \u7684\u6570\u7ec4\u3002
\u6b64\u5916\uff0c\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u7c7b\u578b\u53ef\u4ee5\u662f\u4e0d\u5b8c\u6574\u7c7b\u578b\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 int (*p)[];
\u8868\u660e\u6307\u9488 p
\u6307\u5411\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int
\uff0c\u4e14\u957f\u5ea6\u672a\u77e5\u7684\u6570\u7ec4\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u4e0d\u5173\u5fc3\u6570\u7ec4\u957f\u5ea6\uff0c\u6216\u8005\u6570\u7ec4\u957f\u5ea6\u9700\u8981\u5728\u4e4b\u540e\u7684\u7a0b\u5e8f\u4e2d\u901a\u8fc7\u67d0\u4e9b\u65b9\u6cd5\u786e\u5b9a\u3002\u76f8\u5bf9\u5e94\u5730\uff0c\u65e0\u6cd5\u5bf9\u89e3\u5f15\u7528 p
\u7684\u7ed3\u679c\u4f7f\u7528 sizeof
\u8fd0\u7b97\u7b26\u3002
\u901a\u7528\u6307\u9488\u7c7b\u578b void *
\u7531\u4e8e void
\u4e5f\u5c5e\u4e8e\u4e0d\u5b8c\u6574\u7c7b\u578b\uff0cvoid *
\u540c\u6837\u662f\u5408\u6cd5\u7684\u6307\u9488\u7c7b\u578b\u3002\u5b83\u7684\u5b9e\u9645\u542b\u4e49\u662f\u6307\u9488\u6307\u5411\u4e00\u4e2a\u7c7b\u578b\u672a\u77e5\u7684\u5bf9\u8c61\uff0c\u4e5f\u5373\u6307\u9488\u53ef\u4ee5\u6307\u5411\u4efb\u4f55\u7c7b\u578b\u7684\u5bf9\u8c61\u3002\u81ea\u7136\u5730\uff0c\u6211\u4eec\u65e0\u6cd5\u89e3\u5f15\u7528\u8be5\u7c7b\u578b\u7684\u6307\u9488\u5bf9\u8c61\u3002\u4e0d\u8fc7\uff0c\u5b83\u53ef\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u4efb\u610f\u5176\u4ed6\u7c7b\u578b\u7684\u6307\u9488\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002
\u867d\u7136 C \u8bed\u8a00\u5728 C11 \u6807\u51c6\u524d\u5e76\u672a\u63d0\u4f9b\u6cdb\u578b\u7279\u6027\uff0c\u4f46\u901a\u8fc7\u5f15\u5165 void *
\u7c7b\u578b\u53c2\u6570\uff0c\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u8bbe\u8ba1\u901a\u7528\u63a5\u53e3\uff0c\u4f7f\u7528\u76f8\u540c\u4ee3\u7801\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002\u4e00\u4e2a\u5178\u578b\u7684\u4f8b\u5b50\u662f\uff0cstdlib.h
\u4e2d\u5b9a\u4e49\u7684 qsort
\u4e0e bsearch
\u65b9\u6cd5\u90fd\u901a\u8fc7\u5c06\u6570\u7ec4\u6307\u9488 ptr
\u7684\u7c7b\u578b\u89c4\u5b9a\u4e3a void *
\uff0c\u5b9e\u73b0\u4e86\u65e0\u89c6\u6570\u7ec4\u5143\u7d20\u7c7b\u578b\u91cd\u7528\u6392\u5e8f\u4ee3\u7801\u7684\u6548\u679c\u3002
\u5f53\u7136\uff0c\u56e0\u4e3a\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u7c7b\u578b\u672a\u77e5\uff0c\u6b64\u65f6 C \u8bed\u8a00\u7f16\u8bd1\u5668\u65e0\u6cd5\u5e2e\u4f60\u68c0\u67e5\u7c7b\u578b\u517c\u5bb9\u95ee\u9898\uff0c\u6240\u4ee5\u4f7f\u7528 void *
\u7c7b\u578b\u6307\u9488\u65f6\u9700\u4e07\u5206\u5c0f\u5fc3\u3002
"},{"location":"programming/topic/pointers/#_8","title":"\u503c\u4e0e\u8fd0\u7b97","text":"\u901a\u8fc7\u6307\u9488\u83b7\u5f97\u88ab\u5f15\u7528\u5bf9\u8c61\u7684\u8fc7\u7a0b\u79f0\u4e3a\u89e3\u5f15\u7528\uff0c\u7531\u8fd0\u7b97\u7b26 *
\u5b8c\u6210\uff1b\u901a\u8fc7\u67d0\u4e2a\u5bf9\u8c61\u83b7\u5f97\u6307\u5411\u8be5\u5bf9\u8c61\u6307\u9488\u7684\u8fc7\u7a0b\u79f0\u4e3a\u53d6\u5740\uff0c\u7531\u8fd0\u7b97\u7b26 &
\u5b8c\u6210\u3002
\u7ed3\u5408\u8d4b\u503c\u64cd\u4f5c\uff0c\u53ef\u6839\u636e\u9700\u8981\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u5e76\u4fee\u6539\u6307\u5411\u7684\u5bf9\u8c61\uff0c\u6216\u4ee4\u6307\u9488\u6307\u5411\u4e0d\u540c\u7684\u5bf9\u8c61\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5bf9\u4e8e int
\u7c7b\u578b\u53d8\u91cf a
\uff0c\u8bed\u53e5 p = &a;
\u5c06\u4f7f\u6307\u9488 p
\u7684\u503c\u8bbe\u4e3a a
\u7684\u5185\u5b58\u5730\u5740\uff0c\u4e5f\u5373\u4ee4 p
\u6307\u5411 a
\uff1b\u5728\u6b64\u57fa\u7840\u4e0a\uff0c\u8bed\u53e5 *p = 1;
\u5c06\u6539\u53d8 p \u6307\u5411\u7684\u5bf9\u8c61\uff0c\u4e5f\u5373\u53d8\u91cf a
\u7684\u503c\u3002
\u4e0d\u8fc7\uff0c\u5728\u7f16\u5199\u8868\u8fbe\u5f0f\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u7684\u5f71\u54cd\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8868\u8fbe\u5f0f *p++
\u5c06\u4f7f\u6307\u9488 p
\u7684\u503c\u81ea\u589e 1\uff0c\u800c\u8868\u8fbe\u5f0f (*p)++
\u5c06\u4f7f\u6307\u9488 p
\u6307\u5411\u5bf9\u8c61\u7684\u503c\u81ea\u589e 1\u3002
\u7406\u89e3\u521d\u59cb\u5316\u8bed\u53e5\u4e2d\u7684 *
\u8fd0\u7b97\u7b26
C \u8bed\u8a00\u7684\u8bed\u6cd5\u529b\u56fe\u4f7f\u58f0\u660e\u548c\u4f7f\u7528\u76f8\u4e00\u81f4\u3002
\u5728\u9605\u8bfb\u6307\u9488\u521d\u59cb\u5316\u8bed\u53e5\u65f6\uff0c\u4f60\u53ef\u80fd\u5e38\u5e38\u6df7\u6dc6 *
\u7684\u58f0\u660e\u4e0e\u89e3\u5f15\u7528\u8bed\u6cd5\u3002\u6b63\u786e\u5206\u8fa8\u7684\u8981\u70b9\u5728\u4e8e\uff0c\u521d\u59cb\u5316\u8bed\u53e5\u5206\u4e3a\u58f0\u660e\u548c\u521d\u59cb\u5316\u5668\u4e24\u90e8\u5206\uff0c\u5176\u4e2d\u8d4b\u503c\u53f7 =
\u524d\u7684\u90e8\u5206\u4e3a\u58f0\u660e\uff0c\u8d4b\u503c\u53f7\u53ca\u5176\u540e\u7684\u90e8\u5206\u4e3a\u521d\u59cb\u5316\u5668\u3002
\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5728\u8bed\u53e5 int *ip = *ipp;
\u4e2d\uff0cint *ip
\u4e3a\u58f0\u660e\uff0c= *ipp
\u4e3a\u521d\u59cb\u5316\u5668\uff0c\u8fd9\u6761\u8bed\u53e5\u7684\u542b\u4e49\u662f\uff1a\u58f0\u660e\u4e00\u4e2a\u6307\u5411 int
\u7c7b\u578b\u5bf9\u8c61\u7684\u6307\u9488 ip
\uff0c\u5e76\u5c06\u5b83\u7684\u521d\u59cb\u503c\u8bbe\u4e3a ipp
\u6307\u5411\u5bf9\u8c61\u7684\u503c\u3002
\u91ce\u6307\u9488
\u58f0\u660e\u81ea\u52a8\u4f5c\u7528\u57df\u7684\u5bf9\u8c61\u540e\uff0cC \u8bed\u8a00\u4ec5\u4fdd\u8bc1\u53ef\u4ee5\u6b63\u5e38\u8bbf\u95ee\u5e76\u4fee\u6539\u8be5\u5bf9\u8c61\uff0c\u800c\u4e0d\u4fdd\u8bc1\u5176\u521d\u59cb\u5185\u5bb9\uff0c\u8fd9\u70b9\u5bf9\u6307\u9488\u540c\u6837\u6210\u7acb\u3002\u5982\u679c\u58f0\u660e\u4e86\u4e00\u4e2a\u6307\u9488\u5374\u6ca1\u6709\u8d4b\u503c\uff0c\u8fd9\u4e2a\u6307\u9488\u7684\u6307\u5411\u4fbf\u65e0\u6cd5\u786e\u5b9a\uff0c\u6211\u4eec\u79f0\u5b83\u4e3a\u91ce\u6307\u9488\u3002
\u56e0\u4e3a\u91ce\u6307\u9488\u53ef\u80fd\u6307\u5411\u4efb\u610f\u5185\u5b58\u6bb5\uff0c\u4e0d\u52a0\u9274\u522b\u7684\u968f\u610f\u4f7f\u7528\u53ef\u80fd\u5bfc\u81f4\u8bbf\u95ee\u975e\u6cd5\u5185\u5b58\u3001\u635f\u574f\u6b63\u5e38\u6570\u636e\uff0c\u751a\u81f3\u9020\u6210\u5176\u4ed6\u672a\u77e5\u540e\u679c\u3002\u5c1d\u8bd5\u89e3\u5f15\u7528\u91ce\u6307\u9488\u662f\u6bb5\u9519\u8bef\uff08Segmentation Fault\uff09\u7684\u4e3b\u8981\u8bf1\u56e0\u4e4b\u4e00\u3002\u56e0\u6b64\uff0c\u58f0\u660e\u6307\u9488\u65f6\u52a1\u5fc5\u5b8c\u6210\u521d\u59cb\u5316\u3002
\u6bcf\u79cd\u7c7b\u578b\u7684\u6307\u9488\u90fd\u542b\u6709\u4e00\u4e2a\u8be5\u7c7b\u578b\u7684\u7279\u6b8a\u503c\uff0c\u79f0\u4e3a\u7a7a\u6307\u9488\u503c\u3002\u503c\u4e3a\u7a7a\u7684\u6307\u9488\u4e0d\u6307\u5411\u4efb\u4f55\u5bf9\u8c61\uff0c\u4e14\u89e3\u5f15\u7528\u7a7a\u6307\u9488\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\u3002\u53ef\u4f7f\u7528\u7a7a\u6307\u9488\u7b26\u53f7\u5e38\u91cf NULL
\u4e3a\u6307\u9488\u8d4b\u7a7a\u503c\uff0c\u5b83\u5728 stdio.h
\u3001stdlib.h
\u3001string.h
\u3001stddef.h
\u7b49\u5e38\u7528\u5e93\u4e2d\u5747\u6709\u5b9a\u4e49\u3002\u6839\u636e C \u8bed\u8a00\u6807\u51c6\uff0cNULL
\u7684\u503c\u4e3a 0\u3002
\u7a7a\u6307\u9488\u5e38\u91cf NULL
\u7684\u503c \u6839\u636e C \u6807\u51c6\u5b9a\u4e49\uff0c\u5b8f NULL
\u662f\u5b9e\u73b0\u5b9a\u4e49\u7684\u7a7a\u6307\u9488\u5e38\u91cf\uff0c\u5b83\u53ef\u4ee5\u662f\u503c\u4e3a 0 \u7684\u6574\u6570\u5e38\u91cf\u8868\u8fbe\u5f0f\uff0c\u6216\u8005\u88ab\u8f6c\u6362\u4e3a void *
\u7c7b\u578b\u7684\u6b64\u7c7b\u8868\u8fbe\u5f0f\u3002
\u90a3\u4e48\uff0c\u4e3a\u4ec0\u4e48 NULL
\u7684\u503c\u88ab\u89c4\u5b9a\u4e3a 0 \u5462\uff1f
\u4f60\u53ef\u80fd\u4f1a\u731c\u60f3\uff0c\u8fd9\u662f\u56e0\u4e3a\u5185\u5b58\u5730\u5740 0x0 \u88ab\u7cfb\u7edf\u9884\u7559\u3002\u5bf9\u65e9\u671f\u64cd\u4f5c\u7cfb\u7edf\u800c\u8a00\uff0c\u8fd9\u79cd\u8bf4\u6cd5\u662f\u6210\u7acb\u7684\uff1b\u4f46\u662f\u73b0\u5728\uff0c\u4e0d\u540c\u5e73\u53f0\u5bf9\u7a7a\u6307\u9488\u7684\u503c\u5df2\u7ecf\u6709\u8bb8\u591a\u4e0d\u540c\u7684\u89c4\u5b9a\u3002\u65e0\u8bba NULL
\u7684\u503c\u88ab\u5982\u4f55\u5b9a\u4e49\uff0c\u94fe\u63a5\u5668\u90fd\u5e94\u5c06\u7a7a\u6307\u9488\u7684\u503c\u6539\u4e3a\u76ee\u6807\u5e73\u53f0\u6307\u5b9a\u7684\u7a7a\u6307\u9488\u503c\u3002\u4e3a\u4e86\u5f3a\u8c03\u8fd9\u4e00\u70b9\uff0cC++11 \u5f15\u5165\u4e86 nullptr
\u5173\u952e\u5b57\uff0c\u4f46 C \u6807\u51c6\u5e76\u672a\u5bf9\u6b64\u4f5c\u4efb\u4f55\u4fee\u6539\u3002
\u56de\u5230\u95ee\u9898\u672c\u8eab\uff0c\u5c06 0 \u89c6\u4f5c\u7279\u6b8a\u503c\u7684\u4e60\u60ef\u662f\u4e00\u4e2a\u6bd4\u8f83\u6709\u8bf4\u670d\u529b\u7684\u7406\u7531\u3002\u6b64\u5916\uff0c\u5c06 NULL
\u5b9a\u4e49\u4e3a 0 \u4e5f\u53ef\u4ee5\u7b80\u5316\u8868\u8fbe\u5f0f\uff0c\u5373\u5229\u7528 C \u8bed\u8a00\u5c06 0 \u89c6\u4e3a false \u7684\u7279\u6027\uff0c\u7b80\u5316\u5bf9\u6307\u9488\u662f\u5426\u4e3a\u7a7a\u7684\u5224\u65ad\u3002
\u4e24\u4e2a\u7c7b\u578b\u517c\u5bb9\u7684\u6307\u9488\u95f4\u7684\u8d4b\u503c\u8fd0\u7b97\u3001\u6bd4\u8f83\u8fd0\u7b97\u4e0e\u51cf\u6cd5\u8fd0\u7b97\u662f\u6709\u6548\u7684\u3002\u82e5\u6307\u9488\u7c7b\u578b\u4e0d\u517c\u5bb9\uff0c\u5219\u9700\u8981\u8fdb\u884c\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u3002\u8fd9\u79cd\u8fd0\u7b97\u4ec5\u5728\u5c11\u6570\u60c5\u5f62\u4e0b\u6709\u610f\u4e49\uff0c\u5982\u4e24\u4e2a\u6307\u9488\u4f4d\u4e8e\u540c\u4e00\u6570\u7ec4\u5185\u65f6\u3002
\u6307\u9488\u4e0e\u6574\u6570\u95f4\u7684\u52a0\u6cd5\u6216\u51cf\u6cd5\u8fd0\u7b97\u4e5f\u662f\u6709\u6548\u7684\uff0c\u5176\u542b\u4e49\u662f\u4ee4\u6307\u9488\u524d\u79fb\u6216\u540e\u79fb\u82e5\u5e72\u4e2a\u6307\u5411\u5bf9\u8c61\u7684\u957f\u5ea6\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8868\u8fbe\u5f0f p + n
\u7684\u503c\uff0c\u4ee3\u8868\u6307\u9488 p
\u5f53\u524d\u6307\u5411\u7684\u5bf9\u8c61\u4e4b\u540e\u7b2c n \u4e2a\u5bf9\u8c61\u7684\u5730\u5740\u3002\u8fd9\u79cd\u8fd0\u7b97\u5728\u6570\u7ec4\u4e0e\u5b57\u7b26\u4e32\u64cd\u4f5c\u4e2d\u5341\u5206\u5e38\u89c1\u3002
\u867d\u7136\u5185\u5b58\u5730\u5740\u5f80\u5f80\u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u4f46\u662f\u6307\u9488\u4e0e\u6574\u6570\u4e4b\u95f4\u4e0d\u80fd\u76f8\u4e92\u8f6c\u6362\uff0c0 \u662f\u552f\u4e00\u7684\u4f8b\u5916\uff1a\u5e38\u91cf 0 \u53ef\u4ee5\u8d4b\u503c\u7ed9\u6307\u9488\uff0c\u6307\u9488\u4e5f\u53ef\u4e0e\u5e38\u91cf 0 \u8fdb\u884c\u6bd4\u8f83\u3002\u663e\u7136\uff0c\u6b64\u65f6\u5e38\u91cf 0 \u5c06\u88ab\u89c6\u4e3a\u7a7a\u6307\u9488 NULL
\u3002
\u9664\u4ee5\u4e0a\u8fd0\u7b97\u5916\uff0c\u5176\u4ed6\u5f62\u5f0f\u7684\u6307\u9488\u8fd0\u7b97\u90fd\u662f\u975e\u6cd5\u7684\u3002
"},{"location":"programming/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\u975e\u6cd5\u7684\u3002
\u4e0d\u8fc7\uff0c\u5982\u679c\u6211\u4eec\u671f\u671b\u51fd\u6570\u4ea7\u751f\u526f\u4f5c\u7528\uff0c\u503c\u4f20\u9012\u7684\u65b9\u5f0f\u4fbf\u65e0\u6cd5\u6ee1\u8db3\u9700\u6c42\u3002\u4e3a\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u5f15\u5165\u6307\u9488\u7c7b\u578b\u7684\u53c2\u6570\uff0c\u4ee5\u8fbe\u5230\u4fee\u6539\u5176\u4ed6\u5bf9\u8c61\u7684\u76ee\u7684\u3002
\u6848\u4f8b\uff1a\u4ea4\u6362\u51fd\u6570 \u5047\u8bbe fake_swap
\u51fd\u6570\u5b9a\u4e49\u5982\u4e0b\uff1a
void fake_swap(int x, int y) {\n int tmp = x;\n x = y;\n y = tmp;\n}\n
\u8c03\u7528\u90e8\u5206\u5982\u4e0b\uff1a
int a = 1, b = 2;\nfake_swap(a, b);\n
\u5728\u8c03\u7528 fake_swap
\u51fd\u6570\u540e\u68c0\u67e5 a
\u3001b
\u7684\u503c\uff0c\u53ef\u53d1\u73b0\u5b83\u4eec\u7684\u503c\u5e76\u6ca1\u6709\u4ea4\u6362\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u8c03\u7528 fake_swap
\u51fd\u6570\u65f6\uff0c\u5b9e\u53c2 a
\u3001b
\u7684\u503c\u88ab\u590d\u5236\u7ed9\u5f62\u53c2 x
\u3001y
\uff0c\u51fd\u6570\u4ec5\u4fee\u6539\u4e86\u5f62\u53c2\u7684\u503c\uff0c\u5e76\u672a\u5f71\u54cd\u51fd\u6570\u5916\u90e8\u7684\u5b9e\u53c2\u3002
\u73b0\u5728\uff0c\u6211\u4eec\u5c06 fake_swap
\u51fd\u6570\u4fee\u6539\u4e3a\uff1a
void swap(int *x, int *y) {\n int tmp = *x;\n *x = *y;\n *y = tmp;\n}\n
\u8c03\u7528\u90e8\u5206\u5982\u4e0b\uff1a
int a = 1, b = 2;\nswap(&a, &b);\n
\u5728\u8c03\u7528 swap
\u51fd\u6570\u540e\u68c0\u67e5 a
\u3001b
\u7684\u503c\uff0c\u53ef\u53d1\u73b0\u5b83\u4eec\u7684\u503c\u5df2\u7ecf\u4ea4\u6362\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u8c03\u7528 swap
\u51fd\u6570\u65f6\uff0c\u5b9e\u53c2 a
\u3001b
\u7684\u5730\u5740\u88ab\u590d\u5236\u7ed9\u5f62\u53c2 x
\u3001y
\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0cx
\u3001y
\u5206\u522b\u6307\u5411 a
\u3001b
\u3002\u51fd\u6570\u4fee\u6539\u4e86 x
\u3001y
\u6307\u5411\u5bf9\u8c61\u7684\u503c\uff0c\u4e5f\u5c31\u662f a
\u3001b
\u7684\u503c\uff0c\u56e0\u6b64\u867d\u7136 a
\u3001b
\u5728\u51fd\u6570\u5916\u90e8\uff0c\u4f46\u5b83\u4eec\u7684\u503c\u5df2\u88ab\u6210\u529f\u4fee\u6539\u3002
C \u8bed\u8a00\u4e2d\u7684\u51fd\u6570\u53ea\u6709\u4e00\u4e2a\u8fd4\u56de\u503c\u3002\u82e5\u8981\u8fd4\u56de\u591a\u4e2a\u503c\uff0c\u53ef\u5c06\u6240\u6709\u8fd4\u56de\u503c\u653e\u5165\u7ed3\u6784\u4f53\u4e2d\uff1b\u4f46\u662f\uff0c\u8fd9\u9700\u8981\u989d\u5916\u58f0\u660e\u4e00\u4e2a\u4e34\u65f6\u4f7f\u7528\u7684\u7ed3\u6784\u4f53\u7c7b\u578b\uff0c\u62c6\u89e3\u7ed3\u6784\u4f53\u7684\u8fc7\u7a0b\u4e5f\u8017\u65f6\u8017\u529b\u3002\u4e00\u4e2a\u66f4\u597d\u7684\u65b9\u6848\u662f\uff0c\u5411\u51fd\u6570\u4f20\u9012\u6307\u9488\u53c2\u6570\uff0c\u7531\u51fd\u6570\u901a\u8fc7\u6307\u9488\u5c06\u7ed3\u679c\u5199\u5165\u76ee\u6807\u5bf9\u8c61\u3002\u6211\u4eec\u7ecf\u5e38\u4f7f\u7528\u7684 scanf
\u51fd\u6570\u4fbf\u662f\u4e00\u4e2a\u5178\u578b\u4f8b\u5b50\u3002
"},{"location":"programming/topic/pointers/#_11","title":"\u64cd\u4f5c\u6570\u7ec4","text":"\u4e00\u822c\u800c\u8a00\uff0c\u63d0\u5230\u201c\u6570\u7ec4\u201d\u65f6\uff0c\u6211\u4eec\u8ba8\u8bba\u7684\u65e2\u53ef\u4ee5\u662f\u6570\u7ec4\u7c7b\u578b\uff0c\u4e5f\u53ef\u4ee5\u662f\u6570\u7ec4\u7c7b\u578b\u7684\u5bf9\u8c61\u3002
\u6307\u9488\u4e0e\u6570\u7ec4\u7684\u5173\u7cfb\u5341\u5206\u5bc6\u5207\uff0c\u5b83\u4eec\u4e4b\u95f4\u7684\u8f6c\u6362\u4e5f\u662f C \u8bed\u8a00\u4e2d\u6700\u5e38\u89c1\u7684\u7c7b\u578b\u8f6c\u6362\u4e4b\u4e00\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u7528\u6307\u9488\u7f16\u5199\u7684\u7a0b\u5e8f\u6bd4\u7528\u6570\u7ec4\u7f16\u5199\u7684\u7a0b\u5e8f\u6267\u884c\u901f\u5ea6\u5feb\uff0c\u4f46\u53ef\u8bfb\u6027\u76f8\u5bf9\u8f83\u5dee\u3002
\u9605\u8bfb\u5efa\u8bae
\u4e0b\u6587\u7684\u8ba8\u8bba\u4e2d\u4f1a\u8bb2\u89e3\u6570\u7ec4\u7684\u90e8\u5206\u7279\u6027\uff0c\u4e0d\u8fc7\u4ecd\u7136\u5efa\u8bae\u5728\u719f\u6089\u6570\u7ec4\u540e\u9605\u8bfb\u3002
"},{"location":"programming/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
- \u4f5c\u4e3a\u53d6\u5730\u5740\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\u6570
- \u4f5c\u4e3a sizeof \u7684\u64cd\u4f5c\u6570
- \u4f5c\u4e3a\u7528\u4e8e\u6570\u7ec4\u521d\u59cb\u5316\u7684\u5b57\u7b26\u4e32\u5b57\u9762\u91cf
\u7684\u8bed\u5883\u65f6\uff0c\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u3002
\u4e60\u60ef\u4e0a\uff0c\u6211\u4eec\u5c06\u6570\u7ec4\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u8fc7\u7a0b\uff0c\u79f0\u4e3a\u6570\u7ec4\u9000\u5316\u4e3a\u6307\u9488\u3002
C \u6807\u51c6\u89c4\u5b9a\uff0c\u8868\u8fbe\u5f0f E1[E2]
\u7b49\u4ef7\u4e8e (*((E1) + (E2)))
\u3002\u8fd9\u610f\u5473\u7740\uff0c\u6570\u7ec4\u5143\u7d20\u5728\u5185\u5b58\u4e2d\u8fde\u7eed\u3002\u53e6\u5916\uff0c\u5982\u679c\u786e\u4fe1\u76f8\u5e94\u5143\u7d20\u5b58\u5728\uff0c\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u8d85\u51fa\u6570\u7ec4\u8303\u56f4\u7684\u4e0b\u6807\uff0c\u8bbf\u95ee\u6570\u7ec4\u524d\u540e\u7684\u5143\u7d20\u3002
\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c
C \u8bed\u8a00\u4e0d\u4f1a\u68c0\u67e5\u6570\u7ec4\u4e0b\u6807\u662f\u5426\u8d85\u8fc7\u6570\u7ec4\u957f\u5ea6\uff0c\u5bf9\u6307\u9488\u4e5f\u51e0\u4e4e\u6ca1\u6709\u9650\u5236\u63aa\u65bd\u3002\u5c1d\u8bd5\u8bbf\u95ee\u8d85\u51fa\u6570\u7ec4\u8fb9\u754c\u7684\u5185\u5b58\u5730\u5740\uff0c\u53ef\u80fd\u5bfc\u81f4\u4e0e\u5c1d\u8bd5\u89e3\u5f15\u7528\u91ce\u6307\u9488\u7b49\u540c\u7684\u5371\u5bb3\u3002\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c\u662f\u6bb5\u9519\u8bef\u7684\u4e3b\u8981\u8bf1\u56e0\u4e4b\u4e00\u3002\u56e0\u6b64\uff0c\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u524d\uff0c\u52a1\u5fc5\u5145\u5206\u68c0\u67e5\u6307\u5b9a\u7684\u4e0b\u6807\u4e0e\u6307\u9488\u504f\u79fb\u91cf\u662f\u5426\u5728\u6570\u7ec4\u8303\u56f4\u5185\u3002
\u7531\u4e8e\u590d\u5236\u6570\u7ec4\u7684\u5f00\u9500\u7ecf\u5e38\u5927\u5230\u4e0d\u53ef\u63a5\u53d7\uff0cC \u6807\u51c6\u89c4\u5b9a\uff0c\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u65f6\u6570\u7ec4\u4e5f\u5e94\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u5176\u9996\u5143\u7d20\u6307\u9488\u3002\u6240\u4ee5\uff0c\u5728\u8bed\u6cd5\u5c42\u9762\u4e0a\uff0c\u51fd\u6570\u58f0\u660e\u4e0e\u5b9a\u4e49\u4e2d\uff0c\u5f62\u5982 char str[]
\u7684\u5f62\u53c2\u58f0\u660e\u4e0e char *str
\u662f\u7b49\u4ef7\u7684\uff0c\u4e0d\u8fc7\u524d\u8005\u53ef\u4ee5\u63d0\u9192\u51fd\u6570\u7f16\u5199\u8005\u4e0e\u4f7f\u7528\u8005\u7559\u610f str
\u7684\u5b9e\u9645\u542b\u4e49\u3002\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f20\u5165\u6307\u5411\u5176\u4ed6\u5143\u7d20\u7684\u6307\u9488\uff0c\u8fd9\u5728\u4f20\u53c2\u8fc7\u7a0b\u4e2d\u6ca1\u6709\u533a\u522b\u3002
\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd4\u56de\u7c7b\u578b\u4e2d\u7684\u6570\u7ec4\u4e0d\u4f1a\u81ea\u52a8\u8f6c\u6362\u6210\u6307\u9488\uff0c\u56e0\u6b64\u5f62\u5982 char func() [];
\u7684\u51fd\u6570\u58f0\u660e\u662f\u975e\u6cd5\u7684\u3002
\u6570\u7ec4\u7c7b\u578b\u4e0e\u6307\u9488\u7c7b\u578b\u7684\u533a\u522b
\u5c3d\u7ba1\u5728\u7a0b\u5e8f\u4e2d\u6570\u7ec4\u7ecf\u5e38\u9000\u5316\u4e3a\u6307\u9488\uff0c\u6211\u4eec\u4ecd\u5e94\u8be5\u533a\u5206\u8fd9\u4e24\u4e2a\u7c7b\u578b\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8003\u8651\u5982\u4e0b\u7684\u7a0b\u5e8f\u7247\u6bb5\uff08C \u6807\u51c6\u89c4\u5b9a sizeof
\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u4e3a\u65e0\u7b26\u53f7\u6574\u578b size_t
\uff0c\u5e94\u4f7f\u7528 %zu
\u683c\u5f0f\u6307\u793a\u7b26\u8f93\u51fa\uff09\uff1a
int a[3], *p;\nprintf(\"%zu %zu\", sizeof(a), sizeof(p));\n
\u5b83\u5c06\u4f1a\u8f93\u51fa 12 8
\u3002\u8fd9\u662f\u56e0\u4e3a\uff0ca
\u662f\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a int
\u4e14\u957f\u5ea6\u4e3a 3 \u7684\u6570\u7ec4\u5bf9\u8c61\uff0c\u5728\u591a\u6570\u7cfb\u7edf\u4e2d int
\u7c7b\u578b\u957f\u5ea6\u4e3a 4 \u5b57\u8282\uff0c\u56e0\u6b64 a
\u7684\u957f\u5ea6\u4e3a 12 \u5b57\u8282\uff1b\u800c p
\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u5728\u5e38\u7528\u7684 64 \u4f4d\u7cfb\u7edf\u4e2d\u957f\u5ea6\u4e3a 8 \u5b57\u8282\u3002
\u53e6\u5916\uff0c\u6307\u9488\u7684\u503c\u53ef\u5728\u4efb\u610f\u65f6\u523b\u901a\u8fc7\u8d4b\u503c\u4fee\u6539\uff0c\u800c\u6570\u7ec4\u4e0d\u80fd\u88ab\u8d4b\u503c\u3002
"},{"location":"programming/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
\u6848\u4f8b\uff1a\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u591a\u7ef4\u6570\u7ec4\u5143\u7d20 \u6839\u636e C \u6807\u51c6\u89c4\u5b9a\uff0c\u4e0d\u96be\u63a8\u65ad\u51fa\u8868\u8fbe\u5f0f a[i][j]
\u4e0e\u8868\u8fbe\u5f0f *(*(a + i) + j)
\u7b49\u4ef7\u3002\u4e0d\u8fc7\uff0c\u540e\u8005\u7684\u6c42\u503c\u8fc7\u7a0b\u76f8\u6bd4\u524d\u8005\u66f4\u52a0\u62bd\u8c61\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u5c06\u4ee5\u6b64\u4e3a\u4f8b\u9010\u6b65\u5206\u6790\u5176\u6c42\u503c\u8fc7\u7a0b\u3002
-
\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
"},{"location":"programming/topic/pointers/#_14","title":"\u5b57\u7b26\u4e32","text":"\u6211\u4eec\u77e5\u9053\uff0cC \u8bed\u8a00\u4e2d\u7684\u5b57\u7b26\u4e32\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u7a7a\u5b57\u7b26\uff08\u79f0\u4e3a\u4e2d\u6b62\u5b57\u7b26\uff09\u7ed3\u5c3e\u7684\u5b57\u7b26\u6570\u7ec4\u3002\u56e0\u6b64\uff0c\u4e0a\u4e00\u5c0f\u8282\u7684\u8ba8\u8bba\u540c\u6837\u9002\u7528\u4e8e\u8fd9\u4e00\u5c0f\u8282\u3002
\u7531\u4e8e\u5b57\u7b26\u4e32\u540c\u65f6\u5177\u6709\u6570\u7ec4\u7684\u5c5e\u6027\uff0c\u8ba8\u8bba\u4e0e\u5185\u5b58\u7a7a\u95f4\u6709\u5173\u7684\u6982\u5ff5\u4e0e\u64cd\u4f5c\u65f6\uff0c\u4e3a\u907f\u514d\u6df7\u6dc6\uff0c\u6211\u4eec\u5c06\u6570\u7ec4\u5bf9\u8c61\u5360\u7528\u7684\u5b57\u8282\u6570\u79f0\u4e3a\u5176\u5927\u5c0f\uff0c\u5c06\u5b9e\u9645\u7ec4\u6210\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u6570\u79f0\u4e3a\u5176\u957f\u5ea6\u3002\u4e00\u4e2a\u76f4\u89c2\u7406\u89e3\u662f\uff0c\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u8ba1\u5165\u4e2d\u6b62\u5b57\u7b26\uff0c\u800c\u5176\u957f\u5ea6\u4e0d\u8ba1\u5165\u3002
\u5728 C \u8bed\u8a00\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u662f\u7531\u4e00\u5bf9 \"
\u5305\u56f4\u7684\u4efb\u610f\u957f\u5ea6\u7684\u5b57\u7b26\u5e8f\u5217\uff0c\u5176\u4e2d\u7684\u5b57\u7b26\u53ef\u4ee5\u662f\u4e00\u822c\u5b57\u7b26\u6216\u8f6c\u4e49\u5b57\u7b26\uff0c\u5982 \"abc\"
\u3001\"x y\\nz\"
\u3001\"\"
\u3002\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u672b\u5c3e\u9690\u5f0f\u5305\u542b\u4e2d\u6b62\u5b57\u7b26\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\"\"
\u4ee3\u8868\u5927\u5c0f\u4e3a 1 \u7684\u5b57\u7b26\u6570\u7ec4\uff0c\u5b83\u7684\u552f\u4e00\u5143\u7d20\u4e3a '\\0'
\u3002
\u542b\u7a7a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u5b57\u9762\u91cf \u82e5\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5b57\u7b26\u5e8f\u5217\u5185\u5305\u542b\u7a7a\u5b57\u7b26\uff0c\u5219\u5b83\u8868\u793a\u542b\u6709\u591a\u4e8e\u4e00\u6761\u5b57\u7b26\u4e32\u7684\u6570\u7ec4\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5bf9\u4e8e\u5b57\u7b26\u4e32\u5b57\u9762\u91cf \"abc\\0\"
\uff0c\u5b83\u5305\u542b \"abc\"
\u548c \"\"
\u4e24\u4e2a\u5b57\u7b26\u4e32\u3002
\u4f60\u53ef\u4ee5\u901a\u8fc7 sizeof
\u8fd0\u7b97\u7b26\u548c strlen
\u51fd\u6570\u9a8c\u8bc1\u7a0b\u5e8f\u884c\u4e3a\u3002
\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u7c7b\u578b\u4e3a char [N]
\uff0c\u5176\u4e2d N
\u662f\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\uff0c\u5305\u62ec\u9690\u5f0f\u7684\u4e2d\u6b62\u5b57\u7b26\u3002\u663e\u7136\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u4e5f\u9075\u5b88\u6570\u7ec4\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362\u89c4\u5219\u3002
\u5c1d\u8bd5\u4fee\u6539\u5b57\u7b26\u4e32\u5b57\u9762\u91cf
\u867d\u7136\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u7c7b\u578b\u6ca1\u6709\u6307\u5b9a\u4e3a const
\uff0c\u4f46\u5b83\u5b9e\u9645\u4e0a\u4e5f\u662f\u5e38\u91cf\u3002\u5c1d\u8bd5\u4fee\u6539\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\u3002\u4e00\u822c\u800c\u8a00\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5185\u5bb9\u4f1a\u88ab\u653e\u5165\u53ea\u8bfb\u5185\u5b58\u4e2d\uff0c\u56e0\u6b64\u5c1d\u8bd5\u4fee\u6539\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u9519\u8bef\u3002
\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u672a\u9000\u5316\u60c5\u5f62 \u8003\u8651\u5982\u4e0b\u7a0b\u5e8f\u7247\u6bb5\uff1a
char *str = \"abc\";\nprintf(\"%zu %zu\\n\", sizeof(\"abc\"), sizeof(str));\n
\u5b83\u5c06\u4f1a\u8f93\u51fa 4 8
\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u6b64\u65f6\u5b57\u7b26\u4e32\u5b57\u9762\u91cf \"abc\"
\u88ab\u4f5c\u4e3a sizeof
\u7684\u64cd\u4f5c\u6570\uff0c\u4e0d\u4f1a\u9000\u5316\u4e3a\u6307\u9488\uff0c\u56e0\u6b64\u8868\u8fbe\u5f0f sizeof(\"abc\")
\u7684\u7ed3\u679c\u662f\u5b57\u7b26\u4e32\u6570\u7ec4\u7684\u5927\u5c0f\u3002
\u4e0d\u96be\u60f3\u5230\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5176\u6548\u679c\u76f8\u5f53\u4e8e\u4f7f\u7528\u5bf9\u5e94\u7684\u5b57\u7b26\u6570\u7ec4\u5e38\u91cf\u521d\u59cb\u5316\u3002\u4e0e\u4e00\u822c\u7684\u6570\u7ec4\u521d\u59cb\u5316\u7c7b\u4f3c\uff0c\u6570\u7ec4\u957f\u5ea6\u53ef\u7531\u521d\u59cb\u5316\u5668\u9690\u5f0f\u6307\u5b9a\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 char str[] = \"abc\";
\u7b49\u4ef7\u4e8e\u8bed\u53e5 char str[] = {'a', 'b', 'c', '\\0'};
\uff0c\u5b83\u58f0\u660e\u5e76\u521d\u59cb\u5316\u4e86\u4e00\u4e2a\u957f\u5ea6\u4e3a 4 \u7684\u5b57\u7b26\u6570\u7ec4 str
\u3002
\u6570\u7ec4\u7684\u5927\u5c0f\u53ef\u4ee5\u6bd4\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5927\u5c0f\u5c11 1\uff0c\u6b64\u65f6\u4e2d\u6b62\u5b57\u7b26\u5c06\u88ab\u5ffd\u7565\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u8bed\u53e5 char str[3] = \"abc\";
\u7b49\u4ef7\u4e8e\u8bed\u53e5 char str[3] = {'a', 'b', 'c'};
\u3002
\u6848\u4f8b\uff1a\u9519\u8bef\u7684\u5b57\u7b26\u6570\u7ec4\u521d\u59cb\u5316 \u8003\u8651\u5982\u4e0b\u7a0b\u5e8f\u7247\u6bb5\uff1a
char str[3] = \"abc\";\nchar backdoor[] = \"xyz\";\nprintf(\"%s\", str);\n
\u5b83\u5c06\u4f1a\u8f93\u51fa abcxyz
\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf \"abc\"
\u7684\u5927\u5c0f str
\u7684\u5927\u5c0f\u5927 1\uff0c\u521d\u59cb\u5316\u65f6\u4e2d\u6b62\u5b57\u7b26\u88ab\u5ffd\u7565\uff0cstr
\u6700\u7ec8\u88ab\u521d\u59cb\u5316\u4e3a {'a', 'b', 'c'}
\u3002\u5c06\u5176\u89c6\u4e3a\u5b57\u7b26\u4e32\u5e76\u8f93\u51fa\u65f6\uff0c\u7531\u4e8e str
\u5185\u4e0d\u542b\u4e2d\u6b62\u5b57\u7b26\uff0c\u8f93\u51fa\u51fd\u6570\u5c06\u4f1a\u7ee7\u7eed\u8bbf\u95ee str
\u540e\u7684\u5185\u5b58\u5730\u5740\uff0c\u5373\u51fa\u73b0\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c\u95ee\u9898\u3002
\u7531\u4e8e C \u6807\u51c6\u5e76\u672a\u5bf9\u5b57\u9762\u91cf\u7684\u5185\u5b58\u6392\u5e03\u4f5c\u4efb\u4f55\u89c4\u5b9a\uff0c\u5728\u4e0d\u540c\u73af\u5883\u4e0b\u5b57\u7b26\u4e32\u5e38\u91cf backdoor
\u7684\u5185\u5b58\u5730\u5740\u53ef\u80fd\u4f4d\u4e8e str
\u7684\u5185\u5b58\u5730\u5740\u4e4b\u524d\u3002\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u6539\u53d8\u58f0\u660e\u987a\u5e8f\u4ee5\u8fbe\u5230\u7c7b\u4f3c\u7684\u8f93\u51fa\u6548\u679c\u3002
\u6839\u636e\u9690\u5f0f\u8f6c\u6362\u89c4\u5219\uff0c\u5728\u591a\u6570\u8868\u8fbe\u5f0f\u4e2d\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u5c06\u4f1a\u9690\u5f0f\u8f6c\u6362\u4e3a\u6307\u5411\u5b83\u7684\u6307\u9488\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8be5\u6307\u9488\u7684\u503c\u662f\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u5185\u5b58\u5730\u5740\u3002\u7c7b\u4f3c\u5730\uff0c\u88ab\u7528\u4e8e\u5bf9\u6307\u9488\u7684\u521d\u59cb\u5316\u65f6\uff0c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u4e5f\u4f1a\u9000\u5316\u4e3a\u6307\u9488\u3002
\u5728\u51fd\u6570\u5185\u4fee\u6539\u5b57\u7b26\u4e32\u65f6\uff0c\u4f20\u5165\u7684\u5b57\u7b26\u6570\u7ec4\u5c06\u4f1a\u9000\u5316\u4e3a\u6307\u9488\uff0c\u6570\u7ec4\u7684\u5927\u5c0f\u4fe1\u606f\u56e0\u6b64\u4e22\u5931\u3002\u53ef\u4ee5\u60f3\u5230\uff0c\u5b57\u7b26\u4e32\u672b\u5c3e\u7684\u7a7a\u5b57\u7b26\u6b63\u662f\u4e3a\u8fd9\u79cd\u60c5\u5f62\u8bbe\u8ba1\u7684\u3002
\u7b80\u5316\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570
\u5173\u4e8e\u5229\u7528\u6307\u9488\u7f16\u5199\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\u7684\u6280\u5de7\uff0c\u4f60\u53ef\u4ee5\u53c2\u8003\u300aC \u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u300b\uff08\u4e5f\u5c31\u662f\u7a0b\u8bbe\u8bfe\u7a0b\u4f7f\u7528\u7684\u8bfe\u672c\uff09\u4e2d\u7ed9\u51fa\u7684 strcpy
\u4e0e strcmp
\u51fd\u6570\u7684\u5b9e\u73b0\u8fed\u4ee3\u3002\u672c\u6587\u5bf9\u6b64\u4e0d\u518d\u8d58\u8ff0\u3002
C \u8bed\u8a00\u6807\u51c6\u5e93\u4e2d\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\uff0c\u5b83\u4eec\u5927\u591a\u88ab\u5b9a\u4e49\u5728 string.h
\u5934\u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528\u65f6\u5747\u9700\u4fdd\u8bc1\u63d0\u4f9b\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u7b26\u5408\u7ea6\u5b9a\u3002
\u4e2d\u6b62\u5b57\u7b26\u7f3a\u5931
\u6807\u51c6\u5e93\u4e2d\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\u901a\u8fc7\u68c0\u67e5\u4e2d\u6b62\u5b57\u7b26\u5224\u65ad\u662f\u5426\u5230\u8fbe\u5b57\u7b26\u4e32\u672b\u5c3e\u3002\u56e0\u6b64\uff0c\u5728\u4fee\u6539\u5b57\u7b26\u4e32\u65f6\u52a1\u5fc5\u6ce8\u610f\u4fdd\u7559\u4e2d\u6b62\u5b57\u7b26\u3002\u5982\u679c\u4e2d\u6b62\u5b57\u7b26\u7f3a\u5931\uff0c\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\u5c06\u4f1a\u5bfc\u81f4\u6570\u7ec4\u8bbf\u95ee\u8d8a\u754c\u95ee\u9898\u3002
"},{"location":"programming/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
- \u4f5c\u4e3a\u53d6\u5740\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\u6570
- \u4f5c\u4e3a
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
"},{"location":"programming_lecture/","title":"\u7a0b\u8bbe\u8f85\u5b66\u8bfe\u7a0b \u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057","text":"\u6b22\u8fce\u6765\u5230\u7afa\u9662\u7a0b\u8bbe\u8f85\u5b66\u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057\u7248\u5757 \ud83e\udd17\u3002\u4f60\u53ef\u4ee5\u5728\u5de6\u4fa7\u5bfc\u822a\u680f\u4e2d\u8be6\u7ec6\u6d4f\u89c8\u672c\u6a21\u5757\u7684\u5185\u5bb9\u3002
"},{"location":"programming_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
- \u7f16\u8bd1\u65f6\u6211\u7684\u4ee3\u7801\u7ecf\u5386\u4e86\u4ec0\u4e48\uff1f\u64cd\u4f5c\u7cfb\u7edf\u5982\u4f55\u8fd0\u884c\u6211\u7684\u7a0b\u5e8f\uff1f\u5982\u4f55\u4f7f\u7528\u8c03\u8bd5\u5668\u5feb\u901f\u5b9a\u4f4d\u9519\u8bef\uff1f
- \u6307\u9488\u7a76\u7adf\u662f\u4ec0\u4e48\uff1f\u5185\u5b58\u4e2d\u7684\u6570\u636e\u662f\u5982\u4f55\u7ec4\u7ec7\u7684\uff1f
- C \u6807\u51c6\u5e93\u4e2d\u7684 I/O \u51fd\u6570\u5982\u4f55\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u4ea4\u4e92\uff1f
- C \u6807\u51c6\u5e93\u662f\u5982\u4f55\u7f16\u5199\u7684\uff1f\u600e\u6837\u5199\u51fa\u5177\u6709\u5de5\u4e1a\u5f3a\u5ea6\u7684\u5065\u58ee\u4ee3\u7801\uff1f
- \u5982\u4f55\u4f7f\u7528\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\uff1f
\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u80fd\u591f\u4e3a\u4f60\u5f00\u542f\u4ece C \u8bed\u8a00\u5230\u8ba1\u7b97\u673a\u79d1\u5b66\u4e0e\u6280\u672f\u7684\u771f\u6b63\u7684\u5927\u95e8\u3002\u5982\u679c\u5bf9\u8bfe\u7a0b\u5185\u5bb9\u6709\u4efb\u4f55\u7591\u95ee\u548c\u5efa\u8bae\uff0c\u6b22\u8fce\u4f60\u8054\u7cfb\u6211\u4eec\u3002\u4f60\u53ef\u4ee5\u5728\u4ed3\u5e93\u4e2d\u53d1\u8d77 issue \u6216\u53d1\u9001\u90ae\u4ef6\u5230 zhubaolin228@gmail.com
\u3002
"},{"location":"programming_lecture/#_3","title":"\u8bfe\u7a0b\u5b89\u6392","text":"2023-2024 \u5b66\u5e74\uff0c\u7a0b\u8bbe\u8f85\u5b66\u7cfb\u7edf\u77e5\u8bc6\u62fe\u9057\u8bfe\u9898\u7ec4\u540c\u5b66\u6709\uff1a
- \u6731\u5b9d\u6797 \u6df7\u5408 2205
- \u674e\u82f1\u7426 \u56fe\u7075 2201
- \u8c22\u96c6 \u6df7\u5408 2206
- \u80e1\u80b2\u73ae \u6df7\u5408 2206
- \u82cf\u715c\u7a0b \u56fe\u7075 2201
- \u5b59\u5146\u6c5f \u6df7\u5408 2204
\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\u653e Bilibili
\u5185\u5bb9\u63d0\u8981 - C \u8bed\u8a00\u7a0b\u5e8f\u57fa\u672c\u7ed3\u6784
- \u7f16\u8bd1\u8fc7\u7a0b\uff1a\u4ece\u6e90\u4ee3\u7801\u5230\u53ef\u6267\u884c\u6587\u4ef6
- \u7f16\u8bd1\u5668\u548c\u5f00\u53d1\u5957\u4ef6\uff1a
gcc
\u3001clang
\u548c llvm
\u7a76\u7adf\u662f\u4ec0\u4e48\uff1f - \u8c03\u8bd5\u5668\uff1a\u5982\u4f55\u4f7f\u7528
gdb
\u6216 lldb
\u8bbe\u7f6e\u65ad\u70b9\u3001\u627e\u5230\u6bb5\u9519\u8bef\u7684\u6839\u6e90\uff1f
\u5982\u4f55\u98df\u7528\u672c\u8bb2\u4e49 \u4f5c\u4e3a\u5728\u7ebf\u8bb2\u4e49\uff0c\u6211\u4f1a\u5c3d\u91cf\u5199\u5f97\u8be6\u7ec6\u4e00\u4e9b\uff0c\u4e3a\u540c\u5b66\u4eec\u63d0\u4f9b\u590d\u4e60\u548c\u8fdb\u4e00\u6b65\u6269\u5c55\u7684\u6307\u5f15\u3002\u56e0\u4e3a\u65f6\u95f4\u6709\u9650\uff0c\u5728\u8bfe\u4e0a\u6211\u65e0\u6cd5\u8986\u76d6\u8bb2\u4e49\u4e2d\u6240\u6709\u7684\u5185\u5bb9\u3002\u540c\u5b66\u4eec\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u4e60\u60ef\u9009\u62e9\u5728\u8bfe\u524d\u8bfe\u540e\u6d4f\u89c8\u672c\u8bb2\u4e49\uff5e
\u672c\u6b21\u8bfe\u7684\u6838\u5fc3\u5185\u5bb9\u4ece\u300c\u7a0b\u5e8f\u7684\u7f16\u8bd1\u8fc7\u7a0b\u300d\u5f00\u59cb\u3002\u524d\u9762\u7684\u5185\u5bb9\u4f5c\u4e3a\u9884\u5907\u77e5\u8bc6\uff0c\u5728\u8bfe\u4e0a\u5c06\u4f1a\u5feb\u901f\u5e26\u8fc7\u3002
"},{"location":"programming_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
- \u8ba1\u7b97\u673a\u662f\u5982\u4f55\u8bfb\u61c2\u6211\u5199\u7684\u4ee3\u7801\u7684\uff1f
- \u6211\u7684\u7a0b\u5e8f\u603b\u662f\u51fa\u95ee\u9898\uff0c\u6211\u8be5\u5982\u4f55\u5feb\u901f\u627e\u5230\u9519\u8bef\u7684\u6839\u6e90\uff1f
\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 \u80fd\u8bfb\u61c2\u4ec0\u4e48\uff1f
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 \u90fd\u505a\u4e9b\u4ec0\u4e48\uff1f
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\u5b50 c = a + b;\n
add $t0, $t1, $t2\n
01 2a 40 20\n
void multstore(long x, long y, long *dest) {\n long t = mult2(x, y);\n *dest = t;\n}\n
multstore:\n pushq %rbx\n movq %rdx, %rbx\n call mult2\n movq %rax, (%rbx)\n popq %rbx\n ret\n
53 48 89 d3 48 83 ec 08 e8 00 00 00 00 48 89 03 5b c3\n
\u4e3a\u4ec0\u4e48\u9700\u8981\u9ad8\u7ea7\u8bed\u8a00\uff1f - \u673a\u5668\u8bed\u8a00\u548c\u6c47\u7f16\u8bed\u8a00\u90fd\u662f\u975e\u5e38\u5e95\u5c42\u7684\u8bed\u8a00\uff0c\u7a0b\u5e8f\u5458\u9700\u8981\u5173\u6ce8\u8ba1\u7b97\u673a\u7684\u7ec6\u8282\uff0c\u8fd9\u4f7f\u5f97\u7a0b\u5e8f\u7684\u53ef\u8bfb\u6027\u5f88\u5dee\u3002\u4f7f\u7528\u9ad8\u7ea7\u8bed\u8a00\uff0c\u7a0b\u5e8f\u5458\u80fd\u5c06\u6ce8\u610f\u529b\u8f6c\u79fb\u5230\u8981\u89e3\u51b3\u7684\u95ee\u9898\u4e0a\u6765\u3002
- \u673a\u5668\u8bed\u8a00\u548c\u6c47\u7f16\u8bed\u8a00\u90fd\u662f\u4e0e\u5177\u4f53 CPU \u76f8\u5173\u7684\uff0c\u7a0b\u5e8f\u5458\u9700\u8981\u4e3a\u4e0d\u540c\u7684 CPU \u7f16\u5199\u4e0d\u540c\u7684\u7a0b\u5e8f\uff0c\u53ef\u79fb\u690d\u6027\u5dee\u3002\u4f7f\u7528\u9ad8\u7ea7\u8bed\u8a00\uff0c\u7a0b\u5e8f\u5458\u53ea\u9700\u8981\u5199\u4e00\u6b21\u7a0b\u5e8f\uff0c\u518d\u4f7f\u7528\u7f16\u8bd1\u5668\u5c31\u80fd\u5c06\u5176\u7ffb\u8bd1\u6210\u80fd\u5728\u7279\u5b9a CPU \u7684\u673a\u5668\u8bed\u8a00\u3002
\u524d\u77bb\uff1a\u7b2c\u56db\u4ee3\u548c\u7b2c\u4e94\u4ee3\u7f16\u7a0b\u8bed\u8a00 \u7f16\u7a0b\u8bed\u8a00\u4ecd\u5728\u53d1\u5c55\u6f14\u5316\u3002\u76ee\u524d\u5df2\u7ecf\u6709\u4e86\u7b2c\u56db\u4ee3\u548c\u7b2c\u4e94\u4ee3\u7f16\u7a0b\u8bed\u8a00\u7684\u6982\u5ff5\u3002\u7b2c\u4e09\u4ee3\u7684\u7f16\u7a0b\u8bed\u8a00\u867d\u7136\u662f\u7528\u8bed\u53e5\u7f16\u7a0b\u800c\u4e0d\u76f4\u63a5\u7528\u6307\u4ee4\u7f16\u7a0b\uff0c\u4f46\u8bed\u53e5\u4e5f\u5206\u4e3a\u8f93\u5165\u3001\u8f93\u51fa\u3001\u57fa\u672c\u8fd0\u7b97\u3001\u6d4b\u8bd5\u5206\u652f\u548c\u5faa\u73af\u7b49\u51e0\u79cd\uff0c\u548c\u6307\u4ee4\u6709\u76f4\u63a5\u7684\u5bf9\u5e94\u5173\u7cfb\u3002\u800c\u7b2c\u56db\u4ee3\u4ee5\u540e\u7684\u7f16\u7a0b\u8bed\u8a00\u66f4\u591a\u662f\u63cf\u8ff0\u8981\u505a\u4ec0\u4e48\uff08Declarative\uff09\u800c\u4e0d\u63cf\u8ff0\u5177\u4f53\u4e00\u6b65\u4e00\u6b65\u600e\u4e48\u505a\uff08Imperative\uff09\uff0c\u5177\u4f53\u4e00\u6b65\u4e00\u6b65\u600e\u4e48\u505a\u5b8c\u5168\u7531\u7f16\u8bd1\u5668\u6216\u89e3\u91ca\u5668\u51b3\u5b9a\uff0c\u4f8b\u5982SQL\u8bed\u8a00\uff08SQL\uff0cStructured Query Language\uff0c\u7ed3\u6784\u5316\u67e5\u8be2\u8bed\u8a00\uff09\u5c31\u662f\u8fd9\u6837\u7684\u4f8b\u5b50\u3002
\u5bf9\u673a\u5668\u8bed\u8a00\u6709\u5174\u8da3\uff1f \u8fd9\u91cc\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5c06\u6c47\u7f16\u8bed\u8a00\u8f6c\u6362\u4e3a MIPS \u6307\u4ee4\u96c6\u673a\u5668\u8bed\u8a00\u7684\u57fa\u7840\u4f8b\u5b50\uff0c\u6709\u5174\u8da3\u53ef\u4ee5\u4e86\u89e3\u4e00\u4e0b\u3002
"},{"location":"programming_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
- \u8f93\u5165\uff08Input\uff09\uff1a\u4ece\u952e\u76d8\u3001\u6587\u4ef6\u6216\u8005\u5176\u5b83\u8bbe\u5907\u83b7\u53d6\u6570\u636e\u3002
- \u8f93\u51fa\uff08Output\uff09\uff1a\u628a\u6570\u636e\u663e\u793a\u5230\u5c4f\u5e55\uff0c\u6216\u8005\u5b58\u5165\u4e00\u4e2a\u6587\u4ef6\uff0c\u6216\u8005\u53d1\u9001\u5230\u5176\u5b83\u8bbe\u5907\u3002
- \u57fa\u672c\u8fd0\u7b97\uff1a\u6267\u884c\u6700\u57fa\u672c\u7684\u6570\u5b66\u8fd0\u7b97\uff08\u52a0\u51cf\u4e58\u9664\uff09\u548c\u6570\u636e\u5b58\u53d6\u3002
- \u6d4b\u8bd5\u548c\u5206\u652f\uff1a\u6d4b\u8bd5\u67d0\u4e2a\u6761\u4ef6\uff0c\u7136\u540e\u6839\u636e\u4e0d\u540c\u7684\u6d4b\u8bd5\u7ed3\u679c\u6267\u884c\u4e0d\u540c\u7684\u540e\u7eed\u6307\u4ee4\u3002
- \u5faa\u73af\uff1a\u91cd\u590d\u6267\u884c\u4e00\u7cfb\u5217\u64cd\u4f5c\u3002
\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
- \u7b49\u4ef7\u4e8e
(a--) - b
\u3002\u6309\u7167\u8d2a\u5fc3\u6cd5\uff0c\u7f16\u8bd1\u5668\u8bfb\u5165\u4e24\u4e2a\u8fde\u7eed\u7684 -
\u53f7\u540e\uff0c\u5df2\u7ecf\u4e0d\u53ef\u80fd\u518d\u7ec4\u6210\u4e00\u4e2a\u6709\u610f\u4e49\u7684\u7b26\u53f7\uff0c\u56e0\u6b64\u8fd9\u4e2a\u7b26\u53f7\u88ab\u786e\u5b9a\u4e3a\u540e\u7f00\u9012\u51cf\u8fd0\u7b97\u7b26\u3002\u63a5\u7740\u8bfb\u53d6\u4e0b\u4e00\u4e2a\u7b26\u53f7\u3002 - \u7b49\u4ef7\u4e8e
(a--) - b
- \u7b49\u4ef7\u4e8e
a - (--b)
- \u7b49\u4ef7\u4e8e
y = x
\u3002/*
\u88ab\u8d2a\u5fc3\u6cd5\u89e3\u91ca\u4e3a\u6ce8\u91ca\u7684\u5f00\u5934\u3002 - \u7b49\u4ef7\u4e8e
y = x / (*p)
- \u7b49\u4ef7\u4e8e
(n--) > 0
- \u7b49\u4ef7\u4e8e
(n--) > 0
- \u7b49\u4ef7\u4e8e
(n-) -> 0
\u3002\u8fd9\u662f\u4e00\u4e2a\u65e0\u6548\u7684\u8bed\u53e5\uff0cn-
\u672c\u8eab\u4e0d\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u8868\u8fbe\u5f0f\uff0c\u4e5f\u65e0\u6cd5\u7528\u4f5c ->
\u7684\u64cd\u4f5c\u6570\u3002 - \u7b49\u4ef7\u4e8e
((a++)++) + b
\u3002\u8bf7\u601d\u8003\u4e00\u4e0b\uff0c\u8fd9\u4e2a\u8bed\u53e5\u6709\u6548\u5417\uff1f
\u8bed\u6cd5\uff1a\u6807\u8bc6\u7b26\u3001\u8868\u8fbe\u5f0f\u548c\u8bed\u53e5 \u4e3a\u4e86\u4fbf\u4e8e\u521d\u5b66\u8005\u7406\u89e3\uff0c\u6211\u4eec\u91c7\u7528\u4e00\u5957\u7b80\u5316\u7684\u8bed\u6cd5\u89c4\u5219\uff1a
- \u6807\u8bc6\u7b26\uff08Identifier\uff09\uff1a\u5c31\u662f\u300c\u540d\u5b57\u300d\uff0c\u7528\u4e8e\u6307\u4ee3\u5404\u79cd\u5b9e\u4f53\uff0c\u6bd4\u5982\uff1a\u5bf9\u8c61\u3001\u7c7b\u578b\u3001\u51fd\u6570\u3001\u6807\u7b7e\u3001\u5b8f\u7b49\u7b49\u3002
\u5bf9\u8c61\u7684\u4e0d\u540c\u542b\u4e49 \u5728\u8fd9\u91cc\uff0c\u5bf9\u8c61\uff08Object\uff09\u7684\u542b\u4e49\u4e0e C++ \u4e2d\u4e0d\u540c\u3002\u8fd9\u91cc\u7684\u5bf9\u8c61\u6307\u6570\u636e\u5b58\u50a8\u7684\u4e00\u4e2a\u533a\u57df\uff0c\u5176\u5185\u5bb9\u53ef\u4ee5\u8868\u793a\u503c\u3002\u6bd4\u5982\u4e0b\u9762\u7684\u8bed\u53e5\u521b\u5efa\u4e86\u4e00\u4e2a\u5bf9\u8c61\uff1a
int a;\n
\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u7684\u610f\u601d\u5c31\u662f\u5206\u914d\u4e86\u4e00\u5757\u5b58\u50a8\u7a7a\u95f4\u3002\u6807\u8bc6\u7b26 a
\u7528\u4e8e\u6307\u4ee3\u8fd9\u4e2a\u5bf9\u8c61\u3002\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u6709\u5927\u5c0f\u3001\u751f\u5b58\u671f\u3001\u5b58\u50a8\u5668\u3001\u503c\u7b49\u5c5e\u6027\uff0c\u6211\u4eec\u5c06\u5728\u4e0b\u8282\u8bfe\u8be6\u7ec6\u5c55\u5f00\u3002
- \u8868\u8fbe\u5f0f\uff08Expression\uff09\uff1a\u7531\u8fd0\u7b97\u7b26\uff08
+-*/%
\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
- CPPReference\uff1a\u6807\u8bc6\u7b26
- CPPReference\uff1a\u8868\u8fbe\u5f0f
- CPPReference: \u8bed\u53e5
\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
- \u51fd\u6570\u540d\uff1a\u51fd\u6570\u7684\u540d\u5b57\uff0c\u7528\u6765\u8c03\u7528\u51fd\u6570\u3002
- \u51fd\u6570\u540d\u4e0e\u53d8\u91cf\u540d\u7684\u547d\u540d\u89c4\u5219\u76f8\u540c\u3002
- \u53c2\u6570\uff1a\u51fd\u6570\u7684\u8f93\u5165\uff0c\u53ef\u4ee5\u6709\u591a\u4e2a\u3002
- \u8fd4\u56de\u503c\uff1a\u51fd\u6570\u7684\u8f93\u51fa\uff0c\u53ea\u80fd\u6709\u4e00\u4e2a\u3002
\u4e0b\u9762\u8fd9\u884c\u8bed\u53e5\u88ab\u79f0\u4e3a\u51fd\u6570\u7b7e\u540d\uff08Function Signature\uff09\u6216\u51fd\u6570\u539f\u578b\uff08Function Prototype\uff09\u3002\u5b83\u7ed9\u51fa\u4e86\u51fd\u6570\u5bf9\u5916\u7684\u4e00\u5207\u4fe1\u606f\uff1a
int MyFunc(int a, int b);\n
\u4ece\u91cc\u9762\u770b\uff0c\u51fd\u6570\u662f\u4e00\u7ec4\u6307\u4ee4\u7684\u96c6\u5408\uff0c\u5b83\u4eec\u6309\u7167\u4e00\u5b9a\u7684\u987a\u5e8f\u6267\u884c\uff0c\u5b8c\u6210\u67d0\u4e2a\u7279\u5b9a\u7684\u529f\u80fd\u3002
\u5f53\u6211\u4eec\u8c03\u7528\u4e00\u4e2a\u51fd\u6570\u65f6\uff0c\u6211\u4eec\u5e94\u5f53\u6309\u7167\u51fd\u6570\u7b7e\u540d\u4e2d\u7684\u8981\u6c42\u4f20\u5165\u53c2\u6570\uff0c\u5e76\u53ef\u4ee5\u83b7\u5f97\u5b83\u7684\u8fd4\u56de\u503c\u3002\u5728\u51fd\u6570\u7b7e\u540d\u7684\u8bed\u5883\u4e0b\uff0cvoid
\u8868\u793a\u7a7a\uff0c\u5373\u4e0d\u5b58\u5728\u3002\u4e0b\u9762\u7684\u8fd9\u4e2a\u51fd\u6570\u6ca1\u6709\u53c2\u6570\uff0c\u4e5f\u6ca1\u6709\u8fd4\u56de\u503c\u3002
void MyFunc(void);\n
\u56e0\u4e3a\u6211\u4eec\u6bd4\u8f83\u5173\u5fc3\u51fd\u6570\u8fd4\u56de\u503c\u7684\u7c7b\u578b\uff0c\u6709\u65f6\u4f1a\u628a\u51fd\u6570\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u79f0\u4e3a\u8fd9\u4e2a\u51fd\u6570\u7684\u201c\u7c7b\u578b\u201d\uff0c\u6bd4\u5982\u4f1a\u8bf4 MyFunc
\u8fd9\u4e2a\u51fd\u6570\u662f\u4e00\u4e2a void
\u51fd\u6570\u3002
\u5173\u4e8e void
Q\uff1avoid
\u5230\u5e95\u6709\u54ea\u4e9b\u542b\u4e49\uff1f
A: \u4e0b\u9762\u662f void
\u7684\u4e00\u822c\u7528\u6cd5
void
\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\uff0c\u8868\u793a\u51fd\u6570\u4e0d\u63a5\u53d7\u53c2\u6570\u3002 void
\u4f5c\u4e3a\u51fd\u6570\u8fd4\u56de\u503c\uff0c\u8868\u793a\u51fd\u6570\u4e0d\u8fd4\u56de\u503c\u3002 void*
\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
- \u8fd4\u56de\u503c\uff1a\u51fd\u6570\u8c03\u7528\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0c\u5b83\u7684\u503c\u5c31\u662f\u51fd\u6570\u7684\u8fd4\u56de\u503c\u3002
- \u526f\u4f5c\u7528\uff1a\u9664\u4e86\u8fd4\u56de\u503c\u4ee5\u5916\u7684\u529f\u80fd\u7edf\u79f0\u4e3a\u526f\u4f5c\u7528\u3002
\u4e00\u4e9b\u4f8b\u5b50\uff1a
\u51fd\u6570\u7b7e\u540d \u8fd4\u56de\u503c\u7684\u542b\u4e49 \u526f\u4f5c\u7528 int printf(const char *format, ...);
\u6253\u5370\u7684\u5b57\u7b26\u6570 \u6253\u5370\u5b57\u7b26\u4e32\u5230\u6807\u51c6\u8f93\u51fa int scanf(const char *format, ...);
\u8bfb\u53d6\u7684\u5b57\u7b26\u6570 \u4ece\u6807\u51c6\u8f93\u5165\u8bfb\u53d6\u5b57\u7b26\u4e32 int rand(void);
\u751f\u6210\u7684\u968f\u673a\u6570 \u65e0 void exit(int status);
\u65e0 \u9000\u51fa\u7a0b\u5e8f \u6bcf\u4e2a C \u8bed\u8a00\u7a0b\u5e8f\u90fd\u5fc5\u987b\u5305\u542b\u4e00\u4e2a main
\u51fd\u6570\uff0c\u5b83\u662f\u7a0b\u5e8f\u7684\u5165\u53e3\u3002main
\u7684\u51fd\u6570\u7b7e\u540d\u4e00\u822c\u662f\u8fd9\u6837\u7684\uff1a
int main(void);\nint main(int argc, char *argv[]); //\u4ee5\u540e\u5b66\u547d\u4ee4\u884c\u53c2\u6570\u5c31\u4f1a\u7528\u5230\u8fd9\u79cd\u5f62\u5f0f\n
main
\u7684\u8c03\u7528\u8005\u662f\u64cd\u4f5c\u7cfb\u7edf\u3002\u64cd\u4f5c\u7cfb\u7edf\u770b\u5230 main
\u7684\u7b7e\u540d\u4e2d\u8bf4\u8fd4\u56de\u503c\u4e3a int
\uff0c\u56e0\u6b64\u7cfb\u7edf\u4f1a\u7b49\u5f85 main
\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u3002\u8fd9\u4e2a\u6574\u6570\u4e00\u822c\u88ab\u7528\u4e8e\u544a\u77e5\u64cd\u4f5c\u7cfb\u7edf\u7a0b\u5e8f\u7684\u6267\u884c\u72b6\u6001\uff0c0
\u8868\u793a\u6b63\u5e38\u7ed3\u675f\uff0c\u5176\u4ed6\u503c\u53ef\u4ee5\u4f20\u9012\u5176\u4ed6\u4fe1\u606f\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48 main
\u7684\u672b\u5c3e\u5e94\u5f53\u5199 return 0
\u3002\u5982\u679c main
\u51fd\u6570\u4e2d\u6ca1\u6709 return
\u8bed\u53e5\uff0c\u6709\u4e9b\u7f16\u8bd1\u5668\u4f1a\u4e3a\u4f60\u8865\u5168\uff08\u5176\u4ed6\u51fd\u6570\u4e0d\u4f1a\uff09\u3002\u4f46\u8bf7\u8bb0\u5f97\u5199\u4e0a\uff0c\u8fd9\u662f\u4f60\u7684\u8d23\u4efb\u3002
\u6ca1\u6709\u8fd4\u56de\u503c\u7684\u51fd\u6570\u4e5f\u53ef\u4ee5\u4f7f\u7528 return
\u8bed\u53e5\uff0c\u6b64\u65f6\u5b83\u6ca1\u6709\u8fd4\u56de\u503c\u7684\u4f5c\u7528\uff0c\u800c\u662f\u7ed3\u675f\u5f53\u524d\u51fd\u6570\u7684\u6267\u884c\u5e76\u8fd4\u56de\u3002\u4f8b\u5b50\uff1a
void print_logarithm(double x)\n{\n if (x <= 0.0) {\n printf(\"Positive numbers only, please.\\n\");\n return;\n }\n printf(\"The log of x is %f\", log(x));\n}\n
\u5176\u4ed6\u5efa\u8bae \u6bcf\u4e2a\u51fd\u6570\u90fd\u5e94\u8be5\u8bbe\u8ba1\u5f97\u5c3d\u53ef\u80fd\u7b80\u5355\uff0c\u7b80\u5355\u7684\u51fd\u6570\u624d\u5bb9\u6613\u7ef4\u62a4\u3002\u5e94\u9075\u5faa\u4ee5\u4e0b\u539f\u5219\uff1a
-
\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
\u6269\u5c55\uff1a\u7f16\u8bd1\u548c\u89e3\u91ca \u7b80\u5355\u4e86\u89e3\u4e00\u4e0b\u5c31\u597d\u3002
\u5c06\u9ad8\u7ea7\u8bed\u8a00\u7f16\u5199\u7684\u6e90\u4ee3\u7801\u8f6c\u5316\u6210\u673a\u5668\u8bed\u8a00\u7684\u76ee\u6807\u7a0b\u5e8f\u7684\u8fc7\u7a0b\u7edf\u79f0\u4e3a\u7ffb\u8bd1\uff08Translation\uff09\u3002\u7ffb\u8bd1\u7684\u65b9\u5f0f\u6709\u4e24\u79cd\uff1a\u7f16\u8bd1\uff08Compile\uff09\u548c\u89e3\u91ca\uff08Interpret\uff09\u3002\u7f16\u8bd1\u5c06\u6574\u4e2a\u7a0b\u5e8f\u7ffb\u8bd1\u6210\u673a\u5668\u8bed\u8a00\uff0c\u89e3\u91ca\u5219\u662f\u8fb9\u7ffb\u8bd1\u8fb9\u6267\u884c\u3002
C \u8bed\u8a00\u662f\u5178\u578b\u7684\u7f16\u8bd1\u578b\u8bed\u8a00\uff0c\u6e90\u4ee3\u7801\u9700\u8981\u7ecf\u8fc7\u7f16\u8bd1\u540e\u624d\u80fd\u8fd0\u884c\uff0c\u800c\u7f16\u8bd1\u9636\u6bb5\u5e76\u4e0d\u4f1a\u6267\u884c\u7a0b\u5e8f\u3002Python \u5219\u662f\u5178\u578b\u7684\u89e3\u91ca\u578b\u8bed\u8a00\uff0c\u9010\u53e5\u6267\u884c\u6e90\u4ee3\u7801\uff0c\u4e0d\u9700\u8981\u4ea7\u751f\u53ef\u6267\u884c\u6587\u4ef6\u3002
\u8fd9\u4e9b\u63cf\u8ff0\u7684\u90fd\u662f\u4e00\u79cd\u8bed\u8a00\u7684\u5178\u578b\u7528\u6cd5\u3002\u4e8b\u5b9e\u4e0a C \u8bed\u8a00\u4e5f\u5f00\u53d1\u51fa\u4e86\u76f8\u5e94\u7684\u89e3\u91ca\u5668\uff0cPython \u4e5f\u5f00\u53d1\u51fa\u4e86\u76f8\u5e94\u7684\u7f16\u8bd1\u5668\u3002\u4e24\u79cd\u7ffb\u8bd1\u65b9\u5f0f\u5404\u6709\u4f18\u52a3\u3002
"},{"location":"programming_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\u6811 printf(\"%d:%d is %d minutes after 00:00\\n\", hour, minute, hour * 60 + minute);\n
\u7f16\u8bd1\u5668\u5728\u7ffb\u8bd1\u8fd9\u6761\u8bed\u53e5\u65f6\uff0c\u9996\u5148\u6839\u636e\u4e0a\u8ff0\u8bed\u6cd5\u89c4\u5219\u628a\u8fd9\u4e2a\u8bed\u53e5\u89e3\u6790\u6210\u4e0b\u56fe\u6240\u793a\u7684\u8bed\u6cd5\u6811\uff0c\u7136\u540e\u518d\u6839\u636e\u8bed\u6cd5\u6811\u751f\u6210\u76f8\u5e94\u7684\u6307\u4ee4\u3002\u8bed\u6cd5\u6811\u7684\u672b\u7aef\u7684\u662f\u4e00\u4e2a\u4e2aToken\uff0c\u6bcf\u4e00\u6b65\u5c55\u5f00\u5229\u7528\u4e00\u6761\u8bed\u6cd5\u89c4\u5219\u3002
\u7406\u89e3\u7ec4\u5408\uff08Composition\uff09\u89c4\u5219\u662f\u7406\u89e3\u8bed\u6cd5\u89c4\u5219\u7684\u5173\u952e\u6240\u5728\uff0c\u6b63\u56e0\u4e3a\u53ef\u4ee5\u6839\u636e\u8bed\u6cd5\u89c4\u5219\u4efb\u610f\u7ec4\u5408\uff0c\u6211\u4eec\u624d\u53ef\u4ee5\u7528\u7b80\u5355\u7684\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u8868\u8fbe\u5f0f\u3001\u8bed\u53e5\u642d\u5efa\u51fa\u4efb\u610f\u590d\u6742\u7684\u7a0b\u5e8f\uff0c\u4ee5\u540e\u6211\u4eec\u5b66\u4e60\u65b0\u7684\u8bed\u6cd5\u89c4\u5219\u65f6\u4f1a\u8fdb\u4e00\u6b65\u4f53\u4f1a\u5230\u8fd9\u4e00\u70b9\u3002\u4ece\u4e0a\u9762\u7684\u4f8b\u5b50\u53ef\u4ee5\u770b\u51fa\uff0c\u8868\u8fbe\u5f0f\u4e0d\u5b9c\u8fc7\u5ea6\u7ec4\u5408\uff0c\u5426\u5219\u4f1a\u7ed9\u9605\u8bfb\u548c\u8c03\u8bd5\u5e26\u6765\u56f0\u96be\u3002
\u8868\u8fbe\u5f0f\u4e0d\u5b9c\u8fc7\u5ea6\u7ec4\u5408 \u8fd9\u6d89\u53ca\u4ee3\u7801\u53ef\u8bfb\u6027\u95ee\u9898\u3002\u770b\u770b\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\uff1a
double distance(double x1, double y1, double x2, double y2)\n{\n return sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));\n}\n
\u8fd9\u6837\u5199\u5f88\u7b80\u6d01\uff0c\u4f46\u5982\u679c\u5199\u9519\u4e86\u5462\uff1f\u53ea\u77e5\u9053\u662f\u8fd9\u4e00\u957f\u4e32\u8868\u8fbe\u5f0f\u6709\u9519\uff0c\u6839\u672c\u4e0d\u77e5\u9053\u9519\u5728\u54ea\uff0c\u800c\u4e14\u6574\u4e2a\u51fd\u6570\u5c31\u4e00\u4e2a\u8bed\u53e5\uff0c\u63d2printf\u90fd\u6ca1\u5730\u65b9\u63d2\u3002\u6240\u4ee5\u7528\u4e34\u65f6\u53d8\u91cf\u6709\u5b83\u7684\u597d\u5904\uff0c\u4f7f\u7a0b\u5e8f\u66f4\u6e05\u6670\uff0c\u8c03\u8bd5\u66f4\u65b9\u4fbf\uff0c\u800c\u4e14\u6709\u65f6\u5019\u53ef\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\uff0c\u4f8b\u5982\u4e0a\u9762\u8fd9\u4e00\u884c\u8868\u8fbe\u5f0f\u8981\u628a(x2-x1)\u8ba1\u7b97\u4e24\u904d\uff0c\u5982\u679c\u7b97\u5b8c(x2-x1)\u628a\u7ed3\u679c\u5b58\u5728\u4e00\u4e2a\u4e34\u65f6\u53d8\u91cfdx\u91cc\uff0c\u5c31\u4e0d\u9700\u8981\u518d\u7b97\u7b2c\u4e8c\u904d\u4e86\uff08\u867d\u7136\u8fd9\u4e9b\u4f18\u5316\u73b0\u4ee3\u7f16\u8bd1\u5668\u90fd\u4f1a\u66ff\u4f60\u81ea\u52a8\u5b8c\u6210\uff09\u3002\u4e0b\u9762\u8fd9\u4e2a\u7248\u672c\u662f\u53ef\u8bfb\u6027\u9ad8\u7684\u4ee3\u7801\uff1a
double distance(double x1, double y1, double x2, double y2)\n{\n double dx = x2 - x1;\n double dy = y2 - y1;\n double dsquared = dx * dx + dy * dy;\n double result = sqrt(dsquared);\n\n return result;\n}\n
\u7801\u98ce\u4e0d\u662f\u6b7b\u7684\uff0c\u8bf7\u540c\u5b66\u4eec\u89c6\u60c5\u51b5\u5207\u6362\u7801\u98ce\u3002
"},{"location":"programming_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
- \u8003\u8bd5\u662f\u5168\u82f1\u6587\u3002\u5982\u679c\u5e73\u5e38\u4e0d\u592a\u770b\u82f1\u6587\u6587\u6863/\u6ca1\u600e\u4e48\u5b66/\u82f1\u8bed\u5f88\u5dee\u7684\u540c\u5b66\uff0c\u81f3\u5c11\u4f60\u8003\u524d\u505a\u5386\u5e74\u5377\u7684\u65f6\u5019\u8981\u628a\u751f\u8bcd\u5168\u90e8\u6284\u4e0b\u6765\u8bb0\u4e00\u904d\u3002
- \u4e00\u5b9a\u4e00\u5b9a\u4e00\u5b9a\u8981\u505a\u5386\u5e74\u5377\u3002\u4e0d\u8981\u4ee5\u4e3a\u81ea\u5df1\u4f1a\u5199\u70b9\u4ee3\u7801\u5c31\u80fd\u5e94\u4ed8\u8003\u8bd5\u4e86\uff0c\u5176\u5b9e\u8003\u8bd5\u548c\u4f60\u5199\u4ee3\u7801\u6c34\u5e73\u5e76\u4e0d\u5448\u6b63\u76f8\u5173\u3002\u8003\u8bd5\u7684\u9898\u76ee\u90fd\u662f\u5f88\u7ec6\u8282\u7684\uff0c\u5f88\u591a\u90fd\u662f\u4f60\u5e73\u5e38\u4e0d\u4f1a\u6ce8\u610f\u5230\u7684\uff0c\u6240\u4ee5\u4e00\u5b9a\u8981\u505a\u5386\u5e74\u5377\uff0c\u505a\u5b8c\u4e86\u8fd8\u8981\u770b\u770b\u7b54\u6848\uff0c\u770b\u770b\u81ea\u5df1\u54ea\u91cc\u505a\u9519\u4e86\uff0c\u54ea\u91cc\u6ca1\u6ce8\u610f\u5230\u3002\u8fd9\u91cc\u5c55\u793a\u4e00\u4e2a\u53bb\u5e74 C \u5c0f\u8003\u8bd5\u5e72\u788e\u4e00\u7247\u4eba\u7684\u9009\u62e9\u9898\uff1a
\u5e72\u788e\u4e00\u7247\u4eba\u7684\u9009\u62e9\u9898 Suppose T
is a type name and t
is a variable of type T
. Which of the following is NOT a valid expression?
A. sizeof(T)
B. sizeof(t)
C. sizeof T
D. sizeof t
\u7b54\u6848 \u7b54\u6848\u662f C\uff0c\u4e0d\u77e5\u9053\u4f60\u731c\u5bf9\u4e86\u5417\uff1f
\u5927\u5bb6\u4e00\u822c\u5199\u4ee3\u7801 sizeof
\u540e\u9762\u90fd\u4f1a\u52a0\u62ec\u53f7\u7684\u5bf9\u5427\uff0c\u4f46\u4f60\u77e5\u9053\u4e3a\u4ec0\u4e48\u5417\uff1f\u60f3\u8981\u77e5\u9053\u4e3a\u4ec0\u4e48\uff0c\u9700\u8981\u56de\u987e\u524d\u9762\u5b66\u4e60\u7684\u8bed\u6cd5\u77e5\u8bc6\u3002
sizeof
\u662f\u4e00\u4e2a\u8fd0\u7b97\u7b26\uff0c\u5b83\u6709\u4e24\u79cd\u4f7f\u7528\u65b9\u5f0f\uff1a
sizeof(\u7c7b\u578b)\nsizeof \u8868\u8fbe\u5f0f\n
\u6211\u4eec\u77e5\u9053\uff0ct
\u662f\u8868\u8fbe\u5f0f\uff0c(t)
\u4e5f\u662f\u8868\u8fbe\u5f0f\u3002sizeof(T)
\u7684\u4f7f\u7528\u7b26\u5408\u89c4\u8303\u3002\u56e0\u6b64 A\u3001B\u3001D \u90fd\u662f\u6b63\u786e\u7684\u3002\u4e3a\u4ec0\u4e48\u4e0d\u89c4\u5b9a sizeof \u7c7b\u578b
\u7684\u7528\u6cd5\u5462\uff1f\u56e0\u4e3a\u8fd9\u53ef\u80fd\u5f15\u8d77\u6b67\u4e49\uff0c\u6709\u4e9b\u7c7b\u578b\u540d\u5c31\u643a\u5e26\u7a7a\u683c\uff0c\u6bd4\u5982\uff1ashort int
\u3001struct node
\u7b49\u7b49\u3002\u4e86\u89e3\u4e86\u8fd9\u4e9b\u77e5\u8bc6\uff0c\u4f60\u80fd\u8bf4\u8bf4\u4e0b\u9762\u7684\u8bed\u53e5\u662f\u5426\u5408\u6cd5\u5417\uff1f\u5982\u679c\u5408\u6cd5\uff0c\u4f60\u80fd\u89e3\u91ca\u5b83\u7684\u542b\u4e49\u5417\uff1f\u5982\u679c\u4e0d\u89c4\u5b9a\u7c7b\u578b\u5fc5\u987b\u5e26\u62ec\u53f7\uff0c\u53ef\u80fd\u4f1a\u4ea7\u751f\u54ea\u4e9b\u4e8c\u4e49\u6027\uff1f
sizeof int***p\nsizeof(int)*p\nsizeof int * + 1\n
\u5982\u679c\u4f60\u60f3\u7684\u8bdd\uff0c\u53ef\u4ee5\u518d\u6765\u4e24\u9053\uff1a
C \u5927 16 \u5e74\u9009\u62e9\u9898 In the following notations, _____ can express a character constant( \u5b57\u7b26\u5e38\u91cf ) correctly.
A. '\\x100'
B. 125
C. '\\08'
D. '\\'
\u7b54\u6848 B
"},{"location":"programming_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
- \u9884\u5904\u7406\uff1a\u7531 C \u9884\u5904\u7406\u5668\uff08C Preprocessor\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u6e90\u4ee3\u7801\u4e2d\u7684\u5b8f\u5b9a\u4e49\u5c55\u5f00\uff0c\u5c06\u5934\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u63d2\u5165\u5230\u6e90\u4ee3\u7801\u4e2d\uff0c\u5220\u9664\u6ce8\u91ca\u7b49\u3002\u9884\u5904\u7406\u540e\u7684\u4ee3\u7801\u6587\u4ef6\u4ee5
.i
\u4e3a\u540e\u7f00\u3002 - \u7f16\u8bd1\uff1a\u7531 C \u7f16\u8bd1\u5668\uff08C Compiler\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u9884\u5904\u7406\u540e\u7684\u6587\u4ef6\u7ffb\u8bd1\u6210\u6c47\u7f16\u8bed\u8a00\u3002\u7f16\u8bd1\u540e\u5f97\u5230\u7684\u6c47\u7f16\u4ee3\u7801\u6587\u4ef6\u4ee5
.s
\u4e3a\u540e\u7f00\u3002 - \u6c47\u7f16\uff1a\u7531\u6c47\u7f16\u5668\uff08Assembler\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u6c47\u7f16\u4ee3\u7801\u7ffb\u8bd1\u6210\u673a\u5668\u8bed\u8a00\u3002\u6c47\u7f16\u540e\u5f97\u5230\u7684\u673a\u5668\u4ee3\u7801\u6587\u4ef6\u4ee5
.o
\u4e3a\u540e\u7f00\u3002 - \u94fe\u63a5\uff1a\u7531\u94fe\u63a5\u5668\uff08Linker\uff09\u5b8c\u6210\uff0c\u5b83\u5c06\u591a\u4e2a\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u94fe\u63a5\u540e\u5f97\u5230\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4ee5
.exe
\u4e3a\u540e\u7f00\u3002
"},{"location":"programming_lecture/lecture1/lecture1/#gcc","title":"\u89e3\u8bfb gcc
\u663e\u793a\u7684\u8be6\u7ec6\u4fe1\u606f","text":"\u4e0b\u9762\u8fd9\u4e9b\u6587\u672c\u662f gcc -v -o prog main.c sum.c
\u547d\u4ee4\u7684\u8f93\u51fa\u7ed3\u679c\u3002
gcc \u7684\u8f93\u51fa\u4fe1\u606f \u70b9\u51fb\u6587\u672c\u4e2d\u5e26\u5706\u5708\u7684 +
\u53f7\u53ef\u4ee5\u5c55\u5f00\u8be6\u7ec6\u4fe1\u606f\uff0c\u9ad8\u4eae\u7684\u884c\u662f\u8fd0\u884c\u67d0\u4e2a\u7f16\u8bd1\u5de5\u5177\u7684\u5177\u4f53\u547d\u4ee4\u3002
<!--(1)!-->Using built-in specs.\nCOLLECT_GCC=gcc\nCOLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper\nOFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa\nOFFLOAD_TARGET_DEFAULT=1\nTarget: x86_64-linux-gnu\nConfigured with: ../src/configure -v --with-pkgversion='Ubuntu 12.3.0-1ubuntu1~23.04' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-12-DAPbBt/gcc-12-12.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-DAPbBt/gcc-12-12.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu\nThread model: posix\nSupported LTO compression algorithms: zlib zstd\ngcc version 12.3.0 (Ubuntu 12.3.0-1ubuntu1~23.04) \nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n<!--(2)!--> /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -quiet -v -imultiarch x86_64-linux-gnu main.c -quiet -dumpdir prog- -dumpbase main.c -dumpbase-ext .c -mtune=generic -march=x86-64 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/ccClT5M4.s\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nignoring nonexistent directory \"/usr/local/include/x86_64-linux-gnu\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/include-fixed\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include\"\n<!--(3)!-->#include \"...\" search starts here:\n#include <...> search starts here:\n /usr/lib/gcc/x86_64-linux-gnu/12/include\n /usr/local/include\n /usr/include/x86_64-linux-gnu\n /usr/include\nEnd of search list.\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nCompiler executable checksum: d9353c3f0a32d3e91a16ba312e2a9024\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n<!--(4)!--> as -v --64 -o /tmp/ccEgqpgY.o /tmp/ccClT5M4.s\nGNU assembler version 2.40 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.40\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n<!--(5)!--> /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -quiet -v -imultiarch x86_64-linux-gnu sum.c -quiet -dumpdir prog- -dumpbase sum.c -dumpbase-ext .c -mtune=generic -march=x86-64 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/ccClT5M4.s\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nignoring nonexistent directory \"/usr/local/include/x86_64-linux-gnu\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/include-fixed\"\nignoring nonexistent directory \"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include\"\n#include \"...\" search starts here:\n#include <...> search starts here:\n /usr/lib/gcc/x86_64-linux-gnu/12/include\n /usr/local/include\n /usr/include/x86_64-linux-gnu\n /usr/include\nEnd of search list.\nGNU C17 (Ubuntu 12.3.0-1ubuntu1~23.04) version 12.3.0 (x86_64-linux-gnu)\n compiled by GNU C version 12.3.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP\n\nGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072\nCompiler executable checksum: d9353c3f0a32d3e91a16ba312e2a9024\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog-'\n as -v --64 -o /tmp/ccxMA26W.o /tmp/ccClT5M4.s\nGNU assembler version 2.40 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.40\nCOMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/\nLIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../:/lib/:/usr/lib/\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog.'\n<!--(6)!--> /usr/lib/gcc/x86_64-linux-gnu/12/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/12/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper -plugin-opt=-fresolution=/tmp/ccyzC2ZB.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o prog /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/12/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/12 -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/12/../../.. /tmp/ccEgqpgY.o /tmp/ccxMA26W.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/12/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crtn.o\nCOLLECT_GCC_OPTIONS='-v' '-o' 'prog' '-mtune=generic' '-march=x86-64' '-dumpdir' 'prog.'\n
- \u6700\u5f00\u5934\u662f
gcc
\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u5305\u62ec\u5b83\u8fd0\u884c\u7684\u5e73\u53f0\u3001\u914d\u7f6e\u7684\u9009\u9879\u7b49\u3002 - \u8fd9\u91cc\u8c03\u7528\u4e86
cc1
\u5b8c\u6210\u9884\u5904\u7406\u548c\u7f16\u8bd1\u9636\u6bb5\uff0c\u5c06\u6e90\u4ee3\u7801\u6587\u4ef6 main.c
\u7f16\u8bd1\u6210\u4e86 ASCII \u7f16\u7801\u7684\u6c47\u7f16\u6587\u4ef6 /tmp/ccCWi0p2.s
\u3002 - \u8fd9\u91cc\u663e\u793a\u4e86\u5934\u6587\u4ef6\u641c\u7d22\u8def\u5f84\uff0c\u5982\u679c\u4f60\u7f16\u8bd1\u65f6\u62a5\u9519\u7f3a\u5c11\u5934\u6587\u4ef6\uff0c\u53ef\u4ee5\u68c0\u67e5\u4e00\u4e0b\u8fd9\u91cc\u6709\u6ca1\u6709\u5305\u542b\u5bf9\u5e94\u7684\u8def\u5f84\u3002
- \u8fd9\u91cc\u8c03\u7528\u4e86
as
\u5b8c\u6210\u6c47\u7f16\u9636\u6bb5\uff0c\u5c06\u6c47\u7f16\u6587\u4ef6 /tmp/ccCWi0p2.s
\u7ffb\u8bd1\u6210\u4e86\u673a\u5668\u8bed\u8a00\u6587\u4ef6 /tmp/ccAnKDEo.o
\u3002 - \u63a5\u4e0b\u6765\u53c8\u5bf9
sum.c
\u91cd\u590d\u9884\u5904\u7406\u3001\u7f16\u8bd1\u548c\u6c47\u7f16\u7684\u8fc7\u7a0b\uff0c\u5f97\u5230\u4e86 /tmp/ccgMFTqK.o
\u3002 - \u6700\u540e\u8c03\u7528
collect2
\uff08\u8fd9\u662f ld
\u7684\u5305\u88c5\u7a0b\u5e8f\uff09\u5b8c\u6210\u94fe\u63a5\u9636\u6bb5\uff0c\u5c06\u4e24\u4e2a\u6e90\u4ee3\u7801\u751f\u6210\u7684\u76ee\u6807\u6587\u4ef6 /tmp/ccAnKDEo.o
\u548c /tmp/ccgMFTqK.o
\u4e0e\u5176\u4ed6\u5f88\u591a\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u6210\u4e86\u53ef\u6267\u884c\u6587\u4ef6 prog
\u3002\u8fd9\u5c31\u662f\u4f60\u80fd\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u7684\u7a0b\u5e8f\u3002
\u4e3a\u4ec0\u4e48\u6ca1\u6709\u770b\u89c1\u9884\u5904\u7406\u5668 cpp
\u7684\u6267\u884c\u5462\uff1f \u67d0\u4e9b\u7248\u672c\u7684 gcc
\u4f1a\u5c06\u9884\u5904\u7406\u5668 cpp
\u548c\u7f16\u8bd1\u5668 gcc
\u5408\u5e76\u6210\u4e00\u4e2a\u6307\u4ee4\uff0c\u6bd4\u5982\u4e0a\u9762\u7684 cc1
\uff0c\u8fd9\u6837\u5c31\u4e0d\u7528\u5355\u72ec\u8c03\u7528 cpp
\u4e86\u3002
\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u8be6\u89e3\u5176\u4e2d\u7684\u6bcf\u4e00\u4e2a\u9636\u6bb5\u4ee5\u53ca\u53ef\u80fd\u4f1a\u53d1\u751f\u7684\u95ee\u9898\u3002
"},{"location":"programming_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
- \u7528\u53cc\u5f15\u53f7
#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 - \u7528\u5c16\u62ec\u53f7
#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
- \u9519\u8bef\uff08Error\uff09\uff1a\u7f16\u8bd1\u5668\u65e0\u6cd5\u7ee7\u7eed\u8fdb\u884c\u7f16\u8bd1\u3002\u6bd4\u5982\uff1a\u63d0\u4f9b\u7684\u53c2\u6570\u5217\u8868\u4e0d\u5339\u914d\u3001\u4f7f\u7528\u4e86\u672a\u5b9a\u4e49\u7684\u53d8\u91cf\u3001\u51fd\u6570\u7b49\u3002
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
- \u8b66\u544a\uff08Warning\uff09\uff1a\u8fdd\u53cd\u4e86\u8bed\u6cd5\uff0c\u4f46\u80fd\u591f\u7ee7\u7eed\u7f16\u8bd1\uff0c\u7f16\u8bd1\u51fa\u6765\u7684\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u679c\u5f88\u53ef\u80fd\u4e0e\u4f60\u60f3\u8c61\u7684\u4e0d\u4e00\u6837\u3002\u6bd4\u5982\uff1a\u8f6c\u4e49\u5b57\u7b26\u4e0e\u6570\u636e\u7c7b\u578b\u4e0d\u5339\u914d\u3001\u53d1\u751f\u4e86\u9690\u5f0f\u8f6c\u6362\u7b49\u3002
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\u63a5 hello.o
\u4e2d\u5305\u542b\u4e86 hello.c
\u4e2d\u7684 C \u8bed\u8a00\u4ee3\u7801\u7ffb\u8bd1\u6210\u7684\u4e8c\u8fdb\u5236\u4ee3\u7801\u4ee5\u53ca\u4e00\u4e9b\u6570\u636e\uff0c\u6bd4\u5982\u5b57\u7b26\u4e32 Hello, world.\\n
\u3002\u5982\u679c\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00 hello.o
\uff0c\u4f60\u4f1a\u770b\u89c1\u4e00\u5806\u4e71\u7801\uff0c\u5176\u4e2d\u5939\u6742\u7740\u4e00\u4e9b\u5b57\u7b26\u3002\u56e0\u4e3a\u5b57\u7b26\u5728\u6e90\u6587\u4ef6\u548c\u5185\u5b58\u4e2d\u90fd\u662f\u7528 ASCII \u7f16\u7801\u7684\uff0c\u6240\u4ee5 ASCII \u5b57\u7b26\u4ecd\u80fd\u88ab\u6587\u672c\u7f16\u8f91\u5668\u8bc6\u522b\uff0c\u4f46\u5176\u4ed6\u7684\u673a\u5668\u6307\u4ee4\u548c\u6570\u636e\u53ea\u4f1a\u88ab\u89e3\u8bfb\u4e3a\u4e71\u7801\u3002
\u5982\u679c\u8fd0\u884c ./hello.o
\uff0c\u7ec8\u7aef\u4f1a\u544a\u8bc9\u4f60\u8fd9\u4e2a\u6587\u4ef6\u4e0d\u80fd\u88ab\u64cd\u4f5c\u7cfb\u7edf\u6267\u884c\u3002
exec: Failed to execute process: './hello.o' the file could not be run by the operating system.\n
\u5b83\u8fd8\u7f3a\u5c11\u4e00\u4e9b\u4e1c\u897f\uff0c\u5982\uff1a
- \u542f\u52a8\u4ee3\u7801\uff1a\u542f\u52a8\u7a0b\u5e8f\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u5c06\u63a7\u5236\u6743\u4ea4\u7ed9\u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\uff0c\u4f46\u8fd9\u4e2a\u5165\u53e3\u70b9\u4e0d\u662f
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\u3002
\u4e00\u4e2a\u4e0d\u5e26\u542f\u52a8\u4ee3\u7801\u7684\u4f8b\u5b50 Linux \u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u4e00\u822c\u662f _start
\uff0c\u5b83\u5b8c\u6210\u4e00\u4e9b\u5185\u5b58\u521d\u59cb\u5316\u7684\u5de5\u4f5c\uff0c\u7136\u540e\u8df3\u8f6c\u5230 main
\u51fd\u6570\u3002\u6211\u4eec\u5728\u94fe\u63a5\u9636\u6bb5\u4e0d\u5e26\u4e0a\u542b\u6709\u542f\u52a8\u4ee3\u7801\u7684\u76ee\u6807\u6587\u4ef6\uff0c\u770b\u770b\u5728\u7f3a\u5c11 _start
\u7684\u60c5\u51b5\u4e0b\u4f1a\u53d1\u751f\u4ec0\u4e48\u3002
$ ld hello.o -o hello -lc --dynamic-linker /lib64/ld-linux-x86-64.so.2\nld: warning: cannot find entry symbol _start; defaulting to 0000000000401030\n$ ./hello\nHello World.\nfish: Job 1, './hello' terminated by signal SIGSEGV (Address boundary error)\n
\u8fd9\u4e2a\u7a0b\u5e8f\u6e90\u4ee3\u7801\u6b63\u5e38\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u6bb5\u9519\u8bef\u5462\uff1f
\u5728\u94fe\u63a5\u9636\u6bb5\uff0cld
\u7684\u8f93\u51fa\u8868\u660e\u627e\u4e0d\u5230\u5165\u53e3\u70b9 _start
\uff0c\u56e0\u6b64\u628a\u5165\u53e3\u70b9\u9ed8\u8ba4\u653e\u5728\u4e86 0000000000401030
\u5904\u7684\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u662f main
\u51fd\u6570\u3002\u56e0\u6b64\uff0c\u5f53\u7a0b\u5e8f\u6267\u884c\u5230 main
\u51fd\u6570\u7684\u6700\u540e\u4e00\u6761\u6307\u4ee4\u65f6\uff0c\u4f1a\u7ee7\u7eed\u5f80\u4e0b\u6267\u884c\uff0c\u4f46\u6b64\u65f6\u6808\u5df2\u7ecf\u88ab\u6e05\u7a7a\uff0c\u56e0\u6b64\u4f1a\u53d1\u751f\u6bb5\u9519\u8bef\u3002
\u4f7f\u7528 gdb
\u67e5\u770b\u9519\u8bef\u4f4d\u7f6e\uff1a
Program received signal SIGSEGV, Segmentation fault.\n0x0000000000000001 in ?? ()\n
\u8bc1\u5b9e\u4e86\u4e0a\u9762\u7684\u5206\u6790\u3002
crt
\u662f C Runtime \u7684\u7f29\u5199\u3002C \u8bed\u8a00\u76f8\u5173\u542f\u52a8\u4ee3\u7801\u5728\u8fd9\u4e9b\u76ee\u6807\u6587\u4ef6\u4e2d\uff1a
crt1.o
\uff1a\u8d1f\u8d23\u542f\u52a8\uff0c\u5305\u542b _start
\u548c\u672a\u5b9a\u4e49\u7684 __libc_start_main
\u548c main
\u3002 crti.o
\uff1a\u521d\u59cb\u5316 crtbegin.o
\uff1a\u6784\u9020\uff08C++\u4f9d\u8d56\uff09 crtend.o
\uff1a\u6790\u6784\uff08C++\u4f9d\u8d56\uff09 crtn.o
\uff1a\u7ed3\u675f
Linux \u5e73\u53f0\u4e0b\uff0c\u5b83\u4eec\u7684\u94fe\u63a5\u987a\u5e8f\u4e3a\uff1a
ld crt1.o crti.o [user_objects] [system_libraries] crtn.o\n
- \u5e93\u51fd\u6570\uff1a\u51e0\u4e4e\u6240\u6709 C \u7a0b\u5e8f\u90fd\u4f1a\u7528\u5230\u6807\u51c6\u5e93\u4e2d\u7684\u51fd\u6570\uff0c\u6bd4\u5982
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
\u52a8\u6001\u94fe\u63a5 \u5f53\u4f60\u7684\u7a0b\u5e8f\u4e0e\u52a8\u6001\u5e93\u94fe\u63a5\u65f6\uff0c\u7a0b\u5e8f\u4e2d\u521b\u5efa\u4e86\u4e00\u4e2a\u8868\u3002\u5728\u7a0b\u5e8f\u8fd0\u884c\u524d\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5c06\u9700\u8981\u7684\u5916\u90e8\u51fd\u6570\u7684\u673a\u5668\u7801\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u8fd9\u5c31\u662f\u52a8\u6001\u94fe\u63a5\u8fc7\u7a0b\u3002
\u4e0e\u9759\u6001\u94fe\u63a5\u76f8\u6bd4\uff0c\u52a8\u6001\u94fe\u63a5\u4f7f\u7a0b\u5e8f\u6587\u4ef6\u66f4\u5c0f\uff0c\u56e0\u4e3a\u4e00\u4e2a\u52a8\u6001\u5e93\u53ef\u4ee5\u88ab\u591a\u4e2a\u7a0b\u5e8f\u5171\u4eab\uff0c\u8282\u7701\u78c1\u76d8\u7a7a\u95f4\u3002\u90e8\u5206\u64cd\u4f5c\u7cfb\u7edf\u8fd8\u5141\u8bb8\u52a8\u6001\u5e93\u4ee3\u7801\u5728\u5185\u5b58\u4e2d\u7684\u5171\u4eab\uff0c\u8fd8\u80fd\u591f\u8282\u7701\u5185\u5b58\u3002\u52a8\u6001\u5e93\u5347\u7ea7\u65f6\uff0c\u4e5f\u4e0d\u9700\u8981\u91cd\u5199\u7f16\u8bd1\u4f60\u7684\u7a0b\u5e8f\u3002
\u5728 Linux \u7cfb\u7edf\u4e0a\uff0c\u52a8\u6001\u5e93\u7684\u6587\u4ef6\u540d\u4ee5 .so
\u7ed3\u5c3e\uff0c\u6bd4\u5982 libm.so
\u3002\u5728 Window \u4e0a\uff0c\u52a8\u6001\u5e93\u7684\u6587\u4ef6\u540d\u4ee5 .dll
\u7ed3\u5c3e\uff0c\u6bd4\u5982 libm.dll
\u3002
\u52a8\u6001\u94fe\u63a5\u5177\u6709\u4e0a\u9762\u63cf\u8ff0\u7684\u4f18\u70b9\uff0c\u56e0\u6b64 GCC \u5c3d\u53ef\u80fd\u5730\u6267\u884c\u52a8\u6001\u94fe\u63a5\u3002
\u94fe\u63a5\u76f8\u5173\u7684\u95ee\u9898\u53ef\u80fd\u51fa\u73b0\u5728\u94fe\u63a5\u65f6\uff08\u9759\u6001\u94fe\u63a5\uff09\u3001\u7a0b\u5e8f\u8fd0\u884c\u524d\u548c\u8fd0\u884c\u4e2d\uff08\u52a8\u6001\u94fe\u63a5\uff09\u3002\u4e0b\u9762\u65f6\u4e00\u4e9b\u5e38\u89c1\u7684\u95ee\u9898\u3002
\u672a\u5b9a\u4e49\u7684\u5f15\u7528
\u5f53\u540c\u5b66\u4eec\u5f00\u59cb\u4f7f\u7528\u5176\u4ed6\u5e93\u6784\u5efa\u5927\u578b\u9879\u76ee\u65f6\uff0c\u8fd9\u6216\u8bb8\u4f1a\u6210\u4e3a\u6700\u5934\u75bc\u7684\u95ee\u9898\u3002\u9996\u5148\u5e94\u5f53\u9605\u8bfb\u5e93\u7684\u4f7f\u7528\u8bf4\u660e\uff0c\u63a5\u4e0b\u6765\u641c\u7d22\u7f3a\u5931\u7684\u7b26\u53f7\u53ef\u80fd\u4f4d\u4e8e\u54ea\u4e9b\u5e93\u6587\u4ef6\u4e2d\u3002
\u7f3a\u5931 .dll
\u5e38\u7528 Windows \u7684\u540c\u5b66\u591a\u591a\u5c11\u5c11\u89c1\u8fc7\u8fd9\u4e2a\u62a5\u9519\uff0c\u53ef\u4ee5\u53bb\u7f51\u4e0a\u641c\u7d22\u76f8\u5e94 .dll
\u6587\u4ef6\u653e\u7f6e\u5230\u6b63\u786e\u7684\u76ee\u5f55\u3002
\u7f3a\u5931 .so
Linux \u4e0a\u7684\u52a8\u6001\u5e93\u4e00\u822c\u901a\u8fc7 apt
\u7ba1\u7406\uff0c\u641c\u7d22\u76f8\u5e94\u7684\u5305\u5e76\u5b89\u88c5\u5373\u53ef\u3002
\u4e0b\u9762\u8fd9\u884c\u547d\u4ee4\u5728\u6211\u7684\u7cfb\u7edf\u4e0a\u5b8c\u6210\u4e86 hello
\u7a0b\u5e8f\u7684\u6b63\u786e\u94fe\u63a5\uff0c\u4e0d\u4e00\u5b9a\u80fd\u5728\u4f60\u7684\u7cfb\u7edf\u4e0a\u8fd0\u884c\u3002\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u67e5\u627e\u5e93\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u8ba9\u5b83\u6210\u529f\u8fd0\u884c\u3002
ld --output hello --dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crti.o -lc hello.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crtn.o\n
"},{"location":"programming_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
- \u5982\u679c\u662f\u76ee\u6807\u6587\u4ef6\uff0c\u94fe\u63a5\u5668\u5c06\u8bb0\u5f55\u5176\u4e2d\u7684\u7b26\u53f7\u5b9a\u4e49\u548c\u5f15\u7528\u3002
- \u5982\u679c\u662f\u5e93\u6587\u4ef6\uff0c\u94fe\u63a5\u5668\u5c06\u5c1d\u8bd5\u5339\u914d\u524d\u9762\u8bb0\u5f55\u7684\u672a\u89e3\u6790\u7684\u7b26\u53f7\u5b9a\u4e49\u548c\u5f15\u7528\u3002\u89e3\u6790\u5b8c\u6210\u540e\uff0c\u8be5\u5e93\u4e2d\u6ca1\u6709\u88ab\u4f7f\u7528\u7684\u7b26\u53f7\u5c06\u88ab\u4e22\u5f03\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
- C \u8bed\u8a00\u57fa\u7840\u77e5\u8bc6\u4e0d\u7262\uff1a\u7f16\u8bd1\u90fd\u8fc7\u4e0d\u4e86\uff0c\u4e0d\u5f00
-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\u3002 - \u6ca1\u6709\u4e8b\u5148\u60f3\u597d\u7a0b\u5e8f\u7684\u903b\u8f91\uff1a\u5efa\u8bae\u5728\u52a8\u624b\u5199\u4ee3\u7801\u524d\uff0c\u5148\u60f3\u597d\u81ea\u5df1\u7a0b\u5e8f\u7684\u903b\u8f91\u548c\u6b65\u9aa4\u3002\u8fb9\u5199\u8fb9\u60f3\u7684\u540e\u679c\u5927\u6982\u7387\u662f\u4ee3\u7801\u5199\u5f97\u4e00\u5768\uff08\u9664\u975e\u4f60\u975e\u5e38\u719f\u7ec3\uff09\u3002
- \u4e0d\u4e86\u89e3\u57fa\u672c\u7684\u8c03\u8bd5\u6280\u672f\uff0c\u4e0d\u4f1a\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\uff1a\u672c\u8282\u8bfe\u6211\u4eec\u5c06\u4e3a\u5927\u5bb6\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002
"},{"location":"programming_lecture/lecture1/lecture1/#fprintfstderr","title":"fprintf(stderr)
\u662f\u4f60\u6700\u597d\u7684\u670b\u53cb","text":"\u867d\u7136\u63a5\u4e0b\u6765\u8981\u4ecb\u7ecd\u7684 gdb
\u529f\u80fd\u5f3a\u5927\uff0c\u4f46\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u7b80\u5355\u5730\u6253\u5370\u53d8\u91cf\u5c31\u80fd\u5e2e\u4f60\u5b9a\u4f4d\u95ee\u9898\u6240\u5728\u3002
\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528 fprintf(stderr, ...)
\u6253\u5370\u8c03\u8bd5\u4fe1\u606f\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5b9a\u4f4d\u5230\u7a0b\u5e8f\u4e2d\u7684\u9519\u8bef\u3002fprintf
\u5411\u6307\u5b9a\u7684\u6d41\u8f93\u51fa\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0cstderr
\u662f\u6807\u51c6\u9519\u8bef\u6d41\uff0c\u5b83\u4e0d\u4f1a\u88ab\u7f13\u51b2\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u5728\u7a0b\u5e8f\u5d29\u6e83\u65f6\u770b\u5230\u6700\u540e\u7684\u8c03\u8bd5\u4fe1\u606f\uff08\u8fd9\u4e9b\u8f93\u5165\u8f93\u51fa\u7684\u77e5\u8bc6\u4f1a\u5728\u540e\u9762\u7684\u8bfe\u7a0b\u4e2d\u5b66\u5230\uff09\u3002
\u4ee5\u4e00\u4e2a\u5f02\u5e38\u7ec8\u6b62\u7684\u7a0b\u5e8f\u4e3a\u4f8b\uff1a
#include <stdio.h>\n#include <stdlib.h>\n\nint main(void)\n{\n printf(\"printf \");\n fprintf(stderr, \"fprintf \");\n abort();\n}\n
\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a
$ ./debug\nfprintf fish: Job 1, './debug' terminated by signal SIGABRT (Abort)\n
\u53ef\u4ee5\u770b\u5230\u53ea\u6709 fprintf
\u51fd\u6570\u7684\u8f93\u51fa\u3002\u5982\u679c\u5728 printf
\u8bed\u53e5\u540e\u9762\u52a0\u4e0a\u6362\u884c\u7b26\uff0c\u4f60\u4f1a\u53d1\u73b0 printf
\u7684\u8f93\u51fa\u4e5f\u88ab\u6253\u5370\u51fa\u6765\u4e86\u3002\u56e0\u4e3a\u5f53\u8f93\u51fa\u7f13\u51b2\u533a\u9047\u5230 \\n
\u65f6\u4e5f\u4f1a\u7acb\u5373\u8f93\u51fa\u3002
\u6b64\u5916\uff0c\u5c06\u9519\u8bef\u4fe1\u606f\u5bfc\u5411\u6807\u51c6\u9519\u8bef\u6d41\u8fd8\u6709\u53e6\u4e00\u4e2a\u597d\u5904\uff0c\u5c31\u662f\u4f60\u53ef\u4ee5\u5206\u522b\u6536\u96c6\u8c03\u8bd5\u4fe1\u606f\u548c\u6b63\u5e38\u8f93\u51fa\u3002\u6bd4\u5982\u4f60\u53ef\u4ee5\u5c06\u8c03\u8bd5\u4fe1\u606f\u91cd\u5b9a\u5411\u5230\u4e00\u4e2a\u6587\u4ef6\uff0c\u800c\u5c06\u6b63\u5e38\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u53e6\u4e00\u4e2a\u6587\u4ef6\u3002
$ ./debug 2> debug.log 1> output.log\n
"},{"location":"programming_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
gets.cchar *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\u3002 r
\u6216 run [args]
\uff1a\u8fd0\u884c\u7a0b\u5e8f\u3002[args]
\u662f\u53ef\u9009\u7684\u547d\u4ee4\u884c\u53c2\u6570\u3002 b
\u6216 break <line>
\uff1a\u5728\u6307\u5b9a\u884c\u8bbe\u7f6e\u65ad\u70b9\u3002 b
\u6216 break <function>
\uff1a\u5728\u6307\u5b9a\u51fd\u6570\u8bbe\u7f6e\u65ad\u70b9\u3002 b
\u6216 break *<address>
\uff1a\u5728\u6307\u5b9a\u5730\u5740\u8bbe\u7f6e\u65ad\u70b9\u3002 info breakpoints
\uff1a\u67e5\u770b\u65ad\u70b9\u4fe1\u606f\u3002 delete breakpoints <number>
\uff1a\u5220\u9664\u6307\u5b9a\u7f16\u53f7\u7684\u65ad\u70b9\u3002 continue
\uff1a\u7ee7\u7eed\u6267\u884c\u7a0b\u5e8f\u3002 next
\uff1a\u6267\u884c\u4e0b\u4e00\u884c\u3002 step
\uff1a\u6267\u884c\u4e0b\u4e00\u884c\uff0c\u5982\u679c\u9047\u5230\u51fd\u6570\u8c03\u7528\uff0c\u8fdb\u5165\u51fd\u6570\u5185\u90e8\u3002 print <variable>
\uff1a\u6253\u5370\u53d8\u91cf\u7684\u503c\u3002 print <expression>
\uff1a\u6253\u5370\u8868\u8fbe\u5f0f\u7684\u503c\u3002 watch <expression>
\uff1a\u76d1\u89c6\u8868\u8fbe\u5f0f\u7684\u503c\uff0c\u5f53\u503c\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u7a0b\u5e8f\u4f1a\u505c\u4e0b\u6765\u3002 backtrace
\uff1a\u67e5\u770b\u51fd\u6570\u8c03\u7528\u6808\u3002 finish
\uff1a\u6267\u884c\u5b8c\u5f53\u524d\u51fd\u6570\u540e\u505c\u4e0b\u6765\u3002 q
\u6216 quit
\uff1a\u9000\u51fa gdb
\u3002 help
\uff1a\u67e5\u770b\u5e2e\u52a9\u4fe1\u606f\u3002
"},{"location":"programming_lecture/lecture1/lecture1/#_22","title":"\u68c0\u67e5\u7a0b\u5e8f\u60c5\u51b5","text":"Linux \u7cfb\u7edf\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u8bbe\u5907\u6587\u4ef6 /dev/zero
\uff0c\u5b83\u80fd\u591f\u4f5c\u4e3a\u8f93\u5165\uff0c\u63d0\u4f9b\u65e0\u7a77\u65e0\u5c3d\u7684 0
\u5b57\u8282\u3002\u6211\u4eec\u5c06\u5b83\u4f5c\u4e3a\u8f93\u5165\uff0c\u770b\u770b\u7a0b\u5e8f\u4f1a\u53d1\u751f\u4ec0\u4e48\u3002
(gdb) file gets\nReading symbols from gets...\n(gdb) run < /dev/zero\nStarting program: /mnt/f/Code/_repo/study-assist/docs/programming_lecture/lecture1/code/gets < /dev/zero\n[Thread debugging using libthread_db enabled]\nUsing host libthread_db library \"/lib/x86_64-linux-gnu/libthread_db.so.1\".\n\nProgram received signal SIGSEGV, Segmentation fault.\n0x00005555555551b2 in gets (s=0x7fffffffd760 \"\") at gets.c:8\n8 *dest++ = c;\n
\u56e0\u4e3a\u7a0b\u5e8f\u8bbf\u95ee\u4e86\u975e\u6cd5\u7684\u5730\u5740\u7a7a\u95f4\uff0c\u7cfb\u7edf\u5411\u7a0b\u5e8f\u53d1\u9001\u4fe1\u53f7 SIGSEGV
\uff0c\u7a0b\u5e8f\u7ec8\u6b62\u8fd0\u884c\u3002gdb
\u4f1a\u81ea\u52a8\u505c\u5728\u53d1\u751f\u9519\u8bef\u7684\u4f4d\u7f6e\uff0c\u8fd9\u91cc\u662f gets.c
\u7684\u7b2c 8 \u884c\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 backtrace
\u547d\u4ee4\u67e5\u770b\u51fd\u6570\u8c03\u7528\u6808\u3002
(gdb) backtrace\n#0 0x00005555555551b2 in gets (s=0x7fffffffd760 \"\") at gets.c:8\n#1 0x000055555555521b in echo () at gets.c:18\n#2 0x0000000000000000 in ?? ()\n
\u4f7f\u7528 print
\u547d\u4ee4\u67e5\u770b\u5404\u4e2a\u53d8\u91cf\u7684\u503c\u3002print/x
\u80fd\u591f\u6307\u5b9a\u4ee5\u5341\u516d\u8fdb\u5236\u7684\u5f62\u5f0f\u6253\u5370\u53d8\u91cf\u7684\u503c\u3002
(gdb) print dest\n$1 = 0x7ffffffff001 <error: Cannot access memory at address 0x7ffffffff001>\n(gdb) print s\n$2 = 0x7fffffffd760 \"\"\n(gdb) print dest - s\n$3 = 6305\n(gdb) print c\n$4 = 0\n
gdb
\u4e3a\u4f60\u505a\u4e86\u4e00\u4e9b\u63d0\u793a\uff0c\u6bd4\u5982 dest
\u73b0\u5728\u6240\u6307\u5411\u7684\u5730\u5740 0x7ffffffff001
\u662f\u7a0b\u5e8f\u65e0\u6cd5\u8bbf\u95ee\u7684\u3002\u68c0\u67e5 dest - s
\u7684\u503c\u6211\u4eec\u77e5\u9053\u6b64\u65f6 dest
\u6307\u5411\u7684\u5730\u5740\u5df2\u7ecf\u662f s
\u540e 6305 \u4e2a\u5b57\u8282\uff0c\u8fdc\u8fdc\u8d85\u51fa\u4e86\u6570\u7ec4 s
\u7684\u7a7a\u95f4\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u68c0\u67e5\u5f53\u524d\u8f93\u5165\u7684\u5b57\u7b26 c
\uff0c\u5b83\u663e\u7136\u662f 0
\u3002
"},{"location":"programming_lecture/lecture1/lecture1/#_23","title":"\u65ad\u70b9\u8c03\u8bd5","text":"\u4f7f\u7528 break <filename>:<line>
\u53ef\u4ee5\u5728\u6307\u5b9a\u6587\u4ef6\u6307\u5b9a\u884c\u8bbe\u7f6e\u65ad\u70b9\u3002\u5bf9\u4e8e\u5355\u6587\u4ef6\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u7701\u7565\u6e90\u4ee3\u7801\u6587\u4ef6\u540d\u3002break
\u8fd8\u53ef\u4ee5\u63a5\u6536\u51fd\u6570\u540d\u548c\u5730\u5740\u4f5c\u4e3a\u53c2\u6570\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u6761\u4ef6\u8868\u8fbe\u5f0f\uff0c\u8bf7\u4f7f\u7528 help break
\u67e5\u770b\u8be6\u7ec6\u7528\u6cd5\u3002
\u6211\u4eec\u5728\u7a0b\u5e8f\u7b2c 8 \u884c *dest++=c
\u5904\u8bbe\u7f6e\u4e00\u4e2a\u65ad\u70b9\uff0c\u7136\u540e\u8fd0\u884c\u7a0b\u5e8f\u3002
(gdb) b 8\nBreakpoint 1 at 0x11a3: file gets.c, line 8.\n(gdb) r < /dev/zero\nStarting program: /mnt/f/Code/_repo/study-assist/docs/programming_lecture/lecture1/code/gets < /dev/zero\n\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8 *dest++ = c;\n(gdb) print dest - s\n$1 = 0\n
next
\u547d\u4ee4\u5c06\u4f1a\u5355\u884c\u6267\u884c\u7a0b\u5e8f\uff0c\u4e14\u4e0d\u4f1a\u8fdb\u5165\u51fd\u6570\u5185\u90e8\uff08\u5373\u628a\u6574\u4e2a\u51fd\u6570\u5f53\u4f5c\u4e00\u884c\uff09\u3002step
\u4f1a\u8fdb\u5165\u51fd\u6570\u5185\u90e8\u4e00\u884c\u4e00\u884c\u6267\u884c\u3002continue
\u547d\u4ee4\u5c06\u7ee7\u7eed\u6267\u884c\u7a0b\u5e8f\uff0c\u76f4\u5230\u4e0b\u4e00\u4e2a\u65ad\u70b9\u3002
(gdb) next\n7 while((c = getchar()) != '\\n' && c != EOF)\n(gdb) next\nBreakpoint 1,gets (s=0x7fffffffd760 \"\") at gets.c:8\n8 *dest++ = c;\n(gdb) print dest - s\n$2 =1\n(gdb) continue\nContinuing.\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8 *dest++ = c;\n(gdb) print dest - s\n$3 = 2\n
next
\u548c step
\u547d\u4ee4\u90fd\u53ef\u4ee5\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\uff0c\u8868\u793a\u6267\u884c\u591a\u5c11\u884c\uff0c\u4e14\u4f1a\u5728\u65ad\u70b9\u5904\u505c\u4e0b\u3002continue
\u547d\u4ee4\u4e5f\u53ef\u4ee5\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\uff0c\u8868\u793a\u5ffd\u7565\u63a5\u4e0b\u6765\u5730\u591a\u5c11\u4e2a\u65ad\u70b9\u3002
(gdb) next 20\n\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8 *dest++ = c;\n(gdb) print dest - s\n$4 = 3\n(gdb) continue 20\nWill ignore next 19 crossings of breakpoint 1. Continuing.\n\nBreakpoint 1, gets (s=0x7fffffffd760 \"\") at gets.c:8\n8 *dest++ = c;\n(gdb) print dest - s\n$5 = 23\n
\u8c03\u8bd5\u6280\u5de7 \u76f4\u63a5\u6309 Enter \u952e\uff0cgdb
\u4f1a\u91cd\u590d\u4e0a\u4e00\u6761\u547d\u4ee4\u3002\u8fd9\u6837\u5c31\u4e0d\u7528\u4e00\u76f4\u8f93\u5165 next
\u6216 step
\u4e86\u3002
\u5728\u4e00\u4e9b\u66f4\u4e3a\u590d\u6742\u7684\u7a0b\u5e8f\u4e2d\uff0c\u4f7f\u7528 gdb
\u8c03\u8bd5\u7684\u4f18\u8d8a\u6027\u5c31\u9010\u6e10\u663e\u73b0\u51fa\u6765\u4e86\u3002\u4f60\u4e0d\u7528\u9891\u7e41\u66f4\u6539\u6e90\u4ee3\u7801\u63d2\u5165 printf
\u8bed\u53e5\uff0c\u53ea\u9700\u8981\u5728 gdb
\u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u7136\u540e\u9010\u6b65\u6267\u884c\u7a0b\u5e8f\uff0c\u67e5\u770b\u53d8\u91cf\u7684\u503c\uff0c\u5c31\u80fd\u627e\u5230\u9519\u8bef\u6240\u5728\u3002
\u8fdb\u4e00\u6b65\u5b66\u4e60
\u7531\u4e8e\u4e2a\u4eba\u6c34\u5e73\u4e0d\u8db3\u4ee5\u53ca\u65f6\u95f4\u6709\u9650\uff0c\u6ca1\u80fd\u5199\u51fa\u4e00\u4e2a\u4f53\u9a8c\u8f83\u597d\u7684 GDB \u8c03\u8bd5\u5b9e\u9a8c\u3002\u5341\u5206\u5e0c\u671b\u540c\u5b66\u4eec\u5728\u8bfe\u540e\u53bb\u770b\u770b\u8fd9\u7bc7\u6587\u7ae0Linux C \u4e00\u7ad9\u5f0f\u7f16\u7a0b\uff1a\u7b2c 10 \u7ae0 gdb\uff0c\u628a\u8fd9\u8fb9\u7684\u8c03\u8bd5\u5b9e\u4f8b\u90fd\u8fc7\u4e00\u904d\uff5e
"},{"location":"programming_lecture/lecture1/lecture1/#_24","title":"\u53c2\u8003\u8d44\u6599","text":"\u53c2\u8003\u8d44\u6599 - GCC and Make - A Tutorial on how to compile, link and build C/C++ applications
- Understanding GCC warnings
- The GCC warning flags every C programmer should know about
- What Is /lib64/ld-linux-x86-64.so.2?
- GDB Tutorial: A Walkthrough with Examples
- \u770b\u4e91\uff1aLinux C \u4e00\u7ad9\u5f0f\u5b66\u4e60
"},{"location":"programming_lecture/lecture1/pre_class/","title":"\u8bfe\u524d\uff1a\u51c6\u5907\u5f00\u53d1\u4e0e\u8c03\u8bd5\u73af\u5883","text":"Info
\u672c\u6587\u6863\u66f4\u6539\u81ea\u5468\u5065\u5747\u5b66\u957f\u4e3a\u56fe\u7075\u7a0b\u7b97\u8bfe\u7a0b\u51c6\u5907\u7684\u8d44\u6599\uff0c\u611f\u8c22\u5468\u5065\u5747\u5b66\u957f\u7684\u4ed8\u51fa\u3002
\u5185\u5bb9\u63d0\u8981
\u5728\u53c2\u4e0e\u7ebf\u4e0b\u6388\u8bfe\u524d\uff0c\u540c\u5b66\u4eec\u6700\u597d\u80fd\u591f\u5b89\u88c5\u597d\u76f8\u5173\u7684\u5f00\u53d1\u73af\u5883\uff0c\u4ee5\u4fbf\u80fd\u591f\u66f4\u597d\u7684\u8ddf\u968f\u8001\u5e08\u7684\u8bb2\u89e3\u3002
- \u547d\u4ee4\u884c\u7b80\u4ecb
- WSL \u5b89\u88c5\u5f15\u5bfc
- \u5728 Windows \u4e0a\u5b89\u88c5 C \u8bed\u8a00\u7f16\u8bd1\u5668
- VSCode \u5b89\u88c5\u4e0e\u914d\u7f6e
\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
- \u6253\u5f00\u8fd9\u4e2a\u7f51\u5740\uff1awww.onlinegdb.com\u3002
- \u5b83\u5df2\u7ecf\u4e3a\u4f60\u5199\u597d C \u8bed\u8a00\u7684 Hello World \u7a0b\u5e8f\u6e90\u7801\u3002
- \u5728\u53f3\u4e0a\u89d2\u9009\u62e9 C \u8bed\u8a00\uff0c\u7136\u540e\u70b9\u51fb\u5de6\u4e0a\u89d2\u7684
Run
\u3002 - \u5728\u4e0b\u65b9\uff0c\u4f60\u5c31\u53ef\u4ee5\u770b\u89c1\u7a0b\u5e8f\u7684\u8f93\u51fa\u3002
- \u6309\u4e0b Enter \u952e\u79bb\u5f00\u7ec8\u7aef\u3002\u4e0b\u65b9\u4f1a\u663e\u793a\u51e0\u4e2a\u9009\u9879\uff1a
- Command Line Arguments\uff1a\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u4f60\u4eec\u5e94\u8be5\u4e0d\u4f1a\u5b66\u5230\uff1f
- Standard Input\uff1a\u6807\u51c6\u8f93\u5165\u3002\u4f60\u53ef\u4ee5\u9009\u62e9 Interactive Console\uff08\u5c31\u662f\u6b63\u5e38\u5730\u7528\u952e\u76d8\u548c\u7a0b\u5e8f\u4ea4\u4e92\uff09\u6216\u8005 Text\uff08\u9884\u5148\u51c6\u5907\u4e00\u4e9b\u6587\u672c\u81ea\u52a8\u8f93\u5165\uff0c\u901a\u5e38\u7528\u4e8e\u6d4b\u8bd5 PTA \u7684\u6837\u4f8b\u6570\u636e\uff09\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
- Mac \u548c Linux \u7528\u6237
- \u5b89\u88c5\u597d\u4e86 WSL \u7684 Windows \u7528\u6237
- \u5b89\u88c5\u597d\u4e86 MinGW\u3001MSVC\u3001Cygwin\u3001tdm-gcc \u7b49\u7f16\u8bd1\u5668\u7684 Windows \u7528\u6237
\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
- \u70b9\u51fb\u9875\u9762\u4e2d\u7684\u56fe\u7247\u53ef\u4ee5\u653e\u5927\u67e5\u770b\u3002
- \u5982\u679c\u5b89\u88c5\u8fc7\u7a0b\u9047\u5230\u56f0\u96be\uff0c\u53ef\u4ee5\u5728\u8f85\u5b66\u7fa4\u63d0\u95ee\uff0c\u6216\u79c1\u6233\u6388\u8bfe\u5b66\u957f\uff5e
"},{"location":"programming_lecture/lecture1/pre_class/#shell","title":"Shell \u4f7f\u7528\u62fe\u9057","text":"\u672c\u8282\u6211\u4eec\u8981\u8ba4\u8bc6\u4e00\u4e2a\u5373\u5c06\u6210\u4e3a\u4f60\u7684\u8001\u670b\u53cb\u7684\u4e1c\u897f\u2014\u2014Shell\u3002\u4e0b\u9762\u662f\u540c\u5b66\u4eec\u63a5\u4e0b\u6765\u4f1a\u7ecf\u5e38\u89c1\u5230\u7684\u51e0\u4e2a\u540d\u8bcd\uff1a
- Terminal \u7ec8\u7aef\uff1a\u4e0b\u56fe\u4e2d\uff0c\u8fd9\u4e2a\u7a97\u53e3\u5c31\u662f Windows Terminal\u3002\u5b83\u8d1f\u8d23\u63a5\u6536\u4f60\u7684\u8f93\u5165\uff0c\u628a\u8f93\u5165\u4f20\u9012\u7ed9 Shell\uff0c\u7136\u540e\u628a Shell \u7684\u8f93\u51fa\u663e\u793a\u7ed9\u4f60\u3002\u4f60\u53ef\u4ee5\u4ece\u56fe\u4e2d\u770b\u5230\uff0c\u4e00\u4e2a Terminal \u53ef\u4ee5\u8fde\u63a5\u5230\u591a\u4e2a Shell\uff0c\u5c31\u50cf\u4e00\u53f0\u663e\u793a\u5668\u53ef\u4ee5\u8fde\u63a5\u5230\u591a\u53f0\u7535\u8111\u4e00\u6837\u3002\u628a Terminal \u7406\u89e3\u4e3a\u952e\u76d8\u548c\u663e\u793a\u5668\u5c31\u597d\u3002
- Shell \u547d\u4ee4\u89e3\u91ca\u5668\uff1a\u63a5\u6536\u4f60\u7ed9\u51fa\u7684\u547d\u4ee4\u3001\u6267\u884c\u5e76\u7ed9\u51fa\u54cd\u5e94\u7684\uff0c\u5c31\u662f Shell\u3002\u5982\u679c\u628a Terminal \u7406\u89e3\u4e3a\u952e\u76d8\u548c\u663e\u793a\u5668\uff0c\u90a3\u4e48 Shell \u5c31\u662f\u4e3b\u673a\u3002
- Prompt \u63d0\u793a\u7b26\uff1aShell \u4f1a\u7ed9\u4f60\u4e00\u4e2a\u63d0\u793a\u7b26\uff0c\u544a\u8bc9\u4f60\u5b83\u5df2\u7ecf\u51c6\u5907\u597d\u63a5\u6536\u4f60\u7684\u547d\u4ee4\u4e86\u3002\u5728 Linux \u4e2d\uff0c\u63d0\u793a\u7b26\u4e00\u822c\u662f
$
\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 - Command Line Interface \u547d\u4ee4\u884c\u4ea4\u4e92\u754c\u9762\uff1a\u5f53\u6211\u4eec\u4f7f\u7528\u6587\u672c\u547d\u4ee4\u4e0e\u8ba1\u7b97\u673a\u4ea4\u4e92\u65f6\uff0c\u6211\u4eec\u5c31\u5728\u4f7f\u7528 CLI\u3002\u8fd9\u4e0e\u6211\u4eec\u65e5\u5e38\u751f\u6d3b\u4e2d\u4f7f\u7528\u9f20\u6807\u7684\u56fe\u5f62\u4ea4\u4e92\u754c\u9762\uff08Graphical User Interface\uff0cGUI\uff09\u4e0d\u540c\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
- \u901f\u5ea6\u5feb\uff1a\u5728\u547d\u4ee4\u884c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5feb\u901f\u5730\u8f93\u5165\u547d\u4ee4\uff0c\u800c\u4e0d\u9700\u8981\u4f7f\u7528\u9f20\u6807\u70b9\u51fb\u83dc\u5355\u3002
- \u53ef\u7f16\u7a0b\uff1a\u4f60\u53ef\u4ee5\u7f16\u5199\u811a\u672c\uff0c\u8ba9\u8ba1\u7b97\u673a\u81ea\u52a8\u6267\u884c\u4e00\u7cfb\u5217\u547d\u4ee4\u3002
- \u53ef\u8fdc\u7a0b\uff1a\u4f60\u53ef\u4ee5\u901a\u8fc7\u7f51\u7edc\u8fde\u63a5\u5230\u8fdc\u7a0b\u8ba1\u7b97\u673a\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u4e0e\u5176\u4ea4\u4e92\u3002
\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
"},{"location":"programming_lecture/lecture1/pre_class/#wsl","title":"WSL \u5b89\u88c5\u7b80\u5355\u5f15\u5bfc\uff08\u53ef\u9009\uff09","text":"\u63a8\u8350\u88c5\u4e00\u88c5\uff0c\u5982\u679c\u4e3b\u529b\u673a\u662f Windows \u5728\u4ee5\u540e\u5c06\u5bf9 WSL \u6709\u8f83\u5927\u9700\u6c42
WSL\uff0c\u5168\u79f0 Windows Subsystem for Linux\uff08\u9002\u7528\u4e8e Linux \u7684 Windows \u5b50\u7cfb\u7edf\uff09\uff0c\u662f\u4e00\u9879\u5141\u8bb8\u5f00\u53d1\u8005\u4e0d\u4f9d\u9760\u5355\u72ec\u7684\u865a\u62df\u673a\u6216\u53cc\u542f\u52a8 (dual booting) \u800c\u5728 Windows \u4e0a\u8fd0\u884c Linux \u73af\u5883\u7684\u529f\u80fd\u3002
"},{"location":"programming_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
- \u8bbe\u7f6e\u4e00\u4e2a\u7528\u6237\u540d\uff0c\u5efa\u8bae\u5168\u82f1\u6587\u65e0\u7a7a\u683c
- \u82e5\u6709\u7a7a\u683c\uff0c\u5c06\u4f1a\u53ea\u53d6\u7b2c\u4e00\u4e2a\u7a7a\u683c\u524d\u9762\u7684\u5185\u5bb9\u4f5c\u4e3a\u4f60\u7684\u7528\u6237\u540d
- \u8f93\u5165\u5bc6\u7801\uff0c\u6ce8\u610f\u4f60\u8f93\u5165\u7684\u5b57\u7b26\u4e0d\u4f1a\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\uff0c\u9700\u8981\u76f2\u6253
- \u5982\u679c\u6253\u4e86\u4e71\u4e03\u516b\u7cdf\u7684\u5b57\u7b26\u4e0d\u8981\u614c\uff0c\u786e\u8ba4\u5bc6\u7801\u65f6\u6545\u610f\u6253\u9519\u4f1a\u91cd\u65b0\u8ba9\u4f60\u8bbe\u7f6e\u5bc6\u7801
- \u786e\u8ba4\u5bc6\u7801\u4e0e\u8f93\u5165\u5bc6\u7801\u4e00\u81f4\u624d\u4f1a\u8bbe\u7f6e\u6210\u529f
\u8fd9\u6837\u5c31\u5b8c\u6210\u4e86 WSL2 Ubuntu \u7684\u5b89\u88c5\u3002
\u9519\u8bef\uff1a0x80370114
- \u9996\u5148\u68c0\u67e5\u81ea\u5df1\u662f\u5426\u4e3a Windows 10 \u6216\u8005 Windows 11 \u5bb6\u5ead\u7248\u3002\u8fd9\u4e24\u4e2a\u7248\u672c\u53ef\u80fd\u7f3a\u5931 Hyper-V \u670d\u52a1\uff08WSL \u80cc\u540e\u7684\u865a\u62df\u5316\u652f\u6301\u6280\u672f\uff09\u3002\u8bf7\u6309\u7167\u77e5\u4e4e\uff1a\u5982\u4f55\u5728 Windows 11 Home \u4e2d\u542f\u7528 Hyper-V\u8fd9\u7bc7\u6587\u7ae0\u7684\u65b9\u6cd5\u542f\u7528 Hyper-V\u3002
- \u5982\u679c\u4ecd\u65e0\u6cd5\u89e3\u51b3\uff0c\u518d\u6309\u7167\u77e5\u4e4e\uff1awin10\u4f7f\u7528wsl2\u5b89\u88c5ubuntu\u9047\u52300x80370114\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6cd5\u8fd9\u7bc7\u6587\u7ae0\u91cd\u65b0\u542f\u52a8\u865a\u62df\u673a\u5e73\u53f0\u3002
\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
- \u53ef\u9009\u7684\u5b89\u88c5\u9879
- \u53ef\u4ee5\u5168\u9009\u3002\u5982\u679c\u786e\u5b9a\u4e0d\u9700\u8981\u4e00\u4e9b\u4e1c\u897f\u53ef\u4ee5\u4e0d\u9009\uff0c\u6bd4\u5982\u786e\u5b9a\u81ea\u5df1\u4e0d\u4f1a\u518d\u9700\u8981\u8c03\u8bd5 32 \u4f4d\u7a0b\u5e8f\u7684\u8bdd\u53ef\u4ee5\u4e0d\u9009 gdb32\u3002
- Start Menu items
- \u770b\u4e2a\u4eba\u610f\u613f\uff0c\u53ef\u4ee5\u4e0d\u9009
- Add to PATH
- \u5efa\u8bae\u9009\u4e0a\u3002\u5982\u679c\u4e0d\u9009\u6216\u8005\u5fd8\u9009\u4e86\uff0c\u5c06\u4f1a\u9700\u8981\u81ea\u5df1\u914d\u7f6e tdm-gcc \u7684\u73af\u5883\u53d8\u91cf\u8def\u5f84\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
"},{"location":"programming_lecture/lecture1/pre_class/#vscode","title":"VSCode \u5b89\u88c5\u4e0e\u914d\u7f6e","text":"VSCode \u7684\u5168\u79f0\u662f Visual Studio Code\uff0c\u6ce8\u610f\u5b83\u548c Visual Studio \u5b8c\u5168\u662f\u4e24\u4e2a\u4e1c\u897f
\u4e0d\u5efa\u8bae\u5b89\u88c5 Visual Studio\uff0c\u9664\u975e\u4f60\u6e05\u695a\u4f60\u5b89\u88c5\u5b83\u662f\u4e3a\u4e86\u4ec0\u4e48
\u5728\u8fd9\u91cc\u4ec5\u4ecb\u7ecd Visual Studio Code \u7684\u5b89\u88c5\u3002\u9664\u4e86\u8001\u5e08\u7684\u89c6\u9891\u4e4b\u5916\uff0c\u5927\u5bb6\u5b89\u88c5\u914d\u7f6e\u65f6\u8fd8\u53ef\u4ee5\u53c2\u8003 GZTime \u7684\u6559\u7a0b\uff0c\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bf4\u8fd8\u4e0d\u9519\u3002
"},{"location":"programming_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
WindowsMac Windows \u7684 exe \u5b89\u88c5\u53ef\u4ee5\u5168\u9009\u9ed8\u8ba4\u9009\u9879\u4e00\u8def Next\uff0c\u6bd4\u8f83\u719f\u6089\u7684\u540c\u5b66\u53ef\u4ee5\u81ea\u5b9a\u4e49\u9009\u9879\uff1a
- \u5b89\u88c5\u76ee\u5f55
- \u63a8\u8350\u9ed8\u8ba4 C \u76d8\uff0c\u53ef\u80fd\u8fd0\u884c\u901f\u5ea6\u66f4\u5feb\uff0c\u4e5f\u53ef\u4ee5\u907f\u514d\u4e00\u4e9b\u6743\u9650\u95ee\u9898
- \u5c06 \u201c\u901a\u8fc7 Code \u6253\u5f00\u201d \u64cd\u4f5c\u6dfb\u52a0\u5230 Windows \u8d44\u6e90\u7ba1\u7406\u5668\u6587\u4ef6/\u76ee\u5f55\u4e0a\u4e0b\u6587\u83dc\u5355
- \u9009\u4e2d\u8be5\u9879\u540e\uff0c\u9009\u4e2d\u6587\u4ef6\u6216\u8005\u6587\u4ef6\u5939\uff0c\u53f3\u952e\u83dc\u5355\u4e2d\u4f1a\u51fa\u73b0
\u901a\u8fc7 Code \u6253\u5f00
\u7684\u9009\u9879 - \u5982\u679c\u5e0c\u671b\u53f3\u952e\u83dc\u5355\u4e0d\u90a3\u4e48\u81c3\u80bf\u7684\u8bdd\u53ef\u4ee5\u4e0d\u9009\u8fd9\u4e00\u9879
- \u672c\u4eba\u6ca1\u6709\u9009\u62e9\u8be5\u9009\u9879\uff0c\u53ef\u4ee5\u81ea\u884c\u601d\u8003\u9009\u62e9
- \u5c06 Code \u6ce8\u518c\u4e3a\u53d7\u652f\u6301\u7684\u6587\u4ef6\u7c7b\u578b\u7684\u7f16\u8f91\u5668\uff08\u63a8\u8350\uff09
- \u6253\u5f00\u53d7\u652f\u6301\u7684\u6587\u4ef6\u7c7b\u578b\u65f6\uff0cVSCode \u5c06\u4f1a\u6210\u4e3a\u53ef\u9009\u9879
- \u6dfb\u52a0\u5230 PATH\uff08\u63a8\u8350\uff09
- \u5728\u547d\u4ee4\u884c\u7a97\u53e3/\u7ec8\u7aef\u53ef\u4ee5\u7528
code
\u547d\u4ee4\u6253\u5f00 VSCode
Mac \u7684\u5305\u4e0b\u8f7d\u4e0b\u6765\u4e4b\u540e\u62d6\u5165 Application
\u6587\u4ef6\u5939\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c
- \u6dfb\u52a0\u5230 PATH\uff1a\u5982\u679c\u9700\u8981\u5728\u547d\u4ee4\u884c\u7a97\u53e3/\u7ec8\u7aef\u7528
code
\u547d\u4ee4\u6253\u5f00 VSCode\uff0c\u90a3\u4e48\u9700\u8981\u5982\u4e0b\u64cd\u4f5c - \u6253\u5f00 VSCode \u754c\u9762
- \u4f7f\u7528 Shift + Command + P \u6253\u5f00\u547d\u4ee4\u9762\u677f
- \u8f93\u5165
shell command
\uff0c\u9009\u62e9 Shell Command: Install \u2018code\u2019 command in PATH
\u56de\u8f66\u6267\u884c
"},{"location":"programming_lecture/lecture1/pre_class/#_4","title":"\u63d2\u4ef6\u5b89\u88c5","text":"\u6253\u5f00 VSCode \u540e\uff0c\u5728\u5de6\u4fa7\u7ad6\u680f\u5bfb\u627e\u4e0b\u9762\u8fd9\u4e2a\u56fe\u6807\uff1a
\u70b9\u51fb\u8fd9\u4e2a\u56fe\u6807\u5c31\u8fdb\u5165\u4e86\u63d2\u4ef6\u7ba1\u7406\u3002\u5efa\u8bae\u53ef\u4ee5\u5b89\u88c5\u4e0b\u9762\u4e24\u4e2a\u63d2\u4ef6\uff1a
- C/C++: \u5fae\u8f6f\u81ea\u5bb6\u7684\u63d2\u4ef6\uff0c\u53ef\u7528\u4e8e\u8bed\u6cd5\u8bc6\u522b\u3001\u4ee3\u7801\u9ad8\u4eae
- Chinese(Simplified): \u754c\u9762\u6c49\u5316\u63d2\u4ef6\uff08\u53ef\u9009\uff09
\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
- \u8bb0\u5f97\u4fdd\u5b58\u6587\u4ef6\u540e\u518d gcc \u7f16\u8bd1\uff0c\u53ef\u4ee5\u8003\u8651\u5f00\u542f\u81ea\u52a8\u4fdd\u5b58
- \u5982\u4e0b\u56fe\u6240\u793a\uff0c\u627e\u5230\u5de6\u4e0b\u89d2\u7684\u9f7f\u8f6e\u70b9\u51fb\u540e\u9009\u62e9 Setting \u6216\u8005\u8bbe\u7f6e\uff0c\u51fa\u73b0\u7684\u8bbe\u7f6e\u9875\u9762\u4e2d\u641c\u7d22
auto
\u53ef\u4ee5\u627e\u5230\u5982\u56fe\u6240\u793a\u7684 Auto Save
\u8bbe\u7f6e\u9879\uff0c\u8bbe\u7f6e\u4e3a afterDelay \u5373\u53ef - afterDelay \u662f\u5bf9\u6587\u4ef6\u505a\u51fa\u4fee\u6539\u5c31\u5b9e\u65f6\u4fdd\u5b58\uff0c\u5982\u679c\u5acc\u4fdd\u5b58\u9891\u7387\u8fc7\u9ad8\u53ef\u4ee5\u9009\u62e9 onFocusChange \u6216\u8005 onWindowsChange
- \u6211\u672c\u4eba\u4f7f\u7528\u7684\u662f onFocusChange\uff0c\u8fd9\u6837\u79fb\u52a8\u5230\u7ec8\u7aef\u51c6\u5907\u7f16\u8bd1\u8fd0\u884c\u65f6\u6e90\u4ee3\u7801\u6587\u4ef6\u5c31\u4f1a\u81ea\u52a8\u4fdd\u5b58\uff0c\u65e2\u81ea\u52a8\u4fdd\u5b58\u53c8\u4e0d\u4f1a\u4fdd\u5b58\u592a\u9891\u7e41
- \u5efa\u8bae\u5de5\u4f5c\u76ee\u5f55\u548c\u6587\u4ef6\u540d\u5168\u82f1\u6587\uff0c\u7ed9\u51fa\u4ee5\u4e0b\u51e0\u4e2a\u53cd\u9762\u6848\u4f8b\uff1a
- \u6587\u4ef6\u540d
\u4f5c\u4e1a.c
- \u5de5\u4f5c\u76ee\u5f55
\u7f16\u7a0b
- \u5de5\u4f5c\u76ee\u5f55\u53eb
Coding
\uff0c\u4f46\u662f\u7edd\u5bf9\u8def\u5f84\u662f D:/\u5b66\u4e60\u8d44\u6599/Coding
- \u53ef\u4ee5\u6307\u5b9a\u7f16\u8bd1\u751f\u6210\u7684\u6587\u4ef6\u540d\uff0c\u6bd4\u5982\u4f60\u60f3\u8981\u8f93\u51fa\u6587\u4ef6\u540d\u4e3a
hello.exe
\uff0c\u5c31\u53ef\u4ee5\u6267\u884c gcc test.c -o hello.exe\n
- \u66f4\u591a\u7684 gcc \u9009\u9879\u548c VSCode \u6269\u5c55\u529f\u80fd\u7559\u5f85\u4f60\u4eec\u63a2\u7d22
"},{"location":"programming_lecture/lecture1/pre_class/#vscode-wsl","title":"VSCode + WSL\uff08\u53ef\u9009\uff09","text":"\u524d\u9762\u9009\u62e9\u5b89\u88c5\u4e86 WSL \u7684\u4f7f\u7528 Windows \u4e3b\u529b\u673a\u7684\u540c\u5b66\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\uff0c\u975e\u5e38\u6709\u7528\u7684\u529f\u80fd
\u4ee5\u4e0b\u5f15\u5bfc\u4e3b\u8981\u6309\u7167 Microsoft \u7684\u5b98\u65b9\u6587\u6863\uff0c\u4e5f\u53ef\u4ee5\u53c2\u8003\u5176\u4e2d\u6587\u7248\u3002
"},{"location":"programming_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
- Ctrl + Shift + P\uff0c\u5728\u51fa\u73b0\u7684\u547d\u4ee4\u6846\u4e2d\u8f93\u5165 WSL\uff0c\u9009\u62e9
WSL: Connect to WSL in New Window
\uff08\u6216 WSL: \u5728\u65b0\u7a97\u53e3\u4e2d\u8fde\u63a5\u5230 WSL
\uff09 - \u5c06\u6253\u5f00\u4e00\u4e2a\u65b0\u7684 VSCode \u7a97\u53e3\uff0c\u91cc\u9762\u5df2\u7ecf\u8fde\u63a5\u5230\u9ed8\u8ba4\u7684 WSL \u73af\u5883
\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
"},{"location":"programming_lecture/lecture2/after_class/","title":"\u8bfe\u540e\u62d3\u5c55\uff1a\u7a0b\u5e8f\u548c\u6570\u636e\u5728\u8ba1\u7b97\u673a\u4e2d\u662f\u5982\u4f55\u5b58\u50a8\u7684\uff1f","text":"\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
- \u5b83\u8ba9\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u4ee5\u4e3a\u81ea\u5df1\u5728\u72ec\u5360\u5730\u4f7f\u7528\u4e3b\u5b58\u3002
- \u6bcf\u4e2a\u8fdb\u7a0b\u770b\u5230\u7684\u5185\u5b58\u90fd\u662f\u4e00\u81f4\u7684\uff0c\u79f0\u4e3a\u865a\u62df\u5730\u5740\u7a7a\u95f4\u3002
- \u4e00\u81f4\u6027\u6307\u7684\u662f\u5730\u5740\u7a7a\u95f4\u7684\u4e00\u81f4\u3002\u6bd4\u5982\u53f3\u56fe\u4e2d\uff0c\u5730\u5740\u7a7a\u95f4\u6700\u4e0a\u9762\u7684\u533a\u57df\u4fdd\u7559\u7ed9\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u4ee3\u7801\u548c\u6570\u636e\uff0c\u5e95\u90e8\u533a\u57df\u5b58\u653e\u7528\u6237\u8fdb\u7a0b\u7684\u4ee3\u7801\u548c\u6570\u636e\uff0c\u8fd9\u4e9b\u5bf9\u6240\u6709\u8fdb\u7a0b\u6765\u8bf4\u90fd\u662f\u4e00\u81f4\u7684\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
- \u672a\u5206\u914d\uff1a\u672a\u5206\u914d\uff0c\u4e0d\u5360\u7528\u4efb\u4f55\u78c1\u76d8\u7a7a\u95f4
- \u7f13\u5b58\u7684\uff1a\u5df2\u5206\u914d\uff0c\u5df2\u7ecf\u7f13\u5b58\u5728\u7269\u7406\u5185\u5b58\u4e2d
- \u672a\u7f13\u5b58\u7684\uff1a\u5df2\u5206\u914d\uff0c\u672a\u7f13\u5b58\u5728\u7269\u7406\u5185\u5b58\u4e2d
"},{"location":"programming_lecture/lecture2/after_class/#_5","title":"\u865a\u62df\u5730\u5740\u7a7a\u95f4\u7684\u7ed3\u6784","text":"\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
- \u7a0b\u5e8f\u4ee3\u7801\u548c\u6570\u636e\uff08\u53ea\u8bfb\uff09
- \u5bf9\u6240\u6709\u7684\u8fdb\u7a0b\u6765\u8bf4\uff0c\u4ee3\u7801\u4ece\u67d0\u4e2a\u56fa\u5b9a\u7684\u5730\u5740\u5f00\u59cb\u3002
- \u8fd9\u4e2a\u533a\u57df\u662f\u76f4\u63a5\u6309\u7167\u53ef\u6267\u884c\u76ee\u6807\u6587\u4ef6\u7684\u5185\u5bb9\u521d\u59cb\u5316\u7684\u3002
- \u8fdb\u7a0b\u4e00\u5f00\u59cb\u8fd0\u884c\u65f6\u5c31\u6307\u5b9a\u4e86\u5927\u5c0f\u3002
- \u5806
- \u8c03\u7528
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
- \u5171\u4eab\u5e93
- \u5b58\u653e C \u6807\u51c6\u5e93\u548c\u6570\u5b66\u5e93\u7b49\u5171\u4eab\u5e93\u7684\u4ee3\u7801\u548c\u6570\u636e\u3002
- \u6808
- \u5904\u4e8e\u7528\u6237\u5730\u5740\u7a7a\u95f4\u7684\u9876\u90e8\u3002
- \u7f16\u8bd1\u5668\u7528\u5b83\u6765\u5b9e\u73b0\u51fd\u6570\u8c03\u7528\u3002
- \u6808\u53ef\u4ee5\u52a8\u6001\u5730\u6269\u5c55\u548c\u6536\u7f29\u3002\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6\uff0c\u6808\u7684\u5927\u5c0f\u90fd\u4f1a\u589e\u52a0\uff1b\u6bcf\u6b21\u8fd4\u56de\u65f6\uff0c\u6808\u7684\u5927\u5c0f\u90fd\u4f1a\u51cf\u5c11\u3002
- \u5185\u6838\u865a\u62df\u5185\u5b58
- \u4e0d\u5141\u8bb8\u5e94\u7528\u7a0b\u5e8f\u8bfb\u5199\u8fd9\u4e2a\u533a\u57df\uff0c\u4e5f\u4e0d\u80fd\u8c03\u7528\u5176\u4e2d\u7684\u4ee3\u7801\u3002
- \u7a0b\u5e8f\u53ea\u80fd\u8c03\u7528\u5185\u6838\u5bf9\u8fd9\u5757\u533a\u57df\u6267\u884c\u64cd\u4f5c\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
- \u4e3b\u5b58\u4e2d\u5b58\u653e\u4e86\u4e00\u4e2a\u67e5\u8be2\u8868\uff0c\u7528\u4e8e\u52a8\u6001\u5730\u7ffb\u8bd1\u865a\u62df\u5730\u5740\u3002\u8be5\u8868\u7531\u64cd\u4f5c\u7cfb\u7edf\u7ba1\u7406\u3002
- CPU \u82af\u7247\u4e0a\u7684\u5185\u5b58\u7ba1\u7406\u5355\u5143\uff08Memory Management Unit\uff09\u8d1f\u8d23\u4f7f\u7528\u67e5\u8be2\u8868\u7ffb\u8bd1\u865a\u62df\u5730\u5740\u3002
"},{"location":"programming_lecture/lecture2/lecture2/","title":"\u8bb2\u4e49\uff1aC \u8bed\u8a00\u7684\u7c7b\u578b\u7cfb\u7edf\u4e0e\u5185\u5b58\u6a21\u578b","text":"\u65bd\u5de5\u4e2d
\u672c\u9875\u9762\u6b63\u5728\u65bd\u5de5\uff1a
- \u5c06\u8f83\u96be\u5185\u5bb9\u8fc1\u79fb\u5230\u8bfe\u540e\u6a21\u5757\u3002\u5c31\u7a0b\u5e8f\u8bbe\u8ba1\u8fd9\u95e8\u8bfe\u6765\u8bf4\uff0c\u9700\u8981\u8bb2\u8ff0\u7684\u5185\u5bb9\u62bd\u8c61\u7a0b\u5ea6\u8f83\u9ad8\uff0c\u5982\u5927\u7aef\u6cd5\u3001\u5c0f\u7aef\u6cd5\u7b49\u5177\u4f53\u5185\u5bb9\u5219\u65e0\u9700\u8bb2\u89e3\u3002\u4e0e\u8ba1\u7b97\u673a\u7cfb\u7edf\u6709\u5173\u7684\u5185\u5bb9\u5e94\u5f53\u8fc1\u79fb\u5230\u6269\u5c55\u6a21\u5757
- \u4f18\u5316\u8bb2\u4e49\u7ed3\u6784
Abstract
- \u7a0b\u5e8f\u5185\u5b58\u7a7a\u95f4\u7684\u5e03\u5c40
- C \u7c7b\u578b\u7cfb\u7edf\u7684\u63cf\u8ff0
- \u5982\u4f55\u9605\u8bfb\u58f0\u660e
- \u5982\u4f55\u7ba1\u7406\u5185\u5b58
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":" - \u5341\u8fdb\u5236\uff1a
20231029
- \u4e8c\u8fdb\u5236\uff1a
[0b] 1001101001011001101110101
- \u516b\u8fdb\u5236\uff1a
[0o] 115131565
- \u5341\u516d\u8fdb\u5236\uff1a
[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
- \u274c \u96f6\u57c3\u514b\u65af\u5341\u516b\uff0c\u96f6\u53c9\u5341\u516b\uff0c\u96f6\u4e58\u5341\u516b
- \u2705 \u96f6\u57c3\u514b\u65af\u4e00\u516b\uff0c\u96f6\u53c9\u4e00\u516b
0o23
- \u274c \u96f6\u6b27\u4e8c\u5341\u4e09
- \u2705 \u96f6\u6b27\u4e8c\u4e09
0b1010
- \u274c \u96f6\u5e01\u4e00\u5343\u96f6\u4e00\u5341
- \u2705 \u96f6\u5e01\u4e00\u96f6\u4e00\u96f6
0x10000
- \u274c \u96f6\u57c3\u514b\u65af\u4e00\u4e07\uff0c\u96f6\u53c9\u4e00\u4e07\uff0c\u96f6\u4e58\u4e00\u4e07
- \u2705 \u96f6\u57c3\u514b\u65af\u4e00\u96f6\u96f6\u96f6\u96f6\uff0c\u96f6\u53c9\u4e00\u96f6\u96f6\u96f6\u96f6
"},{"location":"programming_lecture/lecture2/lecture2/#ascii","title":"ASCII","text":"\u6bcf\u4e2a\u5b57\u7b26\u5bf9\u5e94\u4e00\u4e2a\u6570\u5b57\uff0c\u5373\u5176 ASCII \u7801\u3002\u5982 A
\u7684 ASCII \u7801\u4e3a 65
\uff0ca
\u7684 ASCII \u7801\u4e3a 97
\u3002
"},{"location":"programming_lecture/lecture2/lecture2/#_3","title":"\u7c7b\u578b\u7cfb\u7edf","text":"\u7c7b\u578b\u662f\u4e0e\u6570\u636e\u76f8\u5173\u7684\u5c5e\u6027\uff0c\u5b83\u51b3\u5b9a\u4e86\u6570\u636e\u7684\u5b58\u50a8\u65b9\u5f0f\u548c\u53ef\u8fdb\u884c\u7684\u64cd\u4f5c\u3002
\u53d8\u91cf\u662f\u6570\u636e\u7684\u8f7d\u4f53\uff0c\u5b83\u662f\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u7684\u4e00\u5757\u7a7a\u95f4\uff0c\u6709\u7c7b\u578b\u548c\u503c\u3002
"},{"location":"programming_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
- \u5176\u7c7b\u578b\u4e3a
int
\uff0c\u6545\u5360\u7528 4 \u5b57\u8282\u3002
"},{"location":"programming_lecture/lecture2/lecture2/#_7","title":"\u57fa\u672c\u7c7b\u578b","text":"\u7c7b\u578b - cppreference.com
\u6574\u6570\u7c7b\u578b\uff1achar
short
int
long
long long
\u5176\u4e2d\uff0c\u9664\u4e86 char
\u4ee5\u5916\u7684\u7c7b\u578b\u9ed8\u8ba4\u4e3a signed
\uff0c\u5373\u6709\u7b26\u53f7\u6570\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cint
\u5c31\u662f signed int
\u3002\u5c06 signed
\u6362\u4e3a unsigned
\uff0c\u5c31\u5f97\u5230\u4e86\u65e0\u7b26\u53f7\u6570\u3002
\u90a3\u4e48 char
\u5462\uff1f
char
signed char
unsigned char
\u662f\u4e09\u4e2a\u4e0d\u540c\u7684\u7c7b\u578b\uff0c\u5c3d\u7ba1\u5728\u5927\u591a\u6570\u5b9e\u73b0\u4e2d\uff0cchar
\u8868\u73b0\u4e3a\u6709\u7b26\u53f7\u6570\u3002
\u5b57\u7b26\u7c7b\u578b\u89e3\u60d1 \u6216\u8bb8\u4f60\u4f1a\u548c\u6211\u540c\u6837\u5bf9\u4ee5\u4e0b\u51e0\u4e2a\u95ee\u9898\u611f\u5230\u56f0\u60d1\uff1a
- \u4e3a\u4ec0\u4e48\u5b57\u7b26\u5e38\u91cf\u7684\u7c7b\u578b\u662f
int
\u4e14\u957f\u5ea6\u662f 4 \u4e2a\u5b57\u8282\uff1f - \u4e3a\u4ec0\u4e48
getchar()
\u7b49\u51fd\u6570\u8fd4\u56de int
\u800c\u4e0d\u662f char
\uff1f - \u5bbd\u5b57\u7b26\u3001\u591a\u5b57\u8282\u5b57\u7b26\u548c Unicode \u7a76\u7adf\u5982\u4f55\u4f7f\u7528\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
- \u5b57\u7b26\u5e38\u91cf\u7684\u7c7b\u578b\u4e3a\u4ec0\u4e48\u662f
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
- What is the purpose of multi character constants in C? - Quora
- \u5b57\u7b26\u5e38\u91cf - cppreference.com
int c = getchar()
? Why int
? : C_Programming (reddit.com) - \u9690\u5f0f\u8f6c\u6362 - cppreference.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
"},{"location":"programming_lecture/lecture2/lecture2/#_8","title":"\u5b9a\u957f\u6574\u6570\u7c7b\u578b\u4e0e\u5176\u4ed6\u6574\u6570\u7c7b\u578b","text":"\u5728 stdint.h
\u4e2d\u5b9a\u4e49\uff0c\u5982 int8_t
uint8_t
int16_t
uint16_t
int32_t
uint32_t
int64_t
uint64_t
\u3002
sizeof
\u8fd0\u7b97\u7b26\u4e0e offsetof
\u5b8f\u7684\u7ed3\u679c\uff1asize_t
\uff0c\u8db3\u591f\u8868\u793a\u4efb\u4f55\u5bf9\u8c61\u7684\u5927\u5c0f\u3002\u5e38\u88ab\u5b9a\u4e49\u4e3a unsigned long
\u3002
\u5728 stddef.h
\u4e2d\u5b9a\u4e49\uff0cptrdiff_t
\u8868\u793a\u4e24\u4e2a\u6307\u9488\u76f8\u51cf\u7684\u7ed3\u679c\u3002\u5e38\u88ab\u5b9a\u4e49\u4e3a long
\u3002
\u5982\u4f55\u8f93\u51fa\u8fd9\u4e9b\u6574\u6570\u7c7b\u578b\uff1f \u5728 inttypes.h
\u4e2d\u5b9a\u4e49\u4e86\u4e00\u7cfb\u5217\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0c\u5982 PRId32
\u4e00\u822c\u5c55\u5f00\u4e3a \"d\"
\uff0c\u800c PRIu64
\u53ef\u80fd\u5c55\u5f00\u4e3a \"llu\"
\u3002
\u8fd9\u4e9b\u5b9a\u4e49\u5728\u4e0d\u540c\u7684\u5e73\u53f0\u4e0a\u53ef\u80fd\u6709\u6240\u4e0d\u540c\u3002\u4f7f\u7528\u8fd9\u4e9b\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u53ef\u4ee5\u4fdd\u8bc1\u5728\u4e0d\u540c\u5e73\u53f0\u4e0a\u8f93\u51fa\u6b63\u786e\u7684\u7ed3\u679c\uff08\u4e14\u4e0d\u4f1a\u5f15\u53d1\u7f16\u8bd1\u5668\u8b66\u544a\uff09\u3002
uint64_t i = 0xdeadbeefcafebabe;\nprintf(\"%\" PRIu64 \"\\n\", i); // \u5e94\u5f53\u5305\u542b inttypes.h\n
\u5bf9\u4e8e size_t
\u548c ptrdiff_t
\uff0c\u53ef\u4ee5\u4f7f\u7528 %zu
\u548c %td
\u3002
"},{"location":"programming_lecture/lecture2/lecture2/#_9","title":"\u7ed3\u6784\u4f53\u3001\u8054\u5408\u4f53\u3001\u679a\u4e3e\u7c7b\u578b","text":"\u679a\u4e3e\u7c7b\u578b\u5b9e\u8d28\u4e0a\u662f\u6574\u6570\u7c7b\u578b\u3002\u5b83\u7684\u503c\u662f\u7531\u7f16\u8bd1\u5668\u81ea\u52a8\u5206\u914d\u7684\uff08\u4e00\u822c\u4ece 0 \u5f00\u59cb\uff09\uff0c\u4e5f\u53ef\u624b\u52a8\u6307\u5b9a\u3002
\u7ed3\u6784\u4f53\u7684\u5927\u5c0f\u662f\u5176\u6210\u5458\u5927\u5c0f\u7684\u603b\u548c\uff0c\u52a0\u4e0a\u5bf9\u9f50\u6240\u9700\u7684\u586b\u5145\u5b57\u8282\u3002
struct point {\n int x;\n long y;\n};\nstruct point p = {1234, -5678};\nMAGIC(p);\n\nunion un_t {\n long l;\n double d;\n};\nunion un_t un;\nun.d = 3.14159265358979323;\nMAGIC(un);\n\nenum en_t { ENA, ENB, ENC = 114514 };\nMAGIC_R(ENA);\nMAGIC_R(ENC);\n\nMAGIC_PTR(&p.x);\nMAGIC_PTR(&p.y);\nMAGIC_PTR(&un.l);\nMAGIC_PTR(&un.d);\n
\u5728\u5c0f\u7aef\u5e8f\u8ba1\u7b97\u673a\u4e0a\u53ef\u80fd\u7684\u8fd0\u884c\u7ed3\u679c =====\np: 16 (0x10) byte\n0000 d2 04 00 00 00 00 00 00 d2 e9 ff ff ff ff ff ff\n=====\nun: 8 (0x8) byte\n0000 18 2d 44 54 fb 21 09 40\n=====\nENA: 4 (0x4) bytes\n0000 00 00 00 00\n=====\nENC: 4 (0x4) bytes\n0000 52 bf 01 00\n&p.x: 0x16d3cee18\n&p.y: 0x16d3cee20\n&un.l: 0x16d3cee10\n&un.d: 0x16d3cee10\n
"},{"location":"programming_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
"},{"location":"programming_lecture/lecture2/lecture2/#typedef","title":"\u4f7f\u7528 typedef
\u4e3a\u73b0\u6709\u7684\u7c7b\u578b\u5b9a\u4e49\u522b\u540d","text":"int a;\n
\u4f60\u5df2\u7ecf\u5f88\u719f\u6089\u8fd9\u6837\u7684\u58f0\u660e\u4e86\uff0c\u5bf9\u5427\uff1fa
\u662f\u4e00\u4e2a int
\u7c7b\u578b\u7684\u53d8\u91cf\u3002
typedef int a;\n
\u8fd9\u5c31\u662f\u8bf4\uff0ca
\u73b0\u5728\u5c31\u662f int
\u7684\u522b\u540d\u3002\u4f60\u53ef\u4ee5\u8fd9\u6837\u4f7f\u7528\u5b83\uff1a
a b; // \u7b49\u4ef7\u4e8e int b;\n
\u6211\u4eec\u4e4b\u524d\u63d0\u5230\u8fc7\u7684 size_t
\u3001ptrdiff_t
\u3001int8_t
\u7b49\u7c7b\u578b\uff0c\u5c31\u662f\u901a\u8fc7 typedef
\u5b9a\u4e49\u7684\u3002
\u8003\u8bd5\u4e2d\u8fd8\u4f1a\u8981\u6c42\u4f60\u9605\u8bfb\u4ee3\u7801\u7247\u6bb5\uff0c\u4e3a\u5f62\u53c2\u7b49\u4f4d\u7f6e\u586b\u5199\u7c7b\u578b\u58f0\u660e\u3002\u8bf7\u53c2\u8003\u5386\u5e74\u5377\u603b\u7ed3\u4e2d\u7684\u4f8b\u9898\u3002
C \u4e0e C++ \u7684 struct
\u5e76\u4e0d\u5b8c\u5168\u4e00\u81f4
\u5bf9\u4e8e\u7ed3\u6784\u4f53
struct point {\n int x;\n int y;\n}\n
\u5728 C++ \u4e2d\uff0c\u6b64\u58f0\u660e\u5f15\u5165\u7684\u65b0\u7c7b\u578b\u540d\u4e3a point
\uff0c\u800c\u5728 C \u4e2d\uff0c\u6b64\u58f0\u660e\u5f15\u5165\u7684\u65b0\u7c7b\u578b\u540d\u4e3a struct point
\u3002point
\u672c\u8eab\u4e0d\u662f\u4e00\u4e2a\u7c7b\u578b\u540d\u3002
\u4e0b\u9762\u7684\u5199\u6cd5\u662f\u5e38\u89c1\u7684\uff1a
typedef struct point point;\n
\u6b64\u5373\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7c7b\u578b\u540d point
\uff0c\u5176\u4e3a struct point
\u7684\u522b\u540d\u3002
"},{"location":"programming_lecture/lecture2/lecture2/#_11","title":"\u5185\u5b58\u6a21\u578b","text":"\u5728 C \u8bed\u8a00\u7684\u5185\u5b58\u6a21\u578b\u4e2d\uff0c\u5b57\u8282\uff08byte\uff09\u662f\u6700\u5c0f\u7684\u53ef\u5bfb\u5740\u7684\u5185\u5b58\u5355\u5143\uff0c\u5176\u88ab\u5b9a\u4e49\u4e3a\u4e00\u7cfb\u5217\u8fde\u7eed\u7684\u4f4d\uff08bit\uff09\u3002\u53ef\u5bfb\u5740\u610f\u5473\u7740\u6bcf\u4e2a\u5b57\u8282\u90fd\u62e5\u6709\u5176\u7f16\u53f7\uff0c\u5373\u5730\u5740\u3002
MAGIC_PTR(&i);\nMAGIC_PTR(&ll);\nMAGIC_PTR(&d);\nMAGIC_PTR(&f);\n\nMAGIC_SIZED(f, 0x20);\n
"},{"location":"programming_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
\uff09 - \u901a\u8fc7
psi
\u53ef\u4ee5\u8bbf\u95ee i
\u5173\u8054\u7684\u5bf9\u8c61\uff08*psi
\uff09 psi
\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\u503c 2 * i
\u6216 &i
\u6216 &psi
\uff0c\u4e0d\u662f\u6807\u8bc6\u7b26\uff0c\u662f\u53f3\u503c
const 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":" - \u9759\u6001\u5b58\u50a8\u671f\uff08static\uff09 \u5728\u7a0b\u5e8f\u5f00\u59cb\u65f6\u521b\u5efa\uff0c\u5728\u7a0b\u5e8f\u7ed3\u675f\u65f6\u9500\u6bc1\u3002\u5982\u5168\u5c40\u53d8\u91cf\u548c\u9759\u6001\u53d8\u91cf\u3002
- \u81ea\u52a8\u5b58\u50a8\u671f\uff08automatic\uff09 \u5728\u7a0b\u5e8f\u8fdb\u5165\u4f5c\u7528\u57df\u65f6\u521b\u5efa\uff0c\u5728\u7a0b\u5e8f\u79bb\u5f00\u4f5c\u7528\u57df\u65f6\u9500\u6bc1\u3002\u5982\u5c40\u90e8\u53d8\u91cf\u3002
- \u52a8\u6001\u5206\u914d\u5b58\u50a8\u671f\uff08allocated\uff09 \u5728\u7a0b\u5e8f\u663e\u5f0f\u5730\u5206\u914d\u5185\u5b58\u65f6\u521b\u5efa\uff0c\u5728\u7a0b\u5e8f\u663e\u5f0f\u5730\u91ca\u653e\u5185\u5b58\u65f6\u9500\u6bc1\u3002\u5982
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
"},{"location":"programming_lecture/lecture2/lecture2/#_20","title":"\u51fd\u6570\u539f\u578b\u4f5c\u7528\u57df","text":"\u51fd\u6570\u539f\u578b\u4e2d\u7684\u53d8\u91cf\u540d\u3002\u4ece\u5b9a\u4e49\u5904\u5230\u51fd\u6570\u539f\u578b\u7ed3\u675f\u3002
\u53ea\u5728\u4f60\u4f7f\u7528 VLA \u65f6\u9700\u8981\u6ce8\u610f\u8fd9\u4e00\u987a\u5e8f\uff1a
void use_VLA(int n, int m, ar[n][m]);\n
"},{"location":"programming_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
- C \u7684\u8f93\u5165\u8f93\u51fa\u6a21\u578b\uff1a\u7f13\u51b2\u4e0e\u6d41\u7684\u6982\u5ff5
- C \u6807\u51c6 I/O \u51fd\u6570
- \u6587\u4ef6\u7f16\u7801\u4e0e\u6587\u4ef6\u8f93\u5165\u8f93\u51fa
"},{"location":"programming_lecture/lecture3/lecture3/#c","title":"C \u7684\u8f93\u5165\u8f93\u51fa\u6a21\u578b","text":""},{"location":"programming_lecture/lecture3/lecture3/#_1","title":"\u7f13\u51b2","text":"\u5e7f\u4e49\u7684\u7f13\u51b2\u533a\u662f\u5185\u5b58\u7a7a\u95f4\u7684\u4e00\u90e8\u5206\uff0c\u5728\u5185\u5b58\u4e2d\u9884\u7559\u4e86\u4e00\u5b9a\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c\u7528\u6765\u6682\u65f6\u4fdd\u5b58\u8f93\u5165\u548c\u8f93\u51fa\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
- buffer\u7f13\u51b2\u533a\u5b58\u50a8\u901f\u5ea6\u4e0d\u540c\u6b65\u7684\u8bbe\u5907\u6216\u8005\u4f18\u5148\u7ea7\u4e0d\u540c\u7684\u8bbe\u5907\u4e4b\u95f4\u7684\u4f20\u8f93\u6570\u636e\uff0c\u6bd4\u5982\u952e\u76d8\u3001\u9f20\u6807\u7b49\uff1b\u6b64\u5916\uff0cbuffer\u4e00\u822c\u662f\u7528\u5728\u5199\u5165\u78c1\u76d8\u7684\uff1b
- Cache\u7f13\u5b58\u533a\u662f\u4f4d\u4e8eCPU\u548c\u4e3b\u5185\u5b58\u4e4b\u95f4\u7684\u5bb9\u91cf\u8f83\u5c0f\u4f46\u901f\u5ea6\u5f88\u5feb\u7684\u5b58\u50a8\u5668\uff0cCache\u4fdd\u5b58\u7740CPU\u521a\u7528\u8fc7\u7684\u6570\u636e\u6216\u5faa\u73af\u4f7f\u7528\u7684\u6570\u636e\uff1bCache\u7f13\u5b58\u533a\u7684\u8fd0\u7528\u4e00\u822c\u662f\u5728I/O\u7684\u8bf7\u6c42\u4e0a
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
- \u5b8c\u5168\u7f13\u51b2\uff1a\u4ec5\u7f13\u51b2\u533a\u586b\u6ee1\u65f6\u5237\u65b0\u7f13\u51b2\u533a\uff08\u5c06\u5185\u5bb9\u53d1\u9001\u81f3\u76ee\u7684\u5730\uff09\uff0c\u901a\u5e38\u7528\u4e8e\u6587\u4ef6\u8f93\u5165\u3002\u7f13\u51b2\u533a\u7684\u5927\u5c0f\u53d6\u51b3\u4e8e\u7cfb\u7edf\uff0c\u5e38\u89c1\u5927\u5c0f\u4e3a512bits\u548c4096bits\u3002
- \u884c\u7f13\u51b2\uff1a\u51fa\u73b0\u6362\u884c\u7b26\u65f6\u5237\u65b0\u7f13\u51b2\u533a\uff0c\u901a\u5e38\u7528\u4e8e\u952e\u76d8\u8f93\u5165\u3002\u6240\u4ee5\u5728\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
\u6211\u53ef\u4ee5\u66f4\u6539\u8f93\u5165\u65b9\u5f0f\u5417\uff1f UNIX \u5e93\u4e2d\u6709 ioctl()
\u51fd\u6570\u7528\u4e8e\u6307\u5b9a\u5f85\u8f93\u5165\u7684\u7c7b\u578b\uff0c\u4f46\u8fd9\u4e0d\u5c5e\u4e8e C \u6807\u51c6\u3002
ANSI C \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 setbuf()
\u548c setvbuf()
\u63a7\u5236\u7f13\u51b2\uff0c\u4f46\u53d7\u9650\u4e8e\u7cfb\u7edf\u7684\u8bbe\u7f6e\u3002
"},{"location":"programming_lecture/lecture3/lecture3/#_2","title":"\u6d41","text":"C \u5e93\u63d0\u4f9b\u7684\u8f93\u5165\u8f93\u51fa\u65b9\u5f0f\u79f0\u4e3a\u6807\u51c6 I/O\uff0c\u5b83\u4eec\u662f\u5efa\u7acb\u5728\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u5e95\u5c42 I/O \u4e0a\u7684\u3002\u5e95\u5c42 I/O \u4e4b\u95f4\u5e38\u5e38\u4f1a\u6709\u4e00\u4e9b\u5dee\u5f02\uff1a
\u5404\u4e2a\u7cfb\u7edf\u7684\u6587\u4ef6\u5dee\u5f02
\u5dee\u5f02 UNIX Windows MacOS \u6362\u884c\u7b26 \\n
LF \\r\\n
CRLF \\n
(\u8f83\u65e9\u7684 MacOS \u4f7f\u7528 \\r
)LF \u6587\u4ef6\u7ed3\u675f\u7b26 ^D
^Z
^D
\u6ce8\uff1a\u5982 ^Z
\u4ee3\u8868 Ctrl+Z
\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8be5\u7ec4\u5408\u952e\u7ed3\u675f\u952e\u76d8\u8f93\u5165\u3002
\u6587\u4ef6\u7ed3\u5c3e\u4e5f\u4e0d\u4e00\u5b9a\u7531\u6587\u4ef6\u7ed3\u675f\u7b26\u6807\u8bb0\u3002\u4e8b\u5b9e\u4e0a\uff0cUNIX \u7cfb\u7edf\u50a8\u5b58\u6587\u4ef6\u5927\u5c0f\u4fe1\u606f\uff0c\u4f9d\u636e\u6587\u4ef6\u5927\u5c0f\u4fe1\u606f\u51b3\u5b9a\u6587\u4ef6\u672b\u5c3e\u3002
\u4ece\u6982\u5ff5\u4e0a\u770b\uff0cC \u5904\u7406\u7684\u662f\u6d41\u800c\u4e0d\u662f\u6587\u4ef6\u3002\u4e0d\u540c\u5c5e\u6027\u548c\u4e0d\u540c\u79cd\u7c7b\u7684\u8f93\u5165\uff0c\u7531\u5c5e\u6027\u66f4\u7edf\u4e00\u7684\u6d41\u6765\u8868\u793a\u3002\u6d41\u544a\u8bc9\u6211\u4eec\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u5904\u7406\u6587\u4ef6\u7684\u65b9\u5f0f\u6765\u5904\u7406\u952e\u76d8\u8f93\u5165\u3002
C\u8bed\u8a00\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
- \u4e0e\u6807\u51c6\u8f93\u5165\u6d41\u5173\u8054\uff0c\u7528\u4e8e\u8bfb\u53d6\u4f20\u7edf\u7684\u8f93\u5165\u3002\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u5f53\u4e14\u4ec5\u5f53\u80fd\u786e\u5b9a\u6d41\u4e0d\u5f15\u7528\u4ea4\u4e92\u5f0f\u8bbe\u5907\u65f6\u8be5\u6d41\u4e3a\u5b8c\u5168\u7f13\u51b2\u3002
- \u4e0e\u6807\u51c6\u8f93\u51fa\u6d41\u5173\u8054\uff0c\u7528\u4e8e\u5199\u5165\u4f20\u7edf\u7684\u8f93\u51fa\u3002\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u5f53\u4e14\u4ec5\u5f53\u80fd\u786e\u5b9a\u6d41\u4e0d\u5f15\u7528\u4ea4\u4e92\u5f0f\u8bbe\u5907\u65f6\u8be5\u6d41\u4e3a\u5b8c\u5168\u7f13\u51b2\u3002
- \u4e0e\u6807\u51c6\u9519\u8bef\u6d41\u5173\u8054\uff0c\u7528\u4e8e\u5199\u5165\u8bca\u65ad\u8f93\u51fa\u3002\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u8be5\u6d41\u4e0d\u4e3a\u5b8c\u5168\u7f13\u51b2\u3002
\u6587\u4ef6\u63cf\u8ff0\u7b26
\u5f53\u4e00\u4e2a\u7a0b\u5e8f\u6210\u529f\u5411\u64cd\u4f5c\u7cfb\u7edf\u8bf7\u6c42\u8bbf\u95ee\u4e00\u4e2a\u6253\u5f00\u7684\u6587\u4ef6, \u5185\u6838\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6307\u5411\u5185\u6838\u4e2d\u5168\u5c40\u6587\u4ef6\u8868(global file table)\u4e2d\u7684\u5165\u53e3\u70b9(entry)\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26. \u6587\u4ef6\u8868\u5165\u53e3\u70b9\u5305\u542b\u5982: \u6587\u4ef6\u7684inode(\u786c\u76d8\u4e2d\u7684\u4f4d\u7f6e), \u5b57\u8282\u504f\u79fb\u91cf(byte offset), \u4ee5\u53ca\u5bf9\u8fd9\u4e2a\u6570\u636e\u6d41\u7684\u8bbf\u95ee\u9650\u5236(\u53ea\u8bfb, \u53ea\u5199\u7b49)\u3002
\u6587\u4ef6\u63cf\u8ff0\u7b26: \u662f\u8ba1\u7b97\u673a\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u88ab\u6253\u5f00\u6587\u4ef6\u7684\u552f\u4e00\u6807\u8bc6. \u5b83\u7528\u6765\u63cf\u8ff0\u4e00\u79cd\u6570\u636e\u8d44\u6e90, \u4ee5\u53ca\u8fd9\u4e2a\u6570\u636e\u8d44\u6e90\u53ef\u4ee5\u5982\u4f55\u88ab\u8bbf\u95ee\u5230\u3002
\u5728 Unix \u7cfb\u7edf\u5f53\u4e2d, \u524d\u4e09\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b260, 1, 2 \u9ed8\u8ba4\u4e3a stdin stdout stderr
"},{"location":"programming_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
"},{"location":"programming_lecture/lecture3/lecture3/#_6","title":"\u65e0\u683c\u5f0f\u8f93\u5165/\u8f93\u51fa","text":"\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
\u529f\u80fd \u51fd\u6570 \u5931\u8d25\u8fd4\u56de\u503c int getchar(void)
int getc(FILE *stream)
int fgetc(FILE *stream)
\u5355\u5b57\u7b26\u8f93\u5165 EOF char *fgets(char *s, int size, FILE *stream)
char *gets_s( char *str, rsize_t n)
\u5b57\u7b26\u4e32\u8f93\u5165 NULL int ungetc(int c, FILE *stream)
\u653e\u56de\u6587\u4ef6\u6d41 EOF int putchar(int c)
int putc(int c, FILE *stream)
int fputc(int c, FILE *stream)
\u5355\u5b57\u7b26\u8f93\u51fa EOF int puts(const char *s)
int fputs(const char *s, FILE *stream)
\u5b57\u7b26\u4e32\u8f93\u51fa EOF \u6ce8\u610f
-
\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()
?
\u90a3\u4e48\u8fd9\u662f\u5426\u4f1a\u9020\u6210 EOF \u4e0d\u80fd\u88ab\u8bc6\u522b\uff0c\u800c\u662f\u88ab\u770b\u4f5c\u5b57\u7b26\u5462\uff1f #define EOF (-1) // unsigned char\u8f6c\u6362\u6210int\u540e\uff0c\u503c\u90fd\u5927\u4e8e\u7b49\u4e8e0\n
\u5bbd\u5b57\u7b26\u8f93\u5165\u8f93\u51fa\u5b9a\u4e49\u4e8e <wchar.h>
\u5934\u6587\u4ef6\u4e2d\uff0c\u533a\u522b\u5728\u4e8e\u5176\u4e00\u4e2a\u5b57\u7b26\u7684\u957f\u5ea6\u4e0d\u540c\u3002C\u8bed\u8a00\u4e2d\u6709\u4e00\u79cd\u7c7b\u578bwchar_t
,\u5176\u957f\u5ea6\u53d6\u51b3\u4e8e\u7f16\u8bd1\u5668\uff1a
- \u5728msvc\u4e2d\uff0c
wchar_t
\u4e3a16\u4f4d\uff0c\u5373unsigned short
\u7c7b\u578b\u3002 - \u5728gcc/Clang\u4e2d\uff0c
wchar_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
\u529f\u80fd \u51fd\u6570 \u5931\u8d25\u8fd4\u56de\u503c int getwchar(void)
int getwc(FILE *stream)
int fgetwc(FILE *stream)
\u5355\u5b57\u7b26\u8f93\u5165 EOF char *fgetws(char *s, int size, FILE *stream)
\u5b57\u7b26\u4e32\u8f93\u5165 NULL int ungetwc(int c, FILE *stream)
\u653e\u56de\u6587\u4ef6\u6d41 EOF int putwchar(int c)
int fputwc(int c, FILE *stream)` \u5355\u5b57\u7b26\u8f93\u51fa EOF int fputws(const char *s, FILE *stream)
\u5b57\u7b26\u4e32\u8f93\u51fa EOF"},{"location":"programming_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
"},{"location":"programming_lecture/lecture3/lecture3/#_8","title":"\u683c\u5f0f\u5b57\u7b26\u4e32","text":"\u683c\u5f0f\u5b57\u7b26\u4e32const char *format
\u7531\u666e\u901a\u591a\u5b57\u8282\u5b57\u7b26\uff08\u9664\u4e86%\uff09\u548c\u8f6c\u6362\u6307\u793a\u6784\u6210\uff0c\u524d\u8005\u88ab\u590d\u5236\u5230\u8f93\u51fa\u6d41\u800c\u65e0\u66f4\u6539\u3002\u6bcf\u4e2a\u8f6c\u6362\u6307\u793a\u62e5\u6709\u4e0b\u5217\u683c\u5f0f\uff1a
- \u5f15\u5165\u7684 % \u5b57\u7b26
- (\u53ef\u9009)\u4e00\u6216\u591a\u4e2a\u4fee\u6539\u8f6c\u6362\u884c\u4e3a\u7684\u6807\u7b7e\uff1a
- - : \u8f6c\u6362\u7ed3\u679c\u5728\u57df\u5185\u5de6\u6821\u6b63\uff08\u9ed8\u8ba4\u4e3a\u53f3\u6821\u6b63\uff09
- +:\u6709\u7b26\u53f7\u8f6c\u6362\u7684\u7b26\u53f7\u59cb\u7ec8\u524d\u7f6e\u4e8e\u8f6c\u6362\u7ed3\u679c\uff08\u9ed8\u8ba4\u7ed3\u679c\u524d\u7f6e\u8d1f\u53f7\u4ec5\u5f53\u5b83\u4e3a\u8d1f\uff09
- \u7a7a\u683c\uff1a\u82e5\u6709\u7b26\u53f7\u8f6c\u6362\u7684\u7ed3\u679c\u4e0d\u4ee5\u7b26\u53f7\u5f00\u59cb\uff0c\u6216\u4e3a\u7a7a\uff0c\u5219\u524d\u7f6e\u7a7a\u683c\u4e8e\u7ed3\u679c\u3002\u82e5\u5b58\u5728 + \u6807\u7b7e\u5219\u5ffd\u7565\u7a7a\u683c\u3002
- # \uff1a\u8fdb\u884c\u66ff\u7528\u5f62\u5f0f\u7684\u8f6c\u6362\u3002\u51c6\u786e\u7684\u6548\u679c\u89c1\u4e0b\u8868\uff0c\u5176\u4ed6\u60c5\u51b5\u4e0b\u884c\u4e3a\u672a\u5b9a\u4e49\u3002
- 0 \uff1a\u5bf9\u4e8e\u6574\u6570\u548c\u6d6e\u70b9\u6570\u8f6c\u6362\uff0c\u4f7f\u7528\u524d\u5bfc\u96f6\u4ee3\u66ff\u7a7a\u683c\u5b57\u7b26\u586b\u5145\u57df\u3002\u5bf9\u4e8e\u6574\u6570\uff0c\u82e5\u663e\u5f0f\u6307\u5b9a\u7cbe\u5ea6\uff0c\u5219\u5ffd\u7565\u6b64\u6807\u7b7e\u3002\u5bf9\u4e8e\u5176\u4ed6\u8f6c\u6362\uff0c\u4f7f\u7528\u6b64\u6807\u7b7e\u5bfc\u81f4\u672a\u5b9a\u4e49\u884c\u4e3a\u3002\u82e5\u5b58\u5728 - \u6807\u7b7e\u5219\u5ffd\u7565 0 \u3002
- (\u53ef\u9009)\u6307\u5b9a\u6700\u5c0f\u57df\u5bbd\u7684\u6574\u6570\u503c\u6216
*
\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 - (\u53ef\u9009)\u540e\u968f\u6574\u6570\u6216
*
\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\u3002 - (\u53ef\u9009)\u6307\u5b9a\u53c2\u6570\u5927\u5c0f\u7684\u957f\u5ea6\u4fee\u9970\u7b26
- \u8f6c\u6362\u683c\u5f0f\u6307\u793a\u7b26
"},{"location":"programming_lecture/lecture3/lecture3/#printf","title":"printf()
\u4e2d\u8f6c\u6362\u8bf4\u660e\u7684\u610f\u4e49","text":"\u8f6c\u6362\u8bf4\u660e\u5b9e\u9645\u4e0a\u662f\u5728\u5c06\u4ee5\u4e8c\u8fdb\u5236\u5b58\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u4e2d\u7684\u503c\u8f6c\u6362\u6210\u4e00\u4e9b\u5217\u5b57\u7b26\u4fbf\u4e8e\u663e\u793a\u3002\u8f6c\u6362\u5b9e\u9645\u4e0a\u662f\u4e00\u79cd\u7ffb\u8bd1\u8bf4\u660e\u3002
\u4f8b\u5982\uff1ad
\uff1a\u5c06\u4e00\u4e2a\u6709\u7b26\u53f7\u7684\u5341\u8fdb\u5236\u6574\u6570\u8f6c\u6362\u6210\u5341\u8fdb\u5236\u6570\u3002
\u4e0b\u9762\u8ba8\u8bba\u51e0\u79cd\u8f6c\u6362\u8bf4\u660e\u7684\u60c5\u51b5\uff1a
-
\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
"},{"location":"programming_lecture/lecture3/lecture3/#scanf","title":"scanf()
","text":"\u5728\u524d\u9762\u6211\u4eec\u4ecb\u7ecd\u4e86printf()
\u4e2d\u7684\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u548c\u8f6c\u6362\u8bf4\u660e\uff0cscanf()
\u4e2d\u4e5f\u6709\u7c7b\u4f3c\u7684\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u548c\u8f6c\u6362\u8bf4\u660e\u3002
\u590d\u6742\u7684\u4f7f\u7528\u65b9\u6cd5\u8bf7\u67e5\u9605scanf\u3002
\u4e0b\u9762\u4ecb\u7ecd\u4e00\u4e9bscanf()
\u7684\u7279\u6027\uff1a
-
scanf()
\u8981\u5c06\u8bfb\u53d6\u7684\u5185\u5bb9\u5b58\u50a8\u5230\u5bf9\u5e94\u53d8\u91cf\u5730\u5740\u4e2d\uff0c\u800c\u4e0d\u662f\u53d8\u91cf\u540d\u3002\u56e0\u6b64\uff0cscanf()
\u7684\u53c2\u6570\u5e94\u8be5\u662f\u53d8\u91cf\u7684\u5730\u5740\u3002
e.g. scanf.c#include <stdio.h>\n#include <stdio.h>\nint main(void)\n{\n int a;\n float b;\n char str[30];\n int c[10];\n\n scanf(\"%d %f\", &a, &b); // \u8bfb\u53d6\u6574\u6570\u548c\u6d6e\u70b9\u6570\n scanf(\"%s\", str); // \u8bfb\u53d6\u5b57\u7b26\u4e32\n scanf(\"%d\", c); // \u8bfb\u53d6\u6574\u6570\u6570\u7ec4\n return 0;\n}\n
-
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
"},{"location":"programming_lecture/lecture3/lecture3/#_9","title":"\u5b9e\u4f8b","text":""},{"location":"programming_lecture/lecture3/lecture3/#_10","title":"\u5b89\u5168\u7684\u8f93\u5165\u51fd\u6570","text":"\u5199\u4e00\u4e2a\u5b89\u5168\u7684\u8f93\u5165\u51fd\u6570
\u4f17\u6240\u5468\u77e5\uff0cC\u8bed\u8a00\u7684gets
\u51fd\u6570\u662f\u4e00\u4e2a\u975e\u5e38\u4e0d\u5b89\u5168\u7684\u51fd\u6570(\u8bf7\u53c2\u8003\u7cfb\u7edf\u77e5\u8bc6\u62fe\u90571)\uff0c\u5728C11\u4e2d\u88ab\u5f03\u7528\uff0c\u8f6c\u4e3agets_s()
\u3002gets()
\u6781\u6709\u53ef\u80fd\u9020\u6210\u7f13\u51b2\u533a\u6ea2\u51fa\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u5199\u4e00\u4e2a\u5b89\u5168\u7684\u8f93\u5165\u51fd\u6570\u3002
s_gets.cchar * 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
"},{"location":"programming_lecture/lecture3/lecture3/#_12","title":"\u6587\u4ef6\u7f16\u7801\u4e0e\u6587\u4ef6\u8f93\u5165\u8f93\u51fa","text":""},{"location":"programming_lecture/lecture3/lecture3/#_13","title":"\u57fa\u7840\u6982\u5ff5","text":""},{"location":"programming_lecture/lecture3/lecture3/#_14","title":"\u4ec0\u4e48\u662f\u6587\u4ef6\uff1f","text":"\u7b80\u5355\u7684\u8bf4\uff0c\u6587\u4ef6\u662f\u5728\u786c\u76d8\u4e0a\u7684\u4e00\u6bb5\u5df2\u547d\u540d\u7684\u50a8\u5b58\u533a\u3002
\u5bf9\u64cd\u4f5c\u7cfb\u7edf\u800c\u8a00\uff0c\u6587\u4ef6\u66f4\u52a0\u590d\u6742\u3002\u6587\u4ef6\u662f\u5177\u6709\u7b26\u53f7\u540d\u7684\uff0c\u5728\u903b\u8f91\u4e0a\u5177\u6709\u5b8c\u6574\u610f\u4e49\u7684\u4e00\u7ec4\u76f8\u5173\u4fe1\u606f\u9879\u7684\u5e8f\u5217\u3002\u6587\u4ef6\u8fd8\u5305\u62ec\u4e86\u4e00\u4e9b\u989d\u5916\u6570\u636e\uff0c\u4fbf\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u786e\u5b9a\u6587\u4ef6\u7684\u79cd\u7c7b\u3002
c_file.c#include<stdio.h>\n#include<string.h>\n\nint main(int argc, char *argv[]){\n const char *str = \"ckc-agc programming lec3\";\n\n FILE *fp1 = fopen(\"test1.txt\", \"wb+\");\n FILE *fp2 = fopen(\"test2.txt\", \"w+\");\n fprintf(fp1, \"%s\\n%s\\n\", str, argv[0]);\n fprintf(fp2, \"%s\\n%s\\n\", str, argv[0]);\n fwrite(str, sizeof(char), strlen(str), fp1);\n\n // fseek(fp1, 0, SEEK_SET);\n // fprintf(fp1, \"%s\\n\", \"SEEK_SET\");\n fseek(fp1, 0, SEEK_END);\n fprintf(fp1, \"%s\\n\", \"SEEK_END\");\n\n rewind(fp1);\n fprintf(fp1, \"%s\\n\", \"rewind\");\n\n fclose(fp1);\n fclose(fp2);\n}\n
$ file c_file.c\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
- ASCII\u5b57\u7b26\u96c6\uff1a 8bit\uff08\u4e00\u4e2a\u5b57\u8282\uff09\uff0c\u80fd\u8868\u793a\u7684\u6700\u5927\u7684\u6574\u6570\u5c31\u662f255\uff082^8-1=255\uff09\u3002ASCII\u7f16\u7801\uff0c\u5360\u75280 - 127\u7528\u6765\u8868\u793a\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e00\u4e9b\u7b26\u53f7\uff0c\u8fd9\u4e2a\u7f16\u7801\u8868\u88ab\u79f0\u4e3aASCII\u7f16\u7801\uff0c\u6bd4\u5982\u5927\u5199\u5b57\u6bcdA\u7684\u7f16\u7801\u662f65\uff0c\u5c0f\u5199\u5b57\u6bcdz\u7684\u7f16\u7801\u662f122\u3002 \u8fd8\u5bf9\u4e00\u4e9b\u5982'\\n'\uff0c'\\t'\uff0c'#'\uff0c'@'\u7b49\u5b57\u7b26\u8fdb\u884c\u4e86\u7f16\u7801\u3002
- base\u5bb6\u65cf\u7f16\u7801:(base16/base32/base64/base58/base85/base100) \u4f7f\u7528\u5bf9\u5e94\u6570\u91cf\u7684\u5b57\u7b26\u7f16\u7801\u4e8c\u8fdb\u5236\u6570\u636e
- GB2312\u7f16\u7801\uff1a 16bit\uff082\u4e2a\u5b57\u8282\uff09\uff0c\u9002\u7528\u4e8e\u6c49\u5b57\u5904\u7406\u3001\u6c49\u5b57\u901a\u4fe1\u7b49\u7cfb\u7edf\u4e4b\u95f4\u7684\u4fe1\u606f\u4ea4\u6362\uff0c\u901a\u884c\u4e8e\u4e2d\u56fd\u5927\u9646\u3002\u4e2d\u56fd\u5927\u9646\u51e0\u4e4e\u6240\u6709\u7684\u4e2d\u6587\u7cfb\u7edf\u548c\u56fd\u9645\u5316\u7684\u8f6f\u4ef6\u90fd\u652f\u6301GB2312\u3002
- GBK\u7f16\u7801\uff1a 16bit\uff082\u4e2a\u5b57\u8282\uff09\uff0c\u517c\u5bb9GB2312\uff0c\u6536\u5f5521003 \u4e2a\u6c49\u5b57\uff0c\u5171\u6709 23940 \u4e2a\u7801\u4f4d\uff0c\u4e0eUnicode\u7ec4\u7ec7\u7684Unicode\u7f16\u7801\u5b8c\u5168\u517c\u5bb9\u3002
- Unicode\u5b57\u7b26\u96c6\uff1a \u4e3a\u4e86\u7edf\u4e00\u6240\u6709\u6587\u5b57\u7684\u7f16\u7801\uff0cUnicode\u5e94\u8fd0\u800c\u751f\uff0c\u8fd9\u662f\u4e00\u79cd\u6240\u6709\u7b26\u53f7\u7684\u7f16\u7801\u3002Unicode \u662f\u56fd\u9645\u6807\u51c6\u5b57\u7b26\u96c6\uff0c\u5b83\u5c06\u4e16\u754c\u5404\u79cd\u8bed\u8a00\u7684\u6bcf\u4e2a\u5b57\u7b26\u5b9a\u4e49\u4e00\u4e2a\u552f\u4e00\u7684\u7f16\u7801\uff0c\u4ee5\u6ee1\u8db3\u8de8\u8bed\u8a00\u3001\u8de8\u5e73\u53f0\u7684\u6587\u672c\u4fe1\u606f\u8f6c\u6362Unicode \u5b57\u7b26\u96c6\u7684\u7f16\u7801\u8303\u56f4\u662f 0x0000 - 0x10FFFF , \u53ef\u4ee5\u5bb9\u7eb3\u4e00\u767e\u591a\u4e07\u4e2a\u5b57\u7b26\uff0c \u6bcf\u4e2a\u5b57\u7b26\u90fd\u6709\u4e00\u4e2a\u72ec\u4e00\u65e0\u4e8c\u7684\u7f16\u7801\uff0c\u4e5f\u5373\u6bcf\u4e2a\u5b57\u7b26\u90fd\u6709\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u503c\u548c\u5b83\u5bf9\u5e94\uff0c\u8fd9\u91cc\u7684\u4e8c\u8fdb\u5236\u6570\u503c\u4e5f\u53eb\u7801\u70b9
- UTF(UTF-8,UTF-16\u7b49)\uff1a Unicode Transformation Format\uff0c\u53ef\u53d8\u957f\u5ea6\u7f16\u7801\uff0c\u901a\u5e38\u4f7f\u75281~4\u5b57\u8282\u4e3a\u6bcf\u4e2a\u5b57\u7b26\u7f16\u7801\uff0c\u517c\u5bb9ASCII\u7f16\u7801\uff0c\u8fd9\u662f\u4e00\u79cdUnicode\u7684\u4e00\u79cd\u8f6c\u6362\u683c\u5f0f\u3002
\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
\u6807\u51c6\u6587\u4ef6 C\u7a0b\u5e8f\u4f1a\u81ea\u52a8\u6253\u5f003\u4e2a\u6587\u4ef6\uff0c\u5b83\u4eec\u88ab\u79f0\u4e3a\u6807\u51c6\u8f93\u5165\uff08standard input\uff09\u3001\u6807\u51c6\u8f93\u51fa\uff08standard output\uff09\u548c\u6807\u51c6\u9519\u8bef\u8f93\u51fa\uff08standard error output\uff09\u3002\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6807\u51c6\u8f93\u5165\u662f\u7cfb\u7edf\u7684\u666e\u901a\u8f93\u5165\u8bbe\u5907\uff0c\u901a\u5e38\u4e3a\u952e\u76d8\uff1b\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u662f\u7cfb\u7edf\u7684\u666e\u901a\u8f93\u51fa\u8bbe\u5907\uff0c\u901a\u5e38\u4e3a\u663e\u793a\u5c4f\u3002
\u901a\u5e38\uff0c\u6807\u51c6\u8f93\u5165\u4e3a\u7a0b\u5e8f\u63d0\u4f9b\u8f93\u5165\uff0c\u5b83\u662f getchar()
\u548c scanf()
\u4f7f\u7528\u7684\u6587\u4ef6\u3002\u7a0b\u5e8f\u901a\u5e38\u8f93\u51fa\u5230\u6807\u51c6\u8f93\u51fa\uff0c\u5b83\u662fputchar()
\u3001puts()
\u548cprintf()
\u4f7f\u7528\u7684\u6587\u4ef6\u3002\u524d\u6587\u63d0\u5230\u7684\u91cd\u5b9a\u5411\u628a\u5176\u4ed6\u6587\u4ef6\u89c6\u4e3a\u6807\u51c6\u8f93\u5165\u6216\u6807\u51c6\u8f93\u51fa\u3002\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u63d0\u4f9b\u4e86\u4e00\u4e2a\u903b\u8f91\u4e0a\u4e0d\u540c\u7684\u5730\u65b9\u6765\u53d1\u9001\u9519\u8bef\u6d88\u606f\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f7f\u7528\u91cd\u5b9a\u5411\u628a\u8f93\u51fa\u53d1\u9001\u7ed9\u6587\u4ef6\u800c\u4e0d\u662f\u5c4f\u5e55\uff0c\u90a3\u4e48\u53d1\u9001\u81f3\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u7684\u5185\u5bb9\u4ecd\u7136\u4f1a\u88ab\u53d1\u9001\u5230\u5c4f\u5e55\u4e0a\u3002\u8fd9\u6837\u5f88\u597d\uff0c\u56e0\u4e3a\u5982\u679c\u628a\u9519\u8bef\u6d88\u606f\u53d1\u9001\u81f3\u6587\u4ef6\uff0c\u5c31\u53ea\u80fd\u6253\u5f00\u6587\u4ef6\u624d\u80fd\u770b\u5230\u3002
\u7406\u89e3\uff1a\u6807\u51c6I/O\u4e2d\u7528FILE\uff08\u6d41\uff09\u8868\u793a\u4e00\u4e2a\u6253\u5f00\u7684\u6587\u4ef6
"},{"location":"programming_lecture/lecture3/lecture3/#_17","title":"\u6d41\u548c\u6587\u4ef6","text":"C \u6807\u51c6\u662f\u8fd9\u6837\u63cf\u8ff0\u4e24\u79cd\u6d41\u7684\uff1a
- \u6587\u672c\u6d41\uff1a\u7ec4\u6210\u6587\u672c\u884c\u7684\u6709\u5e8f\u5b57\u7b26\u5e8f\u5217\uff0c\u6bcf\u4e00\u884c\u7531\u96f6\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u52a0\u4e0a\u6807\u5fd7\u7ed3\u675f\u7684\u6362\u884c\u7b26\u7ec4\u6210\u3002
- \u5b9e\u73b0\u5b9a\u4e49\uff1a\u6700\u540e\u4e00\u884c\u662f\u5426\u9700\u8981\u6362\u884c\u7b26\u3001\u6362\u884c\u7b26\u6b63\u524d\u9762\u7684\u7a7a\u683c\u662f\u5426\u5728\u8bfb\u53d6\u65f6\u51fa\u73b0\u7b49\u3002
- \u4e8c\u8fdb\u5236\u6d41\uff1a\u5b57\u7b26\u7684\u6709\u5e8f\u5e8f\u5217\u3002
\u5173\u4e8e\u6587\u4ef6\u52a8\u4f5c\uff1a
- \u6253\u5f00\u6587\u4ef6\uff1a\u6d41\u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\uff0c\u5c31\u662f\u4e0e\u8be5\u6587\u4ef6\u5173\u8054\u3002
- \u521b\u5efa\u6587\u4ef6\u4f1a\u4e22\u5f03\u5185\u5bb9\u3002
- \u548c\u6d41\u76f8\u5173\u7684\u6587\u4ef6\u5b9a\u4f4d\u7b26\u5b9a\u4f4d\u5728\u6587\u4ef6\u8d77\u59cb\u4f4d\u7f6e\u3002
- \u9644\u52a0\u6a21\u5f0f\u4e0b\u5b9a\u4f4d\u4f4d\u7f6e\u7531\u5b9e\u73b0\u51b3\u5b9a\u3002
- \u5173\u95ed\u6587\u4ef6\uff1a\u5173\u95ed\u6587\u4ef6\u4f1a\u91ca\u653e\u4e0e\u8be5\u6587\u4ef6\u76f8\u5173\u7684\u8d44\u6e90\u3002
"},{"location":"programming_lecture/lecture3/lecture3/#_18","title":"\u7c7b\u578b\u548c\u5b8f","text":"\u5728 <stdio.h>
\u4e2d\u6709\u5982\u4e0b\u4e0e\u6587\u4ef6\u76f8\u5173\u7684\u7c7b\u578b\u548c\u5b8f\uff1a
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\u3002 - \u4e0d\u8981\u8bd5\u56fe\u63a2\u7d22
FILE *
\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\u3002
fpos_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\u3002 stderr
, stdin
, stdout
\u90fd\u662f FILE*
\u7c7b\u578b\u7684\u8868\u8fbe\u5f0f\u3002 EOF
\u5c55\u5f00\u4e3a\u4e00\u4e2a\u8d1f\u7684\u6574\u503c\u5e38\u91cf\u3002 NULL
SEEK_CUR
\u6587\u4ef6\u5f53\u524d\u4f4d\u7f6e SEEK_END
\u6587\u4ef6\u7ed3\u675f\u4f4d\u7f6e SEEK_SET
\u6587\u4ef6\u5f00\u59cb\u4f4d\u7f6e
"},{"location":"programming_lecture/lecture3/lecture3/#_19","title":"\u51fd\u6570","text":""},{"location":"programming_lecture/lecture3/lecture3/#_20","title":"\u6587\u4ef6\u64cd\u4f5c\uff1a","text":" int remove (const char *filename)
int rename (const char *old, const char *new)
FILE *tmpfile(void)
char * tmpnam(char *s)
"},{"location":"programming_lecture/lecture3/lecture3/#_21","title":"\u6587\u4ef6\u8bbf\u95ee\uff1a","text":" int fclose(FILE *stream)
- \u5173\u95ed\u6587\u4ef6\uff0c\u6e05\u7a7a\u6d41\uff08\u6e05\u7a7a\u6d41\u5c31\u662f\u4f20\u9012\u7f13\u51b2\u6570\u636e\uff09\uff0c\u91ca\u653e\u7f13\u51b2\u3002
int fflush(FILE *stream)
- \u7acb\u5373\u5199\u5165\uff08\u8981\u6c42\u4e0a\u4e00\u6b21\u64cd\u4f5c\u662f\u8f93\u51fa\uff09\u3002
FILE *fopen(const char *filename, const char *mode)
- \u6253\u5f00\u6587\u4ef6\uff0c\u8fd4\u56de\u6587\u4ef6\u6d41\u6307\u9488\u3002
FILE *freopen(const char *filename, const char *mode, FILE *stream)
void setbuf(FILE *stream, char *buf)
- \u5b9a\u4e49\u6d41 stream \u5e94\u5982\u4f55\u7f13\u51b2\u3002\u8be5\u51fd\u6570\u5e94\u5728\u4e0e\u6d41 stream \u76f8\u5173\u7684\u6587\u4ef6\u88ab\u6253\u5f00\u65f6\uff0c\u4e14\u8fd8\u672a\u53d1\u751f\u4efb\u4f55\u8f93\u5165\u6216\u8f93\u51fa\u64cd\u4f5c\u4e4b\u524d\u88ab\u8c03\u7528\u4e00\u6b21
int setvbuf(FILE *stream, char *buf, int mode, size_t size)
- \u521b\u5efa\u4f9b\u6807\u51c6I/O\u51fd\u6570\u66ff\u6362\u4f7f\u7528\u7684\u7f13\u51b2\u533a
"},{"location":"programming_lecture/lecture3/lecture3/#mode","title":"mode \u5b57\u7b26\u4e32\u7684\u542b\u4e49\uff1a","text":"flag meaning r read w write (new or cut) a append (new or append) b binary + update \u6ce8\u610f\u4e0a\u9762\u8bcd\u8bed\u7684\u542b\u4e49\uff0cupdate \u548c append \u80fd\u5199\u5165\u7684\u8303\u56f4\u5e94\u8be5\u662f\u4e0d\u540c\u7684\u3002
- append \u6a21\u5f0f\u4e0b\u6240\u6709\u5199\u64cd\u4f5c\u5f3a\u5236\u52a0\u5230\u6587\u4ef6\u7ed3\u675f\u5904\u3002
- update \u6a21\u5f0f\u4e0b\uff0c\u82e5\u4e0d\u8c03\u7528\u6587\u4ef6\u5b9a\u4f4d\u51fd\u6570\uff0c\u8f93\u5165\u8f93\u51fa\u4e0d\u4e00\u5b9a\u76f8\u4e92\u7d27\u8ddf\u3002
\u5bf9\u4e8e UNIX \u8fd9\u79cd\u53ea\u6709\u4e00\u79cd\u6587\u4ef6\u7c7b\u578b\u7684\u7cfb\u7edf\uff0c\u5e26 b
\u4e0e\u5426\u7684\u6a21\u5f0f\u662f\u76f8\u540c\u7684\u3002 C11 \u4e2d\u65b0\u589e\u4e86 x
\uff0c\u5e26\u8be5\u5b57\u6bcd\u7684\u5199\u6a21\u5f0f\u6253\u5f00\u5b58\u5728\u6587\u4ef6\u4f1a\u5931\u8d25\uff08\u76f8\u5f53\u4e8e\u52a0\u4e86\u4fdd\u62a4\uff09\uff0c\u4e14\u5141\u8bb8\u72ec\u5360\u3002
"},{"location":"programming_lecture/lecture3/lecture3/#_22","title":"\u683c\u5f0f\u5316\u8f93\u5165/\u8f93\u51fa","text":"fprintf
,fscanf
,vfprintf
,vprintf
,vsprintf
"},{"location":"programming_lecture/lecture3/lecture3/#_23","title":"\u5b57\u7b26\u8f93\u5165/\u8f93\u51fa","text":"fgetc
,fgets
,fputc
,fputs
,getc
,getchar
,gets_s
/(gets)
,putc
,putchar
,puts
,ungetc
\u5176\u4e2d\uff0cfgetc()
\u4e0e getc()
\u8fd9\u7c7b\u51fd\u6570\u7684\u4e0d\u540c\u662f\u540e\u8005\u53ef\u80fd\u88ab\u5b9e\u73b0\u4e3a\u5b8f\u3002
"},{"location":"programming_lecture/lecture3/lecture3/#io_1","title":"\u76f4\u63a5 I/O","text":" 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)
"},{"location":"programming_lecture/lecture3/lecture3/#_24","title":"\u6587\u4ef6\u5b9a\u4f4d","text":" int fseek(FILE *stream, long int offset, int whence)
whence
\u53ef\u4ee5\u662f SEEK_SET
\u3001SEEK_CUR
\u3001SEEK_END
- \u7b2c\u4e8c\u4e2a\u53c2\u6570\u8868\u793a\u504f\u79fb\u91cf
- \u5c06\u6587\u4ef6\u7c7b\u6bd4\u4e3a\u6570\u7ec4\uff0c\u5355\u4f4d\u662f\u5b57\u8282\u6570
long int ftell(FILE *stream)
- \u8ddd\u6587\u4ef6\u5f00\u59cb\u5904\u7684\u5b57\u8282\u6570
void rewind(FILE *stream)
"},{"location":"programming_lecture/lecture3/lecture3/#_25","title":"\u5176\u4ed6","text":"\u4ee5\u4e0b\u4e24\u4e2a\u51fd\u6570\u7528\u4e8e\u5904\u7406\u66f4\u5927\u578b\u7684\u6587\u4ef6\uff08long
\u65e0\u6cd5\u8868\u793a\u7684\u504f\u79fb\u503c\uff09
int fgetpos(FILE *stream, fpos_t *pos)
int fsetpos(FILE *stream, const fpos_t *pos)
"},{"location":"programming_lecture/lecture3/pre_class/","title":"\u8bfe\u524d\uff1a\u4e00\u4e9b\u6837\u4f8b","text":"\u628a\u8bb2\u4e49\u91cc\u7684\u5c0f\u7a0b\u5e8f\u548c\u547d\u4ee4\u884c\u8dd1\u4e00\u8dd1\uff0c\u601d\u8003\u4e00\u4e0b\u7559\u4e0b\u7684\u95ee\u9898\uff5e
-
\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()
wrong_cnv.c#include <stdio.h>\n#define num 336\n#define b 65618\nint main(void)\n{\n printf(\"num as short and unsigned short: %hd %hu\\n\", num,num);\n printf(\"-num as short and unsigned short: %hd %hu\\n\", -mnum,-mnum);\n printf(\"num as int and char: %d %c\\n\", num, num);\n printf(\"b as int, short, and char: %d %hd %c\\n\",b, b, b);\n\n float n1 = 3.0;\n double n2 = 3.0;\n long n3 = 2000000000;\n long n4 = 1234567890;\n printf(\"%.1e %.1e %.1e %.1e\\n\", n1, n2, n3, n4);\n printf(\"%ld %ld\\n\", n3, n4);\n printf(\"%ld %ld %ld %ld\\n\", n1, n2, n3, n4);\n return 0;\n}\n
\u8be5\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c\u4e3a(\u7531\u4e8e\u5b9e\u73b0\u662f\u672a\u5b9a\u4e49\u7684\uff0c\u90e8\u5206\u7ed3\u679c\u56e0\u7cfb\u7edf\u548c\u7f16\u8bd1\u5668\u800c\u5f02)\uff1a
num as short and unsigned short: 336 336\n-num as short and unsigned short: -336 65200\nnum as int and char: 336 P\nb as int, short, and char: 65618 336 R\n3.0e+00 3.0e+00 2.0e+09 1.2e+09\n2000000000 1234567890\n0 1074266112 0 1074266112\n
\u4f60\u80fd\u89e3\u91ca\u4e3a\u4ec0\u4e48\u4f7f\u7528%ld \u8f93\u51fa long \u7c7b\u578b\u7684\u503c\u65f6\uff0c\u4e5f\u4f1a\u51fa\u73b0\u9519\u8bef\u5417\uff1f
-
\u5173\u4e8escanf()
confusing_scanf.c#include <stdio.h>\nint main(void)\n{\n char c[100] = {0};\n scanf(\"%s\\n\",&c);\n printf(\"%s\",c);\n}\n
\u8fd9\u4e2a\u7a0b\u5e8f\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u5947\u602a\uff1f
-
\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
"},{"location":"programming_lecture/lecture4/after_class/","title":"\u8bfe\u540e\u6269\u5c55\uff1aC \u6807\u51c6\u5e93\u7684\u5b9e\u73b0","text":"\u65bd\u5de5\u4e2d
\u672c\u9875\u9762\u6b63\u5728\u7f16\u8f91\u4e2d\u3002
"},{"location":"programming_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
- \u5408\u683c\u7a0b\u5e8f\u5458\uff1a
<ctype.h> <stdio.h> <stdlib.h> <string.h>\n
- \u719f\u7ec3\u7a0b\u5e8f\u5458\uff1a
<assert.h> <limits.h> <stddef.h> <time.h>\n
- \u4f18\u79c0\u7a0b\u5e8f\u5458\uff1a
<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
- \u5b57\u7b26\u4e32\u3001\u6570\u7ec4\u3001\u6307\u9488\u7b49\u64cd\u4f5c
- \u547d\u540d\u7a7a\u95f4\uff1a\u5e93\u4e2d\u5b9a\u4e49\u4e86 200 \u4e2a\u4ee5\u4e0a\u7684\u540d\u5b57\uff0c\u4f60\u5e94\u5f53\u77e5\u9053 C \u4e2d\u5404\u79cd\u540d\u5b57\u4f1a\u5982\u4f55\u88ab\u89e3\u6790\u3002
\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
- \u4e00\u4e2a\u5b9e\u73b0\u5fc5\u987b\u4e3a\u6bcf\u4e00\u4e2a\u5e93\u51fd\u6570\u63d0\u4f9b\u4e00\u4e2a\u5b9e\u9645\u7684\u51fd\u6570\uff0c\u5373\u4f7f\u5b83\u5df2\u7ecf\u4e3a\u8be5\u51fd\u6570\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5b8f\u3002
- \u4e00\u4e2a\u51fd\u6570\u7684\u4efb\u4f55\u5b8f\u5b9a\u4e49\u90fd\u53ef\u4ee5\u901a\u8fc7\u7528\u62ec\u53f7\u628a\u51fd\u6570\u7684\u540d\u5b57\u62ec\u4f4f\u6765\u5c40\u90e8\u5730\u6291\u5236\u5b83\u3002\u56e0\u4e3a\u8fd9\u4e2a\u540d\u5b57\u540e\u9762\u6ca1\u6709\u8ddf\u7740\u6307\u793a\u4e00\u4e2a\u5b8f\u51fd\u6570\u540d\u5c55\u5f00\u5730\u5de6\u62ec\u53f7\u3002
- \u7528\u6765\u79fb\u9664\u4efb\u4f55\u5b8f\u5b9a\u4e49\u7684
#undef
\u9884\u5904\u7406\u6307\u4ee4\u7684\u4f7f\u7528\u4e5f\u53ef\u4ee5\u4fdd\u8bc1\u5b9e\u9645\u51fd\u6570\u7684\u5f15\u7528\u3002
atoi()
\u7684\u4f7f\u7528\u65b9\u5f0f
- \u53ef\u80fd\u751f\u6210\u4e00\u4e2a\u5b8f\u51fd\u6570\uff1a
#include <stdlib.h>\nconst char *str;\ni = atoi(str);\n
- \u751f\u6210\u4e00\u4e2a\u5b9e\u9645\u51fd\u6570\u5f15\u7528\uff1a
#include <stdlib.h>\n#undef atoi\nconst char *str;\ni = atoi(str);\n
\u6216\u8005 #include <stdlib.h>\nconst char *str;\ni = (atoi)(str);\n
"},{"location":"programming_lecture/lecture4/after_class/#stdioh","title":"<stdio.h>
\u7684\u5b9e\u73b0\uff1a\u7cfb\u7edf\u8c03\u7528\u4e0e\u5185\u6838\u7f16\u7a0b","text":"\u5728\u6211\u4e2a\u4eba\u770b\u6765\uff0c<stdio.h>
\u7684\u5b9e\u73b0\u6700\u5177\u6311\u6218\u6027\u3002\u4f60\u9700\u8981\u5bf9\u5b9e\u73b0\u5bf9\u5e94\u7684\u64cd\u4f5c\u7cfb\u7edf\u6709\u4e00\u5b9a\u7684\u4e86\u89e3\uff0c\u624d\u80fd\u7f16\u5199\u51fa\u5b8c\u5584\u7684\u4ee3\u7801\u3002
\u672c\u8282\u4ee5 UNIX \u548c POSIX \u89c4\u8303\u7684\u7cfb\u7edf\u8c03\u7528\u4e3a\u51c6\u3002
\u4e00\u4e9b\u5386\u53f2\u7684\u80cc\u666f\uff1a\u6587\u4ef6\u3001\u8bbe\u5907\u548c ioctl
- \u6df7\u4e71\u7684\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf
\u6216\u8bb8\u4f60\u5f88\u96be\u60f3\u8c61\uff0cUNIX \u4e4b\u524d\u7684\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf\u4e3a\u6587\u4ef6\u8d4b\u4e88\u4e86\u5f88\u591a\u7c7b\u578b\u4e0a\u7684\u6982\u5ff5\u548c\u3001\u4f5c\u4e86\u5f88\u591a\u533a\u5206\uff0c\u800c\u4e0d\u662f\u6211\u4eec\u73b0\u5728\u6240\u5e7f\u6cdb\u63a5\u53d7\u7684\u300c\u6587\u4ef6\u5c31\u662f\u4e00\u7cfb\u5217\u8fde\u7eed\u7684\u5b57\u8282\u300d\u7684\u6982\u5ff5\u3002\u8fd9\u8fb9\u6709\u4e00\u6bb5\u63cf\u8ff0\uff0c\u4f60\u53ef\u4ee5\u770b\u770b\uff1a
Typically source code was a distinguished type, different from data. Compilers could read source, compiled programs could read and write 'data.' Thus the creation and inspection of Fortran programs was often walled off from the creation and inspection of other files, with completely different ways to edit and print them. This ruled out the use of programs to generate (or even simply copy) Fortran programs.
- \u4e0d\u7edf\u4e00\u7684\u6587\u672c\u8868\u793a\u548c\u8bbe\u5907\u4ea4\u4e92
\u65e9\u671f\u7a0b\u5e8f\u7684\u8f93\u5165\u8f93\u51fa\u65e0\u6cd5\u72ec\u7acb\u4e8e\u8bbe\u5907\u3002\u6bd4\u5982\uff0c\u5728\u4e0a\u4e2a\u4e16\u7eaa 60 \u5e74\u4ee3\u7684 FORTRAN IV \u4e2d\uff0c\u5728\u78c1\u5e26\u673a\u4e0a\u9700\u8981\u7528 READ INPUT TAPE 5
\uff0c\u8bfb\u53d6\u78c1\u76d8\u4e0a\u9700\u8981\u7528 READ INPUT DISK 1
\u3002\u8fd9\u6837\u7684\u4ee3\u7801\u5728\u4e0d\u540c\u7684\u8bbe\u5907\u4e0a\u9700\u8981\u4fee\u6539\uff0c\u975e\u5e38\u4e0d\u65b9\u4fbf\u3002UNIX \u5c06\u8fd9\u4e9b\u6df7\u4e71\u7684\u8bbe\u5907\u4ea4\u4e92\u5c01\u88c5\u5728\u8bbe\u5907\u5904\u7406\u7a0b\u5e8f\u4e2d\u3002\u5728 UNIX \u7cfb\u7edf\u770b\u6765\uff0c\u5916\u56f4\u8bbe\u5907\u6709\u4e09\u79cd\u7c7b\u578b\uff1a\u5b57\u7b26\u8bbe\u5907\uff08Character devices\uff09\u3001\u5757\u8bbe\u5907\uff08Block devices\uff09\u548c\u7f51\u7edc\u8bbe\u5907\uff08Network devices\uff09\u3002\u8fd9\u4e09\u79cd\u8bbe\u5907\u90fd\u88ab\u62bd\u8c61\u4e3a\u6587\u4ef6\uff0c\u4f7f\u7528\u7edf\u4e00\u7684\u6587\u4ef6\u64cd\u4f5c\u63a5\u53e3\u3002
\u5728 Ken Thompson \u4e3a UNIX \u8bbe\u8ba1\u7edf\u4e00\u7684\u5185\u90e8\u6587\u672c\u5f62\u5f0f\u524d\uff0c\u6587\u672c\u8868\u793a\u4e5f\u662f\u5341\u5206\u6df7\u4e71\u7684\u3002\u7ed3\u675f\u4e00\u884c\u662f\u4f7f\u7528\u56de\u8f66\u8fd8\u662f\u56de\u8f66\u52a0\u6362\u884c\uff0c\u8fd8\u662f\u6362\u884c\u7b26\uff0c\u8fd8\u662f\u66f4\u795e\u5947\u7684\u5b57\u7b26\uff1f\u7ec8\u7aef\u80fd\u4e0d\u80fd\u8bc6\u522b\u548c\u5c55\u5f00\u5236\u8868\u7b26\uff1f\u600e\u6837\u7528\u952e\u76d8\u6807\u5fd7\u6587\u4ef6\u7ed3\u675f\uff1f\u8fd9\u4e9b\u95ee\u9898\u7684\u7b54\u6848\u548c\u7ec8\u7aef\u7684\u751f\u4ea7\u5382\u5546\u4e00\u6837\u591a\u3002UNIX \u4f7f\u7528\u7cfb\u7edf\u8c03\u7528 ioctl
\u6765\u8bbe\u7f6e\u4e00\u4e2a\u8bbe\u5907\u7684\u5404\u79cd\u53c2\u6570\uff0c\u8d1f\u8d23\u5bf9\u5185\u90e8\u6362\u884c\u7ea6\u5b9a\u548c\u5404\u79cd\u7ec8\u7aef\u4e4b\u95f4\u7684\u9700\u8981\u8f6c\u6362\u7684\u5b57\u7b26\u8fdb\u884c\u5904\u7406\u3002
UNIX Devices Drivers
\u9884\u5907\u77e5\u8bc6\uff1aUNIX \u7cfb\u7edf\u8c03\u7528
"},{"location":"programming_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
- \u6309\u7167\u8003\u8bd5\u8981\u6c42\uff0c\u628a\u6807\u51c6\u5e93\u4e2d\u5927\u5bb6\u5e94\u8be5\u77e5\u9053\u7684\u5185\u5bb9\u4ecb\u7ecd\u4e00\u904d\u3002
- \u7ed3\u5408\u4e00\u4e9b\u5e94\u7528\u7684\u4f8b\u5b50\uff0c\u4e32\u8bb2\u4e00\u4e0b\u4e4b\u524d\u7684\u8bed\u6cd5\u91cd\u70b9\u3002
\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
"},{"location":"programming_lecture/lecture4/lecture4/#c_1","title":"\u5bfc\u5f15\uff1aC \u6807\u51c6\u5e93\uff0c\u5b66\u4e9b\u4ec0\u4e48\uff1f","text":""},{"location":"programming_lecture/lecture4/lecture4/#_1","title":"\u4e3a\u4ec0\u4e48\u8981\u5b66\u6807\u51c6\u5e93\uff1f","text":"\u6709\u4e00\u4e2a\u7c97\u6d45\u7684\u7406\u7531\uff0c\u5c31\u662f\u56fe\u65b9\u4fbf\u3002\u5047\u8bbe\u6709\u4e0b\u9762\u8fd9\u4e2a\u58f0\u660e\u5728 main
\u51fd\u6570\u4e2d\u6570\u7ec4\uff1a
int a[100];\n
\u6211\u4eec\u77e5\u9053\uff0c\u8fd9\u4e2a\u6570\u7ec4\u4e0d\u4f1a\u88ab\u521d\u59cb\u5316\u3002\u5982\u679c\u60f3\u8981\u628a\u8fd9\u4e2a\u6570\u7ec4\u5168\u90e8\u7f6e\u4e3a 0\uff0c\u4f60\u4f1a\u600e\u4e48\u5199\u5462\uff1f
\u9996\u5148\u4f1a\u6709\u7684\u60f3\u6cd5\u80af\u5b9a\u662f\uff1a
for (int i = 0; i < 100; ++i)\n a[i] = 0;\n
\u5176\u5b9e\u6807\u51c6\u5e93\u63d0\u4f9b\u4e86\u4e00\u4e2a\u51fd\u6570 memset
\uff0c\u7528\u6765\u8bbe\u7f6e\u4e00\u6bb5\u5185\u5b58\u7684\u503c\uff1a
memset(a, 0, sizeof(a));\n
\u662f\u4e0d\u662f\u5f88\u65b9\u4fbf\u5462\uff1f
\u518d\u6765\u4e00\u4e2a\u4f8b\u5b50\uff0c\u628a\u8f93\u5165\u4e2d\u6240\u6709\u7684\u5c0f\u5199\u5b57\u6bcd\u8f6c\u6362\u6210\u5927\u5199\u5b57\u6bcd\u3002\u5047\u8bbe\u8f93\u5165\u5df2\u7ecf\u5b58\u50a8\u5728 char
\u6570\u7ec4 str
\u4e2d\uff0c\u6839\u636e\u73b0\u6709\u7684\u77e5\u8bc6\uff0c\u4f60\u4f1a\u4e0d\u4f1a\u8fd9\u6837\u5199\uff1a
for(int i = 0; i < strlen(str); ++i)\n if ('a' <= str[i] && str[i] <= 'z')\n str[i] -= 'a' - 'A';\n
\u5176\u5b9e\u6807\u51c6\u5e93\u63d0\u4f9b\u4e86\u5224\u65ad\u5b57\u7b26\u5927\u5c0f\u5199\u7684\u51fd\u6570\uff0c\u4e5f\u63d0\u4f9b\u4e86\u8f6c\u6362\u5927\u5c0f\u5199\u7684\u51fd\u6570\uff1a
for(int i = 0; i < strlen(str); ++i)\n if (islower(str[i]))\n str[i] = toupper(str[i]);\n
\u4e0b\u9762\u7684\u8fd9\u6bb5\u4ee3\u7801\uff0c\u662f\u4e0d\u662f\u6bd4\u4e0a\u9762\u7684\u4ee3\u7801\u7b80\u6d01\uff0c\u5e76\u4e14\u4e00\u773c\u770b\u8fc7\u53bb\u5c31\u80fd\u660e\u767d\u610f\u601d\u5462\uff1f
\u603b\u800c\u8a00\u4e4b\uff0cC \u6807\u51c6\u5e93\u529f\u80fd\u5f3a\u5927\uff0c\u5b83\u7684\u91cd\u8981\u6027\u548c\u8bed\u8a00\u672c\u8eab\u4e00\u6837\u3002\u5b66\u4f1a\u4f7f\u7528\u6807\u51c6\u5e93\uff0c\u8ba9\u4f60\u5c11\u9020\u8f6e\u5b50\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3001\u7b80\u6d01\u6027\u548c\u6b63\u786e\u6027\u3002
"},{"location":"programming_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
- \u7c7b\u578b\u5b9a\u4e49
- \u5b8f
- \u51fd\u6570
\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
- \u4f1a\u9605\u8bfb\u51fd\u6570\u539f\u578b/\u51fd\u6570\u58f0\u660e/\u51fd\u6570\u7b7e\u540d\uff08\u5b83\u4eec\u8bf4\u7684\u662f\u4e00\u4e2a\u4e1c\u897f\uff09\uff1a
int main(void);\n
-
\u6307\u9488 \u7684\u6982\u5ff5
- \u5185\u5b58\u3001\u5185\u5b58\u5730\u5740\u3001\u5bf9\u8c61
- \u6307\u9488\u4e5f\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5b83\u7684\u503c\u662f\u4e00\u4e2a\u5185\u5b58\u5730\u5740
-
\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
"},{"location":"programming_lecture/lecture4/lecture4/#ctypeh","title":"<ctype.h>
","text":"\u5934\u6587\u4ef6 <ctype.h>
\u58f0\u660e\u4e86\u51e0\u4e2a\u53ef\u4ee5\u7528\u4e8e\u8bc6\u522b\u548c\u8f6c\u6362\u5b57\u7b26\u7684\u51fd\u6570\u3002
"},{"location":"programming_lecture/lecture4/lecture4/#ascii","title":"\u80cc\u666f\uff1aASCII \u5b57\u7b26\u96c6","text":"ASCII \u5b57\u7b26\u96c6\u4e2d\u7684\u6570\u5b57\u548c\u5b57\u6bcd\u5927\u5bb6\u5e94\u8be5\u90fd\u5f88\u719f\u4e86\uff0c\u8fd9\u8fb9\u518d\u5bf9\u4e24\u7c7b\u5927\u5bb6\u63a5\u89e6\u6bd4\u8f83\u5c11\u7684\u5b57\u7b26\u5206\u7c7b\u7b80\u5355\u505a\u4e2a\u4ecb\u7ecd\u3002
- \u6253\u5370\u5b57\u7b26\uff1a
0x20
~ 0x7E
- \u63a7\u5236\u5b57\u7b26\uff1a
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
"},{"location":"programming_lecture/lecture4/lecture4/#_4","title":"\u5185\u5bb9","text":"\u8fd9\u4e2a\u5934\u6587\u4ef6\u4e2d\u53ea\u6709\u51fd\u6570\uff0c\u6ca1\u6709\u7279\u522b\u7684\u7c7b\u578b\u548c\u5b8f\u3002
\u8fd9\u4e9b\u51fd\u6570\u7684\u610f\u4e49\u548c\u7528\u6cd5\u975e\u5e38\u663e\u7136\uff0c\u56e0\u6b64\u6211\u4e5f\u4e0d\u505a\u6ce8\u91ca\u3002
- \u5b57\u7b26\u5224\u65ad\u51fd\u6570
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
- \u5b57\u7b26\u8f6c\u6362\u51fd\u6570
int tolower(int c);\nint toupper(int c);\n
"},{"location":"programming_lecture/lecture4/lecture4/#_5","title":"\u4f7f\u7528","text":"<ctype.h>
\u4e2d\u7684\u51fd\u6570\u5bf9 ASCII \u5b57\u7b26\u5927\u81f4\u4f5c\u4e86\u5982\u4e0b\u5212\u5206\uff1a
\u63a7\u5236\u5b57\u7b26\u90a3\u4e9b\u4e0d\u7528\u7ba1\uff0c\u4e0d\u8981\u6c42\u7684\u51fd\u6570\u4e0d\u7528\u7ba1\u3002\u53ea\u8981\u8bb0\u5f97 isspace
\u548c isblank
\u7684\u533a\u522b\u5c31\u884c\u4e86\u3002
isspace
\u548c isblank
\u7684\u533a\u522b
- \u7a7a\u683c\u5b57\u7b26\uff1a
isblank
\u4ec5\u5224\u65ad\u7a7a\u683c
\u548c\u6c34\u5e73\u5236\u8868\u7b26 \\t
\u3002 - \u7a7a\u767d\u5b57\u7b26\uff1a
isspace
\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
"},{"location":"programming_lecture/lecture4/lecture4/#ctypeh_1","title":"<ctype.h>
\u7684\u5b9e\u73b0\uff1a\u5b8f\u4e0e\u4f4d\u8fd0\u7b97","text":"\u9605\u8bfb\u672c\u8282\u9700\u8981\u5177\u5907\u7684\u77e5\u8bc6
- \u4f4d\u8fd0\u7b97
\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
- \u5b8f
\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
- \u7b2c\u4e00\u4f4d\u8868\u793a\u662f\u5426\u662f\u6570\u5b57
- \u7b2c\u4e8c\u4f4d\u8868\u793a\u662f\u5426\u662f\u5c0f\u5199\u5b57\u6bcd
- \u7b2c\u4e09\u4f4d\u8868\u793a\u662f\u5426\u662f\u5927\u5199\u5b57\u6bcd
- \u7b2c\u56db\u4f4d\u8868\u793a\u662f\u5426\u662f\u5b57\u6bcd
\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
- \u867d\u7136\u5b8f\u53ef\u80fd\u6bd4\u51fd\u6570\u5feb\uff0c\u4f46\u662f\u5b83\u4eec\u901a\u5e38\u4f1a\u4ea7\u751f\u66f4\u5927\u7684\u4ee3\u7801\u3002\u5982\u679c\u5728\u5f88\u591a\u5730\u65b9\u6269\u5c55\uff0c\u8fd9\u4e2a\u7a0b\u5e8f\u53ef\u80fd\u5927\u5230\u8ba9\u4f60\u65e0\u6cd5\u60f3\u8c61\u3002
-
\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
ctype.h#define _DI 0x20 /* '0'-'9' */\n#define _LO 0x10 /* 'a'-'z' */\n#define _UP 0x02 /* 'A'-'Z' */\n#define _XA 0x200 /* 'a'-'z', 'A'-'Z' */\nextern const short *_Ctype, *_Tolower, *_Toupper;\n#define isalnum(c) (_Ctype[(int)(c)] & (_DI|_LO|_UP|_XA))\n#define tolower(c) _ToLower[(int)(c)]\n
\u8bfb\u4e00\u4e0b\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u60f3\u8c61\u4e00\u4e0b _Ctype
\u8fd9\u4e2a\u67e5\u627e\u8868\u7684\u6837\u5b50\u3002
\u8003\u8003\u4f60\uff0c\u5bf9\u4e8e ASCII \u5b57\u7b26\u96c6\uff0c\u8fd9\u4e2a\u67e5\u627e\u8868\u6709\u591a\u5927\uff1f
\u4f60\u80fd\u60f3\u4e00\u60f3\u6620\u5c04\u8868\u7684\u5b9e\u73b0\u5417\uff1f
\u540c\u6837\uff0c\u7ed9\u51fa\u51fd\u6570\u7248\u672c\u7684\u5b9e\u73b0\uff1a
isalnum.c#include <ctype.h>\n\nint isalnum(int c)\n { /* test for alphanumeric character */\n return (_Ctype[c] & (_DI|_LO|_UP|_XA));\n }\n
\u4e0b\u9762\u4e24\u5e45\u56fe\u5206\u522b\u5c55\u793a\u4e86 _Ctype
\u548c _Toupper
\u7684\u6837\u5b50\uff1a
_Ctype
_Toupper
\u975e\u5e38\u5730\u7b80\u5355\uff0c\u5bf9\u5427\uff1f\u8fd9\u53ef\u6bd4 'a' <= c && c <= 'z'
\u8fd9\u6837\u7684\u5224\u65ad\u8981\u5feb\u5f97\u591a\u3002
"},{"location":"programming_lecture/lecture4/lecture4/#mathh","title":"<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
- \u6700\u5927\u6b63\u503c\uff1a\\(1.7976931348623157 \\times 10^{308}\\)
- \u6700\u5c0f\u6b63\u503c\uff1a\\(2.2250738585072014 \\times 10^{-307}\\)
\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
- \u5982\u679c\u51fd\u6570\u7684\u8f93\u5165\u53c2\u6570\u4f4d\u4e8e\u5b9a\u4e49\u57df\u5916\uff08\u6bd4\u5982
asin
\u8f93\u5165\u4e86\u4e0d\u5728 \\([-1, 1]\\) \u7684\u503c\uff09\uff0c\u4f1a\u53d1\u751f\u5b9a\u4e49\u57df\u9519\u8bef\u3002 - \u5982\u679c\u7ed3\u679c\u4e0d\u80fd\u88ab\u8868\u793a\u4e3a
double
\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
"},{"location":"programming_lecture/lecture4/lecture4/#_7","title":"\u5185\u5bb9","text":" -
\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
"},{"location":"programming_lecture/lecture4/lecture4/#_8","title":"\u4f7f\u7528","text":" - \u8f93\u5165\u8f93\u51fa\u5168\u90fd\u662f
double
\u7c7b\u578b\uff08\u6ce8\u610f\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u5e26\u6765\u7684\u5f71\u54cd\uff09\u3002 - \u4e09\u89d2\u51fd\u6570\u5747\u4e3a\u5f27\u5ea6\u5236\u3002\u89d2\u5ea6\u5230\u5f27\u5ea6\u7684\u8f6c\u6362\u516c\u5f0f\u4e3a\uff1a\\(\\theta = \\frac{\\pi}{180} \\times \\alpha\\)\u3002
- \u6ca1\u6709
PI
\u8fd9\u4e2a\u5b8f\u3002 - \u53ef\u4ee5\u4f7f\u7528
atan(1)*4
\u4ee3\u66ff\u3002 - GCC \u5b9a\u4e49\u4e86\u4e00\u4e9b\u6570\u503c\u5b8f\uff0c\u5b83\u4eec\u90fd\u4ee5
M_
\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
"},{"location":"programming_lecture/lecture4/lecture4/#stringh","title":"<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
- \u7528\u53cc\u5f15\u53f7\u5f15\u8d77\u7684\u5b57\u7b26\u5e8f\u5217\u662f\u5b57\u7b26\u4e32\u3002\u7f16\u8bd1\u5668\u4f1a\u81ea\u52a8\u6dfb\u52a0\u7a7a\u5b57\u7b26\u3002
scanf
\u4f7f\u7528 %s
\u8bfb\u53d6\u7684\u5b57\u7b26\u5e8f\u5217\u662f\u5b57\u7b26\u4e32\u3002scanf
\u4f1a\u81ea\u52a8\u6dfb\u52a0\u7a7a\u5b57\u7b26\u3002 - ......
"},{"location":"programming_lecture/lecture4/lecture4/#_10","title":"\u5185\u5bb9","text":" - \u7c7b\u578b
size_t\n
- \u5b8f
NULL\n
- \u51fd\u6570
- \u590d\u5236\u51fd\u6570
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
- \u8fde\u63a5\u51fd\u6570
char *strcat(char *dest, const char *src);\nchar *strncat(char *dest, const char *src, size_t n);\n
- \u6bd4\u8f83\u51fd\u6570
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
- \u67e5\u627e\u51fd\u6570
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
- \u5176\u4ed6\u51fd\u6570
void *memset(void *s, int c, size_t n);\n// char *strerror(int errnum);\nsize_t strlen(const char *s);\n
"},{"location":"programming_lecture/lecture4/lecture4/#_11","title":"\u4f7f\u7528","text":"\u4f7f\u7528\u524d\uff0c\u81ea\u5df1\u8ba1\u7b97\u5b57\u7b26\u4e32\u957f\u5ea6\u548c\u5269\u4f59\u7a7a\u95f4\uff0c\u8fd9\u662f\u7f16\u7a0b\u8005\u7684\u8d23\u4efb\u3002\u6216\u8005\u4f7f\u7528\u5e26 n
\u7684\u51fd\u6570\u3002
- \u6709\u4e9b\u51fd\u6570\u53ef\u80fd\u8fd4\u56de\u7a7a\u6307\u9488\uff0c\u8bb0\u5f97\u6d4b\u8bd5\u8fd4\u56de\u7684\u6307\u9488\u3002
"},{"location":"programming_lecture/lecture4/lecture4/#stdlibh","title":"<stdlib.h>
","text":"\u5934\u6587\u4ef6 <stdlib.h>
\u662f\u4e00\u4e2a\u5927\u6742\u70e9\uff0c\u4e3a\u4e86\u5b9a\u4e49\u548c\u58f0\u660e\u90a3\u4e9b\u6ca1\u6709\u660e\u663e\u5f52\u5c5e\u7684\u5b8f\u548c\u51fd\u6570\u3002\u6211\u4eec\u4ec5\u4ecb\u7ecd\u5e38\u7528\u7684\u90e8\u5206\uff1a\u6574\u5f62\u6570\u5b66\u3001\u7b97\u6cd5\u3001\u6587\u672c\u8f6c\u6362\u3001\u73af\u5883\u63a5\u53e3\u548c\u5b58\u50a8\u5206\u914d\u3002
"},{"location":"programming_lecture/lecture4/lecture4/#_12","title":"\u80cc\u666f\uff1a\u6307\u9488\u7684\u6982\u5ff5","text":"\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":" - \u5b8f
RAND_MAX\nEXIT_FAILURE\nEXIT_SUCCESS\n
-
\u51fd\u6570
- \u4f2a\u968f\u673a\u5e8f\u5217\u4ea7\u751f\u51fd\u6570
int rand(void);\nvoid srand(unsigned int seed);\n
- \u6574\u6570\u7b97\u672f\u51fd\u6570
int abs(int n);\ndiv_t div(int numer, int denom);\nlong labs(long n);\nldiv_t ldiv(long numer, long denom);\n
- \u67e5\u627e\u548c\u6392\u5e8f\u51fd\u6570
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
- \u6587\u672c\u8f6c\u6362\uff08\u597d\u7528\u7684\uff09
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
- \u73af\u5883\u901a\u4fe1\uff08\u4e0d\u4ecb\u7ecd\uff09
// 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
"},{"location":"programming_lecture/lecture4/lecture4/#_14","title":"\u4f7f\u7528","text":" 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]\\)\u3002 abs
\u548c labs
\u7528\u4e8e\u6c42\u7edd\u5bf9\u503c\u3002div
\u548c ldiv
\u7528\u4e8e\u6c42\u5546\u548c\u4f59\u6570\u3002 qsort
\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
- \u6587\u672c\u8f6c\u6362\u51fd\u6570\u975e\u5e38\u597d\u7528\u3002\u4f60\u518d\u4e5f\u4e0d\u7528\u5199\u8fd9\u6837\u7684\u4ee3\u7801\u4e86\uff08\u5f53\u7136
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\u3002 realloc
\u76f8\u5f53\u4e8e\u7ed3\u5408\u4e86 malloc
\u3001memcpy
\u548c free
\u7684\u529f\u80fd\u3002
"},{"location":"programming_lecture/lecture4/lecture4/#stdioh","title":"<stdio.h>
","text":"\u5173\u4e8e\u6587\u4ef6\u8f93\u5165\u8f93\u51fa......
\u8fd9\u8fb9\u5217\u51fa\u4e86\u6587\u4ef6\u8f93\u5165\u8f93\u51fa\u7684\u5185\u5bb9\uff0c\u7ed9\u5927\u5bb6\u590d\u4e60\u7684\u65f6\u5019\u53c2\u8003\u7528\u3002\u54b1\u4eec\u8fd9\u8282\u8bfe\u4e0d\u8bb2\u3002
"},{"location":"programming_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
"},{"location":"programming_lecture/lecture4/lecture4/#_16","title":"\u6d41\u7684\u6982\u5ff5","text":"\u5404\u79cd\u8f93\u5165\u8f93\u51fa\u8bbe\u5907\u5b9e\u5728\u662f\u592a\u591a\u4e86\uff08\u7ec8\u7aef\u3001\u78c1\u5e26\u9a71\u52a8\u5668\u3001\u7ed3\u6784\u5316\u5b58\u50a8\u8bbe\u5907......\uff09\u3002\u4e3a\u4e86\u7edf\u4e00\u6982\u5ff5\uff0cC \u8bed\u8a00\u4e2d\u7684\u8f93\u5165\u548c\u8f93\u51fa\u8bbe\u5907\u5168\u90fd\u548c\u903b\u8f91\u6570\u636e\u6d41\u76f8\u5bf9\u5e94\u3002
\u6d41\u5c31\u662f\u5b57\u7b26\u5e8f\u5217\u3002
\u4e0d\u7ba1\u7cfb\u7edf\u3001\u786c\u4ef6\u662f\u600e\u4e48\u5b9e\u73b0\u7684\u3002\u8f93\u5165\u8f93\u51fa\u5230\u4e86 C \u7a0b\u5e8f\u8fd9\u91cc\uff0c\u5c31\u7edf\u4e00\u4e3a\u903b\u8f91\u4e0a\u7684\u6d41\u4e86\u3002
\u6d41\u5173\u8054\u5230\u4e00\u4e2a\u7279\u5b9a\u7684\u6587\u4ef6\u3002
"},{"location":"programming_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
- \u6587\u672c\u6587\u4ef6\uff1a\u5982\u679c\u4e00\u4e2a\u6587\u4ef6\u4e2d\u7684\u4e8c\u8fdb\u5236\u503c\u90fd\u662f\u7528\u6765\u8868\u793a\u5b57\u7b26\u7684\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6587\u4ef6\u5c31\u662f\u6587\u672c\u6587\u4ef6\u3002
- \u4e8c\u8fdb\u5236\u6587\u4ef6\uff1a\u5982\u679c\u4e00\u4e2a\u6587\u4ef6\u4e2d\u7684\u4e8c\u8fdb\u5236\u503c\u4ee3\u8868\u5176\u4ed6\u6570\u636e\uff0c\u6bd4\u5982\u673a\u5668\u8bed\u8a00\u4ee3\u7801\u6216\u8005\u6570\u503c\u6570\u636e\u3001\u56fe\u7247\u6216\u97f3\u4e50\uff0c\u8fd9\u4e2a\u6587\u4ef6\u5c31\u662f\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002
\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
- \u8981\u6c42\u6587\u672c\u6587\u4ef6\u4e2d\u6bcf\u4e00\u884c\u7684\u957f\u5ea6\u76f8\u540c\uff0c\u5426\u5219\u7528\u7a7a\u767d\u5b57\u7b26\u586b\u5145\u3002
- \u5728\u6bcf\u884c\u5f00\u59cb\u6807\u51fa\u884c\u7684\u957f\u5ea6\u3002
"},{"location":"programming_lecture/lecture4/lecture4/#_18","title":"\u6d41\u7684\u7c7b\u578b","text":"C \u8bed\u8a00\u63d0\u4f9b\u4e24\u79cd\u6d41\uff1a\u6587\u672c\u6d41\u548c\u4e8c\u8fdb\u5236\u6d41\u3002
- \u6587\u672c\u6d41\uff1a\u7a0b\u5e8f\u6240\u89c1\u7684\u5185\u5bb9\u53ef\u80fd\u548c\u5b9e\u9645\u5185\u5bb9\u4e0d\u540c\u3002\u5982\u679c\u5c06\u6587\u4ef6\u4ee5\u6587\u672c\u6a21\u5f0f\u6253\u5f00\uff0c\u90a3\u4e48\u5728\u8bfb\u53d6\u6587\u4ef6\u65f6\uff0c\u4f1a\u628a\u672c\u5730\u73af\u5883\u8868\u793a\u7684\u6362\u884c\u7b26\u6216\u6587\u4ef6\u7ed3\u5c3e\u6620\u5c04\u4e3a C \u8bed\u8a00\u4e2d\u7684
\\n
\u548c EOF
\u3002 - \u4e8c\u8fdb\u5236\u6d41\uff1a\u7a0b\u5e8f\u6240\u89c1\u7684\u5185\u5bb9\u548c\u5b9e\u9645\u5185\u5bb9\u4e00\u81f4\u3002\u5982\u679c\u5c06\u6587\u4ef6\u4ee5\u4e8c\u8fdb\u5236\u6a21\u5f0f\u6253\u5f00\uff0c\u90a3\u4e48\u5728\u8bfb\u53d6\u6587\u4ef6\u65f6\uff0c\u4f1a\u628a\u6587\u4ef6\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b57\u8282\u90fd\u6620\u5c04\u4e3a C \u8bed\u8a00\u4e2d\u7684
char
\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":" - \u7c7b\u578b
size_t\nFILE\nfpos_t\n
- \u5b8f
stderr\nstdin\nstdout\nNULL\nEOF\nSEEK_CUR\nSEEK_END\nSEEK_SET\n// BUFSIZ\n// FOPEN_MAX\n// FILENAME_MAX\n
- \u51fd\u6570
- \u6587\u4ef6\u64cd\u4f5c\u51fd\u6570\uff08\u4e0d\u505a\u8981\u6c42\uff09
// int remove(const char *filename);\n// int rename(const char *old, const char *new);\n// FILE *tmpfile(void);\n
- \u6587\u4ef6\u8bbf\u95ee\u51fd\u6570
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
- \u683c\u5f0f\u5316\u7684\u8f93\u5165\u8f93\u51fa\u51fd\u6570
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
- \u5b57\u7b26\u8f93\u5165\u8f93\u51fa\u51fd\u6570
// 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
- \u76f4\u63a5\u8f93\u5165\u8f93\u51fa\u51fd\u6570\uff08\u8003\u8bd5\u4e0d\u7ba1\uff09
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
- \u6587\u4ef6\u5b9a\u4f4d\u51fd\u6570\uff08\u8003\u8bd5\u4e0d\u7ba1\uff09
//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
- \u9519\u8bef\u5904\u7406\u51fd\u6570\uff08\u4e0d\u505a\u8981\u6c42\uff09
// void clearerr(FILE *stream);\n// int feof(FILE *stream);\n// int ferror(FILE *stream);\n// void perror(const char *str);\n
"},{"location":"programming_lecture/lecture4/lecture4/#_20","title":"\u4f7f\u7528","text":"\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\u3002 - \u57fa\u672c\u7684\u6253\u5f00\u3001\u5173\u95ed\u6587\u4ef6
fopen
\u3001fclose
\u7684\u4f7f\u7528\u3002 r
\u3001w
\u3001a
\u3001b
\u7b49\u6a21\u5f0f\u7684\u4f7f\u7528\u3002 - \u5728\u4e00\u4e2a
FILE
\u4e2d\u7528 fscanf
\u3001fprintf
\u8bfb\u5199\u6570\u636e\u3002 fread
\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
- \u4e00\u4e2a\u53ef\u9009\u7684\u7cbe\u5ea6\uff1a\u5c0f\u6570\u70b9\u540e\u8ddf\u4e00\u4e2a\u661f\u53f7\u6216\u4e00\u4e2a\u5341\u8fdb\u5236\u6574\u6570\u3002
- \u5982\u679c\u662f\u6574\u6570\uff0c\u8868\u793a\u6700\u5c0f\u6570\u5b57\u4f4d\u6570\u3002
- \u5982\u679c\u662f\u6d6e\u70b9\u6570\uff0c\u8868\u793a\u5c0f\u6570\u70b9\u540e\u7684\u6700\u5927\u4f4d\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
- \u5982\u679c\u8f6c\u6362\u4e0e\u5b57\u7b26\u5339\u914d\u5931\u8d25\uff0c\u8fd9\u4e2a\u8f93\u5165\u5b57\u7b26\u4f1a\u7559\u5728\u8f93\u5165\u6d41\u4e2d\u3002\u5728\u4f60\u4e0b\u4e00\u6b21\u8bfb\u53d6\u5b57\u7b26\u65f6\uff0c\u5b83\u53ef\u80fd\u4f1a\u6363\u4e71\uff01
- \u8fd9\u4e2a\u51fd\u6570\u7684\u53c2\u6570\u662f\u4ec0\u4e48\u7c7b\u578b\uff1f\u4ec0\u4e48\u65f6\u5019\u8be5\u52a0\u53d6\u503c\u7b26
&
\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
- \u6b63\u5e38\uff1a\u8fd4\u56de\u4f20\u8f93\u7684\u5b57\u7b26\u6570
- \u5f02\u5e38\uff1a\u8fd4\u56de\u8d1f\u6570
scanf
\u3001fscanf
\u3001sscanf
- \u6b63\u5e38\uff1a\u8fd4\u56de\u6210\u529f\u5339\u914d\u5e76\u8d4b\u503c\u7684\u8f93\u5165\u9879\u6570
- \u5f02\u5e38\uff1a\u8fd4\u56de
EOF
\u6587\u4ef6\u5b9a\u4f4d\uff08\u4e0d\u505a\u4ecb\u7ecd\uff09 - \u4e09\u79cd\u4fee\u6539\u6587\u4ef6\u5b9a\u4f4d\u7b26\u7684\u53ef\u80fd\uff1a
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\u3002 fseek
\u3001ftell
\u3001rewind
\uff1a\u8f83\u8001\u7684\u4f20\u7edf\u7684\u6587\u4ef6\u5b9a\u4f4d\u51fd\u6570 fgetpos
\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
"},{"location":"programming_lecture/lecture5/lecture5/","title":"\u6307\u9488\u53ca\u94fe\u8868\u76f8\u5173\u77e5\u8bc6\u70b9\u590d\u4e60","text":"\u6458\u8981
\u8003\u8651\u5230\u672c\u6b21\u8f85\u5b66\u65f6\u95f4\u5df2\u8fd1\u671f\u672b\uff0c\u539f\u5148\u5b89\u6392\u7684\u4ecb\u7ecd\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u5185\u5bb9\u5df2\u7ecf\u4e0d\u592a\u5408\u9002\uff0c\u56e0\u6b64\u672c\u6b21\u8f85\u5b66\u65f6\u95f4\u5c06\u4e3b\u8981\u4ecb\u7ecd\u671f\u672b\u8003\u8bd5\u7684\u90e8\u5206\u91cd\u70b9\u77e5\u8bc6\uff0c\u4ee5\u8bb2\u89e3\u6307\u9488\u4e0e\u94fe\u8868\u4e3a\u4e3b\u3002
\u672c\u6b21\u8f85\u5b66\u7684\u4e3b\u8981\u5185\u5bb9\uff1a
- \u7ed3\u5408\u5386\u5e74\u5377\u590d\u4e60\u6307\u9488\u7684\u4f7f\u7528
- \u94fe\u8868\u76f8\u5173\u77e5\u8bc6\u7684\u590d\u4e60
\u5176\u4e2d\u6211\u4eec\u8f85\u5b66\u5b66\u957f\u5199\u7684\u4e13\u9898\u7b14\u8bb0 \u2014\u2014 \u4e13\u9898\u7b14\u8bb0-\u6307\u9488\u6982\u89c8 \u5df2\u7ecf\u5bf9\u6307\u9488\u8fdb\u884c\u4e86\u8be6\u7ec6\u7684\u4ecb\u7ecd\u3002\u672c\u6b21\u8f85\u5b66\u4e0d\u4f1a\u6df1\u6316\u6307\u9488\u7684\u5185\u5b58\u6a21\u578b\u7b49\u7ec6\u8282\uff0c\u4e3b\u8981\u662f\u9488\u5bf9\u5386\u5e74\u5377\u9898\u76ee\uff0c\u4ee5\u53ca\u8f85\u5b66\u7fa4\u4e2d\u540c\u5b66\u4eec\u6240\u95ee\u7684\u6307\u9488\u76f8\u5173\u7684\u95ee\u9898\uff0c\u8fdb\u884c\u4ee5\u5907\u8003\u4e3a\u76ee\u7684\u7684\u590d\u4e60\u3002
"},{"location":"programming_lecture/lecture5/lecture5/#_2","title":"\u6307\u9488\u7684\u57fa\u672c\u64cd\u4f5c","text":""},{"location":"programming_lecture/lecture5/lecture5/#_3","title":"\u6307\u9488\u7684\u58f0\u660e","text":"\u58f0\u660e\u4e00\u4e2a\u6307\u9488\uff1a
VariableType *pointerName;\n
\u5176\u4e2d VariableType
\u4e3a\u6307\u9488\u6307\u5411\u7684\u53d8\u91cf\u7c7b\u578b\uff0cpointerName
\u4e3a\u6307\u9488\u7684\u540d\u79f0\u3002
\u4f8b\u5982\uff1aint *p;
\u58f0\u660e\u4e86\u4e00\u4e2a\u6307\u5411 int
\u7c7b\u578b\u53d8\u91cf\u7684\u6307\u9488\uff0c\u6307\u9488\u7684\u540d\u79f0\u4e3a p
\u3002
\u6ce8\u610f
VariableType
\u4ee3\u8868\u7c7b\u578b\u8bf4\u660e\u7b26\uff0c\u5982 int
\u3001char
\u6216\u8005\u81ea\u5df1\u5b9a\u4e49\u7684 struct
\u7b49\u3002 *
\u5728\u6307\u9488\u58f0\u660e\u4e2d\u4ee3\u8868\u58f0\u660e\u6307\u9488\u7c7b\u578b\u3002\u6ce8\u610f\uff1a*
\u5728\u6307\u9488\u58f0\u660e\u548c\u6307\u9488\u4f7f\u7528\u4e2d\u4ee3\u8868\u7684\u542b\u4e49\u4e0d\u76f8\u540c\uff01\uff01\uff01\uff01\uff01 pointerName
\u4ee3\u8868\u6307\u9488\u7684\u540d\u79f0\uff0c\u9700\u8981\u7b26\u5408\u6807\u8bc6\u7b26\u547d\u540d\u89c4\u8303\u3002
\u9650\u5b9a\u7b26\u5bf9\u6307\u9488\u7684\u9650\u5b9a
\u9650\u5b9a\u7b26\u5728 C \u8bed\u8a00\u4e2d\u7528\u4e8e\u9650\u5b9a\u53d8\u91cf\u7684\u7c7b\u578b\uff0c\u6700\u5e38\u7528\u7684\u4e3a const
\u9650\u5b9a\u7b26\u3002
\u5728\u6307\u9488\u58f0\u660e\u4e2d\uff0c\u9650\u5b9a\u7b26\u51fa\u73b0\u7684\u4f4d\u7f6e\u51b3\u5b9a\u4e86\u9650\u5b9a\u7b26\u662f\u5bf9\u6307\u9488\u672c\u8eab\u7684\u9650\u5b9a\uff0c\u8fd8\u662f\u5bf9\u6307\u9488\u6307\u5411\u7684\u53d8\u91cf\u7684\u9650\u5b9a\u3002
int n;\nconst int * pc = &n; // pc \u662f\u6307\u5411 const int \u7684\u975e const \u6307\u9488\n// *pc = 2; // \u9519\u8bef\uff1a\u4e0d\u80fd\u901a\u8fc7\u4e0d\u5e26\u8f6c\u578b\u7684 pc \u4fee\u6539 n\npc = NULL; // OK\uff1apc \u81ea\u8eab\u53ef\u4fee\u6539\n\nint * const cp = &n; // cp \u662f\u4e00\u4e2a\u6307\u5411\u975e const \u7684 int \u7684 const \u6307\u9488\n*cp = 2; // OK\uff1a\u901a\u8fc7 cp \u4fee\u6539 n\n// cp = NULL; // \u9519\u8bef\uff1acp \u81ea\u8eab\u4e0d\u80fd\u4fee\u6539\n
\u5927\u4f53\u53ea\u9700\u8981\u8bb0\u4f4f\uff1a\u9650\u5b9a\u7b26\u4f1a\u5bf9\u7d27\u968f\u5176\u540e\u7684\u5bf9\u8c61\u8fdb\u884c\u9650\u5b9a\u5373\u53ef\u3002
\u8fdb\u9636\u4e00\u70b9\u7684\u4f8b\u5b50\uff1a
int * const * pcp = &cp; // \u6307\u5411\u6307\u5411\u975e const \u7684 int \u7684 const \u6307\u9488\u7684\u975e const \u6307\u9488\n
"},{"location":"programming_lecture/lecture5/lecture5/#_4","title":"\u591a\u7ea7\u6307\u9488\u7684\u58f0\u660e","text":"\u5bf9\u591a\u7ea7\u6307\u9488\u7684\u58f0\u660e\uff0c\u53ef\u4ee5\u7528\u9012\u5f52\u7684\u65b9\u5f0f\u7406\u89e3\u3002
\u5bf9\u4e8e\u6307\u5411 int
\u7c7b\u578b\u7684\u4e00\u7ea7\u6307\u9488\uff0c\u5176 VariableType
\u4e3a int
\uff1b\u5bf9\u4e8e\u4e8c\u7ea7\u6307\u9488 int **p
\uff0c\u5373\u6307\u5411\u6307\u5411 int
\u7c7b\u578b\u7684\u6307\u9488\u7684\u6307\u9488\uff0c\u5176 VariableType
\u4e3a int *
\u3002
\u4f8b
int var = 1;\nint *p1 = &var;\nint **p = &p;\n
\u4ed6\u4eec\u7684\u6307\u5411\u5173\u7cfb\u662f\uff1a
(int **)p -> (int *)p1 -> (int)var\n
"},{"location":"programming_lecture/lecture5/lecture5/#_5","title":"\u6307\u9488\u6570\u7ec4\u4e0e\u6570\u7ec4\u6307\u9488","text":"\u5f88\u5bb9\u6613\u641e\u6df7\uff0c\u9700\u8981\u6280\u5de7\u6765\u8bc6\u522b\u3002
\u6bd4\u5982\u4e0b\u9762\u4e24\u6761\u58f0\u660e\uff1a
char *p[10]; // \u5927\u5c0f\u4e3a 10 \u7684\u6570\u7ec4\uff0c\u6570\u7ec4\u5143\u7d20\u662f\u6307\u5411 char \u7c7b\u578b\u7684\u6307\u9488\n\nchar (*p)[10]; // \u6307\u9488\uff0c\u6307\u5411\u5927\u5c0f\u4e3a 10 \u7684 char \u6570\u7ec4\n
\u7262\u8bb0\u987a\u65f6\u9488\u87ba\u65cb\u6cd5\u5219\uff08Clockwise/Spiral Rule\uff09\uff08\u8be6\u89c1\u8f85\u5b66\u7fa4\u7fa4\u6587\u4ef6\u4e2d\u7684\u201c\u6d45\u8c08 C \u8bed\u8a00\u7684\u6570\u636e\u7c7b\u578b.pdf\u201d\uff09\u3002
\u4e8e\u662f\uff0c\u4e0a\u9762\u7684\u4e24\u6761\u58f0\u660e\u5c31\u53ef\u4ee5\u516c\u5f0f\u5316\u5730\u89e3\u91ca\uff1a
char *p[10];
: p is an array 10 of pointers to char. char (*p)[10];
: p is a pointer to an array 10 of char.
\u4e0a\u4e00\u8282\u7684\u591a\u7ea7\u6307\u9488\u58f0\u660e\u540c\u6837\u53ef\u4ee5\u7528\u8fd9\u4e2a\u6cd5\u5219\u8fdb\u884c\u89e3\u91ca\u3002
"},{"location":"programming_lecture/lecture5/lecture5/#_6","title":"\u6307\u9488\u7684\u4f7f\u7528","text":""},{"location":"programming_lecture/lecture5/lecture5/#_7","title":"\u6307\u9488\u7684\u89e3\u5f15\u7528","text":"\u89e3\u5f15\u7528\u8fd0\u7b97\u7b26 *
\u7684\u4e00\u822c\u5f62\u5f0f\u4e3a\uff1a
* \u6307\u9488\u8868\u8fbe\u5f0f\n
\u7ed3\u679c\u4e3a\u6307\u4ee3\u88ab\u6307\u5411\u5bf9\u8c61\u7684\u5de6\u503c\u8868\u8fbe\u5f0f\uff0c\u5373\u53ef\u4ee5\u88ab\u8d4b\u503c\u3002
\u8bb0\u4f4f a[b]
\u7b49\u4ef7\u4e8e *(a + b)
\u3002\u8fd9\u4e2a trick \u5728\u4e00\u4e9b\u9898\u76ee\u4e2d\u5f88\u6709\u7528\u3002
\u4f8b\u9898
Given the declaration: int a[3][3]={1,2,3,4,5,6,7,8,9};
, the value of a[-1][5]
is _____.
Answer \u89e3\u7b54\u6765\u81ea\uff1axg \u2014\u2014 \u7a0b\u5e8f\u8bbe\u8ba1\u8f85\u5b66\u5e38\u95ee\u9898\u76ee\u53ca\u89e3\u6790v1.1.pdf
a[-1]
\u7b49\u4ef7\u4e8e *(a - 1)
\uff0ca - 1
\u4f1a\u4ee5 3 \u4e2a int
\u4e3a\u5355\u4f4d\u5411\u5de6\u79fb\u52a8\uff0c\u5373
0 0 0 1 2 3 4 5 6 7 8 9\n ^\n |\np = *(a - 1)\n
\u4ee4 p = *(a - 1)
\uff0c\u5219\u8981\u6c42\u7684\u503c\u53d8\u4e3a p[5]
\uff0c\u7b49\u4ef7\u4e8e *(p + 5)
\u3002\u5c06\u4e0a\u8ff0\u6307\u9488\u53f3\u79fb 5 \u4e2a int
\u5355\u4f4d\uff0c\u5f97\u5230 3\u3002
\u91ce\u6307\u9488
\u5f53\u6307\u9488\u58f0\u660e\u65f6\u672a\u521d\u59cb\u5316\uff0c\u4e14\u8fd8\u672a\u88ab\u8d4b\u503c\uff0c\u5219\u8fd9\u4e2a\u6307\u9488\u6307\u5411\u65e0\u6cd5\u786e\u5b9a\uff0c\u88ab\u79f0\u4e3a \u91ce\u6307\u9488\u3002
\u91ce\u6307\u9488\u53ef\u80fd\u6307\u5411\u4efb\u610f\u5185\u5b58\uff0c\u5bf9\u5176\u8fdb\u884c\u8bbf\u95ee\u53ef\u80fd\u4f1a\u5bfc\u81f4\u975e\u6cd5\u5185\u5b58\u8bbf\u95ee\uff0c\u4ea7\u751f\u6bb5\u9519\u8bef\u3002
\u5728\u8003\u9898\u4e2d\uff0c\u5c1d\u8bd5\u8bbf\u95ee\u91ce\u6307\u9488\u662f\u9519\u8bef\u7684\u64cd\u4f5c\u3002\u5728\u81ea\u5df1\u5199\u4ee3\u7801\u65f6\u4e5f\u7edd\u4e0d\u80fd\u51fa\u73b0\u91ce\u6307\u9488\u8bbf\u95ee\u3002
\u4f8b\u9898
For the declarations: char *s, str[10];
, statement _____ is completely correct.
A. strcpy(s, \"hello\");
B. str=\"hello\"+1
C. s=*&(str+1)
D. s=str+1
\u9009\u9879 A \u5c31\u662f\u7ecf\u5178\u7684\u91ce\u6307\u9488\u8bbf\u95ee\u3002
"},{"location":"programming_lecture/lecture5/lecture5/#_8","title":"\u53d6\u5740\u64cd\u4f5c","text":"\u53d6\u5740\u8fd0\u7b97\u7b26 &
\u65e9\u5728\u5927\u5bb6\u5b66\u4e60\u8f93\u5165\u8f93\u51fa\u7684\u65f6\u5019\u5c31\u5df2\u7ecf\u63a5\u89e6\u8fc7\u4e86\u3002\u5728\u4f7f\u7528 scanf
\u5bf9 int
\u7b49\u7c7b\u578b\u7684\u53d8\u91cf\u8fdb\u884c\u8bfb\u5165\u7684\u65f6\u5019\uff0c\u4f7f\u7528\u7684\u662f\u5982\u4e0b\u5f62\u5f0f\uff1a
int a;\nscanf(\"%d\", &a);\n
\u8fd9\u91cc\u7684 &
\u5bf9 a
\u8fdb\u884c\u53d6\u5740\u64cd\u4f5c\uff0c\u5bf9 a
\u7684\u5730\u5740\u800c\u4e0d\u662f a
\u7684\u503c\u8fdb\u884c\u8bfb\u5165\u3002
\u4e00\u822c\u5730\uff0c\u53d6\u5740\u8fd0\u7b97\u7b26\u6709\u5982\u4e0b\u51e0\u79cd\u5f62\u5f0f\uff1a
& <function>
\uff1a\u53d6\u51fd\u6570\u7684\u5730\u5740\u3002\u8fd9\u4e2a\u4e0d\u505a\u8981\u6c42\u3002 -
& \u5de6\u503c\u8868\u8fbe\u5f0f
\uff1a\u53d6\u5de6\u503c\u8868\u8fbe\u5f0f\u7684\u5730\u5740\u3002\u7ed3\u679c\u4e3a\u6307\u5411\u5de6\u503c\u8868\u8fbe\u5f0f\u7684\u6307\u9488\u3002
\u5de6\u503c\u8868\u8fbe\u5f0f
\u5de6\u503c\uff0c\u7b80\u5355\u6765\u8bf4\u53ef\u4ee5\u770b\u4f5c\u662f\u5728\u5185\u5b58\u4e2d\u6709\u5bf9\u5e94\u5b58\u50a8\u7a7a\u95f4\u7684\u8868\u8fbe\u5f0f\uff0c\u5982\u53d8\u91cf\u3001\u6570\u7ec4\u5143\u7d20\u3001\u7ed3\u6784\u4f53\u6210\u5458\u7b49\u3002
\u76f8\u53cd\uff0c\u82e5\u8868\u8fbe\u5f0f\u5728\u5185\u5b58\u4e2d\u6ca1\u6709\u5bf9\u5e94\u5b58\u50a8\u7a7a\u95f4\uff0c\u5219\u4e0d\u80fd\u53d6\u5740\uff0c\u6bd4\u5982 &a
\u30011+2
\u7b49\u3002
-
& * \u8868\u8fbe\u5f0f
\uff1a&
\u548c *
\u5f7c\u6b64\u62b5\u6d88\uff0c\u5747\u4e0d\u6c42\u503c\u3002\u8fd9\u4e2a\u4ec5\u4f5c\u4e86\u89e3\u3002
& \u8868\u8fbe\u5f0f [\u8868\u8fbe\u5f0f]
\uff1a\u7b49\u4ef7\u4e8e & *(\u8868\u8fbe\u5f0f + \u8868\u8fbe\u5f0f)
\u7b49\u4ef7\u4e8e \u8868\u8fbe\u5f0f + \u8868\u8fbe\u5f0f
\u3002\u8fd9\u4e2a\u4ec5\u4f5c\u4e86\u89e3\u3002
\u89e3\u5f15\u7528\u4e0e\u53d6\u5740\u64cd\u4f5c\u7684\u5e94\u7528
\u8f93\u5165\u4e00\u4e2a 64 \u4f4d\u65e0\u7b26\u53f7\u6574\u6570 x
\uff0c\u6c42 x
\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u7684 01 \u4e32\u6240\u8868\u793a\u7684 double
\u7c7b\u578b\u53d8\u91cf\u7684\u503c\u3002
Answer unsigned long long x;\nscanf(\"%llu\", &x);\nprintf(\"%lf\\n\", *((double *)&x));\n
"},{"location":"programming_lecture/lecture5/lecture5/#_9","title":"\u901a\u8fc7\u6307\u9488\u8fdb\u884c\u6210\u5458\u8bbf\u95ee","text":"\u5bf9\u4e8e\u7ed3\u6784\u4f53\u7c7b\u578b\u7684\u6307\u9488\uff0cC \u8bed\u8a00\u63d0\u4f9b\u4e86\u4e00\u4e2a\u8fd0\u7b97\u7b26 ->
\uff0c\u7528\u4e8e\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u7ed3\u6784\u4f53\u6210\u5458\u3002
struct Point { int x, y; }; // \u5b9a\u4e49\u7ed3\u6784\u4f53 Point\nstruct Point point = { 1, 2 }; // \u5b9a\u4e49\u7ed3\u6784\u4f53\u53d8\u91cf point\n\nstruct Point *p = &point; // p \u6307\u5411 point \u7ed3\u6784\u4f53\np->x = 3; // \u901a\u8fc7\u6307\u9488 p \u8bbf\u95ee\u7ed3\u6784\u4f53\u6210\u5458 x\n// \u7b49\u4ef7\u4e8e (*p).x = 3;\n
"},{"location":"programming_lecture/lecture5/lecture5/#_10","title":"\u6570\u7ec4\u5230\u6307\u9488\u7684\u9690\u5f0f\u8f6c\u6362","text":"\u9690\u5f0f\u8f6c\u6362
\u6570\u7ec4\u5230\u6307\u9488\u8f6c\u6362
\u4efb\u4f55\u6570\u7ec4\u7c7b\u578b\u7684\u5de6\u503c\u8868\u8fbe\u5f0f\uff0c\u5728\u7528\u4e8e\u5f02\u4e8e\u4e0b\u5217\u8bed\u5883\u65f6
- \u4f5c\u4e3a\u53d6\u5740\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\u6570
- \u4f5c\u4e3a
sizeof
\u7684\u64cd\u4f5c\u6570 - \u4f5c\u4e3a
typeof
\u548c typeof_unqual
\u7684\u64cd\u4f5c\u6570 - \u4f5c\u4e3a\u7528\u4e8e\u6570\u7ec4\u521d\u59cb\u5316\u7684\u5b57\u7b26\u4e32\u5b57\u9762\u91cf
\u4f1a\u7ecf\u5386\u5230\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u975e\u5de6\u503c\u6307\u9488\u7684\u8f6c\u6362\u3002
\u2014\u2014 cppreference-\u9690\u5f0f\u8f6c\u6362
\u7b80\u5355\u6765\u8bf4\uff1a\u7262\u8bb0\u6570\u7ec4\u540d \u4e0d\u7b49\u4e8e \u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u7684\u6307\u9488\uff0c\u5f53\u6570\u7ec4\u540d\u88ab\u53d6\u5740\u8fd0\u7b97\u7b26 &
\u4f5c\u7528\uff0c\u6216\u8005\u4f5c\u4e3a sizeof
\u7684\u64cd\u4f5c\u6570\u65f6\uff0c\u4e0d\u4f1a\u53d1\u751f\u9690\u5f0f\u8f6c\u6362\u3002
\u8fd9\u91cc\u8981\u6ce8\u610f\u7684\u4e00\u70b9\u662f\uff0c\u5c06\u6570\u7ec4\u4f5c\u4e3a\u53c2\u6570\u4f20\u7ed9\u51fd\u6570\u65f6\uff0c\u51fd\u6570\u7684\u5f62\u53c2\u53ea\u80fd\u662f\u6307\u9488\uff0c\u800c\u4e0d\u80fd\u662f\u6570\u7ec4\uff0c\u6b64\u65f6\u6570\u7ec4\u540d\u4f1a\u53d1\u751f\u9690\u5f0f\u8f6c\u6362\u3002
\u6570\u7ec4\u7c7b\u578b\u7528\u4e8e\u51fd\u6570\u5f62\u53c2
\u5f53\u6570\u7ec4\u7c7b\u578b\u7528\u4e8e\u51fd\u6570\u5f62\u53c2\u5217\u8868\u65f6\uff0c\u5b83\u4f1a\u8f6c\u6362\u6210\u5bf9\u5e94\u7684\u6307\u9488\u7c7b\u578b\uff1aint f(int a[2])
\u3001int f(int a[])
\u3001int f(int *a)
\u58f0\u660e\u540c\u4e00\u4e2a\u51fd\u6570\u3002
\u56e0\u4e3a\u51fd\u6570\u5b9e\u9645\u53c2\u6570\u7c7b\u578b\u4e3a\u6307\u9488\u7c7b\u578b\uff0c\u4f7f\u7528\u6570\u7ec4\u5b9e\u53c2\u7684\u51fd\u6570\u8c03\u7528\u4f1a\u8fdb\u884c\u4e00\u4e2a\u6570\u7ec4\u5230\u6307\u9488\u8f6c\u6362\uff1b\u88ab\u8c03\u7528\u51fd\u6570\u65e0\u6cd5\u83b7\u5f97\u5b9e\u53c2\u6570\u7ec4\u7684\u5927\u5c0f\uff0c\u5fc5\u987b\u663e\u5f0f\u4f20\u9012\u3002
\u89c1 \u6bcf\u65e5\u4e00\u9898-29\u3002
Warning
\u53ea\u6709\u6570\u7ec4\u7c7b\u578b\u7528\u4e8e\u51fd\u6570\u5f62\u53c2\u5217\u8868\u65f6\uff0ca[]
\u548c *a
\u624d\u662f\u7b49\u4ef7\u7684\u3002
\u6bd4\u5982\u4f7f\u7528\u5b57\u7b26\u4e32\u5e38\u91cf\u521d\u59cb\u5316\u5b57\u7b26\u4e32\uff1a
\u521b\u5efa\u6307\u5411\u5b57\u7b26\u4e32\u5e38\u91cf\u7684\u6307\u9488\uff0c\u5185\u5bb9\u4e0d\u80fd\u66f4\u6539\uff0c
char *s = \"hello\"; // s \u7c7b\u578b\u4e3a char * \uff0c\u6307\u5411\u5b57\u7b26\u4e32\u5e38\u91cf\ns = \"he11o\"; // OK\n
\u521b\u5efa char \u6570\u7ec4\uff0c\u5185\u5bb9\u88ab\u5b57\u7b26\u4e32\u5e38\u91cf\u521d\u59cb\u5316\uff0c\u5185\u5bb9\u53ef\u4ee5\u66f4\u6539\uff0c
char s[] = \"hello\"; // s \u7c7b\u578b\u4e3a char [6] \uff0c\u6570\u7ec4\u5185\u5bb9\u662f \"hello\\0\" \u7684\u62f7\u8d1d\n// s[] = \"he11o\"; // wrong\n
Question
\u4e0b\u5217\u4ee3\u7801\u7684 val_x
\u548c val_y
\u7684\u7c7b\u578b\u4e00\u6837\u5417\uff1f
int a[10], *p = a;\nType1 val_x = &a;\nType2 val_y = &p;\n
Question
\u4e0b\u5217\u4ee3\u7801\u7684 size_x
\u548c size_y
\u5927\u5c0f\u4e00\u6837\u5417\uff1f
int a[10], *p = a;\nsize_t size_x = sizeof a;\nsize_t size_y = sizeof p;\n
"},{"location":"programming_lecture/lecture5/lecture5/#_11","title":"\u6307\u9488\u7684\u503c\u4e0e\u6307\u9488\u7684\u5730\u5740","text":"\u6307\u9488\u7684\u503c\uff0c\u53c8\u79f0\u4e3a\u6307\u9488\u6240\u6307\u5411\u7684\u5185\u5b58\u533a\u3002
\u5728\u8ba1\u7b97\u673a\u4e2d\uff0c\u5185\u5b58\u4e2d\u7684\u6240\u6709\u5b57\u8282\u90fd\u62e5\u6709\u4e00\u4e2a\u552f\u4e00\u7f16\u53f7\uff0c\u4e5f\u5373\u5185\u5b58\u5730\u5740\u3002\u6307\u9488\u6307\u5411\u67d0\u4e00\u6570\u636e\u7684\u5730\u5740\uff0c\u5373\u6307\u9488\u53d8\u91cf\u5b58\u50a8\u4e86\u8fd9\u4e2a\u6570\u636e\u7684\u5185\u5b58\u5730\u5740\u7684\u7f16\u53f7\u3002
\u6307\u9488\u6240\u5360\u7684\u5b57\u8282\u6570
\u73b0\u5728\u4e00\u822c\u7684\u8ba1\u7b97\u673a\u57fa\u672c\u90fd\u662f 64 \u4f4d\u7cfb\u7edf\uff0c\u4f7f\u7528 64 \u4f4d\u957f\u7684\u5185\u5b58\u5730\u5740\uff0c\u5373\u5185\u5b58\u5730\u5740\u7684\u7f16\u53f7\u662f\u4e00\u4e2a 64 \u4f4d\u6574\u6570\u3002\u5728 64 \u4f4d\u7cfb\u7edf\u4e2d\u4f7f\u7528 sizeof
\u8fd0\u7b97\u7b26\u6c42\u6307\u9488\u7684\u5927\u5c0f\u65f6\uff0c\u5f97\u5230\u7684\u7ed3\u679c\u4e3a 8\u3002
\u6ce8\u610f\uff0c\u4e00\u822c\u6765\u8bf4\u65e0\u6cd5\u9884\u6d4b\u5730\u5740\u7684\u503c\uff0c\u56e0\u4e3a\u5185\u5b58\u5730\u5740\u53d6\u51b3\u4e8e\u7cfb\u7edf\u7684\u5185\u5b58\u5206\u914d\u60c5\u51b5\u3002\u4f46\u90e8\u5206\u60c5\u51b5\u4e0b\u53ef\u4ee5\u786e\u5b9a\u5185\u5b58\u5730\u5740\u7684\u76f8\u5bf9\u4f4d\u7f6e\uff0c\u6bd4\u5982\u540c\u4e00\u6570\u7ec4\u4e2d\u5143\u7d20\u5728\u5185\u5b58\u4e2d\u8fde\u7eed\u3002
\u6b64\u5916\uff0c\u6307\u9488\u540c\u6837\u4e5f\u662f\u4e00\u4e2a\u5728\u5185\u5b58\u4e2d\u6709\u5bf9\u5e94\u5b58\u50a8\u7a7a\u95f4\u7684\u53d8\u91cf\uff0c\u4e5f\u6709\u81ea\u5df1\u7684\u5185\u5b58\u5730\u5740\u3002\u5728\u6307\u9488\u7684\u5185\u5b58\u5730\u5740\u4e2d\uff0c\u5b58\u50a8\u7684\u5185\u5bb9\u662f\u5176\u6307\u5411\u7684\u5185\u5bb9\u7684\u5185\u5b58\u5730\u5740\u3002
\u7c7b\u6bd4\u7406\u89e3
\u5047\u5982\u6709\u4e00\u4e2a\u5f88\u957f\u7684\u6570\u7ec4\uff0c\u5b58\u50a8\u4e86\u4e00\u4e9b\u6570\u636e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u4e0b\u6807\u53bb\u8bbf\u95ee\u6570\u636e\u3002\u5c06\u6570\u7ec4\u4e0b\u6807\u5f53\u4f5c\u6570\u636e\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u53ef\u4ee5\u4ece\u6570\u7ec4\u4e2d\u7684\u67d0\u4e00\u4f4d\u7f6e\u53bb\u8bbf\u95ee\u5176\u5b58\u50a8\u7684\u6570\u7ec4\u4e0b\u6807\u7684\u4f4d\u7f6e\u7684\u6570\u636e\uff0c\u8fd9\u5c31\u53ef\u4ee5\u770b\u4f5c\u662f\u7b80\u5355\u7684\u6307\u9488\u3002
\u4e0b\u6807 31 32 33 34 ... X\narr data0 data1 data2 data3 .... 32\n ^ |\n +--------------------------------+\n
Question
\u90a3\u4e48\u5c31\u6709\u540c\u5b66\u95ee\u4e86\uff1a\u65e2\u7136\u6307\u9488\u7684\u503c\u662f 64 \u4f4d\u6574\u6570\uff0c\u90a3\u80fd\u7528\u5173\u7cfb\u8fd0\u7b97\u7b26\u6bd4\u8f83\u5927\u5c0f\u5417\uff1f
\u7b54\u6848\u662f\uff1a\u90e8\u5206\u60c5\u51b5\u4e0b\u53ef\u4ee5\u3002
\u5173\u7cfb\u8fd0\u7b97\u7b26\u8fdb\u884c\u6307\u9488\u6bd4\u8f83 \u6839\u636e cppreference-\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff0c\u5f53\u8fdb\u884c\u6307\u9488\u6bd4\u8f83\u7684\u65f6\u5019\uff0c\u6709\u4ee5\u4e0b\u8981\u6c42\uff1a
\u4e24\u6307\u9488\u5fc5\u987b\u662f\u517c\u5bb9\u7c7b\u578b\u7684\u6307\u9488\u3002\u4e14\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u4e4b\u4e00\uff1a
- \u4e24\u4e2a\u6307\u9488\u6307\u5411\u540c\u4e00\u5bf9\u8c61\uff0c\u6216\u6307\u5411\u540c\u4e00\u6570\u7ec4\u7684\u5c3e\u540e\u4e00\u4f4d\u7f6e\uff0c\u5219\u76f8\u7b49\u3002
- \u4e24\u4e2a\u6307\u9488\u6307\u5411\u540c\u4e00\u6570\u7ec4\u4e2d\u7684\u4e0d\u540c\u5143\u7d20\uff0c\u5219\u6307\u5411\u6709\u8f83\u5927\u4e0b\u6807\u7684\u5143\u7d20\u7684\u6307\u9488\u6bd4\u8f83\u5927\u3002\uff08\u540c\u4e00\u6570\u7ec4\u4e2d\uff0c\u6307\u5411\u6570\u7ec4\u5c3e\u540e\u4e00\u4f4d\u7f6e\u7684\u6307\u9488\u6700\u5927\uff09
- \u4e24\u4e2a\u6307\u9488\u6307\u5411\u540c\u4e00\u7ed3\u6784\u4f53\u7684\u6210\u5458\uff0c\u5219\u6307\u5411\u7ed3\u6784\u4f53\u58f0\u660e\u4e2d\u8f83\u540e\u58f0\u660e\u7684\u6210\u5458\u7684\u6307\u9488\u66f4\u5927\u3002
- \u6307\u5411\u540c\u4e00\u8054\u5408\u4f53\u6210\u5458\u7684\u6307\u9488\u6bd4\u8f83\u76f8\u7b49\u3002\u8fd9\u4e2a\u4e0d\u505a\u8981\u6c42\u3002
\u9664\u6b64\u4e4b\u5916\uff0c\u6307\u9488\u7684\u6bd4\u8f83\u7ed3\u679c\u662f\u672a\u5b9a\u4e49\u7684\u3002
\u6307\u9488\u7684\u8ba1\u7b97
\u6d89\u53ca\u6307\u9488\u7684\u52a0\u51cf\u53ea\u6709\u4e24\u79cd\u60c5\u51b5\uff1a
-
\u6307\u9488\u7c7b\u578b \u00b1 \u6574\u6570\u7c7b\u578b p + a
\u6216 p - a
\u7ed3\u679c\u4e3a\u6307\u9488 p
\u53f3\u79fb/\u5de6\u79fb a
\u4e2a\u5355\u4f4d\uff0c\u5355\u4f4d\u7531\u6307\u9488\u7684\u7c7b\u578b\u51b3\u5b9a\u3002
\u6bd4\u5982\u8bfb\u5165\u6570\u7ec4\u65f6\u53ef\u4ee5\u4f7f\u7528\uff1ascanf(\"%d\", arr + i)
\u3002
-
\u76f8\u540c\u7c7b\u578b\u7684\u6307\u9488\u76f8\u51cf
\u7ed3\u679c\u4e3a\u4e24\u6307\u9488\u4e4b\u95f4\u5dee\u4e86\u591a\u5c11\u5355\u4f4d\u8ddd\u79bb\uff0c\u800c\u4e0d\u662f\u6307\u9488\u7684\u503c\u76f8\u51cf\u3002
\u4f8b\u9898
\u4ee5\u4e0b\u4ee3\u7801\u7684\u8f93\u51fa\u4e3a _____\u3002
int a[] = {1, 2, 3, 4, 5};\nint *p = a, *q = &a[2];\nprintf(\"%lu\\n\", q - p);\n
"},{"location":"programming_lecture/lecture5/lecture5/#_12","title":"\u4e00\u4e9b\u9898\u76ee","text":"\u9898\u76ee 1
The following code fragment will output _____.
char *week[]={\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"}, **pw=week;\nchar c1, c2;\nc1 = (*++pw)[1];\nc2 = *++pw[1];\nprintf(\"%c#%c#\", c1, c2);\n
Answer \"Mon\\0\" \"Tue\\0\" \"Wed\\0\" \"Thu\\0\" \"Fri\\0\" \"Sat\\0\" \"Sun\\0\"\n ^ ^ ^ ^ ^ ^ ^\n | | | | | | |\nweek: week[0] week[1] week[2] week[3] week[4] week[5] week[6]\n ^\n |\n pw\n
\u9898\u76ee 2
For definitions:
char s[2][3] = {\"ab\", \"cd\"}, *p = (char *)s;\n
the expression _____ is correct and its value is equivalent to the element s[1][1]
.
A. *(s + 3)
B. *s + 2
C. p[1][1]
D. *++p + 2
Answer s: \"ab\\0\" \"cd\\0\"\n ^\n |\ns(\u9690\u5f0f\u8f6c\u6362)(char *[3])\n\ns: \"ab\\0\" \"cd\\0\"\n ^\n |\n p = (char *)s\n
"},{"location":"programming_lecture/lecture5/lecture5/#_13","title":"\u94fe\u8868","text":""},{"location":"programming_lecture/lecture5/lecture5/#_14","title":"\u57fa\u7840\u77e5\u8bc6\u548c\u603b\u7ed3","text":"\u94fe\u8868\u662f\u4e00\u79cd\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u901a\u8fc7\u8282\u70b9\u7684\u5f62\u5f0f\u5b58\u50a8\u6570\u636e\u3002\u6bcf\u4e2a\u8282\u70b9\u5305\u542b\u6570\u636e\u90e8\u5206\u548c\u6307\u5411\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684\u6307\u9488\u3002\u94fe\u8868\u53ef\u4ee5\u662f\u5355\u5411\u7684\u4e5f\u53ef\u4ee5\u662f\u53cc\u5411\u7684\uff0c\u6211\u4eec\u5148\u770b\u770b\u5355\u5411\u94fe\u8868\uff1a
\u5355\u5411\u94fe\u8868\u7684\u4e00\u79cd\u5b9a\u4e49\u65b9\u5f0f
typedef struct Node {\n int data;\n struct Node* next;\n} Node;\n
\u597d\u4e86\uff0c\u6211\u4eec\u5df2\u7ecf\u628a\u94fe\u8868\u7ed9\u5b9a\u4e49\u51fa\u6765\u4e86\u3002\u4f46\u662f\u4f60\u4f1a\u597d\u5947\uff0c\u6211\u4eec\u4e0d\u662f\u53ea\u5b9a\u4e49\u51fa\u4e86\u8282\u70b9\u5417\uff1f\u600e\u4e48\u5df2\u7ecf\u5b9a\u4e49\u5b8c\u4e86\uff1f\u4e8b\u5b9e\u4e0a\uff0c\u8fd9\u51e0\u4e4e\u5c31\u5df2\u7ecf\u662f\u94fe\u8868\u7684\u5b8c\u6574\u7ed3\u6784\u4e86\u2014\u2014\u56e0\u4e3a\u94fe\u8868\u5c31\u662f\u7b80\u5355\u7684\u94fe\u8868\u8282\u70b9\u7684\u4e32\u8054\u3002
\u5927\u5bb6\u90fd\u5df2\u7ecf\u77e5\u9053\u4e86\u94fe\u8868\u7684\u7ed3\u6784\uff0c\u662f\u7c7b\u4f3c\u4e8e\u4e0b\u9762\u8fd9\u6837\u7684\uff1a
\u6240\u4ee5\uff0c\u94fe\u8868\u5176\u5b9e\u5c31\u662f\u4ee5\u4e0b\u7684\u4e1c\u897f\u7684\u7ed3\u5408\uff1a
- \u4e00\u4e2a\u6307\u5411\u5934\u7ed3\u70b9\u7684\u6307\u9488
head
\uff0c\u544a\u8bc9\u6211\u4eec\u4ece\u54ea\u91cc\u5f00\u59cb\u904d\u5386\u6574\u4e2a\u94fe\u8868\u3002 - \u5934\u8282\u70b9\u6307\u5411\u7684\u4e0b\u4e00\u4e2a\u8282\u70b9
head->next
\u3002\u6ce8\u610f\u8fd9\u4e5f\u662f\u4e00\u4e2a\u6307\u9488\u3002 - \u5934\u8282\u70b9\u6307\u5411\u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u8282\u70b9
head->next->next
\u3002 - ...
- \u6700\u540e\u4e00\u4e2a\u8282\u70b9\u3002
\u6211\u4eec\u600e\u4e48\u77e5\u9053\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u662f\u4ec0\u4e48\u5462\uff1f\u6211\u4eec\u89c4\u5b9a\uff0c\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u6307\u5411\u7684\u4f4d\u7f6e\u5c31\u662f NULL
\uff0c\u4e5f\u5c31\u662f 0
\u3002\u8fd9\u6837\uff0c\u53ea\u8981\u5224\u65ad\u8282\u70b9\u7684 .next
\u662f\u5426\u662f NULL
\uff0c\u5c31\u53ef\u4ee5\u77e5\u9053\u8fd9\u4e2a\u8282\u70b9\u662f\u4e0d\u662f\u5c3e\u8282\u70b9\u4e86\u3002\u597d\u4e86\uff0c\u6240\u4ee5\u6211\u4eec\u53ea\u9700\u8981\u82e5\u5e72\u4e2a Node
\uff0c\u7136\u540e\u5c06\u4ed6\u4eec\u4e32\u8054\u2014\u2014\u4e5f\u5c31\u662f\u901a\u8fc7 next
\u8fde\u63a5\uff0c\u5c31\u5f97\u5230\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u94fe\u8868\u3002
\u63a5\u4e0b\u6765\u8ba9\u6211\u4eec\u56de\u5fc6\u4e00\u4e0b\u94fe\u8868\u7684\u5404\u79cd\u64cd\u4f5c\u7684\u5b9e\u73b0\u5427\uff01\u4e0d\u8fc7\u5927\u5bb6\u5728\u5e73\u65f6\u505a\u9898\u7684\u65f6\u5019\u5e94\u8be5\u90fd\u611f\u89c9\u5230\u4e86\uff0c\u94fe\u8868\u6709\u5f88\u591a\u5f88\u591a\u96be\u4ee5\u7422\u78e8\u7684\u7ec6\u8282\u548c\u7279\u6b8a\u60c5\u51b5\uff01\u600e\u4e48\u529e\u5462\uff1f\u51b7\u9759\u4e0b\u6765\u603b\u7ed3\uff0c\u65e0\u975e\u5c31\u662f\u8fd9\u51e0\u79cd\uff1a
- \u7279\u6b8a\u60c5\u51b5 \\(1\\)\uff1a\u5982\u679c\u5934\u6307\u9488\u6307\u5411\u7684\u662f
NULL
\uff0c\u4e5f\u5c31\u662f\u94fe\u8868\u672c\u8eab\u5c31\u4e3a\u7a7a\u4e86\u3002 - \u7279\u6b8a\u60c5\u51b5 \\(2\\)\uff1a\u5982\u679c\u5f53\u524d\u64cd\u4f5c\u5728\u5934\u8282\u70b9\u8fdb\u884c\u3002
- \u7279\u6b8a\u60c5\u51b5 \\(3\\)\uff1a\u5982\u679c\u5f53\u524d\u64cd\u4f5c\u5728\u5c3e\u8282\u70b9\u8fdb\u884c\u3002
\u8fd9\u4e9b\u60c5\u51b5\u5982\u679c\u6ca1\u6709\u8003\u8651\u6e05\u695a\uff0c\u5f88\u53ef\u80fd\u5728\u5199\u4ee3\u7801\u7684\u8fc7\u7a0b\u4e2d\u51fa\u73b0 segmentation fault
\uff0c\u4e5f\u5c31\u662f\u6bb5\u9519\u8bef\u3002\u8fd9\u6781\u5927\u6982\u7387\u662f\u56e0\u4e3a\uff0c\u4f60\u8bbf\u95ee\u4e86 NULL
\u4f4d\u7f6e\u7684\u4e00\u4e9b\u4fe1\u606f\u3002\u6bd4\u5982\u5f53\u524d\u8282\u70b9\u6307\u9488 p
\u6307\u5411\u4e86 NULL
\uff0c\u4f46\u662f\u4f60\u5374\u8bbf\u95ee\u4e86 p->data
\u6216\u8005 p->next
\uff0c\u5c31\u4f1a\u62a5\u9519\u4e86\u3002
"},{"location":"programming_lecture/lecture5/lecture5/#_15","title":"\u5355\u5411\u94fe\u8868\u7684\u5404\u79cd\u7ecf\u5178\u64cd\u4f5c","text":"\u521b\u5efa\u4e00\u4e2a\u8282\u70b9 p
\uff0c\u5176\u6743\u503c\u4e3a w
\uff0c\u5e76\u8fd4\u56de\u8fd9\u4e2a\u8282\u70b9\u7684\u6307\u9488
\u53ea\u9700\u8981\u4f7f\u7528 malloc
\u5373\u53ef\u3002
Node *create(int w){\n Node* newNode = (Node*)malloc(sizeof(Node));\n newNode->next = NULL;\n newNode->data = w;\n return newNode;\n}\n
\u4e00\u4e2a\u7ec6\u8282
\u6ce8\u610f\uff0cmalloc
\u51fd\u6570\u5185\u90e8\u9700\u8981\u5f00\u7684\u8282\u70b9\u5927\u5c0f\u662f sizeof(Node)
\u800c\u4e0d\u662f sizeof(Node*)
\uff0c\u60f3\u60f3\u4e3a\u4ec0\u4e48\uff1f
\u5728\u94fe\u8868\u7684\u5934\u90e8/\u5c3e\u90e8\u63d2\u5165\u4e00\u4e2a\u8282\u70b9 p
\uff0c\u5e76\u8fd4\u56de\u65b0\u94fe\u8868\u7684\u5934\u90e8
\u5148\u770b\u5934\u90e8\u63d2\u5165\u3002
\u9996\u5148\uff0c\u7279\u6b8a\u60c5\u51b5 \\(1\\)\uff0c\u539f\u5148\u94fe\u8868\u662f\u7a7a\u7684\uff0c\u90a3\u80af\u5b9a\u662f\u628a head
\u8d4b\u503c\u4e3a\u65b0\u8282\u70b9\u561b\u3002
\u53d1\u73b0\u53ea\u5269\u4e0b\u7279\u6b8a\u60c5\u51b5 \\(2\\)\uff0c\u90a3 head
\u4e5f\u8981\u8d4b\u503c\u4e3a\u65b0\u8282\u70b9\uff0c\u7136\u540e\u65b0\u8282\u70b9\u8fde\u5411\u8001 head
\u3002
Node *insertAtHead(Node* head, Node* p) {\n if (!head) return p; // \u53ef\u4ee5\u53d1\u73b0\uff0c\u8fd9\u53e5\u8bdd\u4e0d\u5199\u4e5f\u6ca1\u6709\u5f71\u54cd \n p->Next = head;\n return p;\n}\n
\u4e00\u4e2a\u7ec6\u8282
\u4e3a\u4ec0\u4e48 if
\u91cc\u662f !head
\uff1f
\u7136\u540e\u662f\u5c3e\u90e8\u63d2\u5165\u3002\u9996\u5148\u8fd8\u662f\u7279\u6b8a\u60c5\u51b5 \\(1\\)\uff0c\u5904\u7406\u5b8c\u4ee5\u540e\u53ea\u5269\u4e0b\u7279\u6b8a\u60c5\u51b5 \\(3\\) \uff0c\u90a3\u4e48\u6211\u4eec\u53ea\u9700\u8981\u627e\u5230\u5c3e\u8282\u70b9\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u63d2\u5165\u4e86\uff0c\u6700\u540e\u8fd4\u56de\u7684\u4e5f\u53ea\u662f\u539f\u672c\u7684 head
\u3002
Node *insertAtEnd(Node* head, Node* p) {\n if (!head) return p;\n Node* last = head;\n while (last->next) {\n last = last->next;\n }\n last->next = p;\n return head;\n}\n
\u5220\u9664\u6743\u503c\u4e3a key
\u7684\u8282\u70b9\uff0c\u5982\u679c\u6709\u591a\u4e2a\uff0c\u5219\u5220\u9664\u6700\u9760\u8fd1\u5f00\u5934\u7684\uff0c\u6ca1\u6709\u5219\u4e0d\u5220\u9664\uff0c\u8fd4\u56de\u65b0\u94fe\u8868\u7684\u5934\u90e8
\u6700\u7e41\u7410\u6700\u590d\u6742\u7684\u4e00\u4e2a\u64cd\u4f5c\uff0c\u4e5f\u662f\u65b0\u624b\u7684\u5669\u68a6\u3002\u4e0d\u8fc7\u6309\u7167\u4e09\u6b65\u8d70\u5c31\u597d\u4e86\u3002
\u5148\u5904\u7406\u4e00\u4e0b\u7279\u6b8a\u60c5\u51b5 \\(1\\) \u3002
Node *deleteNode(Node* head, int key) {\n if (!head) return NULL;\n}\n
\u7136\u540e\u60c5\u51b5 \\(2\\) \u5462\uff0c\u5934\u7ed3\u70b9\u4f1a\u53d1\u751f\u53d8\u5316\u3002
Node *deleteNode(Node* head, int key) {\n if (!head) return NULL;\n if (head->data == key){\n node* tmp = head->next; //\u8fd9\u4e48\u505a\u662f\u56e0\u4e3a free \u4ee5\u540e\uff0chead->next \u5c31\u4e0d\u80fd\u83b7\u53d6\u4e86\u3002\n free(head);\n return tmp;\n }\n}\n
\u5269\u4e0b\u60c5\u51b5 \\(3\\) \u8fd8\u8981\u7279\u6b8a\u5224\u65ad\u3002\u6211\u4eec\u5148\u627e\u5230\u8981\u5220\u9664\u7684\u4f4d\u7f6e\u3002\u56de\u5fc6\u4e00\u4e0b\u5220\u9664\u7684\u8fc7\u7a0b\uff0c\u6211\u4eec\u9700\u8981\u8bb0\u5f55\u5f53\u524d\u9700\u8981\u88ab\u5220\u9664\u7684\u8282\u70b9\u7684\u6307\u9488 prev
\uff1a
Node *deleteNode(Node* head, int key) {\n if (!head) return NULL;\n if (head->data == key){\n node* temp = head->next; //\u8fd9\u4e48\u505a\u662f\u56e0\u4e3a free \u4ee5\u540e\uff0chead->next \u5c31\u4e0d\u80fd\u83b7\u53d6\u4e86\u3002\n free(head);\n return tmp;\n }\n node* temp = head, prev = NULL;\n while (temp && temp->data != key) {\n prev = temp;\n temp = temp->next;\n }\n if (!temp) return head;\n prev->next = temp->next; //\u4e8b\u5b9e\u4e0a\u76f4\u63a5\u5220\u9664\u5c31\u597d\u4e86\uff0c\u4e0d\u9700\u8981\u5173\u7cfb\u60c5\u51b5 3 \u4e86\uff0c\u4e0d\u8fc7\u7279\u5224\u4e00\u4e0b\u4e5f\u4e0d\u9519\u3002\n free(temp);\n return head;\n}\n
\u6ce8\u610f\uff01
\u7406\u8bba\u8003\u8bd5\u5199\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u4e00\u5b9a\u4e0d\u8981\u5fd8\u8bb0 free
\u88ab\u5220\u9664\u7684\u8282\u70b9\uff01\uff01\uff01\u5c0f\u5fc3\u6263\u5206\uff01\uff01\uff01
\u4e0a\u673a\u4e0d free
\u5012\u662f\u6ca1\u5173\u7cfb\uff08\u6307\u8fd8\u80fd\u901a\u8fc7\uff09\uff0c\u4f46\u8fd8\u662f\u5efa\u8bae\u517b\u6210\u826f\u597d\u7684\u4e60\u60ef\uff0c\u9632\u6b62\u5185\u5b58\u6cc4\u6f0f\uff01
"},{"location":"programming_lecture/lecture5/lecture5/#_16","title":"\u53cc\u5411\u94fe\u8868","text":"\u5176\u5b9e\u6ca1\u4ec0\u4e48\u53ef\u4ee5\u8bb2\u7684\uff0c\u4e5f\u5c31\u662f\u5728 struct
\u7684\u5b9a\u4e49\u4e2d\u52a0\u5165\u4e86 prev
\uff0c\u53ef\u4ee5\u8ba9\u6211\u4eec\u65b9\u4fbf\u7684\u83b7\u53d6\u4e0a\u4e00\u4e2a\u8282\u70b9\u7684\u6307\u9488\uff0c\u8fd9\u6837\u5220\u9664\u8fc7\u7a0b\u4e2d\u5c31\u4e0d\u9700\u8981\u5355\u72ec\u5f00\u53d8\u91cf\u8bb0\u5f55\u4e86\u3002
\u53cc\u5411\u94fe\u8868\u7684\u4e00\u79cd\u5b9a\u4e49\u65b9\u5f0f
typedef struct Node {\n int data;\n struct Node* prev, next;\n} Node;\n
\u7279\u522b\u7684\uff0c\u5934\u7ed3\u70b9\u7684 prev
\u662f NULL
\u3002
\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u9898\u5427~
\u9898\u76ee 3
To delete p
from a doubly linked list, we must do:
A. p->prev=p->prev->prev; p->prev->next=p;
B. p->next->prev=p; p->next=p->next->next;
C. p->prev->next=p->next; p->next->prev=p->prev;
D. p->next=p->prev->prev; p->prev=p->next->next;
Answer C.
"},{"location":"programming_lecture/lecture5/lecture5/#_17","title":"\u6808\u548c\u961f\u5217","text":"\u8fd9\u4e00\u90e8\u5206\u7684\u5185\u5bb9\u76f8\u4fe1\u5927\u5bb6\u5728\u8bfe\u4e0a\u5df2\u7ecf\u6709\u5f88\u597d\u7684\u7406\u89e3\u4e86\uff0c\u4f46\u662f\u4f1a\u51fa\u4e00\u4e9b\u548c\u94fe\u8868\u7ed3\u5408\u7684\u6709\u96be\u5ea6\u7684\u7406\u8bba\u9898\u548c\u7f16\u7a0b\u9898\uff0c\u6240\u4ee5\u7b80\u5355\u5e26\u8fc7\u4e00\u4e0b\uff1a
\u901a\u5e38\u9898\u76ee\u4f1a\u4f7f\u7528\u5355\u5411\u94fe\u8868\u6765\u5b9e\u73b0\u6808\u548c\u961f\u5217\u3002\u4e0d\u8fc7\u5f88\u591a\u9898\u76ee\u5176\u5b9e\u4f1a\u4e0d\u544a\u8bc9\u4f60\uff0c\u94fe\u8868\u54ea\u4e00\u6bb5\u8868\u793a\u6808\u9876\uff0c\u54ea\u4e00\u6bb5\u8868\u793a\u961f\u5934\uff0c\u54ea\u4e00\u6bb5\u8868\u793a\u961f\u5c3e\u3002
\u4e00\u4e2a\u95ee\u9898
\u5982\u679c\u662f\u53cc\u5411\u94fe\u8868\u5176\u5b9e\u6ca1\u6709\u8fd9\u4e48\u591a\u70e6\u607c\uff0c\u4f46\u662f\u73b0\u5728\u662f\u5355\u5411\u7684\u3002\u600e\u4e48\u5224\u65ad\u94fe\u8868\u7684\u5934\u4ee3\u8868\u6808/\u961f\u5217\u7684\u54ea\u4e2a\u90e8\u5206\u5462\uff1f
\u6808\u9876\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u6211\u4eec\u53ea\u9700\u8981\u8bb0\u5f55\u4e00\u4e0b\u94fe\u8868\u7684\u5934\u6307\u9488 head
\uff0c\u5728\u4e0a\u9762\u64cd\u4f5c\uff0c\u53ef\u4ee5\u76f4\u63a5\u5b8c\u6210\u5bf9\u6808\u7684\u6a21\u62df\uff0c\u6240\u4ee5\u94fe\u8868\u7684\u5934\u4ee3\u8868\u6808\u9876\u3002
\u90a3\u961f\u5217\u5462\uff1f\u6211\u4eec\u4e0d\u59a8\u8bd5\u4e00\u4e0b\uff0c\u5047\u8bbe\u94fe\u8868\u5934\u90e8\u4ee3\u8868\u961f\u5c3e\uff0c\u90a3\u4e48\u961f\u5217\u7684\u5165\u961f\u64cd\u4f5c\u5f88\u597d\u5b9e\u73b0\uff0c\u4f46\u662f\uff0c\u51fa\u961f\u9700\u8981\u5728\u94fe\u8868\u5c3e\u90e8\u8fdb\u884c\u64cd\u4f5c\u3002\u6709\u4e00\u4e2a\u5f88\u76f4\u89c2\u7684\u65b9\u6cd5\u5c31\u662f\u540c\u65f6\u8bb0\u5f55\u5e76\u7ef4\u62a4\u94fe\u8868\u7684\u5c3e\u6307\u9488 tail
\uff0c\u4f46\u662f\uff0c\u5220\u9664\u7684\u8bdd\uff0c\u6211\u4eec\u9700\u8981\u77e5\u9053\u5c3e\u6307\u9488\u7684\u524d\u9a71\u8282\u70b9...
\u6240\u4ee5\u4e00\u4e9b\u9898\u76ee\u7684\u5b9e\u73b0\uff0c\u9ed8\u8ba4\u4e86\u94fe\u8868\u7684\u5934\u90e8\u4ee3\u8868\u961f\u5934\u3002\u770b\u4e00\u4e0b\u8fd9\u4e2a\u9898\u76ee\uff1a
\u9898\u76ee 4
Represent a queue by a singly linked list. Given the current status of the linked list as 1->2->3
where x->y
means y
is linked after x
. Now if 4
is enqueued and then a dequeue is done, the resulting status must be:
A. 1->2->3
B. 2->3->4
C. 4->1->2
D. the solution is not unique
Answer B.
\u8fd9\u91cc\u9700\u8981\u989d\u5916\u63d0\u4e00\u4e2a\u53eb\u505a\u5faa\u73af\u961f\u5217\u7684\u4e1c\u897f\u3002\u5b83\u662f\u961f\u5217\u7684\u4e00\u79cd\u53d8\u4f53\uff0c\u901a\u5e38\u4f7f\u7528\u6570\u7ec4\u6765\u5b9e\u73b0\uff0c\u7528\u6765\u8282\u7ea6\u961f\u5217\u7684\u7a7a\u95f4\u3002 \u5faa\u73af\u961f\u5217\u662f\u628a\u987a\u5e8f\u961f\u5217\u9996\u5c3e\u76f8\u8fde\uff0c\u628a\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u8868\u4ece\u903b\u8f91\u4e0a\u770b\u6210\u4e00\u4e2a\u73af\u3002\u901a\u5e38\u7528\u4e24\u4e2a\u53d8\u91cf\u4ee3\u8868\u5f53\u524d\u5faa\u73af\u961f\u5217\u5b58\u50a8\u7684\u7a7a\u95f4\uff1a\u4e00\u4e2a\u662f\u5c3e rear
\uff0c\u4e00\u4e2a\u662f\u5934front
\u3002\u4e0d\u8fc7\u8fd9\u4e2a\u662f\u5f00\u533a\u95f4\u8fd8\u662f\u95ed\u533a\u95f4\u5462\uff0c\u8fd8\u5f97\u770b\u5177\u4f53\u5b9e\u73b0\u65b9\u5f0f\u548c\u9898\u5e72\u8981\u6c42\uff0c\u5927\u5bb6\u6700\u597d\u7ffb\u7ffb\u8001\u5e08\u7684 PPT\uff0c\u770b\u770b\u4e0a\u8bfe\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff0c\u4e07\u4e00\u9898\u76ee\u6ca1\u6709\u7ed9\u51fa\u5b9e\u73b0\u65b9\u5f0f\u5c31\u6309\u7167\u8001\u5e08\u8bb2\u7684\u4e3a\u4e3b\u5427\u3002
\u9898\u76ee 5
Suppose that an array of size 6 is used to store a circular queue, and the values of front and rear are 0 and 4, respectively. Now after 2 dequeues and 2 enqueues, what will the values of front and rear be?
A. 2 and 0
B. 2 and 2
C. 2 and 4
D. 2 and 6
Answer A.
\u5173\u4e8e\u7f16\u7a0b\u90e8\u5206\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u8fd9\u4e2a\u6bcf\u65e5\u4e00\u9898\u3002
"}]}
\ No newline at end of file
diff --git a/sitemap.xml b/sitemap.xml
index 2cbac9f..4001caf 100644
--- a/sitemap.xml
+++ b/sitemap.xml
@@ -2,147 +2,147 @@
https://ckc-agc.bowling233.top/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/contribute/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/test/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/algebra/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/analysis/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/analysis/2023-2024/analysis_lecture1_sequence_limits/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/analysis/analysis1_paper/22test1_answer/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/calculus/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/chemistry/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/lalu/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/other/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/physics/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming/faq/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming/daily/2023/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming/exam/exam/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming/topic/funcptr/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming/topic/pointers/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming_lecture/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming_lecture/lecture1/lecture1/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming_lecture/lecture1/pre_class/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming_lecture/lecture2/after_class/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming_lecture/lecture2/lecture2/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming_lecture/lecture2/pre_class/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming_lecture/lecture3/lecture3/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming_lecture/lecture3/pre_class/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming_lecture/lecture4/after_class/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming_lecture/lecture4/lecture4/
- 2023-12-30
+ 2024-01-01
daily
https://ckc-agc.bowling233.top/programming_lecture/lecture5/lecture5/
- 2023-12-30
+ 2024-01-01
daily
\ No newline at end of file
diff --git a/sitemap.xml.gz b/sitemap.xml.gz
index 2c2a2f5070b40f8cd60b7be443a9c8ebe6b6e50d..e175ab2265ffc8cc555c1f87f8786d781d413b02 100644
GIT binary patch
literal 425
zcmV;a0apGWiwFo^d6H!U|8r?{Wo=<_E_iKh0M(YwZo?o9$M1cLD))va?WAo=v)i6v
zJ4ckd2^s;4on?Ldk$#^iO~NQj{IqJiS#6wCZ2t7r2#rU}mKG%Dj%
zJTJp@sfQx+GEv^YjH*=`_>8qARH0Z%PiBZXtKghrYnSvW^s
z!rAA$STZWz+D(G1xtF?hri}ty6d}ONdI&f
T|4x7UAW;1ae-;^QU=#oV+fUAZ
literal 427
zcmV;c0aX4UiwFpZB#>nS|8r?{Wo=<_E_iKh0M(YwZsQ;j$M1cL$oH7o&Puy0$G!Cl
z+OtK-#74zHm~q{_eX-MgoGVpgIN(2{G5kO?qp6=i2ebNsfZEwzR^*#(1y;F(w%sm!
zdwp5|&7Pa5dJG1ER?*qwF6)W>e<7x6%25*x(qryICs6fqf#TaJHu=A-d0NFWZ*Wn|
zsEt$2ybH!{)Vo^CPUU+ynRskjRXI5?YB4)K{v(kFcWBB@S*?q5U2USvx9!1A_0o25
z3~*`=Qk!!v9xN9aaijSGmvWYZ-j4*yA`&1a3nxtn`ykWhv(lVVWBPy#N1V1dQ)@uc
z7@%koPGd}DXpJ5;F}TcC6s?yYf+)*5ii=iSoZ>RsY9Ngo&6w^3&m~zSg>$lmMw&5M
zI7fZL(dYY^GAiBR^TBmN4ns7tU_8nb3(n<$rT(+Pg-AR(T4Hh`rO6
zVkgf5`P!(kV!bw3cfpe02WVAV`sIT_%@-K>W({Bz006kr&wl^_
diff --git a/test/index.html b/test/index.html
index f78786f..36f5f80 100644
--- a/test/index.html
+++ b/test/index.html
@@ -613,9 +613,9 @@ Bilibili Stats这里和这里的两个项目功能都残缺了,考虑后续部署到服务器上。
-
+
LaTeX¶
simple
\[