FutureLogic Blog → Programming → IGCSE Computer Science

How do 1D and 2D arrays work?

An array stores multiple values of the same data type under one identifier. A one-dimensional (1D) array uses one index to access an element, while a two-dimensional (2D) array uses two indexes, usually a row and a column.

In Cambridge IGCSE Computer Science (0478), arrays organise related data and help programs process it using loops. Learn array indexes, bounds, declarations, trace tables and exam techniques with worked examples.

What is an array?

Imagine storing five student scores. Instead of five separate variables, an array stores related elements of the same data type under one identifier. Each element is accessed using an index.

One identifier. Many values. Each value has an index.

Cambridge syllabus focus

Topic 8 programming: declare and use one- and two-dimensional arrays, store and retrieve elements, and process arrays using iteration. Follow the bounds given in each question.

1D arrays — one index

A 1D array resembles a row of numbered pigeonholes. Here Score contains five integer values, indexed from 1 to 5.

Index12345
Score7265815490

Score[3] selects the element at index 3, which contains 81. The number in square brackets identifies a position, not the stored value.

Declaring and filling a 1D array

A declaration specifies the array bounds and data type. Assignment stores a value at a selected index.

DECLARE Score : ARRAY[1:5] OF INTEGER Score[1] ← 72 Score[2] ← 65 Score[3] ← 81 Score[4] ← 54 Score[5] ← 90 OUTPUT Score[3]

Output: 81. Assigning a new value to Score[3] changes that element only.

Exam tip: These examples use indexes starting at 1. Python lists normally start at 0. In Cambridge pseudocode, follow the declared array bounds rather than assuming the first index.

Check your understanding 1

What is Score[4]?

Reveal answer

54, the element stored at index 4.

2D arrays — two indexes

A 2D array is a grid. The first index can identify the row and the second the column. In this example Mark[2,1] means row 2, column 1.

Column 1Column 2Column 3
Row 1726875
Row 2817789
DECLARE Mark : ARRAY[1:2, 1:3] OF INTEGER Mark[1,1] ← 72 Mark[1,2] ← 68 Mark[1,3] ← 75 Mark[2,1] ← 81 Mark[2,2] ← 77 Mark[2,3] ← 89 OUTPUT Mark[2,3]

Output: 89. Row 2, column 3 contains 89.

Check your understanding 2

Which element contains 68, and what is Mark[2,2]?

Reveal answer

Mark[1,2] contains 68; Mark[2,2] contains 77.

Using a FOR loop to total a 1D array

A loop can visit each element in turn. Initialise the total to zero before adding the scores.

Total ← 0 FOR Index ← 1 TO 5 Total ← Total + Score[Index] NEXT Index OUTPUT Total
IndexScore[Index]Running total
17272
265137
381218
454272
590362

The final output is 362. The trace table records the total after every iteration.

Nested loops for a 2D array

Use an outer loop for rows and an inner loop for columns. The inner loop completes all columns before the next row begins.

FOR Row ← 1 TO 2 FOR Column ← 1 TO 3 OUTPUT Mark[Row, Column] NEXT Column NEXT Row

Output order: 72, 68, 75, 81, 77, 89. The nested loops output 2 × 3 = 6 elements.

Check your understanding 3

How many times does OUTPUT run in the nested loops?

Reveal answer

Six times: two rows multiplied by three columns.

1D and 2D arrays compared

Feature1D array2D array
StructureLine of elementsGrid of elements
IndexesOneTwo
ExampleScore[3]Mark[2,3]
Typical processingOne loopNested loops

Common Cambridge exam mistakes

✗ Confusing index with value.

Score[3] selects the third element; it does not mean the value 3.

✗ Assuming the first index.

Read the declared bounds. Arrays do not always start at index 0.

✗ Missing the second index.

A 2D array needs both row and column indexes.

✗ Forgetting to initialise totals.

Set Total ← 0 before accumulating values.

✗ Accessing outside the bounds.

For indexes 1–5, index 6 is invalid.

Exam focus — original FutureLogic practice

Original Cambridge-style practice questions, not official examination questions. Suggested marks are indicative; actual mark schemes determine credit.

Question 1 (2 marks)

State two differences between 1D and 2D arrays.

Reveal model answer

A 1D array uses one index and resembles a line; a 2D array uses two indexes and resembles a grid.

Question 2 (3 marks)

Declare an INTEGER array Age with indexes 1 to 20 and store 16 at index 4.

Reveal model answer

DECLARE Age : ARRAY[1:20] OF INTEGER and Age[4] ← 16.

Question 3 (3 marks)

Write pseudocode to output all five elements of Score.

Reveal model answer

FOR Index ← 1 TO 5, then OUTPUT Score[Index], then NEXT Index.

Question 4 (4 marks)

Describe how nested loops output a 3-row, 4-column array.

Reveal model answer

Use an outer loop for rows 1–3 and an inner loop for columns 1–4; output the element at each row and column. There are 12 outputs.

Quick quiz

  1. What is an array element?
  2. What does an index identify?
  3. How many indexes select a 2D element?
  4. What is Score[5]?
  5. Why are loops useful with arrays?
  6. What does out of bounds mean?

Quiz answers

Reveal all answers
  1. One stored value.
  2. An element position.
  3. Two.
  4. 90.
  5. They process many elements efficiently.
  6. An index outside the valid range.

Final summary

Array

Multiple same-type values under one identifier.

Index

Selects one element.

1D

One index.

2D

Two indexes.

Loops

Process elements.

Bounds

Specify valid indexes.

One array name. Correct indexes. Every element accounted for.

Ready to practise programming?

Use the Knowledge Library to reinforce arrays, selection and iteration.