ProgrammingStudy Notes

Deep Dive: Scope Example

Part of Variable ScopeGCSE Computer Science

This study notes covers Deep Dive: Scope Example within Variable Scope for GCSE Computer Science. Revise Variable Scope in Programming for GCSE Computer Science with 15 exam-style questions and 10 flashcards. This topic appears less often, but it can still be a useful differentiator on mixed-topic papers. It is section 4 of 6 in this topic. Use this study notes to connect the idea to the wider topic before moving on to questions and flashcards.

Topic position

Section 4 of 6

Practice

15 questions

Recall

10 flashcards

Deep Dive: Scope Example

global score = 0  // Global - accessible everywhere

function addPoints(points)
    local bonus = 10  // Local - only in this function
    score = score + points + bonus
endfunction

addPoints(5)
print(score)  // Works - score is global
print(bonus)  // ERROR - bonus doesn't exist here

Keep building this topic

Read this section alongside the surrounding pages in Variable Scope. That gives you the full topic sequence instead of a single isolated revision point.

Practice Questions for Variable Scope

Where can a local variable be accessed?

  • A. Anywhere in the program
  • B. Only within the subprogram where it is declared
  • C. Only in the main program body
  • D. In any subprogram that calls the original subprogram
1 markfoundation

Identify and explain the scope error in this pseudocode: function calculateTotal(price, quantity) local total = price * quantity endfunction calculateTotal(10, 5) output total

2 marksstandard

Quick Recall Flashcards

What is a global variable?
A variable declared outside all subprograms, accessible anywhere in the program
What is variable scope?
Where a variable can be accessed in the code

Want to test your knowledge?

PrepWise has 15 exam-style questions and 10 flashcards for Variable Scope — with adaptive difficulty and instant feedback.

Join Alpha