Arrays have a fixed length and one data type

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Arrays have a fixed length and one data type

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A student declares DECLARE Scores : ARRAY[1:30] OF INTEGER. How many elements can Scores hold?
A As many as needed, it grows automatically
B 30 elements, and the size is fixed
2. Which declaration is valid in IGCSE pseudocode?
A DECLARE Marks : ARRAY[1:5] OF INTEGER
B DECLARE Marks : ARRAY[1:5] OF INTEGER, STRING
3. True or false: one array can store the names (STRING) and the ages (INTEGER) of 10 students together.
A True - an array can mix STRING and INTEGER
B False - every element must be the same data type
4. A table holds a student's name, age and test mark for 20 students. What is the best way to store it using 1D arrays?
A Separate arrays: Names (STRING), Ages (INTEGER) and Marks (INTEGER)
B One array of STRING that holds names, ages and marks mixed
5. An array is declared as ARRAY[1:10] OF STRING. What happens if the program needs to store an 11th item?
A The array cannot hold it - the size was fixed at declaration
B The array automatically becomes ARRAY[1:11]

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1DECLARE Marks : ARRAY[1:30] OF INTEGER AAn array can only have one data type. You cannot list STRING and INTEGER together. Use two arrays, one for each type.
2DECLARE Names : ARRAY[1:5] OF STRING BDECLARE Name : ARRAY[1:20] OF STRING DECLARE Age : ARRAY[1:20] OF INTEGER
3A table holds names (STRING) and ages (INTEGER), so you use two separate arrays of the same length, one for each data type. CCreates an array with exactly 30 elements, and every element must be an INTEGER. The size is fixed once declared.
4The size of an array is set when it is declared. The upper bound 10 means it holds exactly 10 elements and cannot grow. DDECLARE Scores : ARRAY[1:10] OF INTEGER
5DECLARE Data : ARRAY[1:3] OF STRING, INTEGER EMarks is an ARRAY OF INTEGER, so a STRING cannot be stored in it. The value must be an INTEGER such as 0.
6Marks[1] <- "Absent" FCreates an array that holds exactly 5 STRING values. It cannot store an INTEGER in any element.

Definitions

ARRAY[1:30] OF INTEGER

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
DECLARE Scores : ARRAY[1:30] OF _______
2.
// Space for exactly 25 names DECLARE Names : ARRAY[1:__] OF STRING
3.
DECLARE Names : ARRAY[1:30] OF STRING DECLARE Marks : ARRAY[1:30] OF _______
4.
DECLARE Prices : _____[1:10] OF REAL
5.
// 12 temperatures such as 18.5 and 21.0 DECLARE Temps : ARRAY[1:12] OF ____

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A DECLARE M:ARRAY[1:5] OF REAL
B M[1] ← 72
C M[2] ← "absent"
Question 2
A DECLARE N:ARRAY[1:3] OF STRING
B N[1] ← "Ava"
C N[2] ← 16
D N[3] ← "Zoe"
Question 3
A DECLARE T:ARRAY[1:7] OF REAL
B Day ← 1
C WHILE Day <= 8 DO
D T[Day] ← 0.0
E Day ← Day + 1
F ENDWHILE
Question 4
A DECLARE N:ARRAY[1:3] OF STRING
B DECLARE S:ARRAY[1:3] OF REAL
C N[1] ← "Ava"
D S[1] ← N[1]
Question 5
A DECLARE G:ARRAY[1:5] OF CHAR
B G[1] ← 95
C OUTPUT G[1]

Answer Key

Arrays have a fixed length and one data type
Section A: Quick Questions
Q1
B — 30 elements, and the size is fixed
Q2
A — DECLARE Marks : ARRAY[1:5] OF INTEGER
Q3
B — False - every element must be the same data type
Q4
A — Separate arrays: Names (STRING), Ages (INTEGER) and Marks (INTEGER)
Q5
A — The array cannot hold it - the size was fixed at declaration
Section B: Match the Pairs
Q1
DECLARE Marks : ARRAY[1:30] OF INTEGER → Creates an array with exactly 30 elements, and every element must be an INTEGER. The size is fixed once declared.
Q2
DECLARE Names : ARRAY[1:5] OF STRING → Creates an array that holds exactly 5 STRING values. It cannot store an INTEGER in any element.
Q3
A table holds names (STRING) and ages (INTEGER), so you use two separate arrays of the same length, one for each data type. → DECLARE Name : ARRAY[1:20] OF STRING DECLARE Age : ARRAY[1:20] OF INTEGER
Q4
The size of an array is set when it is declared. The upper bound 10 means it holds exactly 10 elements and cannot grow. → DECLARE Scores : ARRAY[1:10] OF INTEGER
Q5
DECLARE Data : ARRAY[1:3] OF STRING, INTEGER → An array can only have one data type. You cannot list STRING and INTEGER together. Use two arrays, one for each type.
Q6
Marks[1] <- "Absent" → Marks is an ARRAY OF INTEGER, so a STRING cannot be stored in it. The value must be an INTEGER such as 0.
Section C: Definitions
Q1
ARRAY[1:30] OF INTEGER — An array has a fixed size set when it is declared, and every element must be the same data type, so STRING and INTEGER cannot be mixed in one array.
Section D: Fill in the Blanks
Q1
DECLARE Scores : ARRAY[1:30] OF INTEGER
Q2
// Space for exactly 25 names DECLARE Names : ARRAY[1:25] OF STRING
Q3
DECLARE Names : ARRAY[1:30] OF STRING DECLARE Marks : ARRAY[1:30] OF INTEGER
Q4
DECLARE Prices : ARRAY[1:10] OF REAL
Q5
// 12 temperatures such as 18.5 and 21.0 DECLARE Temps : ARRAY[1:12] OF REAL
Section E: Spot the Error
Q1
C — M is declared as an array of REAL, so every element must be a number. A STRING such as "absent" cannot be stored in it. The line should be M[2] ← 65.
Q2
C — N is an array of STRING, so every element must be text. The number 16 is a different data type and cannot be mixed in. The line should be N[2] ← "Liam".
Q3
C — The array has a fixed size of 7 elements. A loop that runs while Day is 8 tries to use T[8], which does not exist. The condition should be Day <= 7.
Q4
D — N[1] holds a STRING, but S is an array of REAL, so it can only hold numbers. Names and marks need separate arrays, each with its own type. The line should be S[1] ← 72.5.
Q5
B — G is an array of CHAR, so every element must be a single character. The number 95 is the wrong data type. The line should be G[1] ← 'A'.