Memory Efficiency: Arrays are stored in Random Access Memory (RAM). Because elements are contiguous and of the same size, the CPU can jump directly to any element using the formula: .
Static Nature: The size of an array is typically fixed upon declaration. This allows the operating system to reserve a specific block of memory, ensuring that the data remains organized and accessible without the overhead of resizing.
Linear vs. Tabular: 1D arrays represent a simple list (linear), while 2D arrays represent a grid or table. A 2D array is essentially an "array of arrays," where each element of the primary array is itself another array.
Declaration: To use an array, you must first define its identifier and size. For example, creating a blank array of size 10 reserves those 10 slots in memory.
Assignment: Values are placed into specific slots using the assignment operator and the index. For a 1D array, this looks like array[index] = value; for a 2D array, it is array[row][column] = value.
Accessing: To retrieve a value, you reference its index. In a 2D array, you must provide two coordinates (indices) to locate a specific cell.
Traversing: Iterating through an array is commonly done using a FOR loop. For a 1D array, a single loop visits every index. For a 2D array, nested loops are required: the outer loop typically iterates through rows, while the inner loop iterates through columns.
Verify Index Order: In 2D array questions, always check if the coordinates are provided as (Row, Column) or (Column, Row). Examiners often provide an example to clarify the expected order; use it as a template.
The Boundary Check: Always remember that the last valid index is . If an array has 5 elements, attempting to access array[5] will result in an 'index out of bounds' error.
Data Type Consistency: Ensure that all data being assigned to the array matches the declared type. Mixing integers and strings in a standard array is a common logical error.
Trace Nested Loops: When analyzing 2D array traversal, trace the inner loop completely for every single iteration of the outer loop to ensure you are visiting cells in the correct sequence.