User manual
mikroBasic PRO for PIC32
MikroElektronika
203
The number of assigned values must not exceed the specied 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 rst element is m[0][0] and last one is m[4][9]. The rst element of the 4th row would be m[3][0].
Strings
A string represents a sequence of characters equivalent to an array of char. It is declared like this:
string[string_length]
The specier string_length is a number of characters a string consists of. The string is stored internally as the given
sequence of characters plus a nal null character (zero). This appended “stamp” does not count against string’s total
length.
A null string (“”) is stored as a single null character.
You can assign string literals or other strings to string variables. The string on the right side of an assignment operator
has to be shorter than another one, or of equal length. For example:
dim msg1 as string[20]
dim msg2 as string[19]
main:
msg1 = “This is some message”
msg2 = “Yet another message”
msg1 = msg2 ‘ this is ok, but vice versa would be illegal
Alternately, you can handle strings element–by–element. For example:
dim s as string[5]
‘ ...
s = “mik”
‘ s[0] is char literal “m”
‘ s[1] is char literal “i”
‘ s[2] is char literal “k”
‘ s[3] is zero
‘ s[4] is undened
‘ s[5] is undened