The order in which the operators are executed is significant. Consider the expression:
1 + 2 * 3
The value of this expression depends upon whether the addition or multiplication is done first. If the addition is done first, the result is 9; otherwise, it is 7. To resolve this type of ambiguity, VTS assigns priorities to operators - operators with higher priority are done first. Multiplication has a higher priority than addition, so in the previous example the correct result is 7. If the addition were intended to be done before the multiplication, the expression could be written as:
(1 + 2) * 3
Parentheses ( ) force the expression within them to be done first. The following two expressions have the same value:
1 + 2 * 3
1 + (2 * 3)
Some operators have equivalent priorities, such as addition and subtraction. In these cases the evaluation is done starting with the left-most operator. For example:
1 - 2 + 4 * 5
could be equally written :
(1 - 2) + (4 * 5)
A detailed list of all VTS operators and their priority levels is given in the Operators section. If there is any doubt as to whether or not parentheses are required, you should include them. There is no penalty to pay in terms of speed or memory requirements for placing redundant parentheses in an expression.
Note: When doing comparisons between two operands of different types, the second operand is always cast to the type of the first. This can cause differing comparison results depending on the order of the operands.