← IGCSE Computer Science Paper 2

Tracing a program that calls a procedure

A table used to trace a call: record the value given to each parameter, follow the procedure's statements, then return to the next line of the main program.

Understanding Tracing a program that calls a procedure in IGCSE Computer Science Paper 2

What it does: Each call gives the parameter a new value, so each call is traced separately. Total is declared and set inside the procedure, so it does not keep its value from an earlier call. Output appears in the order the statements run. The procedure runs at the CALL, before the main program continues to the next line. Arguments are matched to parameters in order. The first value goes to the first parameter, and the second value goes to the second. The first row of the trace table records the argument value: Num = 3.

Common mistakes: The trace table has a column for the parameter N, which gets the value 4 from the call. M is never declared or given a value, so the line should be R ← N * 2. Assignment puts the value on the right into the variable on the left. When tracing, Sum must be given A + B (2 + 3 = 5), so the line should be Sum ← A + B.

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 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.

Learning
Duo
A procedure is called with CALL ShowDouble(4). What is the first thing to record in the trace table?
The value 4 stored in the parameterThe final output of the whole program
Matches
CALL Show(3) traced with Num = 0 in the first row
↓
The parameter must be given the value passed in the call (3), not 0 or a blank
Applying
Meanings
Term
trace table
Meaning
A table used to trace a call: record the value given to each parameter, follow the procedure's statements, then return to the next line of the main program.
Practice
PROCEDURE ShowTotal(Price : INTEGER, Qty : INTEGER)
Testing
Gaps
Show(5)
Check Answer
Spots
2 DECLARE R : INTEGER
3 R ← M * 2

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

The 'Octopus' badge — Multi-Tasker, 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. A procedure is called with CALL ShowDouble(4). What is the first thing to record in the trace table?
A. The final output of the whole program
B. The value 4 stored in the parameter ✓
Start a trace by recording the value given to each parameter. Then follow the procedure's statements one at a time.
2. PROCEDURE Greet(Name) is called by CALL Greet("Sam") and then CALL Greet("Mia"). What does the Name column show?
A. "Sam" for the first call, "Mia" for the second call ✓
B. "Sam" for both calls
Each call gives the parameter a new value, so the trace table needs a new row of values for each call.
3. When the last statement of a procedure has finished, where does the trace go next?
A. Back to the first line of the procedure
B. To the line after the CALL in the main program ✓
Control returns to the next line of the main program after the CALL. The procedure does not run again unless it is called again.
4. Main program: OUTPUT "Start", CALL Show(5), OUTPUT "End". Show(N) outputs N. In which order is the output shown?
A. Start, 5, End ✓
B. Start, End, 5
Output appears in the order the statements run. The procedure runs at the CALL, before the main program continues to the next line.
5. A procedure has the local variable Total ← 0 as its first line. It is called twice. What is Total at the start of the second call?
A. 0, because the local variable is reset each call ✓
B. The value left over from the first call
Local variables only exist while the procedure runs. They start fresh on every call, so the trace table restarts them each time.

Match the Pairs

CALL ShowDouble(4) → In the trace table, the parameter Num is given the value 4 before any statement in the procedure runs
CALL Greet("Sam")\nOUTPUT "Bye" → The greeting is output first, then control returns to the main program and Bye is output second
Two calls with different values need two sets of rows in the trace table: Num is 2 for the first call, then 5 for the second → CALL Square(2)\nCALL Square(5)
A local variable is reset in each call, so Total starts again from 0 every time the procedure runs → PROCEDURE Add(N : INTEGER)\n DECLARE Total : INTEGER\n Total ← 0 + N
CALL Show(3) traced with Num = 0 in the first row → The parameter must be given the value passed in the call (3), not 0 or a blank
Trace of 2nd call: Count = 5 carried over from 1st call → A local variable does not keep its value between calls; it starts fresh each time the procedure is called

Key Term

trace table
A table used to trace a call: record the value given to each parameter, follow the procedure's statements, then return to the next line of the main program.

Fill in the Blanks

1. CALL Show(5) OUTPUT "Back in main"
Hint: Type the keyword that starts a procedure call in the main program.
2. PROCEDURE Double(Num : INTEGER) OUTPUT Num * 2 ENDPROCEDURE
Hint: Type the parameter name whose recorded value is used in the calculation.
3. PROCEDURE Show(Num : INTEGER) OUTPUT Num ENDPROCEDURE
Hint: Type the keyword that ends the procedure, where control passes back to the main program.
4. PROCEDURE AddTen(Num : INTEGER) Sum ← Num + 10 OUTPUT Sum
Hint: Type the local variable whose value is rebuilt in a new trace table row for every call.
5. PROCEDURE Show(Num : INTEGER) OUTPUT Num ENDPROCEDURE
Hint: Type the data type for a parameter that holds a whole number.

Spot the Error

Question 1
A PROCEDURE Double(N : INTEGER)
B DECLARE R : INTEGER
C R ← M * 2
D OUTPUT R
E ENDPROCEDURE
F CALL Double(4)
Line C — The trace table has a column for the parameter N, which gets the value 4 from the call. M is never declared or given a value, so the line should be R ← N * 2.
Question 2
A PROCEDURE Add(A, B : INTEGER)
B DECLARE Sum : INTEGER
C A + B ← Sum
D OUTPUT Sum
E ENDPROCEDURE
F CALL Add(2, 3)
Line C — Assignment puts the value on the right into the variable on the left. When tracing, Sum must be given A + B (2 + 3 = 5), so the line should be Sum ← A + B.
Question 3
A PROCEDURE Greet(Name : STRING)
B OUTPUT "Hello ", "Name"
C ENDPROCEDURE
D CALL Greet("Ava")
Line B — "Name" in quotes is the literal text Name. It would print Hello Name instead of the value held in the parameter. It should be OUTPUT "Hello ", Name so that Ava is output.
Question 4
A PROCEDURE Show(N : INTEGER)
B OUTPUT N * N
C ENDPROCEDURE
D Show(3)
E CALL Show(5)
Line D — A procedure is run with the CALL keyword. Without it the first call never happens, so the trace has no row for N = 3. The line should be CALL Show(3).
Question 5
A PROCEDURE Count(N : INTEGER)
B DECLARE T INTEGER
C T ← N + 1
D OUTPUT T
E ENDPROCEDURE
F CALL Count(7)
Line B — A DECLARE statement needs a colon between the variable name and its data type. The local variable T should be declared as DECLARE T : INTEGER.

Student with a class code? Join your class →