mikroC
making it simple...
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 2-dimensional array:
float m[50][20];
Variable m is an array of 50 elements, which in turn are arrays of 20 floats each.
Thus, we have a matrix of 50x20 elements: the first element is
one is
If you are not initializing the array in the declaration, you can omit the first dimen-
sion of multi-dimensional array. In that case, array is located elsewhere, e.g. in
another file. This is a commonly used technique when passing arrays as function
parameters:
int a[3][2][4];
void func(int n[][2][4]) { /* we can omit first dimension */
//...
n[2][1][3]++;
}//~
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}};
MikroElektronika: Development tools - Books - Compilers
/* 2-dimensional array of size 50x20 */
. First element of the 5th row would be
m[49][19]
/* 3-dimensional array of size 3x2x4 */
/* increment the last element*/
mikroC - C Compiler for Microchip PIC microcontrollers
, the last
m[0][0]
.
m[0][5]
page
67
Need help?
Do you have a question about the PIC Microcontrollers PIC12 and is the answer not in the manual?