9618 · 10.2
Arrays — FAQ
Frequently asked questions for 9618 Arrays. Direct answers first, then deeper explanation — then practise with marking.
Why do some programming languages start array indices at 0, but Cambridge pseudocode often uses 1?
0-based indexing (starting at 0) is common in languages like Python, Java, and C++ because the index represents an 'offset' from the starting memory address of the array. The first element is at offset 0. However, 1-based indexing (starting at 1) is often more intuitive for humans ('the first item', 'the second item'). Cambridge pseudocode allows either but typically uses 1-based indexing in exam questions. It's crucial to be consistent and follow the bounds given in the question.
What's the difference between an array and a list?
In the context of A-Level Computer Science, the key difference is that an array is a static data structure, meaning its size is fixed upon creation. A list is typically a dynamic data structure, meaning it can grow or shrink as needed. For your exams, especially in Paper 2 pseudocode, you will almost always be working with static arrays.
What happens if I try to access an index that doesn't exist?
This causes a run-time error called an 'index out of bounds' error. For an array declared as MyData : ARRAY[1:10] OF INTEGER, trying to access MyData[0] or MyData[11] would trigger this error. Your program would likely halt. It's a common logical error that you must guard against in your code, for example by ensuring loop bounds are correct.
Can I store different data types in the same array?
No. An array is a homogeneous data structure, which means all its elements must be of the same data type specified in the declaration (e.g., all INTEGER or all STRING).