char str1[]="hello world";
char str2[]="hello world";
char* str3="hello world";
char* str4="hello world";
str1和str2是两个字符串数组,分别为它们分配12个字节的空间,并把“hello world”的内容分别复制到数组中去。这是两个初始地址不同的数组,因此str1和str2也不相同。
str3和str4是两个指针,无需为他们分配内存以存储字符串的内容,只需要把它们指向“hello world”在内存中的地址就可以了。由于“hello world”是常量字符串,它在内存中只有一个拷贝,因此str3和str4指向的是同一个地址。