📖
Expert-C-Programming-Note
  • C专家编程笔记
  • 第一章
    • 1-1 空格对宏的影响(p6)
    • 1-2 char**与const char**(p19)
    • 1-3 -1的unsigned类型(p23)
  • 第二章
    • 2-1 malloc字符串(p28)
    • 2-2 巧用static(p35)
    • 2-3 运算符的优先级(p38)
    • 2-4 在同一代码块执行"malloc"和"free"(p48)
  • 第三章
    • 3-1 C语言生命的优先级规则(p64)
    • 3-2 使用typedef简洁声名(p67)
  • 第四章
    • 4-1 数组与指针不相同(p81)
    • 4-2 char *a 与 char a
  • 第五章
    • 5-1 动态链接思考(p94)
  • 第六章
    • 6-1 bss段(p119)
  • 第七章
    • 7-1 segmentation fault(p159)
  • 第八章
    • 8-1 类型转换(p172)
  • 第九章
    • 9-1 为什么C语言把数组形参当做指针(p205)
    • 9-2 多维数组一瞥(p213)
Powered by GitBook
On this page

Was this helpful?

  1. 第二章

2-1 malloc字符串(p28)

无论在什么时候执行这样一条语句 malloc(strlen(str)) 基本上可以断定它是错的,因为字符串处理函数一般都包含一个额外空间,用于容纳 '\0' 字符

正确应是 malloc(strlen(str) + 1)

Previous第二章Next2-2 巧用static(p35)

Last updated 5 years ago

Was this helpful?