Like algebraic operators, programming language operators perform common operations on one or more operands. Arithmetic, logical, bitwise, and address operators are provided. Each has a precedence, and each is a member of a class that determines its valid operand types, type of result, and conversions rules.
Unary operators operate on a single data object or expression to the right of the unary operator. For example, - is the common negative operator, used to negate arithmetic sign, as in -x or -ABS(x+y) . Unary operators have the highest precedence, so unary operators are always executed before adjacent binary operators. Adjacent unary operators execute from right to left.
Binary operators combine two operands into a single value. When the operands are of different data type, the operand with the lower data type is promoted aka converted to the higher data type before the operation is performed.
As in algebra, operators have precedence. Operators with higher precedence are executed before adjacent operators, even when they appear later in an expression.
In a+b*c , the b*c is performed first, then added to a . Precedence limits the need for parentheses to group sub-expressions. Parentheses can make natural execution order more visible, and override natural execution order when desired.
For example, a+(b*c) operates the same as the previous example, while (a+b)*c forces a+b to occur first, the result of which is then multiplied by c.
Arithmetic operators are the kind usually encountered in algebra. They combine numeric operands and produce a numeric result.
Bitwise operators combine numeric integer operands and produce a numeric integer result, but operate on a bit-by-bit basis, without carry/borrow propagation from bit to bit.
Logical operators combine numeric or string operands, and produce a logical result, meaning $$TRUE (-1), or $$FALSE (0).