An operator is a language element that determines the operation performed by an expression on its contained subexpressions. It commonly works with operands and gives the expression its operational meaning. A binary operation, for example, combines a left operand, an operator, and a right operand; “discount of rental price before discount” can calculate 20% of $60 as $12. section 11.1 section 11.5.3
Operators are classified by placement and operand count:
- Infix operators appear between operands, as in 1 / 2; binary operations use this placement. section 11.1
- Prefix operators appear before their operands, as with logical negation (! false) and arithmetic negation (- 42). section 11.1
- Postfix operators appear after their operands, as with increment and decrement operations such as i++ and j--. section 11.1
- Common binary operators include arithmetic (*, /, +, -), logical (&&, ||), and comparison (<, ≤, =, ≠, ≥, >) operators. section 11.6
Discount calculation
Represent “discount of rental price before discount” as a binary operation: the left operand evaluates to the discount value, the “of” operator determines the calculation, and the right operand evaluates to the rental price before discount. With values of 20% and $60, the result is $12. section 11.1
Figure 11.2 The expression for calculating the value of rental price after discount from the values of discount and rental price before discount
Trace the rental-price expression used to calculate the value after discount from the discount and pre-discount rental-price values. section 11.1






