Is the following code safe if a null pointer is passed in?
if(ptr && *ptr == value) { //do something }
Does the order of the checks
If the pointer is invalid (or rather NULL as pointed out), in the first version short-circuiting will prevent the evaluation of *ptr == value, so the first one is safe.
NULL
*ptr == value
The second one will always access *ptr, whether it is valid or not.
*ptr