COMPUTER SCIENCE CAFÉ
  • WORKBOOKS
  • BLOCKY GAMES
  • GCSE
    • CAMBRIDGE GCSE
  • IB
  • A LEVEL
  • LEARN TO CODE
  • ROBOTICS ENGINEERING
  • MORE
    • CLASS PROJECTS
    • Classroom Discussions
    • Useful Links
    • SUBSCRIBE
    • ABOUT US
    • CONTACT US
    • PRIVACY POLICY
  • WORKBOOKS
  • BLOCKY GAMES
  • GCSE
    • CAMBRIDGE GCSE
  • IB
  • A LEVEL
  • LEARN TO CODE
  • ROBOTICS ENGINEERING
  • MORE
    • CLASS PROJECTS
    • Classroom Discussions
    • Useful Links
    • SUBSCRIBE
    • ABOUT US
    • CONTACT US
    • PRIVACY POLICY
8.2 | ARRAYS
Topics from the Cambridge IGCSE (9-1) Computer Science 0984 syllabus 2023 - 2025
ON THIS PAGE
SECTION 1 | WHAT IS AN ARRAY
​SECTION 2 | TYPES OF ARRAYS

 8.1 PROGRAMMING CONCEPTS
 8.1 PROGRAMMING CONCEPTS CONTINUED

 YOU ARE HERE | 8.2 ARRAYS
8.3 FILE HANDLING
Picture

ARRAYS

SECTION 1 | WHAT IS AN ARRAY
​An array is a collection of elements, each identified by at least one array index or key. Arrays can store data of the same type and are useful for organising data systematically for easy access and manipulation. 

They are just like the normal variables except they can hold multiple items of data and like variables they have the same naming conventions such as:

NAMING RULES
✘ Cannot start the name with a number
​✘ Cannot contain spaces
​✘ Cannot use command words such as print, python, turtle, exit, for, while and many more...

​NAMING CONVENTIONS
✓Should start with a lowercase letter
✓If more than one word used the first letter uppercase of proceeding words or use _ to join words
​✓Names should be meaningful to the content of the variable
SECTION 2 | TYPES OF ARRAYS
One-dimensional (1D) Arrays
A one-dimensional array is a linear list of elements that are of the same type and are accessed by a single index. This type of array is simple and efficient for storing data that naturally forms a sequence.
  • Example Use | A common use of 1D arrays is to store a list of items like user names or a series of numerical values such as test scores.
  • Sample Array for a Scenario | Imagine you're managing a small music concert and need to keep track of the names of bands performing:

bands = ["The Foo Bar", "Baz Quux", "Quuz Corge"]

Two-dimensional (2D) Arrays
A two-dimensional array, often called a matrix, is an array of arrays where each entry in the main array can hold another array. This setup allows for a grid-like structure, which is excellent for more complex data organizations that require accessing elements via two indices (rows and columns).
  • Example Use | 2D arrays are useful for applications such as creating game boards, spreadsheets, or storing data in table form, where each row could represent a record and each column a type of information about that record.
  • Sample Array for a Scenario | Suppose you are a teacher recording grades in different subjects for a class of three students. Each row represents a student, and each column represents a different subject.

grades = [
  [87, 92, 78],  # Grades for Student 1
  [91, 85, 90],  # Grades for Student 2
  [88, 84, 82]   # Grades for Student 3
SECTION 3 | DECLARING ARRAYS
Declaring an array involves specifying its type and the number of elements it will hold. This process can vary significantly between programming languages. Below, we expand on how to declare one-dimensional (1D) and two-dimensional (2D) arrays in both Python and using the CIE pseudocode conventions.

DECLARING 1D ARRAYS
  • PSEUDOCODE
  • PYTHON
<
>
​In the CIE pseudocode, an array must be explicitly declared with its size and type, which makes it clearer how many items the array can hold and what type they are.

# Declare an array 'fruits' capable of holding three strings, indexed from 1 to 3.
DECLARE fruits : ARRAY[1:3] OF STRING

# Assign values to each position in the array.
fruits[1] ← "apple"
fruits[2] ← "banana"
fruits[3] ← "cherry"
To declare a one-dimensional array in Python, which is typically done using lists, you simply assign a list of elements to a variable. Here, the elements can be of any type: strings, numbers, or even other lists.

# Declaring a 1D array with string elements
fruits = ["apple", "banana", "cherry"]

# This creates a list of fruits with three elements.
DECLARING 2D ARRAYS

A two-dimensional array in Python is essentially a list of lists. Each sublist represents a row in the array.

Imagine a classroom with three students and their grades in three different subjects (Math, Science, English). It would be  logical to arrange of data in rows and columns, as you would expect to see if you put the data in a spreadsheet. Here we create a 2D array in Pseudocode an Python with the same row and column structure.
  • PSEUDOCODE
  • PYTHON
<
>
# Declare a 2D array 'grades' with 3 rows and 3 columns, each cell to hold an integer representing a grade.
DECLARE grades : ARRAY[1:3, 1:3] OF INTEGER

# Assigning grades
# Each row corresponds to a student, and each column corresponds to a subject: Math, Science, English

grades[1, 1] ← 85  # Student 1, Math
grades[1, 2] ← 90  # Student 1, Science
grades[1, 3] ← 88  # Student 1, English

grades[2, 1] ← 78  # Student 2, Math
grades[2, 2] ← 92  # Student 2, Science
grades[2, 3] ← 80  # Student 2, English

grades[3, 1] ← 90  # Student 3, Math
grades[3, 2] ← 85  # Student 3, Science
grades[3, 3] ← 87  # Student 3, English
​# Declaring a 2D array to store grades for three students in three subjects
grades = [
  [85, 90, 88],  # Grades for Student 1: Math, Science, English
  [78, 92, 80],  # Grades for Student 2: Math, Science, English
  [90, 85, 87]   # Grades for Student 3: Math, Science, English
]
# This creates a table-like structure where each row represents a student and each column a subject.
SECTION 4 | USING ARRAYS
Arrays are used for storing data that can be logically grouped together, such as the grades of students, temperature readings, or spatial coordinates.

​
Picture
ALSO IN THIS TOPIC
 8.1 PROGRAMMING CONCEPTS
 8.1 PROGRAMMING CONCEPTS CONTINUED

 8.2 ARRAYS
 8.3 FILE HANDLING
TOPIC 8 ANSWERS
​
Picture
SUGGESTIONS
We would love to hear from you
SUBSCRIBE 
To enjoy more benefits
We hope you find this site useful. If you notice any errors or would like to contribute material then please contact us.