Pearson Edexcel · GCSE · Computer Science

    Course version: Pearson-GCSE-Computer-Science · Version from Mar 2026

    Subprograms

    Subprograms are the building blocks of efficient, professional code. By breaking large problems into smaller functions and procedures, you make your programs easier to write, test, and maintain—a core skill that examiners test heavily in both theory and practical papers.

    • 4 min read
    • 3 worked examples
    • 5 practice questions
    • 6 key terms

    Study Notes

    Overview

    Subprograms are self-contained blocks of code designed to perform specific tasks within a larger program. Think of them as mini-programs inside your main program. In GCSE Computer Science, understanding subprograms is critical because they form the foundation of modular programming and decomposition—the process of breaking down a complex problem into smaller, manageable parts.

    This topic is heavily tested because it shows examiners that you can write structured, professional code rather than long, repetitive scripts. You will need to know the difference between functions and procedures, how to pass data using parameters, and how variable scope (local vs global) affects your code.

    Key Concepts

    Concept 1: Procedures vs Functions

    The most fundamental distinction in this topic is between a procedure and a function.

    • Procedure: A subprogram that performs a specific task but does not return a value to the calling code. It simply executes its instructions and finishes.
    • Function: A subprogram that performs a task and returns a value to the calling code using a return statement.

    **Why does this matter?**Examiners will specifically ask you to write either a function or a procedure. If they ask for a function and you omit the return statement, you will lose marks. If they ask for a procedure and you include a return statement, you will lose marks.

    Functions vs ProceduresOpen full-size image (opens in a new tab)

    Concept 2: Parameters and Arguments

    To make subprograms reusable, we need to be able to give them data to work with. We do this using parameters and arguments.

    • Parameter: The variable name declared in the subprogram definition (e.g., def greet(name): where name is the parameter).
    • Argument: The actual value passed into the subprogram when it is called (e.g., greet("Alice") where "Alice" is the argument).

    **Why use parameters?**Parameters allow a single subprogram to process different data each time it is called, making the code highly reusable. Without parameters, subprograms would only be able to perform exactly the same operation on exactly the same data every time.

    Concept 3: Local vs Global Scope

    Scope refers to the areas of a program where a variable can be accessed or modified.

    • Local Variable: Declared inside a subprogram. It only exists while that subprogram is running and is destroyed when the subprogram finishes. It cannot be accessed from outside the subprogram.
    • Global Variable: Declared outside any subprogram (usually at the top of the program). It can be accessed and modified from anywhere in the program.

    **Best Practice for Exams:**Examiners prefer you to use local variables and pass data via parameters rather than relying on global variables. Overusing global variables makes code harder to debug and maintain, as any part of the program could change the variable's value unexpectedly.

    Local vs Global ScopeOpen full-size image (opens in a new tab)

    Practical Applications

    In real-world software development, nobody writes a program as one massive script. Video games, operating systems, and web applications are all built using thousands of interconnected subprograms.

    For your exam, you will often be asked to trace the execution of code containing subprograms or to write your own subprograms to solve specific problems, such as validating user input or calculating a total score.

    Check what you remember

    Read the wording for your board, then hide it and explain Subprogram in your own words. Rough notes are fine. This is a self-check, with no mark or grade.

    Reference: Pearson Edexcel

    A self-contained block of code designed to perform a specific task within a larger program.
    Pearson Edexcel

    Interactive Diagrams

    2 interactive diagrams to visualise key concepts

    Conceptual Flow Outline

    Main Program Start
    ➔Call function calculate(5, 10)
    Call function calculate(5, 10)
    ➔Subprogram: calculate(x, y)
    Subprogram: calculate(x, y)
    ➔result = x + y
    result = x + y
    ➔return result (15)
    Main Program receives 15

    Flow of execution when calling a function

    Conceptual Flow Outline

    Main Program Start
    ➔Call procedure display_menu()
    Call procedure display_menu()
    ➔Subprogram: display_menu()
    Subprogram: display_menu()
    ➔print('1. Play')
    print('1. Play')
    ➔print('2. Quit')
    Main Program continues

    Flow of execution when calling a procedure

    Worked Examples

    3 worked examples — open one to explore the question and available guidance.

    Practice Questions

    Try the question, then reveal an answer plan or example response

    Q1

    State one advantage of using subprograms in a large software project. (1 mark)

    1 mark
    foundation

    Hint: Think about what happens if you need to use the same code multiple times.

    Q2

    A programmer has written a procedure called check_password. It checks if a password is valid, but the main program needs to know if the password passed or failed the check. Explain why check_password should be changed to a function. (2 marks)

    2 marks
    standard

    Hint: What is the defining feature of a function that a procedure lacks?

    Q3

    Write a procedure called draw_box that takes two parameters: width and height. The procedure should output a box made of asterisks (*) based on the dimensions provided. You may write in pseudocode or a high-level language. (5 marks)

    5 marks
    challenging

    Hint: You will need nested loops: an outer loop for the height (rows) and an inner loop for the width (columns).

    Q4

    Explain why it is considered good programming practice to use local variables rather than global variables where possible. (3 marks)

    3 marks
    challenging

    Hint: Think about what happens if multiple subprograms try to change the same global variable.

    Q5

    Look at the following Python code:
    python
    score = 10
    def add_bonus(bonus):
    score = score + bonus
    return score

    final = add_bonus(5)
    print(final)

    Identify the scope error in this code and explain how to fix it. (3 marks)

    3 marks
    standard

    Hint: Look at how the subprogram is trying to use the variable score.

    Ready to test yourself interactively?

    Active recall beats reading alone. Answer questions on Subprograms with instant AI scoring and mark scheme guidance.

    Start interactive practice

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge

    Exam technique

    How to turn what you know into marks

    How to approach the question

    Always highlight the command word and the required subprogram type (function or procedure). If it says 'function', immediately write 'return' at the bottom of your answer space so you don't forget it.

    How to structure your answer

    For coding questions: Define header -> Write logic -> Return (if function). For written questions: State the fact -> Use 'because' -> Link to the scenario.

    Timing

    Approximately 1 minute per mark. A 4-mark coding question should take 4-5 minutes.

    Common pitfalls

    • Using print() instead of return in a function. Examiners will penalise this heavily.
    • Trying to access a local variable from the main program. This shows a fundamental misunderstanding of scope.

    What the command words want

    Write
    Produce syntactically correct code or clear pseudocode.
    Compare
    Identify similarities AND differences - use comparative language.
    Explain
    Say HOW or WHY - use 'because' to link cause and effect.
    Describe
    Say what happens or what something is like - use correct terminology.
    Evaluate
    Consider both sides, use evidence, make a judgement.
    State/Give
    Brief factual answer - 1-2 words or a short phrase.
    Watch or listen (optional)
    🎙 Podcast Episode
    Subprograms
    0:00-0:00

    Test your understanding of Subprograms

    Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.

    Take topic quiz

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge

    More Computer Science Study Guides

    View all

    Algorithms

    Pearson Edexcel
    GCSE

    Master the logic behind every computer program. This topic covers how to design, trace, and evaluate algorithms using sequence, selection, and iteration, plus the essential searching and sorting techniques you'll need for your exam.

    Binary

    Pearson Edexcel
    GCSE

    Mastering binary is essential for understanding how computers store and process all data. This topic covers converting between number bases, performing binary arithmetic, understanding shifts, and recognizing overflow — key skills that frequently appear in exams and form the foundation of computer science.

    Constructs

    Pearson Edexcel
    GCSE

    Master the fundamental building blocks of all software: Sequence, Selection, and Iteration. This topic is the core of Computer Science and tests your ability to think like a real programmer, enabling you to read, trace, and write code confidently for the exam.

    Cybersecurity

    Pearson Edexcel
    GCSE

    Master the critical threats to digital systems and the methods used to protect them. This high-yield GCSE Computer Science topic explores malware, social engineering, and the technical defences essential for earning top marks.

    Data

    Pearson Edexcel
    GCSE

    Master the language of computers. This topic covers how binary underpins everything from text and images to sound and data compression, ensuring you can secure crucial calculation marks in your exam.

    Data storage and compression

    Pearson Edexcel
    GCSE

    Master the fundamentals of binary data storage and the critical importance of compression. This topic is calculation-heavy and frequently tested, requiring you to confidently convert between binary units and understand the trade-offs between lossless and lossy compression methods.