Parameters of subroutines — AQA A-Level Computer Science
Parameters are special variables defined in a subroutine header that receive values or references, known as arguments, passed during an execution call. In AQA A-Level Computer Science, mastering how data is passed by value or by reference is fundamental to procedural modularity, variable scope, and stack frame memory management.
Parameters of subroutines explained
Parameters are variables listed in a subroutine's definition that receive values when the subroutine is called.
Read the full explanation
The values supplied at the call are called arguments. Parameters pass data into a subroutine so that it can work on different values each time it runs, without needing separate code for each case. For example, a subroutine defined as calculateArea(width, height) receives its two parameters when it is called as calculateArea(5, 3), so width takes the value 5 and height takes the value 3 inside the subroutine. Where a subroutine needs to send a result back, it can return a value to the caller. Parameters therefore let a single subroutine process data passed to it and produce output, which supports reuse and keeps data handling explicit and controlled.
Your focus
- Be able to describe the use of parameters to pass data within programs.
Parameters of subroutines exam tips
Topic Overview
Subroutines (functions and procedures) rely on parameters to receive data and execute modular tasks across an application. In AQA A-Level Computer Science, understanding subroutine interfaces involves distinguishing between formal parameters declared in subroutine signatures and actual arguments supplied during invocation.
This topic directly links to computer architecture and memory management, specifically how the call stack allocates stack frames for parameters, return addresses, and local variables. It also forms the foundation of procedural programming, interface abstraction, and defensive programming against unintended side effects.
Key Concepts
- →Formal parameters versus actual arguments: formal parameters are defined in subroutine headers, while actual arguments are values/variables passed during execution.
- →Pass by value (ByVal): a copy of the actual argument value is passed to the subroutine's local parameter; changes inside the subroutine do not alter the original caller data.
- →Pass by reference (ByRef): the memory address of the argument is passed; operations directly mutate the caller original data.
- →Call stack integration: parameters are pushed onto the call stack within a stack frame along with return addresses and local variables upon subroutine invocation.
Marking Points
- Explains that parameters are named variables in the subroutine definition that receive data at the point of call.
- Distinguishes parameters, which are the names in the definition, from arguments, which are the values supplied in the call.
- Explains that the same subroutine can process different data by being called with different arguments.
- Explains that a subroutine can return a value to the calling part of the program.
Examiner Tips
- 💡Use a short example such as a subroutine with two parameters and a call that supplies two arguments, then trace the values.
- 💡State both the direction of data flow and the purpose, for example data is passed in so the subroutine can work on different values.
- 💡Keep parameters and arguments distinct in every answer.
- 💡Always state what happens to the original variable in memory when asked to explain ByVal vs ByRef in exam questions.
- 💡When tracing pseudocode, draw a quick memory box trace showing which variable names point to the same memory location to avoid miscalculating values after execution.
- 💡Use accurate terminology such as 'stack frame', 'memory address/pointer', and 'local copy' to secure technical AO1 marks.
Common Mistakes
- Confuses parameters and arguments by using the terms interchangeably; parameters are the names in the definition and arguments are the values passed in the call.
- States that parameters are global variables; parameters are local to the subroutine that defines them.
- Describes parameters without explaining that they carry data into the subroutine, so the reason for using them is missing.
- Believing 'ByVal' protects global variables from all changes: While ByVal protects the passed argument variable itself, any global variables referenced directly inside the subroutine can still be modified.
- Assuming functions only use ByVal and procedures only use ByRef: Both functions and procedures can receive parameters via either mechanism depending on language implementation and design choices.
- Confusing return values with ByRef updates: A return value transfers an explicit single value back via the evaluation of a function, whereas ByRef mutates variables across their existing references.
Revision Plan
- 1Day 1-2: Master core terminology (formal parameters, actual arguments, signatures, interfaces).
- 2Day 3-4: Practice manual execution traces comparing ByVal and ByRef parameter passing using AQA pseudocode.
- 3Day 5-6: Review stack frames and explain how passing arrays ByVal vs ByRef impacts call stack memory.
- 4Day 7: Complete past exam questions focusing on code analysis and short-answer explanation questions.
Exam Question Types
- 📋Code tracing: Given a pseudocode snippet with ByVal and ByRef parameters, determine the printed variable values at the end of the program.
- 📋Comparison definitions: 2 to 4 mark questions asking for precise differences between passing by value and passing by reference.
- 📋Structured evaluations: Discussing the trade-offs of using ByRef versus ByVal when handling complex data structures in resource-constrained systems.
Command Word Expectations (AQA)
Requires a cause-and-effect answer. When explaining ByVal or ByRef, state the technical mechanism (e.g., copying value vs passing address) and the resulting impact on the original variable.
Requires a brief, precise answer without detailed expansion, such as identifying variable values from a code trace or naming a parameter type.
How Students Lose Marks (Examiner Pitfalls)
Step-by-Step Worked Solutions
Question: A program contains the following subroutine: SUBROUTINE Process(ByVal a : INTEGER, ByRef b : INTEGER) a = a + 5 b = b + a ENDSUBROUTINE The main program executes: x = 10 y = 20 Process(x, y) OUTPUT x, y State the output produced by the program and justify your answer with reference to parameter passing mechanisms.
- 1.Step 1: Identify how each argument is passed. Variable x is passed ByVal to parameter a; variable y is passed ByRef to parameter b.
- 2.Step 2: Trace local executions inside 'Process'. Parameter 'a' receives a copy of x (10), and 'b' points directly to the memory address of y (20).
- 3.Step 3: Execute line 1: a = 10 + 5 = 15. Because 'a' is ByVal, this modification is local to the subroutine and leaves x as 10.
- 4.Step 4: Execute line 2: b = 20 + 15 = 35. Because 'b' is ByRef, modifying 'b' alters the actual variable y in the calling program.
- 5.Step 5: Subroutine terminates, discarding local stack variables. Determine final outputs: x remains 10, y has become 35.
Question: Explain two advantages of passing a large compound data structure (such as a 10,000-element array) by reference rather than by value in an algorithm.
- 1.Step 1: Consider the memory implications of 'ByVal'. Passing by value creates a duplicate copy of all 10,000 elements on the call stack, requiring significant additional memory space.
- 2.Step 2: Consider the performance/execution time implications of 'ByVal'. Copying 10,000 elements takes clock cycles, introducing processing overhead.
- 3.Step 3: Formulate points around 'ByRef'. Passing by reference passes only a pointer/memory address (typically 4 or 8 bytes), saving memory and executing faster because no duplicate data is copied.