Skip to main content
Northern IrelandSoftware Systems DevelopmentSyllabus dot point

How are one- and two-dimensional arrays declared, indexed and traversed to store collections of related data?

One-dimensional and two-dimensional arrays - declaration, indexing, traversal with loops, and using parallel arrays to hold related data.

A CCEA A-Level Software Systems Development answer on one- and two-dimensional arrays: declaration, zero-based indexing, traversing with loops, and using parallel arrays to store related collections of data.

Generated by Claude Opus 4.812 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. The answer
  3. Examples in context
  4. Try this

What this dot point is asking

CCEA wants you to declare and use one-dimensional and two-dimensional arrays: how an array stores many values of the same type under one name, how elements are reached by an index (usually zero-based), and how a loop traverses an array to process every element. You should also know how parallel arrays hold related fields and when a 2D array is the better structure. Array traversal with totals, searches and counts is examined directly.

The answer

One-dimensional arrays

declare scores as array[0..4] of integer
scores[0] = 18
scores[1] = 25
// ... up to scores[4]

The array name plus an index selects one element: scores[2] is the third element. The size is fixed when the array is created, and an index outside the valid range causes an out-of-bounds error.

Traversing an array

A loop visits each element in turn. Because the indices are known (0 to length minus one), a definite (count-controlled) loop is the natural choice.

Two-dimensional arrays and parallel arrays

A two-dimensional array is a table of rows and columns, with each element reached by two indices, grid[row][col]. It suits naturally grid-shaped data such as a board, a map or a table of marks, and a nested loop processes it.

Parallel arrays are several 1D arrays of the same length where the same index in each refers to one logical record: names[i], ages[i] and marks[i] together describe one student. They are a simple way to store related fields before record or object structures are introduced.

Worked example: finding the highest value and its position

Examples in context

Example 1. A class register. A 1D array present of Booleans, one per student, records attendance; a single loop counts the trues to give the number present. Storing the marks in a parallel names and marks pair means names[i] and marks[i] describe the same student, and one traversal can print every name with its mark.

Example 2. A seating plan. A 2D array seats[row][col] of a theatre marks each seat free or booked. A nested loop scans every row and column to count empty seats or to find the first free seat, which would be awkward and error-prone with dozens of separate 1D arrays, one per row.

Try this

Q1. State the range of valid indices for an array declared with size 8, assuming zero-based indexing. [1 mark]

  • Cue. 0 to 7.

Q2. Write a loop to add 1 to every element of an integer array counts of length n. [3 marks]

  • Cue. for i = 0 to n - 1 then counts[i] = counts[i] + 1 then next i.

Q3. Give one advantage of a single two-dimensional array over many one-dimensional arrays for storing a grid of data. [2 marks]

  • Cue. The whole grid is one structure processed by a nested loop, keeping the row-column relationship together and making the data easier to extend.

Exam-style practice questions

Practice questions written in the style of CCEA exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

CCEA 20196 marksAn array `scores` holds the test marks of 30 students. Write pseudocode to calculate and output the average mark, and explain how the array is indexed.
Show worked answer →

An array is indexed by position, usually starting at 0, so a 30-element array scores has valid indices 0 to 29. Each element is accessed as scores[i].

total = 0
for i = 0 to 29
    total = total + scores[i]
next i
average = total / 30
print(average)

A counter-controlled loop walks the index i from 0 to 29, adding each element to a running total; dividing the total by the number of elements gives the average. Using the array length rather than a hard-coded 30 (for example length(scores)) would make the code safer if the size changed.

Markers reward correct zero-based indexing, a loop that visits every element exactly once, a running total accumulated correctly, and the division by the count to find the average.

CCEA 20215 marksExplain what a two-dimensional array is, and describe a situation where it is more suitable than several one-dimensional arrays.
Show worked answer →

A two-dimensional array is a table of elements arranged in rows and columns, where each element is accessed by two indices, a row and a column, for example grid[row][col]. It stores data that is naturally grid-shaped.

A good situation is a seating plan or a spreadsheet of marks: rows could be students and columns could be subjects, so marks[2][4] is the mark of student 2 in subject 4. This is more suitable than several separate one-dimensional arrays because the relationship between rows and columns is kept in one structure, a single nested loop can process the whole table, and adding another student or subject does not mean creating a new array. Other grid examples are a noughts-and-crosses board, a map of tiles, or a timetable.

Markers reward the rows-and-columns / two-index definition, a valid grid example, and a clear reason why one 2D array beats many 1D arrays (one structure, nested-loop processing, easier to extend).

Related dot points

Sources & how we know this