char s1[]="this"
char *s2 = "this"
if(s1=="this"){
printf("s1 is equal to 'this' \n");
}
if(s2=="this"){
printf("s2 is equal to 'this'\n");
}
注意,不会输出"s1 is equal to 'this' \n",会输出"s2 is equal to 'this'\n",因为s=="this"比较的实际上是内存地址。
所以如果比较字符串是否相同,还是应该使用strcmp(x1,x2)。返回值等于x1-x2;