当前正在读取K&;然后才偶然发现了char指针.在《rn》一书中定义字符指针时,没有关于内存分配的内容,也许稍后会解释.但这根本没有意义,所以我正在寻求帮助:)
1
// No errors
char *name;
char *altname;
strcpy(altname,name);
2
// No errors, internals of *name have been successfully moved to *altname
char *name = "HI";
char *altname;
strcpy(altname, name);
3
// Segmentation fault, regardless of how I define *altname
char *name = "HI";
char *altname = "randomstring";
strcpy(altname, name);
4
// Segmentation fault, regardless of how I define *altname
char *name;
char *altname = " ";
strcpy(altname, name);
5
// copies internals of *name only if size of char s[] > 8???
char s[9];
char n[] = {'c', 'b'};
char *name = n;
char *altname = s;
strcpy(altname, name);
为什么第一个示例即使没有分配内存,也不会产生错误?
为什么第二个成功地将name复制到altname,即使没有为altname分配内存;
为什么第三个和第四个单芯转储?
为什么第五个要求s的大小为>;8.