Why isn't (“Maya” == “Maya”) true in C++?

前端 未结 8 1363
野趣味
野趣味 2020-12-29 05:21

Any idea why I get \"Maya is not Maya\" as a result of this code?

if (\"Maya\" == \"Maya\") 
   printf(\"Maya is Maya \\n\");
else
   printf(\"Maya is not Ma         


        
8条回答
  •  我在风中等你
    2020-12-29 05:46

    What you are doing is comparing the address of one string with the address of another. Depending on the compiler and its settings, sometimes the identical literal strings will have the same address, and sometimes they won't (as apparently you found).

提交回复
热议问题