One- & Two-Dimensional Arrays Flashcards

All 7 cards in this deck

What is an array?

A data structure that holds a collection of values of the same data type under one identifier, with each value accessed by its index.

True or false? In the array scores, the first element is scores[1].

False. Array indexes start at 0, so the first element is scores[0].

How do you store a value in, and read a value from, one element of a 1D array?

e.g. scores ← [0, 0, 0]

Use the array's identifier with the index in square brackets:

  • store: scores[0] ← 10
  • read: OUTPUT scores[0] → 10

How is one element of a 2D array accessed in AQA pseudo-code?

e.g. an array score with 3 rows and 2 columns

With two indexes, each in its own square brackets, row first: score[0][1] is row 0, column 1.

How do you process every element of a 2D array?

e.g. an array with 3 rows and 2 columns

Use nested loops — an outer loop counting through the rows and an inner loop counting through the columns.

In AQA pseudo-code, how do you create an array and fill it with values in one statement?

e.g. an array colours holding red, green and blue

List the values in square brackets: colours ← ['red', 'green', 'blue']. The array has as many elements as values listed (3).

What does LEN return when it is used on an array?

e.g. names ← ['Ali', 'Bea', 'Cai']

The number of elements in the array, here 3. Indexes start at 0, so the last index is LEN(names) - 1, which is 2.