Listing 7.5 showed how to apply the operators assignment (=), equals (==), and increment (++) to enumerators. Numerous other operators can be used with enumerators; they are listed in Table 7.4.
Binary | +, - |
Unary | ++, --, ~ |
Comparison operators | ==, !=, <, >, <=, >= |
Logical | &, |, ^ |
Assignment | =, +=, -= |
Primary | sizeof |
You have not met all of the symbols displayed in Table 7.4. The operators relevant to enumerators are included here for completeness and overview; they will be discussed in relation to enumerators in due time.
The binary operators + and - cannot be applied to two enumerator types. Instead, they are meant to combine one enumerator operand with one integer value operand, such as the following:
currentDay = currentDay + 1;
This statement is equivalent to
currentDay++;
The binary operators (+) and (-) do not look for the next enumerator in the list (just like the increment and decrement operators). They only add or subtract the integer value from the value the enumerator represents.