in BASIC ROM:
|List of all BASIC keywords|
Type: Command General Programming-Syntax: DIM <Variable>(<d1>[,<d2>[,<d3>...]])[, <Variable>(<d1>[,<d2>[,<d3>...]])...]
Note that the dimension sizes represent the last, or "highest", index number available. Since the lower limit for the indices is always fixed at zero, specifying a dimension of n reserves space for n+1 variables "along" that dimension.
Omitting the list of dimension sizes causes a ?SYNTAX ERROR IN line. Previously DIMensioned arrays cannot be "re-dimensioned" through a second DIM command; this will raise a ?REDIM'D ARRAY ERROR IN line.
Note that using an array without DIMensioning is actually legal in Commodore BASIC: If a BASIC program e.g. starts assigning values to an array not "declared" in a prior DIM statement, the interpreter "auto-DIMensions" the array to a size of 10+1=11 elements along each specified dimension. Like other arrays, such "auto-DIMensioned" arrays cannot be re-dimensioned later through an explicit DIM command.
Indices to arrays are handled internally by signed positive 16-bit integers, which in theory gives them a range from 0 to 32767, resulting in up to 32768 variables along that dimension. Indices outside this range will raise an ?ILLEGAL QUANTITY ERROR. The number of dimensions are counted in a single-byte register, and thus has a limit at 255 dimensions. But memory limitations will cause an ?OUT OF MEMORY ERROR IN line long before an array attains such sizes.
DIM A$(4) One-dimensional array with room for 4+1=5 strings. DIM C%(2,3) Two-dimensional array with 2+1=3 integers along the first dimension, and 3+1=4 dimensions along the second, giving a total of 12 integers. DIM T(8,1,5) Three-dimensional array with (8+1)×(1+1)×(5+1)=108 real variables. DIM B$(CT%) DIMensioning a string array according to a size held in a variable
Q(10)=10 Bad coding, but legal - automatic DIMensioning, whereas Q(10) has got the value 10 and Q(0) until Q(9) the value 0 !