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.
Procedure
A subroutine that performs an action but does not return any value to the calling code.
Function
A subroutine that performs a calculation and returns exactly one value to the calling code.
Write pseudocode for a procedure that prints a greeting, and a function that calculates the area of a circle.
- 1
First, declare the procedure (no return value):
- 2
PROCEDURE printGreeting(name: STRING) OUTPUT "Hello, " + name + "!" ENDPROCEDURE - 3
Next, declare the function (specify return type and return a value):
- 4
FUNCTION calculateArea(radius: REAL) RETURN REAL CONSTANT PI = 3.14159 area = PI * radius * radius RETURN area ENDFUNCTION - 5
When called, the procedure directly produces output, while the function returns a value that can be stored:
myArea = calculateArea(5)stores the result inmyArea.
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.
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.
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.
Identify formal and actual parameters in: PROCEDURE addScore(studentID: INTEGER, newScore: INTEGER) ... addScore(currentStudent, 95)
- 1
Formal parameters are found in the subroutine definition:
studentIDandnewScore. - 2
Actual parameters are passed when calling the subroutine:
currentStudent(the variable holding the actual ID) and95(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.
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.
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.
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
If passed by value: A copy of
y = 10is assigned tox. Changingxto 20 only modifies the copy. Output is10. - 2
If passed by reference:
xpoints to the same memory asy. Changingxto 20 updates the original value. Output is20.
4. Return Values and Use Casesβ β β βββ± 3 min
Test your understanding so far:
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.
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.
Write a subroutine to swap two integers, what parameter passing do you need?
- 1
We need to modify the original two variables, so we use a procedure with both parameters passed by reference (marked
REFin CIE pseudocode): - 2
PROCEDURE swap(a: INTEGER REF, b: INTEGER REF) temp = a a = b b = temp ENDPROCEDURE - 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 |
Function | Returns one value, for calculations | Always include a |
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.
