Seneca

Arrays

Computer Science: KS3, topic 2.1.14

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 each pair to show which statement about arrays is true.

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

  • Look at this code: array names[3] names[0] = "Amy" names[1] = "Ben" names[2] = "Cal" print(names[1]) What does this code output?

Practise this topic for free