#include<iostream>
#include<string>
using namespace std;
int main() {
int a = 5;
cout << &a << endl;//取地址
cout << (void*)a << endl;//强制类型转换
char str1[] = "abc";
char str2[] = "abc";
const char str3[] = "abc";
const char str4[] = "abc";
const char* str5 = "abc";
const char* str6 = "abc";
const char* str7 = "bcd";
cout<<"char str[]:"<<(str1 == str2)<<endl;//0
cout <<"str1的地址"<<(void*)str1<<endl;
cout<<"str2的地址"<<(void*)str2<<endl;
cout << endl;
cout<< "const char str[]:"<<(str3==str4)<<endl;//0
cout<<"str3的地址"<<(void*)str3<<endl;
cout<<"str4的地址"<<(void*)str4<<endl;
cout << endl;
cout<< "const char* str(same):"<<(str5==str6)<<endl;//1
cout<<"str5的地址"<< (void*)str5 << endl;
cout<<"str6的地址"<< (void*)str6 << endl;
cout << endl;
cout<<"const char* str(different):"<<(str5==str7)<<endl;//0
cout<<"str5的地址"<<(void*)str5 << endl;
cout<<"str7的地址"<<(void*)str7 << endl;
return 0;
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交