Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_c
提交
a0c19017
S
skill_tree_c
项目概览
CSDN 技术社区
/
skill_tree_c
通知
24
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_c
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
a0c19017
编写于
10月 24, 2021
作者:
L
luxin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add 2 exercises
上级
9f497aae
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
574 addition
and
21 deletion
+574
-21
data/3.C语言高阶/6.存储管理/2.内存动态管理/config.json
data/3.C语言高阶/6.存储管理/2.内存动态管理/config.json
+35
-0
data/3.C语言高阶/6.存储管理/2.内存动态管理/memory_management.c
data/3.C语言高阶/6.存储管理/2.内存动态管理/memory_management.c
+55
-0
data/3.C语言高阶/6.存储管理/2.内存动态管理/memory_management.json
data/3.C语言高阶/6.存储管理/2.内存动态管理/memory_management.json
+7
-0
data/3.C语言高阶/6.存储管理/2.内存动态管理/memory_management.md
data/3.C语言高阶/6.存储管理/2.内存动态管理/memory_management.md
+239
-0
data/3.C语言高阶/6.存储管理/2.分配内存:malloc()和free()/config.json
data/3.C语言高阶/6.存储管理/2.分配内存:malloc()和free()/config.json
+0
-11
data/3.C语言高阶/7.标准函数库/1.数学库/config.json
data/3.C语言高阶/7.标准函数库/1.数学库/config.json
+11
-8
data/3.C语言高阶/7.标准函数库/1.数学库/math.c
data/3.C语言高阶/7.标准函数库/1.数学库/math.c
+0
-0
data/3.C语言高阶/7.标准函数库/1.数学库/math.json
data/3.C语言高阶/7.标准函数库/1.数学库/math.json
+7
-0
data/3.C语言高阶/7.标准函数库/1.数学库/math.md
data/3.C语言高阶/7.标准函数库/1.数学库/math.md
+23
-0
data/3.C语言高阶/7.标准函数库/2.通用工具库/config.json
data/3.C语言高阶/7.标准函数库/2.通用工具库/config.json
+2
-1
data/3.C语言高阶/7.标准函数库/2.通用工具库/qsort.c
data/3.C语言高阶/7.标准函数库/2.通用工具库/qsort.c
+0
-0
data/3.C语言高阶/7.标准函数库/2.通用工具库/qsort.json
data/3.C语言高阶/7.标准函数库/2.通用工具库/qsort.json
+7
-0
data/3.C语言高阶/7.标准函数库/2.通用工具库/qsort.md
data/3.C语言高阶/7.标准函数库/2.通用工具库/qsort.md
+23
-0
data/3.C语言高阶/7.标准函数库/3.断言库/assert.c
data/3.C语言高阶/7.标准函数库/3.断言库/assert.c
+24
-0
data/3.C语言高阶/7.标准函数库/3.断言库/assert.json
data/3.C语言高阶/7.标准函数库/3.断言库/assert.json
+7
-0
data/3.C语言高阶/7.标准函数库/3.断言库/assert.md
data/3.C语言高阶/7.标准函数库/3.断言库/assert.md
+130
-0
data/3.C语言高阶/7.标准函数库/3.断言库/config.json
data/3.C语言高阶/7.标准函数库/3.断言库/config.json
+4
-1
未找到文件。
data/3.C语言高阶/6.存储管理/2.内存动态管理/config.json
0 → 100644
浏览文件 @
a0c19017
{
"node_id"
:
"e75bdc3470954cb38bdfcf4f0ed3680b"
,
"keywords"
:
[
"存储管理"
,
"内存管理"
,
"内存动态管理"
,
"C语言"
],
"children"
:
[
{
"内存分配:malloc()"
:
{
"keywords"
:
[
"内存分配"
,
"malloc"
,
"C语言"
],
"children"
:
[]
}
},
{
"内存释放:free()"
:
{
"keywords"
:
[
"内存释放"
,
"free"
,
"C语言"
],
"children"
:
[]
}
}
],
"export"
:
[
"memory_management.json"
]
}
\ No newline at end of file
data/3.C语言高阶/6.存储管理/2.内存动态管理/memory_management.c
0 → 100644
浏览文件 @
a0c19017
#include <stdio.h>
#include <stdlib.h>
#define N 5
int
*
readline
(
int
*
mem_size
)
{
int
*
array
=
NULL
;
int
size
=
N
;
array
=
(
int
*
)
malloc
((
size
+
1
)
*
sizeof
(
int
));
if
(
array
==
NULL
)
{
printf
(
"内存分配失败!
\n
"
);
exit
(
-
1
);
}
int
value
;
int
count
=
0
;
printf
(
"请输入一串整数(以空格隔开)
\n
(Win按Ctrl+Z结束)
\n
(Mac先按回车,再按Ctrl+D结束):
\n
"
);
while
(
scanf
(
"%d"
,
&
value
)
!=
EOF
)
{
++
count
;
if
(
count
>
size
)
{
size
+=
N
;
array
=
realloc
(
array
,
(
size
+
1
)
*
sizeof
(
int
));
if
(
array
==
NULL
)
{
printf
(
"重新分配内存空间失败!
\n
"
);
exit
(
-
1
);
}
}
array
[
count
]
=
value
;
}
array
[
0
]
=
count
;
*
mem_size
=
size
;
return
array
;
}
int
main
()
{
int
i
,
mem_size
,
count
;
int
*
array
=
readline
(
&
mem_size
);
count
=
array
[
0
];
printf
(
"------------------------------
\n
"
);
printf
(
"内存空间大小为:%d
\n
实际使用量为:%d
\n
"
,
mem_size
,
count
+
1
);
printf
(
"实际存储数据为:"
);
for
(
i
=
1
;
i
<=
count
;
++
i
)
printf
(
"%d "
,
array
[
i
]);
free
(
array
);
return
0
;
}
\ No newline at end of file
data/3.C语言高阶/6.存储管理/2.内存动态管理/memory_management.json
0 → 100644
浏览文件 @
a0c19017
{
"type"
:
"code_options"
,
"author"
:
"卢昕"
,
"source"
:
"memory_management.md"
,
"exercise_id"
:
"a714745a7e4d4543a90483a3be3a0f73"
}
\ No newline at end of file
data/3.C语言高阶/6.存储管理/2.内存动态管理/memory_management.md
0 → 100644
浏览文件 @
a0c19017
# 内存动态管理
使用动态分配内存的方式,模拟C++中Vector容器,实现动态数组的构建。请选出正确答案。
## 答案
```
c
#include <stdio.h>
#include <stdlib.h>
#define N 5
int
*
readline
(
int
*
mem_size
)
{
int
*
array
=
NULL
;
int
size
=
N
;
array
=
(
int
*
)
malloc
((
size
+
1
)
*
sizeof
(
int
));
if
(
array
==
NULL
)
{
printf
(
"内存分配失败!
\n
"
);
exit
(
-
1
);
}
int
value
;
int
count
=
0
;
printf
(
"请输入一串整数(以空格隔开)
\n
(Win按Ctrl+Z结束)
\n
(Mac先按回车,再按Ctrl+D结束):
\n
"
);
while
(
scanf
(
"%d"
,
&
value
)
!=
EOF
)
{
++
count
;
if
(
count
>
size
)
{
size
+=
N
;
array
=
realloc
(
array
,
(
size
+
1
)
*
sizeof
(
int
));
if
(
array
==
NULL
)
{
printf
(
"重新分配内存空间失败!
\n
"
);
exit
(
-
1
);
}
}
array
[
count
]
=
value
;
}
array
[
0
]
=
count
;
*
mem_size
=
size
;
return
array
;
}
int
main
()
{
int
i
,
mem_size
,
count
;
int
*
array
=
readline
(
&
mem_size
);
count
=
array
[
0
];
printf
(
"------------------------------
\n
"
);
printf
(
"内存空间大小为:%d
\n
实际使用量为:%d
\n
"
,
mem_size
,
count
+
1
);
printf
(
"实际存储数据为:"
);
for
(
i
=
1
;
i
<=
count
;
++
i
)
printf
(
"%d "
,
array
[
i
]);
free
(
array
);
return
0
;
}
```
## 选项
### A
```
c
#include <stdio.h>
#include <stdlib.h>
#define N 5
int
*
readline
(
int
*
mem_size
)
{
int
*
array
=
NULL
;
int
size
=
N
;
array
=
(
int
*
)
malloc
((
size
+
1
)
*
sizeof
(
int
));
if
(
array
==
NULL
)
{
printf
(
"内存分配失败!
\n
"
);
exit
(
-
1
);
}
int
value
;
int
count
=
0
;
printf
(
"请输入一串整数(以空格隔开)
\n
(Win按Ctrl+Z结束)
\n
(Mac先按回车,再按Ctrl+D结束):
\n
"
);
while
(
scanf
(
"%d"
,
&
value
)
!=
EOF
)
{
++
count
;
if
(
count
>
size
)
{
size
+=
N
;
array
=
realloc
(
array
,
(
size
+
1
)
*
sizeof
(
int
));
if
(
array
==
NULL
)
{
printf
(
"重新分配内存空间失败!
\n
"
);
exit
(
-
1
);
}
}
array
[
count
]
=
value
;
}
array
[
0
]
=
count
;
*
mem_size
=
size
+
1
;
free
(
array
);
return
array
;
}
int
main
()
{
int
i
,
mem_size
,
count
;
int
*
array
=
readline
(
&
mem_size
);
count
=
array
[
0
];
printf
(
"------------------------------
\n
"
);
printf
(
"内存空间大小为:%d
\n
实际使用量为:%d
\n
"
,
mem_size
,
count
+
1
);
printf
(
"实际存储数据为:"
);
for
(
i
=
1
;
i
<=
count
;
++
i
)
printf
(
"%d "
,
array
[
i
]);
return
0
;
}
```
### B
```
c
#include <stdio.h>
#include <stdlib.h>
#define N 5
int
*
readline
(
int
*
mem_size
)
{
int
*
array
=
NULL
;
int
size
=
N
;
array
=
(
int
*
)
malloc
((
size
+
1
)
*
sizeof
(
int
));
if
(
array
==
NULL
)
{
printf
(
"内存分配失败!
\n
"
);
exit
(
-
1
);
}
int
value
;
int
count
=
0
;
printf
(
"请输入一串整数(以空格隔开)
\n
(Win按Ctrl+Z结束)
\n
(Mac先按回车,再按Ctrl+D结束):
\n
"
);
while
(
scanf
(
"%d"
,
&
value
)
!=
EOF
)
{
++
count
;
if
(
count
>
size
)
{
size
+=
N
;
array
=
realloc
(
array
,
(
size
+
1
)
*
sizeof
(
int
));
if
(
array
==
NULL
)
{
printf
(
"重新分配内存空间失败!
\n
"
);
exit
(
-
1
);
}
}
array
[
count
]
=
value
;
}
array
[
0
]
=
count
;
*
mem_size
=
size
+
1
;
return
array
;
}
int
main
()
{
int
i
,
mem_size
,
count
;
int
*
array
=
readline
(
&
mem_size
);
count
=
array
[
0
];
printf
(
"------------------------------
\n
"
);
printf
(
"内存空间大小为:%d
\n
实际使用量为:%d
\n
"
,
mem_size
,
count
+
1
);
printf
(
"实际存储数据为:"
);
for
(
i
=
1
;
i
<=
count
;
++
i
)
{
printf
(
"%d "
,
array
[
i
]);
free
(
&
array
[
i
]);
}
free
(
array
);
return
0
;
}
```
### C
```
c
#include <stdio.h>
#include <stdlib.h>
#define N 5
int
*
readline
(
int
*
mem_size
)
{
int
*
array
=
NULL
;
int
size
=
N
;
array
=
malloc
(
size
+
1
);
if
(
array
==
NULL
)
{
printf
(
"内存分配失败!
\n
"
);
exit
(
-
1
);
}
int
value
;
int
count
=
0
;
printf
(
"请输入一串整数(以空格隔开)
\n
(Win按Ctrl+Z结束)
\n
(Mac先按回车,再按Ctrl+D结束):
\n
"
);
while
(
scanf
(
"%d"
,
&
value
)
!=
EOF
)
{
++
count
;
if
(
count
>
size
)
{
size
+=
N
;
array
=
realloc
(
array
,
(
size
+
1
)
*
sizeof
(
int
));
if
(
array
==
NULL
)
{
printf
(
"重新分配内存空间失败!
\n
"
);
exit
(
-
1
);
}
}
array
[
count
]
=
value
;
}
array
[
0
]
=
count
;
*
mem_size
=
size
+
1
;
return
array
;
}
int
main
()
{
int
i
,
mem_size
,
count
;
int
*
array
=
readline
(
&
mem_size
);
count
=
array
[
0
];
printf
(
"------------------------------
\n
"
);
printf
(
"内存空间大小为:%d
\n
实际使用量为:%d
\n
"
,
mem_size
,
count
+
1
);
printf
(
"实际存储数据为:"
);
for
(
i
=
1
;
i
<=
count
;
++
i
)
printf
(
"%d "
,
array
[
i
]);
free
(
array
);
return
0
;
}
```
data/3.C语言高阶/6.存储管理/2.分配内存:malloc()和free()/config.json
已删除
100644 → 0
浏览文件 @
9f497aae
{
"node_id"
:
"e75bdc3470954cb38bdfcf4f0ed3680b"
,
"keywords"
:
[
"存储管理"
,
"内存管理"
,
"C语言"
],
"children"
:
[],
"export"
:
[]
}
\ No newline at end of file
data/3.C语言高阶/7.标准函数库/1.数学库/config.json
浏览文件 @
a0c19017
{
{
"node_id"
:
"77363abd916c4981b595f44138f53e0a"
,
"node_id"
:
"77363abd916c4981b595f44138f53e0a"
,
"keywords"
:
[
"keywords"
:
[
"标准函数库"
,
"标准函数库"
,
"标准库"
,
"标准库"
,
"C语言"
"C语言"
],
],
"children"
:
[],
"children"
:
[],
"export"
:
[]
"export"
:
[
"math.json"
]
}
}
\ No newline at end of file
data/3.C语言高阶/7.标准函数库/1.数学库/math.c
0 → 100644
浏览文件 @
a0c19017
data/3.C语言高阶/7.标准函数库/1.数学库/math.json
0 → 100644
浏览文件 @
a0c19017
{
"type"
:
"code_options"
,
"author"
:
"卢昕"
,
"source"
:
"math.md"
,
"exercise_id"
:
"f764910c876044a3ba3d538a76520386"
}
\ No newline at end of file
data/3.C语言高阶/7.标准函数库/1.数学库/math.md
0 → 100644
浏览文件 @
a0c19017
#
## 答案
```
c
```
## 选项
### A
```
c
```
### B
```
c
```
### C
```
c
```
data/3.C语言高阶/7.标准函数库/2.通用工具库/config.json
浏览文件 @
a0c19017
...
@@ -6,5 +6,5 @@
...
@@ -6,5 +6,5 @@
"C语言"
"C语言"
],
],
"children"
:
[],
"children"
:
[],
"export"
:
[]
"export"
:
[
"qsort.json"
]
}
}
\ No newline at end of file
data/3.C语言高阶/7.标准函数库/2.通用工具库/qsort.c
0 → 100644
浏览文件 @
a0c19017
data/3.C语言高阶/7.标准函数库/2.通用工具库/qsort.json
0 → 100644
浏览文件 @
a0c19017
{
"type"
:
"code_options"
,
"author"
:
"卢昕"
,
"source"
:
"qsort.md"
,
"exercise_id"
:
"902f13f3450445e9b2fa9cb99d78a2b8"
}
\ No newline at end of file
data/3.C语言高阶/7.标准函数库/2.通用工具库/qsort.md
0 → 100644
浏览文件 @
a0c19017
#
## 答案
```
c
```
## 选项
### A
```
c
```
### B
```
c
```
### C
```
c
```
data/3.C语言高阶/7.标准函数库/3.断言库/assert.c
0 → 100644
浏览文件 @
a0c19017
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define N 10
void
*
mem_cpy
(
void
*
dest
,
const
void
*
src
,
size_t
len
)
{
assert
(
dest
!=
NULL
&&
src
!=
NULL
);
char
*
tmp_dest
=
(
char
*
)
dest
;
char
*
tmp_src
=
(
char
*
)
src
;
while
(
len
--
)
*
tmp_dest
++
=
*
tmp_src
++
;
return
dest
;
}
int
main
()
{
int
*
dest
=
NULL
;
int
*
src
=
(
int
*
)
malloc
(
N
*
sizeof
(
int
));
dest
=
mem_cpy
(
dest
,
src
,
N
);
return
0
;
}
\ No newline at end of file
data/3.C语言高阶/7.标准函数库/3.断言库/assert.json
0 → 100644
浏览文件 @
a0c19017
{
"type"
:
"code_options"
,
"author"
:
"卢昕"
,
"source"
:
"assert.md"
,
"exercise_id"
:
"4f37695a19624483b4f9e0b694bc3723"
}
\ No newline at end of file
data/3.C语言高阶/7.标准函数库/3.断言库/assert.md
0 → 100644
浏览文件 @
a0c19017
# 安全问题的检查
请从下列选项中选出存在潜在安全问题的程序。
## 答案
```
c
#include <stdio.h>
#include <stdlib.h>
#define N 10
void
*
mem_cpy
(
void
*
dest
,
const
void
*
src
,
size_t
len
)
{
char
*
tmp_dest
=
(
char
*
)
dest
;
char
*
tmp_src
=
(
char
*
)
src
;
while
(
len
--
)
*
tmp_dest
++
=
*
tmp_src
++
;
return
dest
;
}
int
main
()
{
int
*
dest
=
NULL
;
int
*
src
=
(
int
*
)
malloc
(
N
*
sizeof
(
int
));
dest
=
mem_cpy
(
dest
,
src
,
N
);
return
0
;
}
```
## 选项
### A
```
c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 10
void
*
mem_cpy
(
void
*
dest
,
const
void
*
src
,
size_t
len
)
{
if
(
dest
==
NULL
)
{
fprintf
(
stderr
,
"dest is NULL
\n
"
);
abort
();
}
if
(
src
==
NULL
)
{
fprintf
(
stderr
,
"src is NULL
\n
"
);
abort
();
}
char
*
tmp_dest
=
(
char
*
)
dest
;
char
*
tmp_src
=
(
char
*
)
src
;
while
(
len
--
)
*
tmp_dest
++
=
*
tmp_src
++
;
return
dest
;
}
int
main
()
{
int
*
dest
=
NULL
;
int
*
src
=
(
int
*
)
malloc
(
N
*
sizeof
(
int
));
dest
=
mem_cpy
(
dest
,
src
,
N
);
return
0
;
}
```
### B
```
c
#include <stdio.h>
#include <stdlib.h>
#define N 10
#define DEBUG
void
*
mem_cpy
(
void
*
dest
,
const
void
*
src
,
size_t
len
)
{
#ifdef DEBUG
if
(
dest
==
NULL
)
{
fprintf
(
stderr
,
"dest is NULL
\n
"
);
abort
();
}
if
(
src
==
NULL
)
{
fprintf
(
stderr
,
"src is NULL
\n
"
);
abort
();
}
#endif
char
*
tmp_dest
=
(
char
*
)
dest
;
char
*
tmp_src
=
(
char
*
)
src
;
while
(
len
--
)
*
tmp_dest
++
=
*
tmp_src
++
;
return
dest
;
}
int
main
()
{
int
*
dest
=
NULL
;
int
*
src
=
(
int
*
)
malloc
(
N
*
sizeof
(
int
));
dest
=
mem_cpy
(
dest
,
src
,
N
);
return
0
;
}
```
### C
```
c
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define N 10
void
*
mem_cpy
(
void
*
dest
,
const
void
*
src
,
size_t
len
)
{
assert
(
dest
!=
NULL
&&
src
!=
NULL
);
char
*
tmp_dest
=
(
char
*
)
dest
;
char
*
tmp_src
=
(
char
*
)
src
;
while
(
len
--
)
*
tmp_dest
++
=
*
tmp_src
++
;
return
dest
;
}
int
main
()
{
int
*
dest
=
NULL
;
int
*
src
=
(
int
*
)
malloc
(
N
*
sizeof
(
int
));
dest
=
mem_cpy
(
dest
,
src
,
N
);
return
0
;
}
```
data/3.C语言高阶/7.标准函数库/3.断言库
/config.json
→
data/3.C语言高阶/7.标准函数库/3.断言库/config.json
浏览文件 @
a0c19017
...
@@ -6,5 +6,7 @@
...
@@ -6,5 +6,7 @@
"C语言"
"C语言"
],
],
"children"
:
[],
"children"
:
[],
"export"
:
[]
"export"
:
[
"assert.json"
]
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录