What is the difference in between using:
if( pointer == NULL)
And
if(!pointer)
I am concerned with the differences between the two in respect to the following points:
1. Are they different for the compiler? If yes, then how?
2. Which of the two is the recommended coding style for general use and why?
3. Can you please explain how NULL is "seen" by the compiler.
Edit: For the sake of simplicity let pointer be of type int *.
Assuming pointer is a pointer type, if (pointer == NULL) is anachronistic and poor C++ since the the null pointer value in C++ is nullptr in C++ with type nullptr_t.
if (!pointer) is the much preferred idiom.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With