Study Guide

Procedures, Functions and Parameters

Computer ScienceΒ· 15 min read

1. Core Distinction: Procedures vs Functionsβ˜…β˜…β˜†β˜†β˜†β± 4 min

Modular programming splits large, complex programs into smaller, reusable blocks called subroutines. This makes code easier to test, debug, and reuse across multiple parts of a program. There are two core types of subroutines in CIE A-Level Computer Science.

πŸ“˜ Definition

Procedure

A subroutine that performs an action but does not return any value to the calling code.

πŸ“˜ Definition

Function

A subroutine that performs a calculation and returns exactly one value to the calling code.

πŸ“ Worked Example

Write pseudocode for a procedure that prints a greeting, and a function that calculates the area of a circle.

  1. 1

    First, declare the procedure (no return value):

  2. 2
    PROCEDURE printGreeting(name: STRING)
        OUTPUT "Hello, " + name + "!"
    ENDPROCEDURE
    
  3. 3

    Next, declare the function (specify return type and return a value):

  4. 4
    FUNCTION calculateArea(radius: REAL) RETURN REAL
        CONSTANT PI = 3.14159
        area = PI * radius * radius
        RETURN area
    ENDFUNCTION
    
  5. 5

    When called, the procedure directly produces output, while the function returns a value that can be stored: myArea = calculateArea(5) stores the result in myArea.

2. Formal vs Actual Parametersβ˜…β˜…β˜†β˜†β˜†β± 3 min

Parameters are inputs passed to a subroutine to make it reusable for different values. CIE exams regularly test the distinction between formal and actual parameters, which is a common 1-2 mark theory question.

πŸ“˜ Definition

Formal Parameter

A placeholder variable declared in the subroutine definition that holds the input while the subroutine runs.

Example:

In FUNCTION calculateArea(radius: REAL), radius is the formal parameter.

πŸ“˜ Definition

Actual Parameter

The concrete value or variable passed into the subroutine when it is called.

Example:

In myArea = calculateArea(5), 5 is the actual parameter.

πŸ“ Worked Example

Identify formal and actual parameters in: PROCEDURE addScore(studentID: INTEGER, newScore: INTEGER) ... addScore(currentStudent, 95)

  1. 1

    Formal parameters are found in the subroutine definition: studentID and newScore.

  2. 2

    Actual parameters are passed when calling the subroutine: currentStudent (the variable holding the actual ID) and 95 (the literal score value).

3. Parameter Passing: By Value vs By Referenceβ˜…β˜…β˜…β˜†β˜†β± 5 min

This is one of the most frequently tested concepts in CIE 9618 theory exams, appearing in almost every paper 1. The core difference is how changes to the parameter inside the subroutine affect the original variable.

πŸ“˜ Definition

Pass by Value

A copy of the actual parameter's value is created for the subroutine to use. Changes to the formal parameter do not affect the original variable in calling code.

πŸ“˜ Definition

Pass by Reference

A reference (memory address) of the original actual parameter is passed. Changes to the formal parameter modify the original variable in calling code.

πŸ“ Worked Example

Predict the output of the code below for both passing methods:

DECLARE y : INTEGER
y = 10
PROCEDURE changeValue(x : INTEGER)
    x = x * 2
ENDPROCEDURE
CALL changeValue(y)
OUTPUT y
  1. 1

    If passed by value: A copy of y = 10 is assigned to x. Changing x to 20 only modifies the copy. Output is 10.

  2. 2

    If passed by reference: x points to the same memory as y. Changing x to 20 updates the original value. Output is 20.

4. Return Values and Use Casesβ˜…β˜…β˜…β˜†β˜†β± 3 min

βœ“ Quick check

Test your understanding so far:

  1. Which of the following is a defining feature of a function?

    • It can never take parameters

    • It always returns a value to calling code

    • It can only use pass by reference

    • It cannot be reused

    Reveal answer
    1 β€”

    Correct! Functions are defined by returning a value, unlike procedures.

  2. If you modify a pass by value parameter inside a subroutine, what happens to the original variable?

    • The original variable is modified

    • Only the copy of the parameter is modified

    • The program throws an error

    • The actual parameter changes but the formal does not

    Reveal answer
    1 β€”

    Correct! Pass by value passes a copy, so only the copy is changed.

πŸ“ Worked Example

Write a subroutine to swap two integers, what parameter passing do you need?

  1. 1

    We need to modify the original two variables, so we use a procedure with both parameters passed by reference (marked REF in CIE pseudocode):

  2. 2
    PROCEDURE swap(a: INTEGER REF, b: INTEGER REF)
        temp = a
        a = b
        b = temp
    ENDPROCEDURE
    
  3. 3

    If we passed by value, the original variables would not change, so the swap would not work. If we needed only one value returned, we would use a function instead.

5. Common Pitfalls

Wrong move:

Treating a procedure like a function and assigning its output to a variable

Why:

Procedures do not return values, so this causes syntax/runtime errors and loses marks in practical exams

Correct move:

Use a function if you need to get a value back from the subroutine, only use procedures for actions with no return

Wrong move:

Confusing pass by value and pass by reference when predicting output

Why:

Exams intentionally test this distinction, and it is the most common source of lost marks in code tracing questions

Correct move:

Remember: Pass by Value changes the Value (copy), Pass by Reference changes the Original (reference)

Wrong move:

Mixing up formal and actual parameter names in exam answers

Why:

CIE mark schemes require correct naming of parameter types to award marks

Correct move:

Remember: Formal = Definition (F = Form = Definition), Actual = Call (A = Actual = Call)

Wrong move:

Trying to return multiple values from a single CIE pseudocode function

Why:

CIE A-Level pseudocode only allows one return value per function, so this is not accepted

Correct move:

If you need to modify multiple values, use a procedure with pass by reference parameters instead

6. Quick Reference Cheatsheet

Concept

Key Feature

Exam Note

Procedure

No return value, performs action

Use PROCEDURE keyword, don't assign result

Function

Returns one value, for calculations

Always include a RETURN statement

Formal Parameter

Placeholder in subroutine definition

Found in the subroutine declaration

Actual Parameter

Value/variable passed at call

Found when you invoke the subroutine

Pass by Value

Copy passed, original unchanged

No side effects on calling variables

Pass by Reference

Address passed, original modified

Required for swapping or multiple changes

When this came up on past exams

AI-estimated based on syllabus patterns β€” cross-check with official past papers for accuracy. Use only as revision-focus signals.

  • 2022 Β· 12

    Parameter passing type comparison

  • 2023 Β· 11

    Procedure vs function distinction

Going deeper

What's Next

Procedures, functions, and parameters are the foundation of all modular programming, which is core to both CIE 9618 Paper 1 (theory) and Paper 2 (practical) assessments. Mastering parameter passing is critical for tracing code output in theory questions and writing clean, working programs for your practical exam. These concepts are used constantly in every advanced programming topic you will study next, from recursion to object-oriented programming. Building a solid understanding now will make learning more complex topics much easier.