is there a pragmatic reason to use “if (0 == p) ” instead of “if (!p)”?

后端 未结 12 739
难免孤独
难免孤独 2021-02-05 06:18

I\'m inclined to write if statements by using logical negation operator:

if (!p)
    some_code();

Some people around me tend to use explicit co

12条回答
  •  误落风尘
    2021-02-05 06:52

    With if (0 == p) you force the comparison to enter that "if scope" in that case. I mean, it will be clear that you want to do that in case p is equals 0. By just using (!p) its not explicit what you want to know. It could be null, false, etc.

提交回复
热议问题