Array Architect
How to store lists of values in one- and two-dimensional arrays, how zero-based indexing works, how to iterate over an array, and how a record groups related fields together.
Get the method right under pressure
Free interactive practice on the steps that lose marks under exam pressure.
Start revising freeWhat you'll cover
Storing a whole list at once
A single variable holds one value, but a program often needs a whole list, such as the scores of a class or the pixels in a grid. An array stores many values under one name, and each value has a numbered position. This module shows how to declare an array, reach any item by its index, loop through it, and how a record groups related fields.
Array words to know
Learn these before you index and iterate.
One dimension against two
Arrays can be a line or a grid.
Count the positions from zero
The first item of an array sits at index 0, so an array of n items runs from index 0 up to index n minus 1. Reaching past that last index is out of range. For a two-dimensional array give the row first and the column second, as in board[row][col], and loop over both with one loop inside another.
Match the term
- array
- index
- element
- record
- a list of values under one name
- the numbered position of an item
- a single value in the list
- related fields grouped together
Match the operation
- declare
- index into
- iterate
- access a 2D cell
- set up a new array to hold values
- read one item by its position
- loop through every item in turn
- give a row index and a column index
Where is the first item?
An array called scores holds four values. At which index is the first value stored?
- Index 0
- Index 1
- Index 4
- It has no index
True about arrays
Select the TWO statements that are true about arrays.
- Many values are stored under one name
- The first item is at index 0
- Each item must have a different name
- An array can hold only one value
Find the last index
An array holds 5 items and the first is at index 0. Subtract 1 from the number of items to find the index of the last item. What is the answer?
Order the array steps
Put the steps of using an array in order, earliest first.
- Declare the array
- Store values in it
- Loop through the items
- Use each value in turn
Complete the rules
An array stores many values under one _____. Each item is reached by its _____, and the first item sits at position _____. A two-dimensional array is like a grid, reached by a row and a _____ index.
Spot the valid index
An array names holds 3 items at index 0, index 1 and index 2. Tap the TWO ways of reading an item that are in range.
- names[0]
- names[2]
- names[3]
- names[5]
Choose the structure
Read each need and choose the best data structure.
- You need to store the scores of 30 pupils as a simple list. What suits this best?
- You need to store the squares of a chessboard, with rows and columns. What suits this best?
- You need to keep a player name, age and score together as one item. What suits this best?
Explain arrays and records
Explain how an array stores and reaches its values, and how a record is different from an array.
- Say what an array is and how indexing starts
- Explain the difference between a one-dimensional and a two-dimensional array
- Explain what a record is used for