Questions tagged «nul»

4
字符数组应如何用作字符串?
我知道C中的字符串只是字符数组。因此,我尝试了以下代码,但给出了奇怪的结果,例如垃圾输出或程序崩溃: #include <stdio.h> int main (void) { char str [5] = "hello"; puts(str); } 为什么不起作用? 它可以用干净地编译gcc -std=c17 -pedantic-errors -Wall -Wextra。 注意:对于在声明字符串时未能为NUL终止符分配空间而引起的问题,本帖子旨在用作规范的FAQ。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.