如果我写:
char arr[8] = "abc";
Is there any specification over what arr[4]
might be? I did some tests with
Clang and it seems that the remaining chars in the array are set to null.
Also, char arr[8] = "";
zeroes every byte. Not sure if this is a compiler
convenience, standard behavior, pure coincidence or I got it wrong.
void a()
{
char arr[8] = "abc"; /* breakpoint here, line 3 */
strcpy(arr, "1234567");
}
int main()
{
a();
a();
return 0;
}
夸张记录:
Breakpoint 1, a () at str.c:3 3 char arr[8] = "abc"; (gdb) s Current language: auto; currently minimal 4 strcpy(arr, "1234567"); (gdb) p arr $1 = "abc 00 00 00 00" (gdb) c Continuing. Breakpoint 1, a () at str.c:3 3 char arr[8] = "abc"; (gdb) p arr $2 = "1234567" (gdb) s 4 strcpy(arr, "1234567"); (gdb) p arr $3 = "abc 00 00 00 00"