1. sizeof 和 strlen 的对比
1.1 sizeof
在学习操作符的时候,我们学习了 sizeof,sizeof 是计算变量所占内存空间大小的 ,单位是字节 ,如果操作数是类型 的话,计算的是使用类型创建的变量所占内存空间的大小。
sizeof 只关注占用内容空间的大小,不在乎内存中存放什么数据。
1.2 strlen
strlen 是C语言库函数,功能是求字符串长度。
统计的是从 strlen 函数的参数 str 中这个地址开始向后,\0 之前字符串中字符的个数。
strlen 函数会一直向后找 \0 字符,直到找到为止,所以可能存在越界查找。
1.3 sizeof 和 strlen 的对比
sizeof:1.sizeof 是操作符
2.sizeof 计算操作数所占内存的大小,单位是字节
3.不关注内存中存放什么数据
strlen:1.strlen 是库函数,使用需要包含头文件 string.h
2.strlen 是求字符串长度的,统计的是 \0 之前字符的个数
3.关注内存中是否有 \0 ,如果没有 \0 ,就会持续往后找,可能会越界。
2. 数组和指针笔试题解析
2.1

2.2

2.3

2.4

2.5

2.6

2.7

2.8

3.指针运算经典例题
3.1

3.2

3.3

3.4

简单解释一下

3.5

简单解释一下

3.6

简单解释一下

3.7(很难)

如有需要,评论区留言,我出一个新文章解析。
注:好题值得推敲。