环境 :Linux Ubuntu 14.04
#include<stdio.h>
#include<string.h>
#include<malloc.h>
int main()
{
char *str1;
char *str2="hello";
char *str3="world";
str1=malloc(3*sizeof(char));
strcpy(str1,str3);// copy 1
puts(str1);
strcpy(str2,str3);// copy 2
puts(str2);
return 0;
}
为什么str2这种分配内存的方式 copy 2不能执行成功(puts(str2)不能输出),而str1这种分配内存的方式能成功,两者有什么区别?