IGCSE · Practice questions · Procedures, functions, parameters and scope

Call it, reuse it.

Six original Cambridge-style questions on subroutines in 0478 pseudocode, with mark points.

Original questions All questions on this page are original work, written in the Cambridge IGCSE style. They are not from past papers. They test the same concepts and skills the syllabus rewards.
Keep these straight

Procedure or function?

01
Explain
[3 marks]

Explain the difference between a procedure and a function, including how each is called.

  • A function returns a single value; a procedure does not return a value. ✓
  • A procedure is called with CALL as a statement on its own. ✓
  • A function is called as part of an expression, e.g. assigned to a variable or output. ✓
02
Recall
[2 marks]

Describe what is meant by a local variable and a global variable.

  • Local: declared inside a procedure or function and can only be used within it. ✓
  • Global: declared in the main program and can be used anywhere in the program. ✓
03
Write
[4 marks]

Write a function Average that takes three integer parameters and returns their mean as a real number.

  • FUNCTION Average(A : INTEGER, B : INTEGER, C : INTEGER) ✓
  • RETURNS REAL at the end of the header ✓
  • RETURN (A + B + C) / 3 (brackets needed) ✓
  • ENDFUNCTION ✓
04
Trace
[3 marks]

State the output of this pseudocode.

FUNCTION Double(N : INTEGER) RETURNS INTEGER
    RETURN N * 2
ENDFUNCTION

PROCEDURE Show(N : INTEGER)
    OUTPUT "Value: ", N
ENDPROCEDURE

DECLARE X : INTEGER
X ← Double(3)
CALL Show(X + 1)
CALL Show(Double(X))
  • X ← Double(3) = 6. ✓
  • Show(6 + 1) outputs Value: 7. ✓
  • Double(6) = 12, so Show outputs Value: 12. ✓
05
Write
[3 marks]

Write a procedure Greet with a STRING parameter Name and an INTEGER parameter Times that outputs "Hello " followed by the name, Times times. Then write a statement that calls it for the name Sam, twice.

  • PROCEDURE Greet(Name : STRING, Times : INTEGER) ✓
  • FOR Count ← 1 TO Times, OUTPUT "Hello ", Name, NEXT Count, ENDPROCEDURE ✓
  • CALL Greet("Sam", 2) ✓
06
Analysis
[2 marks]

A student writes CALL Total ← Add(2, 3), where Add is a function. Explain what is wrong and correct it.

  • CALL is only used for procedures; a function is used inside an expression. ✓
  • Correct: Total ← Add(2, 3). ✓

Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.