Unary Operators |
Top Previous Next |

Since a constant can be negative, we could have an expression like:
2 * -3
Do not confuse the minus sign shown here for the minus sign used to do subtraction. This minus sign is called a unary operator because it operates only on the 3 and indicates that the 3 is negative.
Any factor (or sub-expression) can have the unary operators "-" and "+". Because the "+" operator really does not do anything, it can always be left out. It is sometimes used to emphasize that a number is positive.
When unary operators are used in expressions with other operators, the unary operations are done first unless parentheses are used to force a different order of evaluation.
Here are some expressions using unary operators:
2 * -3 equals -6 +2 +2 equals 4 6+ -4 equals 2 -$40/16 equals -4 -4 - -6 equals 2 -^A + $41 equals 0 -(4+6) equals -10 2*--3 equals 6 |