Scope

Computer Science: OCR A Level, topic 7.1.5

Scope

The scope of a variable is the group of areas of the code from which it can be accessed.

Local scope

Local scope

  • A variable defined within a subroutine will have local scope.
  • This means that they can only be accessed within that subroutine.
Global scope

Global scope

  • A variable can be made global by adding the 'global' keyword in front of it when it is first used.
  • Global variables may be accessed by any part of the whole program.

Test yourself on Scope

  • What is global scope?

Practise this topic for free