#include<iostream>
using namespace std;
int main()
{
char str1[]="hello word";
char str2[]="hello word";
char *str3 ="hello word";
char *str4 ="hello word";
if(str1==str2)
{
cout<<"str1 and str2 are the same"<<endl;
}
else
{
cout<<"str1 and str2 not same"<<endl;
}
if(str3==str4)
{
cout<<"str3 and str4 are the same"<<endl;
}
else
{
cout<<"str3 and str4 not same"<<endl;
}
system("pause");
return 0;
}
字符数组和常量字符串
为了节省内存C++把常量字符串放到单独的一个内存区域,当几个指针赋值给相同的常量字符串时,它们实际上指向的是相同的地址.
但是用常量初始化数组就完全不同.
两个操作系统系统会分配两个12个字节的栈空间.
C++的内存分配图