Accessing array elements
Each element of an array is accessed via its base name and an index into the array. An index is also known as a subscript. Each element is accessed using the following form:
arrayName[ index ]
Here, index
is a value between 0
and the (array size minus 1
). We can access any element of an array using this form. Just as with defining an array, the index may be a literal value, a variable, the result of a function call, or the result of an expression, as follows:
float anArray[10] = {2.0};
int counter = 9;
float aFloat = 0.0;
aFloat = anArray[ 9 ]; // Access last element.
aFloat = anArray[ counter ]; // Access last element
...