📄 Paper 1 · 4.1 Fundamentals of Programming
✓ Free lesson
4.1.1a Data Types, Variables & Constants
AQA 7517 · A-Level Computer Science · ~15 min read
Notes
Video
Slides
Worksheet
Quiz

Data Types

A data type determines what kind of value a variable can hold and what operations can be performed on it. AQA 7517 requires knowledge of the following data types:

Data TypeDescriptionExample
IntegerWhole number, positive or negative, no fractional part42, -17, 0
Real/FloatNumber with a fractional (decimal) part3.14, -0.5, 2.0
BooleanLogical value — either True or False onlyTrue, False
CharacterA single symbol from the character set'A', '7', '!'
StringA sequence of zero or more characters"Hello", "CS Zone"
Date/TimeRepresents a date and/or time value2024-09-01, 14:30:00

Records

A record (or struct in some languages) groups together related items of data that may be of different types under one identifier.

Example — a student record might contain: name (String), age (Integer), isEnrolled (Boolean), grade (Real)

Arrays

An array is an ordered, indexed collection of elements all of the same data type. In AQA A-Level, 1D and 2D arrays are examinable:

  • 1D array: a list — scores[0..4] holds 5 integers indexed 0–4
  • 2D array: a grid — grid[0..2, 0..2] represents a 3×3 matrix

User-Defined Data Types

AQA 7517 requires you to understand that programmers can define their own data types based on the built-in (language-defined) types. This allows modelling of real-world entities more accurately.

Variables

A variable is a named memory location whose value can change during program execution. Variables must be:

  • Declared — the name and type are established before use
  • Assigned — given a value using an assignment statement ( in AQA pseudocode, = in Python)

Variable Declaration in AQA Pseudocode

DECLARE score : INTEGER — declares a variable named score of type INTEGER

score ← 85 — assigns the value 85 to score

Scope of Variables

Local variables are declared inside a subroutine and only exist while that subroutine is executing. They cannot be accessed from outside.

Global variables are declared outside all subroutines and can be accessed from anywhere in the program. They persist for the entire lifetime of the program.

FeatureLocal VariableGlobal Variable
Declared inInside a subroutineOutside all subroutines
Accessible fromOnly within that subroutineAnywhere in the program
LifetimeOnly while subroutine runsWhole program execution
Preferred?✓ Yes — avoids side effectsUse sparingly — risk of unintended changes

Constants

A constant is a named value that cannot be changed during program execution. Once defined, its value is fixed.

In AQA pseudocode: CONSTANT PI ← 3.14159

In Python: by convention, PI = 3.14159 (all caps signals a constant, though Python doesn't enforce immutability)

Advantages of Using Named Constants

  • Readability: TAX_RATE is clearer than 0.20 scattered through code
  • Maintainability: change the value in one place — affects all uses automatically
  • Reduces errors: prevents accidental modification of a fixed value
  • Self-documenting: the name explains what the value represents
Exam tip: Be precise about the difference between a variable (value can change) and a constant (value cannot change). Know why named constants are preferred over magic numbers. For scope: local variables are good practice because they prevent unintended side effects — AQA may ask you to justify using local over global variables for 2–3 marks.
⚠️ Common Mistakes
  • Confusing character (single symbol) with string (sequence of characters) — 'A' is a character, "A" is a string of length 1
  • Saying variables "store data permanently" — variables exist in RAM and are lost when the program ends
  • Forgetting that local variables do NOT persist between subroutine calls — each call creates a fresh copy
  • Thinking Python enforces constants — it does not; ALL-CAPS is just a naming convention
  • Saying constants "cannot be declared" in Python — they can, but Python doesn't prevent you from reassigning them
✅ Notes completed!
Video coming soon

What's covered in this video

  • • All AQA 7517 data types with examples and exam applications
  • • Variable declaration, assignment and scope (local vs global)
  • • Constants — definition, declaration and advantages
  • • Records, arrays and user-defined types
Click slide or press arrow keys to navigate

Worksheet — 4.1.1a Data Types, Variables & Constants

8 questions · instantly marked · AQA 7517 standard

Q1State the data type most suitable for storing a student's percentage score in an exam.[1]
✅ Mark scheme
Mark scheme
Real/Float [1] — accept Integer [1] with justification that whole number % is acceptable; do not accept String.
Q2Explain the difference between a variable and a constant, giving one example of each.[4]
✅ Mark scheme
Mark scheme
A variable is a named memory location whose value can change during execution [1]; e.g. score, count, name [1]. A constant is a named value that cannot be changed once set [1]; e.g. PI, MAX_ATTEMPTS, TAX_RATE [1].
Q3State three advantages of using named constants rather than literal values (magic numbers) in a program.[3]
✅ Mark scheme
Mark scheme
Any three: improved readability — name is self-documenting [1]; easier maintenance — change value in one place [1]; reduces risk of errors from inconsistent values [1]; prevents accidental modification [1].
Q4Explain the difference between a local variable and a global variable. Justify why local variables are generally considered better practice.[4]
✅ Mark scheme
Mark scheme
Local variable declared inside a subroutine and only accessible within it [1]; global variable declared outside subroutines and accessible throughout the program [1]. Local variables are better practice because they cannot be accidentally changed by other parts of the program [1]; this prevents side effects and makes programs easier to debug and maintain [1].
Q5A program uses the value 0.2 (the VAT rate) in multiple calculations. A programmer writes:
CONSTANT VAT_RATE ← 0.2
Explain why this is better than using 0.2 directly in each calculation.
[2]
✅ Mark scheme
Mark scheme
If the VAT rate changes, only one line needs updating [1]; the name VAT_RATE makes the code self-documenting/easier to understand [1].
Q6State the most appropriate data type for each of the following: (a) a person's name, (b) the number of items in stock, (c) whether a user is logged in, (d) the price of an item.[4]
✅ Mark scheme
Mark scheme
(a) String [1]; (b) Integer [1]; (c) Boolean [1]; (d) Real/Float [1].
Q7What is a record data type? Give an example of how a record could be used to model a product in an online shop.[3]
✅ Mark scheme
Mark scheme
A record groups related data items of different types under one identifier [1]; e.g. a Product record could contain: productName (String) [½], price (Real) [½], stockLevel (Integer) [½], isAvailable (Boolean) [½] — award [1] for a sensible record with at least two different types correctly stated and [1] for correctly applying it to the online shop scenario.
Q8A programmer declares: DECLARE grid : ARRAY[0..2, 0..2] OF INTEGER. State the dimensions of this array and explain what grid[1,2] refers to.[2]
✅ Mark scheme
Mark scheme
It is a 3×3 (3 rows, 3 columns) 2D array of integers [1]; grid[1,2] refers to the element in row index 1, column index 2 (second row, third column) [1].
Topic Quiz
Question 1 of 15
You scored
out of 15
Card 1 of 12
Click to reveal definition
🎉
All cards reviewed!
TermDefinition
🎯

Mini Test — 4.1.1a Data Types, Variables & Constants

10 questions · 10 marks · 10 minutes

First lesson
1 of 70 · AQA 7517
4.1.1b Sequence, Selection & Iteration →