0984

Arrays

Programming · 4 question types

What an Array Is

An array is a named, ordered collection of values of the same data type, stored as a single variable. Each value is accessed using an .

Three things make arrays different from ordinary variables:

  • One name, many values. Instead of Score1, Score2, Score3, ..., Score30, you can use a single array Scores with 30 elements.
  • Same data type for every . An array of integers can only hold integers; an array of strings can only hold strings.
  • Fixed size. The size is set when the array is declared and (in CIE pseudocode) does not change.

Arrays are essential because programs almost always need to handle many values at once: a class of students, a row of pixels in an image, a list of stock prices, a sequence of network packets.