Which of the following is not true about Global Variables:
2025
Which of the following is not true about Global Variables:
- A.
The values of the Global variables which are sent to the called function may be changed inadvertently by the called function.
- B.
Functions are supposed to be independent and isolated modules. This character is lost, if they use global variables.
- C.
It is not immediately apparent to the reader which values are being sent to the called function
- D.
A function that uses global variables does not suffer from reusability.
Attempted by 345 students.
Show answer & explanation
Correct answer: D
Answer: The statement "A function that uses global variables does not suffer from reusability." is not true — functions that use global variables do suffer from reduced reusability.
Why this is false:
Hidden dependencies: the function relies on external state not visible in its signature, which hinders reuse in other contexts.
Side effects: global variables can be modified by different parts of the program, making behavior unpredictable and hard to isolate.
Testing and maintenance: functions depending on globals are harder to unit-test and to reason about, reducing maintainability and reusability.
Concurrency and namespace issues: globals can cause race conditions in concurrent code and naming collisions in large codebases.
Why the other statements are true:
The values of global variables accessed by a called function may be changed inadvertently by that function, producing unexpected side effects.
Functions are intended to be independent modules; using globals creates implicit coupling and removes that independence.
When functions rely on global variables, it is not immediately apparent which values are being used, hiding dependencies from readers.
Recommendation: prefer passing required data explicitly via parameters, keep functions pure when possible, and minimize use of mutable global state to improve reusability, testability, and maintainability.
A video solution is available for this question — log in and enroll to watch it.