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

后端 未结 12 779
难免孤独
难免孤独 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 07:16

    Use (0 == p) or (p == 0) for readability. That ! is easier to overlook at first glance than == 0

    Use (0 == p) if you have a habit of ignoring compiler warnings, and want to know when you use = rather than ==.

提交回复
热议问题