<?xml version="1.0" encoding='utf-8'?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title="Short-circuit evaluation - Page 14 - Wikipedia">
<p>
<a accesskey="1" href="page.php?w=Short-circuit_evaluation&amp;p=13">1.Previous</a><br />
<a accesskey="3" href="page.php?w=Short-circuit_evaluation&amp;p=15">3.Next</a>
</p>
<p>If the first sub-expression checks whether an expensive computation is needed and the check evaluates to false, one can eliminate expensive computation in the second argument. <br/>
# It permits a construct where the first expression guarantees a condition without which the second expression may cause a <a href="page.php?w=run-time_error">run-time error</a>.</p>

<p>Both are illustrated in the following C snippet where minimal evaluation prevents both null pointer dereference and excess memory fetches:<syntaxhighlight lang="c">bool isFirstCharValidAlphaUnsafe(const char* p) {    return isalpha(p[0]); // SEGFAULT highly possible with p == NULL}</syntaxhighlight></p><p>
<a accesskey="1" href="page.php?w=Short-circuit_evaluation&amp;p=13">1.Previous</a><br />
<a accesskey="3" href="page.php?w=Short-circuit_evaluation&amp;p=15">3.Next</a>
</p>

<do type="prev" label="Search">
        <go href="search.wml"/>
</do>

</card>
</wml>
