Write the NULL first to avoid errors (optional). The main disadvantage to the PTR == NULL method is the chance that you'll accidentally type ptr = NULL instead,
assigning the NULL value to that pointer. This can cause a major headache. Since testing for (in)equality treats the operands symmetrically, you can get exactly the same result by writing
if (NULL == ptr) instead. This is more typo-resistant, since an accidental NULL = ptr creates a simple compile error.
- This looks a little awkward to some programmers, but it's perfectly valid. Which approach you use just depends on personal preference, and how good your compiler is at detecting the if (ptr = NULL) error.