📄 Paper 1 · 4.1 Fundamentals of Programming
⭐ Pro
4.1.1f Subroutines, Parameters & Returning Values
AQA 7517 · A-Level Computer Science · ~18 min read

Subroutines

A subroutine is a named block of code that performs a specific task. It can be called (invoked) from any part of the program, allowing code reuse and modular design.

AQA 7517 recognises two types of subroutine:

TypeDescriptionReturns a value?
ProcedurePerforms a task without returning a value; used for its side effects (e.g. printing output)No
FunctionPerforms a task AND returns a value back to the callerYes

Defining and Calling Subroutines in AQA Pseudocode

Procedure (no return value)

PROCEDURE greet(name : STRING)
    OUTPUT "Hello, " & name
ENDPROCEDURE

// Calling the procedure:
CALL greet("Ada")

Function (with return value)

FUNCTION square(n : INTEGER) RETURNS INTEGER
    RETURN n * n
ENDFUNCTION

// Calling the function:
result ← square(5)   // result = 25

Parameters and Arguments

Parameters are the variables listed in the subroutine definition — they receive values when the subroutine is called.

Arguments are the actual values passed to a subroutine when it is called.

Example: in PROCEDURE greet(name : STRING), name is the parameter. When we call CALL greet("Ada"), "Ada" is the argument.

Passing by Value vs. Passing by Reference

MethodDescriptionOriginal variable affected?
By valueA copy of the argument is passed — changes inside the subroutine do NOT affect the originalNo
By referenceThe memory address of the variable is passed — changes inside DO affect the originalYes

In AQA A-Level, passing by value is the default. Passing by reference requires explicit marking (BYREF keyword or indicated in the question).

Multiple Parameters

FUNCTION add(a : INTEGER, b : INTEGER) RETURNS INTEGER
    RETURN a + b
ENDFUNCTION

total ← add(3, 7)   // total = 10

Benefits of Using Subroutines

  • Code reuse — write once, call many times; no code duplication
  • Modularity — break complex problems into smaller, manageable parts (decomposition)
  • Readability — well-named subroutines make code self-documenting
  • Easier debugging — test each subroutine in isolation
  • Easier maintenance — change a subroutine in one place to update all callers
  • Abstraction — callers don't need to know the implementation details

Scope in Subroutines

Parameters and local variables inside a subroutine have local scope — they exist only within the subroutine and are destroyed when it returns. Global variables declared outside subroutines are accessible everywhere.

Exam tip: Know the AQA keywords precisely: PROCEDURE … ENDPROCEDURE for procedures; FUNCTION … RETURNS type … ENDFUNCTION for functions; RETURN to return a value; CALL to invoke a procedure. Know the difference between passing by value (default — copy) and passing by reference (affects original). This is commonly tested at A-Level for 3–6 marks.
⚠️ Common Mistakes
  • Confusing procedures and functions — procedures don't return values; functions do (and must use RETURN)
  • Forgetting RETURN in a function — in AQA, you MUST use RETURN to specify what the function returns
  • Using CALL with a function — you CALL procedures; you use functions by assigning their return value
  • Confusing parameters (definition) with arguments (call)
  • Thinking pass by value modifies the original — it does NOT; only pass by reference does
Click through the slides at your own pace. Use arrow keys or click to advance.
Click slide or press arrow keys to navigate

Worksheet — 4.1.1f Subroutines, Parameters & Returning Values

8 questions · instantly marked · AQA 7517 standard

Q1State the difference between a procedure and a function in AQA pseudocode.[2]
✅ Mark scheme
Mark scheme
A procedure performs a task without returning a value [1]; a function performs a task AND returns a value to the caller [1].
Q2Write an AQA pseudocode FUNCTION called cube that takes an integer parameter n and returns n cubed.[3]
✅ Mark scheme
Mark scheme
FUNCTION cube(n : INTEGER) RETURNS INTEGER [1]; RETURN n * n * n (or n^3) [1]; ENDFUNCTION [1].
Q3Explain the difference between a parameter and an argument, using an example.[2]
✅ Mark scheme
Mark scheme
A parameter is a variable listed in the subroutine definition (e.g. n in FUNCTION square(n)) [1]; an argument is the actual value passed when calling the subroutine (e.g. 5 in square(5)) [1].
Q4Explain passing by value and passing by reference. State which method is the default in AQA pseudocode.[4]
✅ Mark scheme
Mark scheme
Passing by value sends a copy of the value — changes inside the subroutine do not affect the original variable [1]; passing by reference sends the memory address — changes inside DO affect the original [1]; the default in AQA pseudocode is passing by value [1]; passing by reference is used for efficiency with large data or when the subroutine must modify the caller's variable [1].
Q5Give four benefits of using subroutines in a large program.[4]
✅ Mark scheme
Mark scheme
Any four: code reuse — write once, call many times [1]; modularity / decomposition into smaller tasks [1]; improved readability / self-documenting [1]; easier debugging — test each part in isolation [1]; easier maintenance — change in one place [1]; abstraction — caller doesn't need to know implementation [1].
Q6Write a PROCEDURE called printStars that takes an integer parameter n and outputs n asterisks on one line.[3]
✅ Mark scheme
Mark scheme
PROCEDURE printStars(n : INTEGER) [1]; FOR i ← 1 TO n; OUTPUT "*" (or equivalent loop) [1]; ENDPROCEDURE [1]. Award [2] for correct logic with minor AQA pseudocode deviations.
Q7A function max2 takes two integers a and b and returns the larger. Write this in AQA pseudocode.[4]
✅ Mark scheme
Mark scheme
FUNCTION max2(a : INTEGER, b : INTEGER) RETURNS INTEGER [1]; IF a > b THEN RETURN a [1]; ELSE RETURN b [1]; ENDIF; ENDFUNCTION [1].
Q8A programmer has a variable total : INTEGER and calls a procedure that increments it. Explain whether passing by value or by reference is needed, and why.[2]
✅ Mark scheme
Mark scheme
Passing by reference is needed [1] because the procedure must modify the caller's variable — passing by value would only modify a local copy, leaving the original total unchanged [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 — Subroutines

10 questions · 10 minutes

← 4.1.1e Exception Handling
6 of 70 · AQA 7517
4.1.1g Stack Frames & Recursion →