Arrays - LucasMW/mongaComp GitHub Wiki
Arrays
Besides the three base types: int, float and char, monga has the array type
An array type is always an array of another type, i.e arrays can be arrays of base types or arrays of arrays recursively:
Arrays are declared like this:
int[] vectorOfInts;
float[] fArray;
int[][] intMatrix;
Before they can be used, arrays must be initialized:
fArray = new float[4];
vectorOfInts = new int[10];
Arrays are accessed using an int typed index
fv = fArray[2];
iv = vectorOfInts[i];
However accessing an initialized array area (out of bounds area) will result in undefined behavior (probably crashing the program)
Wrong:
fArray[9];
vectorOfInts[-1];
Arrays of arrays must be initialized each row, through a loop.
Here is an example:
char[][] charMatrix;
charMatrix = new char[][10];
int i;
i=0;
while(i<10) {
charMatrix[i] = new char[10];
}
This creates a 10x10 char matrix ready to be used