Prepare for the A Level Computer Science OCR Exam with engaging quizzes, detailed explanations, and effective study tips. Maximize your readiness and boost your confidence for exam day!

Practice this question and more.


What is the defining characteristic of a local variable?

  1. A variable that can only be accessed within its own class

  2. A variable that has a global scope and lifetime

  3. A variable that can only be used in a specific function

  4. A variable that exists for the duration of the program

The correct answer is: A variable that can only be used in a specific function

A local variable is characterized by its scope, which is limited to the block of code or function in which it is declared. This means that it can only be accessed and utilized within that specific function, ensuring its existence is temporary and isolated. Once the function completes execution, the local variable is typically destroyed, and its value cannot be accessed outside of that context. In contrast, options that describe a variable with a global scope or lifetime, or those that suggest it persists throughout the program's runtime, pertain to global variables or different types of storage, not local variables. Thus, identifying that a local variable can only be utilized within a specific function accurately captures its defining characteristic.