this is often used with loops. all arrays consist of contiguous memory locations. the lowest address corresponds to the first element and the highest address to the last element. arrays can be thought of as a collection of variables of the same type.
SINGLE DIMENSIONAL ARRAY
with this type of arrays, only one index value is needed to access an element.
#declaration
dataType arrayName[arraySize];
#declaration with initialization
dataType arrayName[arraySize] = {elements...};
* when the compiler encounters array notation with subscripting such as arrayName[1],
it converts it to pointer by using the following
- arrayBaseAddress + sizeof(dataType) * index
- e.g., 0x2000 + 8bytes * 2
- 0x2000 is the arrayBaseAddress
- 8bytes is the size of the data
- if using 8 bytes long int as in "long int arrayName[3] = {100, -25, 3};
- 2 is the third element
MULTI-DIMENSIONAL ARRAY
in a multi-dimensional array, the first subscript operator represent ROWS, while the second subscript operator represents COLUMNS.