In the pre-C++11 days it was considered better practice to write:
if (ptr == NULL)
Rather than:
if (!ptr)
This was for two reasons. It is more efficient because it didn't need to cast to bool. And there was no guarantee that the macro NULL
would indeed evaluate to the boolean false
. Is this still true in C++11? Is it preferable to write
if (ptr == nullptr)
Rather than
if (!ptr)
Or is the second fine now?