Tracing a program that calls a function
Tracing a call: follow the function's statements to RETURN, then replace the call with the returned value (here 500) and finish evaluating the expression.
Understanding Tracing a program that calls a function in IGCSE Computer Science Paper 2
What it does: The call is replaced by 500, so Total holds 500 after the assignment. The function returns 9 + 16 = 25, the call is replaced by 25, and 25 is output. The whole call SumSquare(10, 20) is replaced by the returned value 500. Then you finish the expression: 500 + 1 = 501. 7 MOD 2 = 1, so 1 = 0 is FALSE. The call IsEven(7) is replaced by FALSE, so the IF takes the ELSE branch and outputs Odd. RETURN sends the value back and ends the function straight away. Tracing continues in the code that made the call.
Common mistakes: Sq returns a value that OUTPUT uses, so it must be a FUNCTION with RETURNS INTEGER. A procedure cannot return a value. The call Sq(4) is replaced by 16 and then output. The function returns N * N, which is a whole number, so the return type must be INTEGER, not STRING. Sq(3) is replaced by 9, then 1 is added to give 10.
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 419–428) and word search (Modules 419–438).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
SumSquare(10, 20)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →