Arrays are collections of variables of any single data type, including strings. Elements are numbered from a lower bound of 0 to an upper bound less than 2147483648.
Arrays start out empty; they have no elements and take up no space in memory, except for their XLONG handle that initially contains 0. Arrays must be dimensioned before their contents can be read or written. When an array is dimensioned by a DIM statement, any existing content are freed, a new array is created, and its contents is initialized to zero. When an array is dimensioned, the address of element 0 of its highest dimension is stored in its handle.
When an array is redimensioned in a REDIM statement, the values of elements in the old array that are also in the new array are preserved. All new elements are zeroed.
DIM vs REDIM
After DIM creates or resizes an array, it clears all elements to zero. In contrast, REDIM preserves the values of all elements in the original array that are also in the new array, and initializes any new elements to zero. REDIM preserves data even in multi-dimensional arrays.
DIM and REDIM can create arrays with 0 to 8 dimensions. Zero dimension arrays are empty arrays. The lowest dimension is the rightmost. All other dimensions are called higher dimensions. Element indices are separated by commas and appear between square brackets, as in a[b,c,d]. Arrays are thus easily distinguishable from expressions, intrinsics, and functions.
An entire array is referenced when the square brackets are empty, as in n or n$.
Empty arrays are FALSE, while arrays with any number of elements are TRUE. This makes testing for empty arrays simple and efficient, as illustrated by the following examples:
IF a THEN PRINT "a has contents"
IFZ a THEN PRINT "a is empty"
A whole array can be passed by reference to a function by leaving the square brackets empty, as in:
a = Func(a,@b,@c).
When arrays are passed to functions, their type is checked against the argument list in the declaration of the function being called. If the type of the array is not the same as the declared type, a type-mismatch error occurs. However, if the keyword ANY appears before an array argument in the function declaration, any type of array may be passed. The called function will receive the array as whatever type array is shown in the argument list on its FUNCTION line. The type of the array can be tested with TYPE(), as in t=TYPE(a), and ATTACH can attach it to an array of the appropriate type.