Using the equality operator == to compare two strings for equality in C

前端 未结 9 675
悲&欢浪女
悲&欢浪女 2020-11-22 16:38
int main (int argc, **argv)
{
       if (argv[1] == \"-hello\")
            printf(\"True\\n\");
       else
            printf(\"False\\n\");
}
         


        
9条回答
  •  深忆病人
    2020-11-22 17:14

    When you're using ==, you're comparing pointers. That is, it will return true if the two operands refer to the same string in memory. Therefore, it's unsuitable for use in comparing strings lexicographically.

提交回复
热议问题