Section 14.6 Comparison and Boolean Operators
Comparison operators are used to compare two variables or values. They are useful when decisions need to be made based on how one variable compares to another. Any variable stored with a value that’s not zero will be considered to be logically TRUE. Any variable stored with a value of zero will be considered to be logically FALSE.
Comparison operators return Boolean values (TRUE values will be stored as a value of one, and FALSE values will be stored as a value of zero) based on the result of the operation. The comparison operators (all of which are binary operations; that is, they require two operands) are shown in Table 14.6.1.
| Operator | Description |
|---|---|
== |
Equal to |
!= |
Not equal to |
> |
Greater than |
>= |
Greater than or equal to |
< |
Less than |
<= |
Less than or equal to |
Boolean operators are used to make logical decisions based on the results of one or more comparison operations. Table 14.6.2 lists all of the Boolean operators (AND and OR are binary operations while NOT is a unary operation). It is important to note that Boolean operators use two symbols (with the exception of NOT), whereas bitwise operators only use one.
| Operator | Description |
|---|---|
&& |
Logical AND |
|| |
Logical OR |
! |
Logical NOT |
