Learn in your language
Skip to content
IGCSE · Cambridge (CIE) · 0984

Use local and global variables

Control where a variable can be accessed and reduce unintended changes between routines.

Section 8 · Programming

Cambridge IGCSE Computer Science 0984 · Programming · 2026–2028 Version 4 · 0984 (9–1) · 8.1
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 scope describe?

What you will learn

  • Distinguish local and global scope
  • Trace a variable within a procedure
  • Prefer a clear scope for maintainable code

Local variables belong to a routine

A local variable is declared inside a procedure or function and is available only there. It can be used as temporary working data without changing a same-named variable elsewhere.

Parameters also provide local names for values supplied by a caller. When the routine finishes, its local working values are no longer available to other routines.

Global variables are shared more widely

A global variable can be accessed in more than one part of a program. This can be useful for genuinely shared state, but any routine that changes it can affect other code.

Prefer local variables and parameters when possible. They make it easier to see which values a routine reads and changes.

Pause and explain

A value is needed by only one function. Which scope is usually clearer?

Put the idea to work

Worked example

A procedure calculates a temporary discount. Where should TemporaryPrice be declared if no other routine needs it?

Show the worked solution
  1. The value is only used inside the procedure.
  2. Declare TemporaryPrice within that procedure.
  3. This makes the variable local and limits accidental use elsewhere.

Answer Declare TemporaryPrice locally inside the discount procedure.

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.

1 · Guided

A function declares Result inside itself. Can the main program use Result directly after the function ends? Explain.

Give me a hint

Consider where a local identifier is in scope.

Compare my reasoning
  1. Result is local to the function.
  2. The main program is outside that scope.
  3. Return the result or use an explicitly shared value instead.

No; a local variable is only available inside its function. Return the value if the caller needs it.

Look for these in your work

  • Scope identified
  • Suitable alternative
2 · Independent

A global Attempts variable is changed by three procedures. Give one risk and one way to reduce it.

Give me a hint

Think about hidden dependencies.

Compare my reasoning
  1. Any procedure can change Attempts unexpectedly.
  2. Use a local value or pass Attempts as a parameter where appropriate.
  3. Keep only truly shared state global.

The shared value can change unexpectedly; pass it explicitly or keep it local when possible.

Look for these in your work

  • Risk stated
  • Scope improvement
3 · Transfer

Two procedures both use a local variable named Index. Does this make them overwrite each other's Index? Explain.

Give me a hint

Each routine has its own local scope.

Compare my reasoning
  1. The names are local to separate routines.
  2. Each routine has its own value while it runs.
  3. They do not overwrite each other solely because the identifiers match.

No; each local Index belongs to its own routine, so the matching names are separate variables.

Look for these in your work

  • Scopes distinguished
  • Conclusion correct

Common mistakes

  • Assuming a local variable can be read outside its routine
  • Changing a global value without documenting the side effect
  • Using global state when a parameter would make the dependency clear
Recall without your notes

What can you explain now?

Where can a local variable normally be used?

Compare with the explanation

Inside the routine where it is declared

Its scope is limited to that procedure or function.

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 are parameters often clearer than changing a global variable?

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.

Keep learning Computer Science (9-1)

Course scope and assessment

165 original lessons map the listed objectives across all 10 main topics in the 2026–2028 Version 4 syllabus. Cambridge states that 0984 has the same subject content as 0478, with 9–1 grading. Three retained introductory lessons remain available but are not counted as syllabus-mapped teaching. The 2023–2025 syllabus remains unmapped. The separately published 2029–2031 syllabus changes to Python 3 only and removes pseudocode; this 2026–2028 route does not cover those changes. 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. Practical programming in an executable browser workspace, full timed-paper practice and human subject-teacher review remain outstanding. Practice is self-checked and does not award an official Cambridge grade.

StudyForA · Learn with understanding

Original teaching content and links to official sources. Check your exam year and qualification before using a resource.