logo

AQA A-Level Computer Science practice

What happens if a program attempts to use a local variable outside the subroutine in which it was declared?

Try the question first, then check the answer and practise the same topic again.

At a glance

MCQ

Type

practice

Style

Topic

Programming

Exam-style question

Try this first

What happens if a program attempts to use a local variable outside the subroutine in which it was declared?.

  1. A.The variable is not accessible from that location
  2. B.The variable automatically becomes a global variable
  3. C.The variable keeps its final value and is available everywhere
  4. D.The variable is copied into every other subroutine

Answer and explanation

Concise answer

The variable is not accessible from that location

Why this is correct

Local variables have scope limited to their own subroutine. Code outside that subroutine cannot access them as local variables.

Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

No flashcards are published for this page yet.

Related practice questions