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

前端 未结 9 596
悲&欢浪女
悲&欢浪女 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:19

    Because argv[1] (for instance) is actually a pointer to the string. So all you're doing is comparing pointers.

提交回复
热议问题