Jon*_*ler 16
鉴于:
char s1, s2;
...
s1 = s2; // Assigns value in s2 to s1
strcpy(s1, s2); // Error detected by compiler; strcpy() takes char pointers
Run Code Online (Sandbox Code Playgroud)
鉴于:
char *s1, *s2;
...
s1 = s2; // s1 points to the same 'string' that s2 does
strcpy(s1, s2); // the space pointed to by s1 contains the same
// characters as the space pointed to by s2.
Run Code Online (Sandbox Code Playgroud)
在第二种情况(指针)中,有许多警告要确保为实际字符串分配足够的空间 - 而不是指针.三点表示要确保事情初始化的工作.