Arrays Flashcards
Card 1 of 7
All 7 cards in this deck
What is an array?
A data structure that holds multiple values of the same data type in sequence, with a fixed size set when it is declared.
True or false? In the array
scores, the first element isscores[1].False. Array indexes start at 0, so the first element is
scores[0].An algorithm totals a 3-element array using
for x = 0 to 2. What must be changed so it works for a 5-element array?Only the FOR loop line:
for x = 0 to 4, keeping the same counter variable (or use the length of the array).How is a 2D array declared and how is one element accessed?
e.g. an array
scorewith 3 rows and 2 columnsDeclared with rows and columns:
array score[3,2]; an element is accessed with both indexes, e.g.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.
How can a 2D array be used to emulate a database table?
Each row stores one record and each column stores one field (attribute) of every record.
In OCR Exam Reference Language, how do you declare an array and fill it with values in one line?
e.g. an arraycoloursholding red, green and blueList the values in square brackets:
array colours = ["red", "green", "blue"]— the size (3) is set by the number of values.