Arrays
The notes
What is an array?
A collection of elements of the same data type, stored in contiguous memory locations.
- Ordered sequence
- Fixed size
Structure and terms
- Index: starts at 0
- Element/value (example array: 5, 12, 8, 20 at indexes 0 to 3)
- Size/length
Key properties
- Consecutive memory: elements sit next to each other
- Homogeneous (same type): all elements are the same type, such as integer or string
- Fixed size: cannot easily grow or shrink
Common operations
- Accessing: read an element by index, e.g. myArray[2]
- Modifying: change an element, e.g. arr[1] = 99
- Iterating (looping): visit the elements one by one, e.g. with a for-each loop
Analogies
- Train carriages in a row
- Numbered lockers
- A row of post boxes
Data structures deck
Make them stick
Sign in to see every card full size, tick the ones you've got, come back to the rest later, and keep your own notes on each card.
Watch the lesson
Data structures, Lesson 2, from 4:02: What is an array?








