Mark said:
Am I right that in the following code I don't need to put parentheses in
order to have it evaluated correctly (i.e. first verify that the result
of a() isn't equal to 10, and then check if the result of b() greater
than 7):
if (a() != 10 || b() > 7)
return -1;
Logical "and" and "or" will "short circuit". But you should be
using "and" (&&) and *not* "or" (||). This is *not* because of
operator precedence, but the way that logical "and" and "or" are
defined in C.
With the logical "and", if the left argument is false (0), then
the right argument is *not* evaluated. Whether the right argument
is true or false, the result of the "and" will be false if the
left argument is false.
With the logical "or", if the left argument is false (0), then the
right argument *is* evaluated. If the left argument of a logical
"or" is false, then the value of the operation depends on whether
the right argument is true or false.
--
+----------------------------------------+
| Charles and Francis Richmond |
| |
| plano dot net at aquaporin4 dot com |
+----------------------------------------+