void main()
{
char str1[] = "abc";
char str2[] = "abc";
const char str3[] = "abc";
const char str4[] = "abc";
const char *str5 = "abc";
const char *str6 = "abc";
char *str7 = "abc";
char *str8 = "abc";
printf("%x\n",str1); //0x12ff7c
printf("%x\n",str2);//0x12ff7c
printf("%x\n",str3);//0x12ff7c
printf("%x\n",str4);//0x12ff7c
printf("%x\n",str5);//46f020
printf("%x\n",str6);//46f020
cout << ( str1 == str2 ) << endl; // 0
cout << ( str3 == str4 ) << endl; // 0
cout << ( str5 == str6 ) << endl; // 1
cout << ( str7 == str8 ) << endl; // 1
cout << ( str5 == str7) <<endl; //1
cout << ( str6 == str7) <<endl; //1
}
对于字符数组 是在局部的空间中分别的地址, 看出在局部地址中分配地址是 在栈中分配的,
但是字符串 是全局变量 ,对应的是字符串常量,保存在只读的内存区内 ,相同的字符串只能在一个地址中,所以他们的地址是相同的