C++ stops evaluating logical expressions as soon as the result is known. For &&, if the left is false, the right never runs. For ||, if the left is true, the right is skipped.
This prevents crashes. if (ptr != nullptr && ptr->value > 0) checks ptr first. If null, the second condition never runs, avoiding a null pointer error. Order matters for performance.
if (cheapCheck() && expensiveCheck()) runs the cheap test first. If it fails, the expensive test is skipped entirely.