OCR GCSE Computer Science Paper 2 Practice 2026 - Free Practice Questions and Study Guide

Question: 1 / 400

In programming, what is the opposite of a local variable?

Private Variable

Global Variable

A local variable is one that is declared within a specific function or block of code and can only be accessed within that context. Its scope is limited to the function it resides in, meaning once the function finishes execution, the local variable is no longer accessible or usable.

The opposite of a local variable is a global variable, which is declared outside any function or block of code and can be accessed from any location in the program. This broader accessibility allows different functions to share and manipulate the same global variable, which is essential for certain programming tasks. However, using global variables can lead to code that is harder to debug and maintain since any part of the code can change the global variable's value.

Private variables are used in specific contexts, generally in object-oriented programming to keep it accessible only within the class itself, but they do not serve as an opposite to local variables in terms of scope. Static variables have a different purpose as well, maintaining their value between function calls within a local scope, rather than being accessible globally. Constant variables refer to values that do not change over time but also do not relate to the scope in the same way local and global variables do.

Get further explanation with Examzify DeepDiveBeta

Static Variable

Constant Variable

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy