Chapter 3 Programming the
VIC
20
Computer 69
ARITHMETIC
OPERATORS
An arithmetic operator specifies addition, subtraction, multiplication,
division, or exponentiation. Arithmetic operations are performed using
floating point numbers. Integers are automatically converted to floating
point numbers before
an
arithmetic operation
is
performed, and the result
is
automatically converted back to an integer if an integer variable represents
the result.
The data operated on by any operator
is
referred to
as
an operand.
Arithmetic operators each require two operands, which may
be
numbers,
numeric variables, or a combination of both.
Addition
(+).
The plus sign specifies that the data (or operand) on the
left of the plus sign
is
to be added to the data (or operand) on the right. For
numeric quantities this
is
straightforward addition.
The plus sign
is
also used
to
"add"
strings. In this case, however, the
plus sign does not add the values
of
the strings. Instead, the strings arejoined
together, or
concatenated, to form one longer string. The difference between
numeric addition and string concatenation can be visualized as follows:
Addition of numbers: num1+num2 = num3
Addition of strings: string1+string2 = stringlstring2
Using concatenation, strings containing up to
255
characters can be
developed.
"FOR"+"WARD"
results in "FORWARD"
"HI"+
"
"+"THERE"
results in "HI THERE"
A$+
B$
results in concatenation of
the two strings represented
by string variable labels
A$
and
B$
"1"+ CH$+E$ results in the character "1,"
followed by concatenation of
the two strings represented
by
string variable labels
CH$ and
E$
If
A$
is
set equal to
"FOR"and
B$
is
set equal to
"W
ARD,"then
A$
+
B$
would generate the same results
as
"FOR"
+
"WARD."
Should you try to build a string longer than
255
characters, a STRING
TOO LONG error
is
flagged.