Skip to topic
    ← Back to course topics

    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

    1. 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
    1. 1Day 1-2: Master core terminology (formal parameters, actual arguments, signatures, interfaces).
    2. 2Day 3-4: Practice manual execution traces comparing ByVal and ByRef parameter passing using AQA pseudocode.
    3. 3Day 5-6: Review stack frames and explain how passing arrays ByVal vs ByRef impacts call stack memory.
    4. 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)
    Explain

    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.

    State

    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)
    Pitfall: Confusing passing by value with passing by reference when predicting variable states after subroutine execution.
    ❌ Weak Answer (Loses Marks):Passing by value changes the variable outside the subroutine, but passing by reference makes a copy of it.
    Example improved answer:Passing by value creates a local duplicate of the actual parameter value in a new memory address, ensuring modifications inside the subroutine do not alter the caller variable. Passing by reference passes the memory address of the original argument, meaning any operations within the subroutine directly mutate the caller original variable.
    Examiner Tip: Explicitly mention memory addresses or copies. State clearly whether the original variable in the calling routine is modified or remains unchanged.
    Pitfall: Interchanging the formal definitions of 'parameter' and 'argument'.
    ❌ Weak Answer (Loses Marks):They both mean the variables you put inside the brackets of a function.
    Example improved answer:A parameter (formal parameter) is the variable defined in the subroutine signature or declaration. An argument (actual parameter) is the actual data value or variable reference supplied to the subroutine when it is called at runtime.
    Examiner Tip: Use the terms 'formal parameter' for definition and 'actual argument' for invocation to guarantee marks on definitions.
    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. 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. 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. 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. 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. 5.Step 5: Subroutine terminates, discarding local stack variables. Determine final outputs: x remains 10, y has become 35.
    Final Answer: Output: 10, 35. Justification: 'x' is passed by value, so the local modification to 'a' does not affect 'x'. 'y' is passed by reference, so mutating 'b' modifies 'y' in place.

    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. 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. 2.Step 2: Consider the performance/execution time implications of 'ByVal'. Copying 10,000 elements takes clock cycles, introducing processing overhead.
    3. 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.
    Final Answer: 1. Memory efficiency: Passing by reference only transfers a memory address pointer rather than duplicating 10,000 elements on the stack, preventing stack overflow and saving RAM. 2. Execution speed: Avoids the time overhead required by the CPU to read and copy every array element to a new stack frame.
    Active Recall Memory Test
    What is the difference between a parameter and an argument?
    Key Fact: A parameter is the variable identifier in the subroutine definition; an argument is the actual value or variable supplied to the subroutine when it is called.
    What gets passed into the subroutine when a variable is passed ByRef?
    Key Fact: The memory address (or pointer) of the variable.
    Why can passing a large record ByVal cause a runtime error in deep recursion?
    Key Fact: Each recursive call copies the entire record onto a new stack frame, rapidly exhausting available call stack memory and causing a stack overflow.
    Frequently Asked Questions
    What is the difference between passing by value and passing by reference?
    When an argument is passed by value, the subroutine receives a distinct copy of the data, so changes made inside the subroutine have no effect on the original variable. When passed by reference, the subroutine receives the actual memory address of the original variable. Consequently, any changes made to the parameter directly modify the original variable in the caller scope.
    Are parameters always stored on the call stack?
    In conceptual AQA A-Level Computer Science theory, parameters are placed into the subroutine stack frame on the call stack alongside the return address and local variables. In physical modern CPU architectures, calling conventions may optimize execution by passing the first few parameters through CPU registers (such as RCX or RDX) before resorting to the stack for remaining arguments.
    Why would a programmer choose ByVal if ByRef is faster?
    ByVal is safer because it guarantees subroutine independence and avoids unintended side effects. If a subroutine modifies a ByRef parameter by mistake, it corrupts the calling program state. ByVal enforces encapsulation, making modular code easier to debug, test, and maintain.
    How does Python handle parameter passing compared to ByVal and ByRef?
    Python uses a mechanism commonly called 'pass by object reference' or 'call by assignment'. If you pass an immutable object (like an integer, string, or tuple), it behaves like pass by value because the value cannot be mutated in place. If you pass a mutable object (like a list or dictionary), modifications to the object inside the function affect the original object, behaving similarly to pass by reference.