Mikroelektronika MIKROE-724 データシート

ページ / 726
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
205
Here are a few examples of array declaration:
dim weekdays as byte[7]
dim samples  as word[50]
main:
  ‘ Now we can access elements of array variables, for example:
  samples[0] = 1
  if samples[37] = 0 then
    ‘ ...
Constant Arrays
Constant array is initialized by assigning it a comma-delimited sequence of values within parentheses. For example:
‘ Declare a constant array which holds number of days in each month:
const MONTHS as byte[12] = (31,28,31,30,31,30,31,31,30,31,30,31)
Note that indexing is zero based; in the previous example, number of days in January is 
MONTHS[0]
 and number of 
days in December is 
MONTHS[11]
.
The number of assigned values must not exceed the specified length. Vice versa is possible, when the trailing “excess” 
elements will be assigned zeroes.
For more information on arrays of 
char
, refer to Strings.
Multi-dimensional Arrays
Multidimensional arrays are constructed by declaring arrays of array type. These arrays are stored in memory in such 
way that the right most subscript changes fastest, i.e. arrays are stored “in rows”. Here is a sample 2-dimensional 
array:
dim m as byte[5][10]   ‘ 2-dimensional array of size 5x10 
A variable 
m
 is an array of 5 elements, which in turn are arrays of 10 byte each. Thus, we have a matrix of 5x10 elements 
where the first element is 
m[0][0]
 and last one is 
m[4][9]
. The first element of the 4th row would be 
m[3][0]
.