logo

Question detail

Explain two differences between a variable and a constant in a programming language. Include one suitable example of each.

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

At a glance

Question

Type

practice

Style

Topic

Programming

Exam-style question

Try this first

Explain two differences between a variable and a constant in a programming language. Include one suitable example of each.

Model answer

What a good answer should say

  • A variable is a named value that may be changed while the program runs.
  • For example, in Python, score = 0 could later be followed by score = 10.
  • A constant is a named value intended not to change while the program runs.
  • For example, in C#, const int MAX_TRIES = 3; declares a named constant.

Explanation

Why this works

The key distinction is whether the value is expected to change. The examples show a variable being assigned a new value and a C# constant being declared with the const keyword.

A complete answer should explain both the changing nature of a variable and the fixed intended nature of a constant.

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.