检查指针是不是NULL通过简单写入if(pointer)或我必须使用它是否安全if(pointer != NULL)?
NULL
if(pointer)
if(pointer != NULL)
c++ null pointers if-statement null-pointer
假设我有 Foo* foo = nullptr;
Foo* foo = nullptr;
如果我确认是否foo就是nullptr,我可以把写
foo
nullptr
if (!foo)
或者我应该写
if (foo == nullptr)
c++ pointers
c++ ×2
pointers ×2
if-statement ×1
null ×1
null-pointer ×1