An array is a fixed‑size, homogeneous data structure that stores a sequence of items of the same data type in contiguous memory locations. Each item is called an element and is identified by an index. The index range is defined by a lower‑bound and an upper‑bound that are declared explicitly.
| Characteristic | What the syllabus expects | Exam‑relevant note |
|---|---|---|
| Fixed size | The number of elements is set when the array is declared; it cannot be altered at run‑time. | Declare the size before any input or processing. |
| Homogeneous | All elements must be of the same data type (INTEGER, REAL, CHARACTER, etc.). | Mixing types causes a compilation error. |
| Explicit lower‑bound | Both 0‑based and 1‑based indexing are allowed, but the lower‑bound must be stated in the declaration. | e.g. DECLARE scores[1:5] or DECLARE scores[0:4]. |
| Random (direct) access | Any element can be read or written directly using its index. | No need to scan previous elements. |
| Maximum three levels of nesting | Loops or conditionals may be nested, but not more than three deep. | Exceeding this limit loses marks. |
| Maximum two parameters per sub‑program | A procedure or function can have at most two arguments. | Design your array‑handling routines accordingly. |
| Language / Pseudocode | Declaration (lower‑bound → upper‑bound) | Initialisation (if any) |
|---|---|---|
| Cambridge Pseudocode (exam style) | DECLARE name[lower:upper] OF |
Optional – elements are undefined until assigned. |
| Python (list used as array) | myArray = [] # lower‑bound is 0 by convention |
myArray = [3, 7, 2, 9] |
| Java | int[] myArray; // size fixed when created |
myArray = new int[]{3, 7, 2, 9}; |
| C++ | int myArray[4]; |
int myArray[4] = {3, 7, 2, 9}; |
value ← myArray[i] – retrieves the element at index i.myArray[i] ← newValue – stores newValue at index i.n:
upper‑bound = lower‑bound + n – 1DECLARE i, lower, upper, total AS INTEGER
total ← 0
FOR i ← lower TO upper
total ← total + myArray[i]
END FOR
int[] scores = {78, 85, 92, 67, 80};
int total = 0;
for (int i = 0; i < scores.length; i++) {
total += scores[i];
}
double average = total / (double)scores.length; // real‑division
DECLARE A[0:2][0:2], B[0:2][0:2], C[0:2][0:2] # 3×3 matrices
/* initialise A and B – omitted for brevity */
FOR i ← 0 TO 2
FOR j ← 0 TO 2
C[i][j] ← A[i][j] + B[i][j]
END FOR
END FOR
| Operation | Pseudocode syntax | Typical use in the exam |
|---|---|---|
| Declare | DECLARE name[lower:upper] OF |
First line of any program that uses an array. |
| Read (input) | INPUT name[i] |
Collect a series of values from the candidate. |
| Write (output) | OUTPUT name[i] |
Display a single element or a computed result. |
| Assign | name[i] ← expression |
Store a calculated value. |
| Loop (iteration) | FOR i ← lower TO upper … END FOR |
Process every element; may be nested (max 3 levels). |
| Search (linear) | IF name[i] = target THEN … END IF |
Locate a specific value; often combined with EXIT FOR. |
| File handling (read/write whole array) | OPEN file FOR INPUTFOR i ← lower TO upper READ file → name[i]END FORCLOSE file |
Topic 8.3 – reading a list of marks from a file and writing results back. |
sum / 5.0).EXIT FOR to stop early.i where i < lower‑bound or i > upper‑bound is a run‑time error (array‑bounds overflow). Always use the declared bounds in loop limits./*--- Read 10 integer marks from a file called "marks.txt" ---*/
DECLARE marks[1:10] OF INTEGER
OPEN "marks.txt" FOR INPUT
FOR i ← 1 TO 10
READ "marks.txt" → marks[i]
END FOR
CLOSE "marks.txt"
/*--- Process the marks (e.g., find the highest) ---*/
DECLARE max ← marks[1]
FOR i ← 2 TO 10
IF marks[i] > max THEN
SET max ← marks[i]
END IF
END FOR
/*--- Write the result to a file called "result.txt" ---*/
OPEN "result.txt" FOR OUTPUT
WRITE "result.txt" ← "Highest mark: " & max
CLOSE "result.txt"
Notice the explicit lower‑bound 1, the use of OPEN … FOR INPUT/OUTPUT, and the loop limits that match the array bounds.
Task: Write a program that reads **five** integer test scores into an array, then outputs the highest score, the average (to one decimal place), and tells whether a given mark m is present in the array.
DECLARE scores[1:5] OF INTEGER
DECLARE i, max, sum, m AS INTEGER
DECLARE average AS REAL
DECLARE found AS BOOLEAN ← FALSE
/*--- Input phase ---*/
FOR i ← 1 TO 5
INPUT scores[i]
END FOR
/*--- Find maximum and sum ---*/
SET max ← scores[1]
SET sum ← 0
FOR i ← 1 TO 5
IF scores[i] > max THEN
SET max ← scores[i]
END IF
SET sum ← sum + scores[i]
END FOR
/*--- Average (real division) ---*/
SET average ← sum / 5.0
/*--- Search for a specific mark ---*/
INPUT "Enter mark to search for: " → m
FOR i ← 1 TO 5
IF scores[i] = m THEN
SET found ← TRUE
EXIT FOR
END IF
END FOR
/*--- Output results ---*/
OUTPUT "Highest score: " & max
OUTPUT "Average score: " & average
IF found THEN
OUTPUT "Mark " & m & " is in the list."
ELSE
OUTPUT "Mark " & m & " is NOT in the list."
END IF
1 in the declaration.← and the Boolean variable found.THEN and ELSE.5.0.lower‑bound … upper‑bound).i <= n instead of i < n for 0‑based arrays).sum / 5 yields an INTEGER).lower‑bound TO upper‑bound; never mix size and bound.1.0).Arrays are a core data structure in the IGCSE Computer Science syllabus. To obtain full marks you must be able to:
FOR loops (max 3 nesting levels).Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.