Exam-style question
Try this first
Explain two advantages of using named constants. Use the example of a program that uses the same maximum number of attempts in several places.
Model answer
What a good answer should say
- A named constant can improve readability because a name such as MAX_TRIES communicates the purpose of the value more clearly than repeatedly writing 3.
- It can also make maintenance easier: if the maximum is changed from 3 to 5, the programmer can update the constant declaration rather than searching for every occurrence of the literal value.
- Using one named constant also helps the different parts of the program use the same intended value.
Explanation
Why this works
The answer identifies meaningful naming and easier updating as advantages. It also links those advantages to the stated situation, rather than merely listing them.
The explanation must remain focused on named constants and their use in a program.
Common mistake
No common mistake is linked to this question yet.
