Return values from functions
Define a typed function, return a result and use it as part of a larger expression.
Exam scope and assessment notes
This sequence follows Cambridge IGCSE Computer Science 0984, 2026–2028 syllabus Version 4. It covers section 8.1 (Programming concepts) only. Pseudocode examples use the published Cambridge format; the separate 2029–2031 syllabus is not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers, a browser-based programming workspace and human subject-teacher review remain outstanding. Cambridge states that 0984 has the same 2026–2028 subject content as 0478, with 9–1 grading. In June and November, Cambridge lists 0984 in Administrative zone 3 and for centres in Oman and the UAE. Confirm availability for your centre and exam series with Cambridge International. The separately published 2029–2031 syllabus changes to Python 3 only and removes pseudocode; this 2026–2028 route does not cover those changes.
Before you begin
- Be comfortable following an ordered algorithm and tracing variable values. Each lesson introduces the Cambridge pseudocode form it uses.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
What does RETURN do inside a function?
What you will learn
- Declare function parameters and return type
- Use RETURN to provide one value
- Call a function inside an expression
A function has a declared result type
Write FUNCTION Name(parameters) RETURNS Type and close it with ENDFUNCTION. Parameters are typed inputs; the RETURNS type tells the caller what value will be produced.
Use RETURN in the function body to send one result back. The value should match the declared return type.
Use the returned value at the call site
A function call is an expression, so it can appear on the right side of an assignment or inside OUTPUT. Do not write CALL before a function.
A function should have a clear result for every path. Check conditions so that each possible input reaches a RETURN statement.
Pause and explain
Which is a valid way to use a function named DoubleValue?
Worked example
Create a function that returns the greater of two integer values.
Show the worked solution
- Declare two INTEGER parameters and an INTEGER return type.
- Compare the values with IF.
- Return the larger one and use the call in an assignment.
Answer FUNCTION Maximum(A : INTEGER, B : INTEGER) RETURNS INTEGER IF A > B THEN RETURN A ELSE RETURN B ENDIF ENDFUNCTION Largest ← Maximum(7, 4) // 7
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
A function adds 4 and 5 and returns an INTEGER. What value does Result ← Add(4,5) store?
Give me a hint
Follow the returned expression.
Compare my reasoning
- Add returns 4 + 5.
- The function result is 9.
- The assignment stores that value in Result.
Result is 9.
Look for these in your work
- Return evaluated
- Assignment traced
State the header for a function called IsEven that receives an INTEGER and returns a BOOLEAN.
Give me a hint
The result is a logical value.
Compare my reasoning
- Name the parameter Number : INTEGER.
- Write RETURNS BOOLEAN.
- Close the definition with ENDFUNCTION after its body.
FUNCTION IsEven(Number : INTEGER) RETURNS BOOLEAN.
Look for these in your work
- Parameter typed
- Return type stated
A function returns a REAL for positive input but has no return in its ELSE branch. What problem can this cause?
Give me a hint
Check that every possible path has a defined function result.
Compare my reasoning
- A non-positive input may reach the ELSE branch.
- The caller expects a REAL value.
- Define a returned result or handle the input explicitly in that branch.
The function may finish without the required value; provide a valid REAL result or an explicit handling path for every input.
Look for these in your work
- Missing path identified
- Return coverage proposed
Common mistakes
- Omitting the RETURNS type
- Using CALL for a function
- A branch that reaches the end without returning a value
What can you explain now?
How is a function's value used by its caller?
Compare with the explanation
As part of an expression
The returned value replaces the function call in an expression.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
Why is CALL not used when a function is part of an expression?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.