Cambridge IGCSE Computer Science (0478) · lesson 31 of 35 · 25 min
Arrays
An array is a data structure that stores multiple values of the same type under a single variable name, accessed by an index. In Cambridge pseudocode, arrays are declared as:
DECLARE scores : ARRAY[1:10] OF INTEGER
Elements are accessed with: scores[1], scores[2], etc.
Store and sum 5 test scores
DECLARE scores : ARRAY[1:5] OF INTEGER
total ← 0
FOR i ← 1 TO 5
INPUT scores[i]
total ← total + scores[i]
NEXT i
OUTPUT total / 5
String Handling
Extract initials from first and last name
INPUT firstName, lastName
initials ← SUBSTRING(firstName, 1, 1) & SUBSTRING(lastName, 1, 1)
OUTPUT UCASE(initials)
An array declared as ARRAY[1:5] OF INTEGER can store how many elements?
- 4
- 5
- 6
- 10
Answer: 5
Indices 1 to 5 inclusive = 5 elements.
What does LENGTH(“Cambridge”) return?
- 8
- 9
- 10
- 7
Answer: 9
“Cambridge” has 9 characters.
Which operator concatenates two strings in Cambridge pseudocode?
- +
- &
- *
- ||
Answer: &
Cambridge pseudocode uses & for string concatenation.
Previous lesson: Sequence, selection, and iteration
Back to Cambridge IGCSE Computer Science (0478)
Next lesson: Procedures and functions