Other modern operators
At this stage you may be wondering if ternary operators (operators that work on three operands) exist? Maybe even more than three?
Indeed, there are operators that operate on more than two operands. They are relatively scarce and are usually defined for specific math operations.
One ternary operator that is used in logic and in computer science is the if-then operator. This operator is denoted by ? (a question mark) and : (a colon) that are written between the three operands like this:
operand a ? operand b : operand c
This operator receives three statements. The first is a condition, the second is an instruction what to do if the condition is true, and the third operand is an instruction what to do if the condition is false.
For example: “It is raining outside” ? “Take an umbrella” : “Don’t take an umbrella”
The meaning of this statement is – check if it is raining outside. If the answer is positive then take an umbrella. If the answer is negative, don’t take an umbrella.
Many operators are used to perform special functions in spreadsheet programs like Microsoft’s “Excel” or Apple’s “Numbers”. Perhaps you are familiar with the MOD and DIV operators?
The MOD operator calculates the remainder that is left when applying the division operator. For example, 7 MOD 2 = 1 since 7÷2 = 3 with a remainder of 1.
The DIV operator calculates the quotient that is left when applying the division operator. For example, 7 DIV 2 = 3 since 7÷2 = 3. The quotient is 3 and the remainder is 1.
© Davidson Institute of Science Education, the educational arm of the Weizmann Institute of Science