title: Why do logical operators in C not evaluate the entire expression when it's not necessary to?
body: <p>I was reading my textbook for my computer architecture class and I came across this statement.</p>
  
  <blockquote>
    <p>A second important distinction between the logical operators '<code>&amp;&amp;</code>' and '<code>||</code>' versus their bit-level counterparts '<code>&amp;</code>' and '<code>|</code>' is that the logical operators do not evaluate their second argument if the result of the expression can be determined by evaluating the first argument. Thus, for example, the expression <code>a &amp;&amp; 5/a</code> will never cause a division by zero, and the expression <code>p &amp;&amp; *p++</code> will never cause the dereferencing of a null pointer. (Computer Systems: A Programmer's Perspective by Bryant and O'Hallaron, 3rd Edition, p. 57)</p>
  </blockquote>
  
  <p>My question is why do logical operators in C behave like that? Using the author's example of <code>a &amp;&amp; 5/a</code>, wouldn't C need to evaluate the whole expression because <code>&amp;&amp;</code> requires both predicates to be true? Without loss of generality, my same question applies to his second example.</p>