User manual

Table Of Contents
202
mikoC PRO for PIC32
MikroElektronika
Arrays in Expressions
When the name of an array comes up in expression evaluation (except with operators & and sizeof), it is implicitly
converted to the pointer pointing to array’s rst element. See Arrays and Pointers for more information.
Multi-dimensional Arrays
An array is one-dimensional if it is of scalar type. One-dimensional arrays are sometimes referred to as vectors.
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 of 2-dimensional
array:
oat m[50][20]; /* 2-dimensional array of size 50x20 */
A variable m is an array of 50 elements, which in turn are arrays of 20 oats each. Thus, we have a matrix of 50x20
elements: the rst element is m[0][0], the last one is m[49][19]. The rst element of the 5th row would be m[4]
[0].
If you don’t initialize the array in the declaration, you can omit the rst dimension of multi-dimensional array. In that
case, array is located elsewhere, e.g. in another le. This is a commonly used technique when passing arrays as
function parameters:
int a[3][2][4]; /* 3-dimensional array of size 3x2x4 */
void func(int n[][2][4]) { /* we can omit rst dimension */
...
n[2][1][3]++; /* increment the last element*/
}
void main() {
...
func(a);
}
You can initialize a multi-dimensional array with an appropriate set of values within braces. For example:
int a[3][2] = {{1,2}, {2,6}, {3,7}};