Arrays Cambridge IGCSE Computer Science revision
Not started
Learn it
In plain words
Thirty students each have a mark. You could invent thirty variables: Mark1, Mark2, Mark3. Or you could have one variable with thirty numbered slots. That is an array, and it is what makes loops powerful.
6 things to know
- An array is a data structure that stores several items of the same data type under one name. Each item is reached by its index, a number giving its position.
- A one-dimensional array is a single list: DECLARE Marks : ARRAY[1:30] OF INTEGER. Marks[3] ← 72 stores 72 in the third slot.
- A two-dimensional array is a table with rows and columns: DECLARE Seats : ARRAY[1:3, 1:4] OF BOOLEAN has 3 rows and 4 columns, 12 slots altogether. Seats[2, 4] is row 2, column 4.
- A variable can be used as the index. That is what lets a loop visit every slot in turn.
- A FOR loop reads or writes every element of a 1D array. A 2D array needs a nested loop: one loop for the rows and one inside it for the columns.
- The first index can be 0 or 1. The question will say which.
Worked example
Marks is an array holding five marks at indexes 1 to 5. Describe pseudocode that adds them up.
- Set Total ← 0.
- Loop FOR Index ← 1 TO 5.
- Inside the loop, Total ← Total + Marks[Index].
- End the loop with NEXT Index. Total now holds the sum of all five marks.
Tips and tricks
- Every element of an array has the same data type. A list that mixes names and ages needs two arrays.
- Watch the limits of the loop. An array declared [1:30] has no slot 0 and no slot 31.
It lands in your notebook with its questions as flashcards.
Arrays: 6 questions and answers
These are the quiz’s questions. Do the quiz first, then come back here for the ones that got you.
What is an array?
Each item is reached by its index.
What is the index of an array element?
Marks[3] is the element at position 3.
How many elements does an array declared ARRAY[1:10] OF INTEGER have?
Indexes 1 to 10.
How many elements does an array declared ARRAY[1:4, 1:5] OF REAL have?
4 rows × 5 columns.
Which structure is used to visit every element of a 2D array?
One loop for the rows, with a loop for the columns inside it.
Scores holds 5, 8, 2, 9 at indexes 1 to 4. What is Scores[3]?
It is the third element.
Quiz
6 questions
Tap an answer and you’ll see straight away whether it’s right, and why.
Worksheet
3 questions, 6 marks. Write your answers on paper, then check them.
Arrays
Cambridge IGCSE Computer Science 0478 · 6 marks · papermunch.org
Name ______________________________ Date ______________
Write a pseudocode statement to declare a one-dimensional array called Names that holds 20 strings.[2]
Show answerHide answer
DECLARE Names : ARRAY[1:20] OF STRING
Describe what is meant by an array.[2]
Show answerHide answer
A data structure that holds several values of the same data type under one name. Each value is accessed using its index.
An array is declared as ARRAY[1:5, 1:8] OF INTEGER. State how many elements it has and which loops are needed to visit all of them.[2]
Show answerHide answer
40 elements. A nested loop: one loop for the 5 rows and one inside it for the 8 columns.
Answers: Arrays
- 1. DECLARE Names : ARRAY[1:20] OF STRING
- 2. A data structure that holds several values of the same data type under one name. Each value is accessed using its index.
- 3. 40 elements. A nested loop: one loop for the 5 rows and one inside it for the 8 columns.



