疑问
char*是按照地址进行比较么?
测试代码
const char* temp1 = "ada";
const char* temp2 = "ada";
char temp3[] = "ada";
char temp4[] = "ada";
int n = 1;
if (("qwe" < "qwe") || ("qwe" > "qwe"))
printf("3%d", n);
if ((temp1 > temp2) || (temp1 < temp2))
{
printf("2%d", n);
}
if ((temp3 > temp4) || (temp3 < temp4))
{
printf("1%d", n);
}
运行结果
11
结论
查阅资料 char* 是按照地址进行比较的,但是我测试的结果char*就是比较的字符串是否相等(也测试了其他代码),char[]是按照地址比较的,可能是编译器进行了优化,还是源码有所改进,欢迎大佬批评指正,我十分困惑
我是先测试的c++代码,c++也是这样的,然后才试了c
c++还是好好用string字符串吧!