Next: Logic
Prev: Precedence
C-- provides seven operators for doing arithmetic, two unary
operators and five binary operators. These operators apply primarily to
integers, but the addition operator also applies to strings. Using
these operators on inappropriate data is an error of type ~type.
The unary - operator takes the negative of an integer value. The
expression -(3 + 4) has the value -7. The unary +
operator has no effect on its argument, and is provided only for
completeness.
The binary operator * performs multiplication on its arguments.
The expression (3 * 4) has the value 12. The binary
operators / and % perform integer division and modulus,
respectively, on their arguments. The expressions (13 / 5) and
(13 % 5) have the values 2 and 3 respectively.
The binary operators + and - perform addition and
subtraction. The expressions (3 + 4) and (3 - 4) have the
values 7 and -1 respectively. The binary +
operator can also apply to strings and lists, in which case it performs
concatenation; the expression ("foo" + "bar") has the value
"foobar", and the expression (["foo", "bar"] + ["baz"])
has the value ["foo", "bar", "baz"].