GCSE Computer Science · public explanation

Strings, Arrays and Records

Explore strings, arrays and records for GCSE programming. Follow indexing and data operations, and choose a structure that suits the information stored.

Read the explanation and worked examples, then choose your exam board to continue with activities and practice in your account.

OCR J277On the specificationOCR J277 2.2.3

Apply strings, arrays and records using OCR Exam Reference Language or a studied language only when requested.

AQA 8525 (2027+)On the specificationAQA 8525 (2027+) 3.2.6, 3.2.8

Apply strings, arrays and records in the precise response format printed on the paper.

Choose the structure from the question

A data structure organises related values so a program can select and use the required information. In our worked library, a book label is a string, stock counts are stored in arrays, and a record groups named facts about one book. These structures answer different questions; they are not interchangeable names for a single value.

A string is an ordered sequence of characters, including any stored spaces or punctuation. An array is an indexed collection: an index identifies a position, and the element at that position holds a value. A record uses named fields, such as title, copies and loanable, about one entity. Its fields may have different types. Choose the structure before choosing a position or field.

Library questionStructureSelector
Which character is in the book label?String: BOOK 27A stated character position
How many copies of the second book are at North?One-dimensional stock arrayOne index
How many copies are at a particular branch for a particular book?Two-dimensional stock arrayRow and column indices
Does library policy allow this book to be borrowed?Record describing one bookNamed loanable field

Inspecting and joining strings

A string is an ordered sequence of characters. Length counts characters, including spaces. Position/indexing identifies where a character occurs. A substring, also called a slice, selects a consecutive part. Concatenation joins strings in order.

Always use the indexing and endpoint convention specified in the question. For this example, positions start at zero and substring length means the number of characters to take.

Operation on PORT-27Result
Length7
Character at index 0P
Substring from index 5, length 227
Concatenate BAY- and 27BAY-27

One-dimensional arrays, grids and records

An array stores an ordered collection accessed by index. In the OCR model an array has a fixed length. A two-dimensional array uses two indices, often row then column. Check index bounds: a zero-indexed array of length four has valid indices 0 through 3.

A record groups named fields about one entity. A pupil record could contain a string name, an integer age and a Boolean consent flag. These fields may have different types. A table can be represented as rows of records or a two-dimensional collection, but its rows and columns must retain their meanings.

RowColumn 0: MondayColumn 1: Tuesday
0: Room A1821
1: Room B1720

Read, calculate, then store only the selected element

Use this stock-desk example. North has four integer counts: [8, 13, 5, 10]. Positions start at zero, so index 1 selects the second count, 13. Four delivered copies belong to that book. Read 13, calculate 13 + 4 = 17, then store 17 at index 1. A calculation and an assignment are different events.

After storage the array is [8, 17, 5, 10]. Its four positions have not changed; the last valid index remains 3. An array length counts elements, not total copies: neither 17 nor the sum of the counts is this array's length. OCR uses fixed-length arrays; all arrays in these worked examples also have explicitly fixed dimensions.

Replacing a count with zero keeps that element. For example, removing five copies from the five at index 2 would store zero there, not remove the position or shift the other counts. An assigned zero is different from a value that has not yet been assigned.

EventTemporary calculationStill stored at index 1
Before readingNot calculated13
Read index 1Read value 1313
Calculate 13 + 41713
Store at index 11717

Keep row, column and named field distinct

Continue the library example with North as row 0 and South as row 1. Each of four columns identifies one book. The table below starts after North's delivery but before South's delivery. Indices are row first: row 1, column 0 selects 4; reversing those two valid indices selects North's 17 instead.

A delivery adds six to South's column-2 book. Select row 1, column 2, read 7, calculate 13, and store it at that intersection only. South becomes [4, 11, 13, 9]; North stays [8, 17, 5, 10]. Row 2 does not exist, so reversing [1,2] into [2,1] is invalid, not another way to address the same cell.

The selected book is River Walk. A record can represent its title as String, copies as Integer 13, and loanable as Boolean True. These are named fields of one entity, not adjacent array positions to guess. The loanable flag states a borrowing policy; a later copies update does not automatically recalculate that flag. If a system stores both a grid count and a separate record count, it must explicitly keep them consistent; the two storage locations are not automatically linked.

Branch rowBook column 0Book column 1Book column 2Book column 3
0: North817510
1: South41179

Continue with your exam board

The course combines lesson videos, interactive activities, topic questions and original exam mocks. Sign in to use the learning tools and save your progress; your account’s course access applies.

Independent learning resources. Not endorsed by AQA or OCR. These public introductions complement the full course and the official specification.