Pearson Edexcel · GCSE · Computer Science

    Course version: 1CP2 · Version from Sept 2020

    Be able to write functions that may or may not take parameters but must…

    Full specification wording

    Subprograms: 6.6.2 be able to write functions that may or may not take parameters but must return values, and procedures that may or may not take parameters but do not return values

    A subprogram is a named block of code you can call repeatedly.

    Checked against the Pearson Edexcel 1CP2 specification (opens in a new tab) on .

    • Point 2 of 3
    • 4 key terms

    Study notes

    From the checked teaching notes for this specification point.

    The idea

    A subprogram is a named block of code you can call repeatedly. A function must return a value to the caller, so the call can be used inside an expression, for example total = add(3, 4). A procedure does not return a value; it is called as a statement, for example printMenu(). Either kind may take parameters or none: a function with no parameters might return a random number, and a procedure with parameters might display a formatted name. Decide the kind by asking whether a value must come back. If yes, write a function with a return statement that supplies a value of the expected type on every path. If no, write a procedure and pass any data it needs as parameters. Parameters are the named inputs in the definition; arguments are the actual values supplied at the call.

    What earns the marks

    • A function must return a value, so its call can be used where a value is required, such as in an assignment or expression.
    • A procedure does not return a value and is called as a standalone statement.
    • Parameters are declared in the subprogram definition; arguments are the values passed when it is called.
    • A function needs a return statement that provides a value on every possible path.
    • Choosing function or procedure depends on whether the caller needs a value back.

    Common mistakes and how to put them right

    • Thinking every subprogram that has a name and brackets is a function.

      Put it right: A procedure is identified by not returning a value, not by its syntax alone.

    • Believing a function cannot take parameters.

      Put it right: Functions may take none, one or several parameters and still must return a value.

    • Assuming a procedure can never receive data.

      Put it right: Procedures may take parameters even though they return nothing.

    • Writing a function that prints a result but never returns it.

      Put it right: Printing is output, not returning a value to the caller.

    Exam tips

    • For each subprogram in a question, state whether a value must be returned and justify the choice from how the call is used.
    • Check that every path through a function body reaches a return statement with a suitable value.
    • When tracing code, follow the arguments into the parameters and the returned value back to the call site.

    Try the lesson

    The start of the Subprograms: 6.6.2 be able to write functions that may or may not take parameters but must return values, and procedures that may or may not take parameters but do not return values lesson, made from checked teaching notes for this specification point.

    Have a go first

    A programmer is writing a subprogram in pseudocode that receives a student's score as an integer, determines whether the score is 50 or above, and sends a Boolean value (TRUE or FALSE) back to the calling statement. Which subprogram header correctly follows standard conventions?

    Listen

    A subprogram is a named block of code you can call repeatedly. A function must return a value to the caller, so the call can be used inside an expression, for example total = add(3, 4). A procedure does not return a value; it is called as a statement, for example printMenu(). Either kind may take parameters or none: a function with no parameters might return a random number, and a procedure with parameters might display a formatted name. Decide the kind by asking whether a value must come back. If yes, write a function with a return statement that supplies a value of the expected type on every path. If no, write a procedure and pass any data it needs as parameters. Parameters are the named inputs in the definition; arguments are the actual values supplied at the call. A strong answer earns marks for these points. A function must return a value, so its call can be used where a value is required, such as in an assignment or expression. A procedure does not return a value and is called as a standalone statement. Parameters are declared in the subprogram definition; arguments are the values passed when it is called. A function needs a return statement that provides a value on every possible path. Exam tip: For each subprogram in a question, state whether a value must be returned and justify the choice from how the call is used.

    See it

    A top-down flowchart starting from a node labelled Subprogram, which leads to a decision node asking whether the caller needs a value back. The Yes branch leads to a node labelled Write a function, which branches to two nodes: Must return a value, leading to a node saying a return statement supplies a value on every path, and May take parameters or none. The No branch leads to a node labelled Write a procedure, which branches to two nodes: Does not return a value, leading to a node saying it is called as a standalone statement, and May take parameters or none.
    It shows how to decide between writing a function and a procedure, based on whether the caller needs a value back, and the key features of each.

    Key words

    Say what each word means before you turn the card.

    Function

    Try answering aloud or in your head before turning the card.

    Procedure

    Try answering aloud or in your head before turning the card.

    Parameters

    Try answering aloud or in your head before turning the card.

    Arguments

    Try answering aloud or in your head before turning the card.

    See every definition
    Function
    A subprogram that must return a value to the caller, so its call can be used inside an expression.
    Procedure
    A subprogram that does not return a value and is called as a standalone statement.
    Parameters
    The named inputs declared in the subprogram definition, which may be zero or more for both functions and procedures.
    Arguments
    The actual values supplied at the call, which are passed into the parameters.

    There is more to this lesson

    The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.

    Carry on with the full lesson

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

    Test your understanding of Subprograms: 6.6.2 be able to write functions that may or may not take parameters but must return values, and procedures that may or may not take parameters but do not return values

    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