C programming/Caveats

From Teknologisk videncenter
< C programming
Revision as of 07:13, 28 August 2012 by Heth (talk | contribs) (Created page with "This article contains C programming syntaxes and equations that behave in a strange way. =Logical && and logical ||= When using the logical AND (&&) or the logical OR (||) the ex...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This article contains C programming syntaxes and equations that behave in a strange way.

Logical && and logical ||

When using the logical AND (&&) or the logical OR (||) the expression is evaluated from left to right. Consider the following code.

    i=1;
    j=8;
 if (( i == 0 ) && (( j++ ) > 0 )) {
  ...code...
 }

The statement of the left side of && evaluates to false the rigth side of the statement is never evaluated - and j is never incremented.

Links