
Concepts - 7
For example,
GOTOE is not ok
EGOTO is ok
String variables are limited to 255 characters. Arrays may be any leng th, may be multidimensional, and include str ings.
String and array space is limited only by available memory.
Numeric variables take seven bytes of memory. Two bytes for the name, one byte for the length and four bytes for the
value. String variables are stored with a 7– byte header and byte– for– byte as the string was assigned. The header and
string are stored in different locations.
String Variables
CAM BASIC reserves 100 bytes for strings on power– up. Using the CLEAR statement, mor e or less memory may be
reserved. The reserved m emory is shared by all the strings. String constants do not use any of the reserved space. For
example,
10 A$="This is a string constant"
does not use any of the reserved space as the string is a constant.
In the example below, A$ and B$ do not use reser ved string space, but C$ does.
10 A$ = "Hello"
20 B$ = "there"
30 C$ = A$+B$
In this example, only B$ uses reserved space.
10 A$ = "Hello"
20 B$ = A$
Strings may be compared using the same relational operators that are used with numbers. The string operators are:
+ Adding or concatenating
= equal
<> not equal
> greater than
< less than
>= greater than or equal
<= less than or equal
Consider the following program:
10 A$ = "ABC"
20 B$ = "ABD"
30 IF A$ > B$ THEN PRINT "YES" : ELSE PRINT "NO"
RUN
NO
Strings are compared on a character– by– character basis. In the exam ple above B$ is greater than A$, as the ASCII
value of D is greater than that of C.
Commentaires sur ces manuels