strcmp behaviour

后端 未结 3 2028
死守一世寂寞
死守一世寂寞 2021-02-05 14:37

When I run the following code:

#include 

int main(int argc, char *argv[])
{
    int p = 0;

    p = strcmp(NULL,\"foo\");

    return 0;
}
         


        
3条回答
  •  青春惊慌失措
    2021-02-05 14:59

    What you are doing is undefined. strcmp requires valid pointers to null-terminated strings.

    NULL is not a pointer to a null-terminated string.

提交回复
热议问题