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;

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2022-12-23
  • 2021-12-28
猜你喜欢
  • 2021-06-21
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2021-10-01
相关资源
相似解决方案