使用之间有什么区别:
if( pointer == NULL)
Run Code Online (Sandbox Code Playgroud)
和
if(!pointer)
Run Code Online (Sandbox Code Playgroud)
我关注两者在以下几点上的
区别:1.它们对编译器有何不同?如果是,那怎么样?
2.两者中哪一种是一般用途的推荐编码方式,为什么?
你能解释一下编译器如何"看到"NULL.
编辑:为简单起见,指针的类型为int*.
假设pointer是一个指针类型,if (pointer == NULL)是不合时宜和不好的C++,因为C++中的空指针值是nullptrC++中的类型 nullptr_t.
if (!pointer)是多优选的成语.