zaterdag 16 juni 2007

Boolean Expressions And True Value

In a bolean expression, with that I mean a expression that produces a true or false result, if the result of an expression is != 0 then it is true.

Example:
for (char ch = 'a'; strcmp(word, "mate"); ch++)

strcmp returns as result a zero if word contains the same word as "mate".
so then it stops this loop. But strcmp returns a negative value if the first argument is earlier in the ASCII code table, which is the case in this example, although I did not show that. The whole point is, even while the result of strcmp is negative, it is seen as a value other than zero, so the expression yields a true, until the strings are the same.
strcmp returns a positive value if the first string folows the second string alphabeticaly.

Geen opmerkingen: