#include<iostream>
using namespace std;
int main(){
cout<<"1."<<("join" == "join" ? "":"not ")<<"equal\n";
char buffer1[6] = "Hello";
char buffer2[6] = "Hello";
cout<<"\n2.buffer1 and buffer2 are "<<(buffer1 == buffer2 ? "" :"not ")<<"equal\n";
printf("buffer1地址是%p\n",&buffer1);
printf("buffer2地址是%p\n",&buffer2);
char* str1="good";
char* str2="good";
cout<<"\n3.str1 and str2 are "<<(str1 == str2 ? "":"not ")<<"equal\n";
printf("str1地址是%p\n",&str1);
printf("str2地址是%p\n",&str2);
if(!strcmp(str1,str2))
cout<<"In strcmp,str1 and str2 are equal\n";
return 0;
}
如这个程序所示,在书本上应该是三个都相等,因为它们的地址不一样,但是我用VC++运行结果却是:
求分析一下,不是说用“==”比较时候,如果地址不同会导致不相等吗?