TutorChase logo
Login
AQA A-Level Computer Science

2.1.3 Fields and records

Records are used in programming to store data with different types under a single logical structure, ideal for modelling real-world entities like people or products.

What is a record?

A record is a user-defined data structure that allows the grouping of fields—each potentially of a different data type—into one logical unit. This structure is extremely useful when modelling real-world objects where each attribute or field may hold a different type of data.

For example, consider a student. A student’s name is a string, their ID is an integer, and their average grade is a floating-point number. Rather than managing this data using separate variables or multiple arrays, a record allows all of this information to be stored together in one structured and logically grouped form.

Key features of records:

  • A record groups multiple fields together.

  • Each field can be of a different data type (heterogeneous data).

  • Fields are accessed using descriptive names, not indices.

  • A record typically represents a single logical entity such as a student, employee, product, or vehicle.

Real-world context:

Records are used in numerous practical applications:

Take your grades to the next level!

UPGRADING TO PREMIUM UNLOCKS
AI Tutor
AI-powered study assistant
instant feedback and guidance
Predicted Papers
Examiner-style predicted papers
based on recent exam trends
Practice Questions
All exam practice questions
by topic for each subject
Study Notes
All detailed revision notes
written by expert teachers
Cheat Sheets
Quick revision summaries
perfect for last-minute review
Past Papers
Complete collection
of practice and past exam papers
Email
Password
Confirm Password
Already have an account?

Practice Questions

FAQ

Yes, records can store arrays or lists as one of their fields, allowing for even more complex data structures. This approach is especially useful when a field needs to hold multiple values of the same type. For example, a Student record could include a Grades field, which is an array of floating-point numbers representing the student’s test scores. This enables a single record to store both individual details (such as name and ID) and a structured collection of related data (such as all the marks they’ve received). In pseudocode, this could look like: Grades: ARRAY OF Float within the record definition. You can then assign and access elements like student.Grades[0]. Using arrays within records is common in scenarios such as tracking attendance over time, storing a history of transactions, or maintaining a list of preferences for a user. This structure also supports iteration over the internal array, offering powerful functionality when processing grouped data.

Records support abstraction by allowing programmers to encapsulate related data under a single identifier, hiding unnecessary implementation details from other parts of the program. Instead of managing individual variables for each field, a record provides a single, named unit that represents a complete object or entity. This simplifies function and procedure design, as entire records can be passed as parameters rather than multiple separate arguments. For instance, a Procedure DisplayStudent(student: Student) can process all student-related data using just one parameter. This promotes cleaner, more maintainable code. Furthermore, using records enhances modularity because developers can design components that operate on well-defined data structures, making each module more reusable and easier to understand. Changes to the internal structure of the record (e.g. adding a new field) can often be confined to the record definition and the modules that specifically work with it, reducing the risk of introducing errors in unrelated parts of the program.

Records are stored in memory as contiguous blocks, with each field occupying space according to its data type and alignment rules. When a record is declared, the computer allocates enough memory to store all of its fields in the specified order. Unlike primitive variables which are stored individually and accessed directly, records require the program to manage field offsets within the block. For example, if a record has an integer, a boolean, and a float, the system calculates the starting address and then reserves space for each field sequentially. Accessing a field involves calculating the memory offset based on its position in the record structure. This memory layout ensures that all fields are grouped together, making access efficient and data retrieval predictable. However, alignment and padding may be introduced by some systems to match hardware constraints. Despite the extra memory considerations, records offer strong organisation advantages, especially for structured data manipulation.

Whether a record is passed by value or by reference depends on the specific programming language or the rules of the pseudocode being used. In strict AQA pseudocode, this distinction is generally abstracted, but it is important to understand in practical programming terms. Passing by value means a copy of the record is made and given to the procedure, so any changes made within that procedure do not affect the original record. In contrast, passing by reference means the original record is accessed and modified directly, so changes are retained after the procedure finishes. High-level languages like Python or JavaScript generally pass complex structures like records (or objects) by reference, while C allows the choice between value and reference depending on whether you pass the address of the structure. When using pseudocode, assume that unless otherwise stated, records are passed in such a way that allows field access and possible mutation, simulating reference-like behaviour.

Validation and error checking with records involve ensuring that the data assigned to each field is appropriate, complete, and meets any predefined constraints. This typically happens at the time of input, assignment, or just before using the data in operations. For instance, if a Student record contains a Grade field, you may want to validate that the grade is a float between 0 and 100. This validation can be implemented by using conditional statements immediately after input or within setter procedures. Type validation ensures that only the correct data type is assigned (e.g. rejecting a string for an integer field). Range checking is another common technique, especially for numerical fields. Records can also include flags or status fields to indicate whether the data is valid or complete. If an array of records is used, a loop can systematically check each one for issues. Comprehensive validation ensures that your program behaves predictably and avoids logic or runtime errors stemming from corrupted or unexpected data.

Hire a tutor

Please fill out the form and we'll find a tutor for you.

1/2
Your details
Alternatively contact us via
WhatsApp, Phone Call, or Email