Skip to main content
ScotlandComputer ScienceSyllabus dot point

How does a program store single values and whole collections of data?

Data types and structures: variables of simple types, 1-D arrays, records, and parallel arrays or arrays of records, with string operations.

An SQA Higher Computing Science answer on data types and structures, covering simple variable types, 1-D arrays, records, parallel arrays and arrays of records, plus string operations such as concatenation.

Generated by Claude Opus 4.811 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 key area is asking
  2. Simple data types
  3. 1-D arrays
  4. Records
  5. Parallel arrays versus arrays of records
  6. String operations
  7. Examples in context
  8. Try this

What this key area is asking

The SQA wants you to know the data types a program uses to store single values, and the data structures used to store collections: 1-D arrays, records, and parallel arrays or arrays of records. You should also know basic string operations, especially concatenation.

Simple data types

Choosing the right type matters: a price should be a real, a count of items an integer, a yes/no flag a Boolean. Using the wrong type wastes memory or causes errors, for example storing a count as a real and getting rounding surprises.

1-D arrays

A 1-D array (a one-dimensional array) stores a fixed number of values of the same type under a single name, each reached by its index (position). An array of 5 reals can hold five temperatures; temps[0] is the first, temps[4] the last (most languages index from 0).

Records

A record groups together related items of data, called fields, which may be of different types, under one name. A record for a book might be:

RECORD Book IS { STRING title, STRING author, INTEGER year }

Unlike an array, a record's fields are named (myBook.title, myBook.year) and can be different types. A record models one thing (one book, one pupil, one product) with all its attributes kept together.

Parallel arrays versus arrays of records

There are two ways to store many things that each have several attributes.

  • Parallel arrays: one array per attribute, kept in step by index. For pupils: names[i] and scores[i] refer to the same pupil. This works but is fragile - if the arrays ever get out of step, the data is silently wrong.
  • Array of records: one array whose elements are records, so each element holds all of one thing's attributes together: pupils[i].name, pupils[i].score.

String operations

A string is a sequence of characters. The key operation at Higher is concatenation: joining strings end to end. To build a full name from two strings with a space between them:

fullName = firstName & " " & lastName

The & (or + in some languages) joins the strings; the literal " " inserts the separating space. The result is itself a string. Concatenation is used to build output messages, file lines and labels from smaller pieces.

Examples in context

Almost every program manipulates structured data this way. A contacts app stores each contact as a record (name, number, email) in an array of records (or a list); a spreadsheet row is effectively a record and the sheet an array of records; a game's high-score table is an array of records (name, score). Databases formalise the same idea as rows in a table. Mastering arrays of records at Higher is the bridge to the Database area, where the same data lives in tables of fields.

Try this

Q1. State the data type you would use to store whether a payment has been made. [1 mark]

  • Cue. Boolean (true or false).

Q2. State one advantage of an array of records over two parallel arrays. [1 mark]

  • Cue. Related fields are kept together in one element, so the arrays cannot drift out of step.

Q3. Write an expression that concatenates town and postcode with a comma and space between them. [2 marks]

  • Cue. town & ", " & postcode.

Exam-style practice questions

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

SQA Higher (style)4 marksA program stores, for 100 pupils, each pupil's name and test score. Describe a record structure suitable for one pupil, and explain why an array of records is better than two separate parallel arrays for this task.
Show worked answer →

A record for one pupil groups related fields of different types under one name, for example:

RECORD Pupil IS { STRING name, INTEGER score }

An array of records (ARRAY OF Pupil of size 100) stores all 100 pupils, where each element holds one pupil's name and score together.

It is better than two parallel arrays (one of names, one of scores indexed in step) because the related data is kept together in one element: there is no risk of the two arrays getting out of step, the code reads more clearly (pupils[i].name, pupils[i].score), and a whole pupil can be passed around as a single value.

Markers reward a correct record with two appropriately typed fields and a valid advantage such as keeping related data together and avoiding parallel arrays drifting out of step.

SQA Higher (style)2 marksA variable firstName holds "Ada" and lastName holds "Lovelace". Write an expression using concatenation to produce the full name "Ada Lovelace", and name the data type of the result.
Show worked answer →

Concatenation joins strings end to end. To get a space between the names, a space string is concatenated in the middle:

fullName = firstName & " " & lastName

(the & operator joins strings; some languages use +). The result "Ada Lovelace" is of type STRING.

Markers reward a correct concatenation that includes the separating space and identifying the result as a string.

Related dot points

Sources & how we know this