logo

Question detail

Which statement best contrasts a local variable with a global variable?

Try the question, check the answer, then read the explanation to understand the curriculum point.

At a glance

MCQ

Type

practice

Style

Topic

Programming

Exam-style question

Try this first

Which statement best contrasts a local variable with a global variable?.

  1. A.A local variable can be used throughout the whole program, while a global variable can be used only inside one function.
  2. B.A local variable is available only within its defined local section, while a global variable is available from a wider part of the program.
  3. C.A local variable must contain text, while a global variable must contain a number.
  4. D.A local variable is created before a program starts, while a global variable is created only inside a function.

Model answer

What a good answer should say

  • A local variable is available only within its defined local section, while a global variable is available from a wider part of the program.

Explanation

Why this works

The key difference is scope. A local variable is restricted to the part of the program where it is defined, whereas a global variable can be accessed from a wider part of the program.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

No flashcards are published for this page yet.

Related practice questions

No questions are published for this page yet.