C uses short circuit calculations in logical expressions (operator && , operator || , etc.).
In the expression a && b value of b will be evaluated only if a true (nonzero). This is because if a is false (zero), then the value of b will not result in the expression a && b .
For your specific case, (*searchNodePtr).data is a valid expression if searchNodePtr points to a valid object (and is not NULL ). Otherwise, it gives undefined behavior.
So, your first case assumes that searchNodePtr is non-NULL, dereferencing it (giving undefined behavior, which means that all bids are disabled if searchNodePtr is actually NULL), and THEN testing if searchNodePtr is NULL.
The second case checks that searchNodePtr not NULL, and then evaluates (*searchNodePtr).data and tests to see if it is true (nonzero). This is the right way to do such things.
By the way, (*searchNodePtr).data more readily expressed as searchNodePtr->data . But you still have to check if searchNodePtr not NULL.
Peter source share