Page 91 - 6437
P. 91
}
}
return 0;
}
When the above code is compiled and executed, it produces the following result:
a[0][0]: 0
a[0][1]: 0
a[1][0]: 1
a[1][1]: 2
a[2][0]: 2
a[2][1]: 4
a[3][0]: 3
a[3][1]: 6
a[4][0]: 4
a[4][1]: 8
As explained above, you can have arrays with any number of dimensions, although it is
likely that most of the arrays you create will be of one or two dimensions.
Passing Arrays to Functions
If you want to pass a single-dimension array as an argument in a function, you would
have to declare a formal parameter in one of following three ways and all three declaration
methods produce similar results because each tells the compiler that an integer pointer is going to
be received. Similarly, you can pass multi-dimensional arrays as formal parameters.
Way-1
Formal parameters as a pointer:
void myFunction(int *param)
{
.
.
.
}
94