Programming constructs - CCEAArrays

Computer programs use data stores to organise the different types of data they contain. Data stores can be either a constant, variable or an array, and contain inputs, outputs, functions, instructions, sequences and more.

Part ofDigital Technology (CCEA)Digital development concepts (programming)

Arrays

A can only store one value. If you need to store multiple values you will need to use an .

An array is a set of values of the same stored under one identifier. When arrays are created, the program needs to know their size. It needs to know how many elements you want to store.

When an array or any variable is created in a program this is called .

Example:

fruit = ['Banana', 'Apple', 'Pear', 'Lemon']

Each element in an array refers to a specific memory location. We access the elements in an array using the .

Example of an array

Note: Computers count from zero, so the first number in the array is always counted as 0. The last element in an array with n elements will have the index n-1. If an array has 10 elements then the last number will be 9 (0-9).

Did you know? Arrays in Python

Arrays in Python differ from other programming languages as it uses lists instead of arrays. Python 'lists' are more flexible than arrays as they can contain different data types and their length can vary in size.

It is often convenient to use a list where you do not know what the data type or length of your list will be. However, arrays are a more direct way of accessing data in memory so they are much faster and more efficient.