Arrays

Computer Science: OCR A Level, topic 4.1.3

Arrays

Arrays are really useful when you have access to large amounts of related data, but you don't want to store in multiple variables.

Arrays

Arrays

  • An array is a data structure that stores a fixed number of values under a single identifier.
  • The values must be of the same type.
Array elements

Array elements

  • Each piece of data inside an array is called an element.
  • Each element has an index, which is its position within the array.
  • We start counting the indices from 0.
Arrays in pseudocode

Arrays in pseudocode

  • An array of ten items can be created using the following syntax:
  • array name_of_array[10]
  • Values can be assigned as follows:
  • name_of_array[0] = "Hello"
  • Values can be accessed as follows:
  • print(name_of_array[0])

Test yourself on Arrays

  • Toggle until all are correct: Which of these is true of arrays?

  • How do we access the first element of an array?

Practise this topic for free