Arrays Cambridge IGCSE Computer Science (9–1) 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

  1. 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.
  2. A one-dimensional array is a single list: DECLARE Marks : ARRAY[1:30] OF INTEGER. Marks[3] ← 72 stores 72 in the third slot.
  3. 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.
  4. A variable can be used as the index. That is what lets a loop visit every slot in turn.
  5. 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.
  6. 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.

  1. Set Total ← 0.
  2. Loop FOR Index ← 1 TO 5.
  3. Inside the loop, Total ← Total + Marks[Index].
  4. 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.
6 questions, about 2 minutes.

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.

  1. What is an array?
    • a single number
    • a set of items of the same data type stored under one name (the answer)
    • a type of loop
    • a file on a disk

    Each item is reached by its index.

  2. What is the index of an array element?
    • its value
    • its position in the array (the answer)
    • its data type
    • its name

    Marks[3] is the element at position 3.

  3. How many elements does an array declared ARRAY[1:10] OF INTEGER have?
    • 9
    • 10 (the answer)
    • 11
    • 100

    Indexes 1 to 10.

  4. How many elements does an array declared ARRAY[1:4, 1:5] OF REAL have?
    • 9
    • 16
    • 20 (the answer)
    • 25

    4 rows × 5 columns.

  5. Which structure is used to visit every element of a 2D array?
    • one IF statement
    • a single loop
    • a nested loop (the answer)
    • a CASE statement

    One loop for the rows, with a loop for the columns inside it.

  6. Scores holds 5, 8, 2, 9 at indexes 1 to 4. What is Scores[3]?
    • 5
    • 8
    • 2 (the answer)
    • 9

    It is the third element.

Still stuck on this one?Ask in the Papermunch Discord, or help someone else who is. Discord is for ages 13 and up.Join the server

Things you can type

Or go straight to

Or browse a shelf