在C语言中,字符串数组的初始化会自动在字符串的末尾添加'\0'字符,以表示字符串的结束。这意味着剩余的数组空间会被初始化为'\0',形成一个空字符串。以Xcode自带的clang编译器为例,通过运行gcc -S main.c命令查看汇编输出,可以发现这一过程。当数组的大小发生变化时,字符串后面的'\0'也会相...
l_main.str: .asciz "Hello\000\000\000\000"当数组的大小变化时,这串字符后面的 0 也会...
编译器会有意把后面6个char填成0,因此我认为这是标准规定的。https://godbolt.org/g/RVmm9i 查了...
or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration. ...