0% found this document useful (0 votes)
61 views

6.2.3 Array Variables: GW-BASIC User's Reference

Arrays allow storing and accessing groups of related values using array variables and subscripts. One-dimensional arrays use a single subscript, while multi-dimensional arrays use multiple subscripts separated by commas. Array elements are referenced starting with subscript 0 unless otherwise declared. The amount of memory required to store variables depends on their type, with integers requiring 2 bytes and single-precision numbers requiring 4 bytes.

Uploaded by

monee143
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

6.2.3 Array Variables: GW-BASIC User's Reference

Arrays allow storing and accessing groups of related values using array variables and subscripts. One-dimensional arrays use a single subscript, while multi-dimensional arrays use multiple subscripts separated by commas. Array elements are referenced starting with subscript 0 unless otherwise declared. The amount of memory required to store variables depends on their type, with integers requiring 2 bytes and single-precision numbers requiring 4 bytes.

Uploaded by

monee143
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

6.2.

3 Array Variables
An array is a group or table of values referenced by the same variable name. Each element in an array is referenced by an array variable that is a subscripted integer or an integer expression. The subscript is enclosed within parentheses. An array variable name has as many subscripts as there are dimensions in the array. For example,
V(10)

references a value in a one-dimensional array, while


T(1,4)

references a value in a two-dimensional array. The maximum number of dimensions for an array in GW-BASIC is 255. The maximum number of elements per dimension is 32767.

Note If you are using an array with a subscript value greater than 10, you should use the DIM statement. Refer to the GW-BASIC User's Reference for more information. If a subscript greater than the maximum specified is used, you will receive the error message "Subscript out of range."

Multidimensional arrays (more than one subscript separated by commas) are useful for storing tabular data. For example, A(1,4) could be used to represent a two-row, five-column array such as the following:
Column 0 1 2 3 4

Row 0 10 20 30 40 50 Row 1 60 70 80 90100

In this example, element A(1,2)=80 and A(0,3)=40. Rows and columns begin with 0, not 1, unless otherwise declared. For more information, see the OPTION BASE statement in the GW-BASIC User's Reference.

6.2.4 Memory Space Requirements for Variable Storage

The different types of variables require different amounts of storage. Depending on the storage and memory capacity of your computer and the size of the program that you are developing, these can be important considerations. Variable Required Bytes of Storage Integer 2 Single-precision 4 Double-precision8 Arrays Required Bytes of Storage Integer 2 per element Single-precision 4 per element Double-precision8 per element Strings: Three bytes overhead, plus the present contents of the string as one byte for each character in the string. Quotation marks marking the beginning and end of each string are not counted.

6.3 Type Conversion


When necessary, GW-BASIC converts a numeric constant from one type of variable to another, according to the following rules:

If a numeric constant of one type is set equal to a numeric variable of a different type, the number is stored as the type declared in the variable name. For example:
10 A% = 23.42 20 PRINT A% RUN 23

If a string variable is set equal to a numeric value or vice versa, a "Type Mismatch" error occurs.

During an expression evaluation, all of the operands in an arithmetic or relational operation are converted to the same degree of precision; that is, that of the most precise operand. Also, the result of an arithmetic operation is returned to this degree of precision. For example:
10 D# = 6#/7 20 PRINT D# RUN .8571428571428571

The arithmetic is performed in double-precision, and the result is returned in D# as a double-precision value.
10 D = 6#/7 20 PRINT D RUN .8571429

The arithmetic is performed in double-precision, and the result is returned to D (singleprecision variable) rounded and printed as a single-precision value.

Logical operators convert their operands to integers and return an integer result. Operands must be within the range of -32768 to 32767 or an "Overflow" error occurs. When a floating-point value is converted to an integer, the fractional portion is rounded. For example:
10 C% = 55.88 20 PRINT C% RUN 56

If a double-precision variable is assigned a single-precision value, only the first seven digits (rounded), of the converted number are valid. This is because only seven digits of accuracy were supplied with the single-precision value. The absolute value of the difference between the printed double-precision number, and the original single-precision value, is less than 6.3E-8 times the original single-precision value. For example:
10 A = 2.04 20 B# = A 30 PRINT A;B# RUN 2.04 2.039999961853027

You might also like