Prepare for the A Level Computer Science OCR Exam with engaging quiz questions and interactive flashcards. Get ready to excel in your exam with comprehensive study materials designed to bolster your knowledge and confidence.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What is the defining feature of a Local Variable?

  1. It can be used anywhere in the program

  2. It is only accessible within the function or block it is defined

  3. It persists throughout the entire program

  4. It holds values that are shared across different functions

The correct answer is: It is only accessible within the function or block it is defined

The defining feature of a Local Variable is that it is only accessible within the function or block in which it is defined. This means that the variable's scope is limited to that specific function, and it cannot be accessed or modified from outside that function. This encapsulation allows for greater control over data and helps to prevent unintended interference between different parts of the program, as each function can have its own local variables that do not affect others. In contrast, global variables are accessible from anywhere in the program, which would be why the first option would not apply. The third option points to the characteristic of global variables as well, as local variables do not persist throughout the entire program; their lifetime is confined to the execution of the function in which they are created. The fourth option inaccurately suggests that local variables share values across different functions, while in reality, they are unique to their defining context.