← IGCSE Computer Science Paper 2

Calling a function inside an expression

A function call is written inside an expression, with no CALL keyword. The returned value replaces the call, then the rest of the expression is worked out.

Understanding Calling a function inside an expression in IGCSE Computer Science Paper 2

What it does: The function name and its values are written directly in the expression on the right. There is no CALL keyword, which is only used for procedures. The call is replaced by 500, giving 500 + 1 = 501. The +1 is not added to the 10 or the 20. The function runs first and its returned value takes the place of the call. Then the + 1 is calculated.

Common mistakes: CALL is only used with procedures. A function is called by writing its name and brackets inside the expression, so it should be Total ← Sq(5) + 1. A function call inside an expression is not a complete statement. The value must be used, for example with OUTPUT or by storing it in a variable: OUTPUT Cost(Price, Tax) + 1.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 409–418) and word search (Modules 399–418).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
SumSquare is a function. Which line calls it correctly inside an expression?
Total ← SumSquare(10, 20) + 1Total ← CALL SumSquare(10, 20) + 1
Matches
Total ← CALL SumSquare(10, 20) + 1
↓
CALL is used with a function. CALL is only for procedures. A function call is written inside the expression without CALL: Total ← SumSquare(10, 20) + 1.
Applying
Meanings
Term
SumSquare(10, 20) + 1
Meaning
A function call is written inside an expression, with no CALL keyword. The returned value replaces the call, then the rest of the expression is worked out.
Practice
FUNCTION SumSquare(X : INTEGER, Y : INTEGER) RETURNS INTEGER
Testing
Gaps
Total ← (10, 20) + 1
Check Answer
Spots
3ENDFUNCTION
4Total ← CALL Sq(5) + 1

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Squirrel' badge — Module Hoarder, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. SumSquare is a function. Which line calls it correctly inside an expression?
A. Total ← SumSquare(10, 20) + 1 ✓
B. Total ← CALL SumSquare(10, 20) + 1
CALL is only used with procedures. A function call goes inside an expression, with its name and values in brackets.
2. Which statement about calling a function is correct?
A. It is used as part of an expression, such as OUTPUT SumSquare(10, 20) ✓
B. It is a complete statement on its own, such as SumSquare(10, 20)
A function call is not a complete statement. Its returned value must be used, for example in OUTPUT or an assignment.
3. SumSquare(10, 20) returns 500. What value does SumSquare(10, 20) + 1 give?
A. 501 ✓
B. 31
The call is replaced by 500, giving 500 + 1 = 501. The +1 is not added to the 10 or the 20.
4. What happens when the computer works out SumSquare(10, 20) + 1?
A. The +1 is added to the 10 and 20 first, then the function runs
B. The returned value replaces the call, then the rest of the expression is worked out ✓
The function runs first and its returned value takes the place of the call. Then the + 1 is calculated.
5. Do you write the CALL keyword when using a function?
A. Yes, every subroutine must start with CALL
B. No, you just write the function name and values in brackets ✓
CALL is for procedures only. Functions are written inside expressions without it.

Match the Pairs

Total ← SumSquare(10, 20) + 1 → The function is called with 10 and 20. Its returned value replaces the call, then 1 is added and the answer is stored in Total.
Answer ← 2 * Cube(3) → Cube is called with 3. The returned value replaces Cube(3), then it is multiplied by 2 and stored in Answer.
A function is called by writing its name with the values in brackets. No CALL keyword is used. → Result ← SumSquare(3, 4)
A function call is not a complete statement on its own. It is placed inside an expression so the returned value is used. → Score ← Double(5) + 10
Total ← CALL SumSquare(10, 20) + 1 → CALL is used with a function. CALL is only for procedures. A function call is written inside the expression without CALL: Total ← SumSquare(10, 20) + 1.
SumSquare(10, 20) + 1 → The function call and calculation are written on their own as a statement, so the returned value is not stored or output. It should be assigned or output, e.g. Total ← SumSquare(10, 20) + 1.

Key Term

SumSquare(10, 20) + 1
A function call is written inside an expression, with no CALL keyword. The returned value replaces the call, then the rest of the expression is worked out.

Fill in the Blanks

1. Total ← SumSquare(10, 20) + 1
Hint: Type the name of the function being called inside the expression.
2. Result ← 2 * SumSquare(1, 2)
Hint: Type the arithmetic operator that multiplies the returned value by 2.
3. Total ← SumSquare(10, 20) + 1
Hint: Type the assignment symbol that stores the finished expression in the variable.
4. IF IsEven(8) = TRUE THEN OUTPUT "Even" ENDIF
Hint: Type the keyword that follows an IF condition containing a function call.
5. OUTPUT SumSquare(10, 20) + 1
Hint: Type the keyword that displays the value of the expression, since a function call alone is not a complete statement.

Spot the Error

Question 1
A FUNCTION Sq(N) RETURNS INTEGER
B RETURN N * N
C ENDFUNCTION
D Total ← CALL Sq(5) + 1
E OUTPUT Total
Line D — CALL is only used with procedures. A function is called by writing its name and brackets inside the expression, so it should be Total ← Sq(5) + 1.
Question 2
A Price ← 20
B Tax ← 5
C Cost(Price, Tax) + 1
Line C — A function call inside an expression is not a complete statement. The value must be used, for example with OUTPUT or by storing it in a variable: OUTPUT Cost(Price, Tax) + 1.
Question 3
A A ← 10
B B ← 20
C Result ← SumSquare A, B + 1
D OUTPUT Result
Line C — The arguments of a function call must be inside brackets after the function name. It should be Result ← SumSquare(A, B) + 1.
Question 4
A Length ← 6
B Width ← 4
C OUTPUT "Working out area"
D OUTPUT Rect(Length) + 10
Line D — Rect needs two values (Length and Width). The call must pass every argument, so it should be OUTPUT Rect(Length, Width) + 10.
Question 5
A Double(4) * 3 ← Total
B OUTPUT Total
C OUTPUT Total + 1
Line A — The variable being assigned to goes on the left of the arrow. The function call is part of the expression on the right: Total ← Double(4) * 3.

Student with a class code? Join your class →