几个指针指向相同的常量字符串
当几个指针指向相同的常量字符串,它们实际上会指向相同的内存地址。
int main()
{
char str1[] = "abcdefg";
char str2[] = "abcdefg";
const char *str3 = "1234567";
const char *str4 = "1234567";
if (str1 == str2)
cout << "str1== str2"<<endl;
else
cout << "str1!= str2" << endl;
if (str3 == str4)
cout << "str3== str4" << endl;
else
cout << "str3!= str4" << endl;
return 0;
}
输出结果: