Page 41 - Programming Microcontrollers in C
P. 41
26 Chapter 1 Introduction to C
is not positive, the square root of a negative number is imaginary
and the equation has complex roots. Handle both real and complex
roots in your program.
Relational or Logical Operators
The relational operators are all binary operators. When contained
in an expression, the program will evaluate the left operand and then
the right operand. These operands will be compared, and if the com
parison shows that the meaning of the operator is correct, the program
will return 1. Otherwise, the program will return a 0. In the vocabu
lary of C, FALSE is always zero. If calculated by a logical expression,
TRUE will always be one. However, if the argument of a conditional
expression is anything but zero, it will respond as if the argument is
TRUE. In other words, FALSE is always zero and TRUE is anything
else. The relational operators are:
< (less than)
<= (less than or equal to)
> (greater than)
>= (greater than or equal to)
These operators all have the same precedence, which is slightly higher
than the following equality operators:
== (is equal to)
!= (is not equal to)
The logical operators are && and ||. The first operator indicates a
logical AND and the second a logical OR. A logical AND will return
TRUE if both of its operands are TRUE, and a logical OR will return
TRUE if either of its operands is TRUE. The logical OR has lower
precedence than the logical AND. The precedence of the logical AND
is lower than the precedence of the relational operators and the equal
ity operators.
In the evaluation of long logical expressions, the program starts
on the left side of the expression and evaluates the expression until it
knows whether the whole expression is true or false, and it then exits
the evaluation and returns a proper value. For example, suppose there