Exam-style question
Try this first
A program uses the same tax rate in several calculations. Which approach best applies the idea of a named constant?.
- A.Store the rate under a meaningful constant name and use that name in the calculations
- B.Use a different literal rate in each calculation
- C.Store the rate in a variable and deliberately change it before every calculation
- D.Replace the rate with a comment
Model answer
What a good answer should say
- Store the rate under a meaningful constant name and use that name in the calculations
Explanation
Why this works
A named constant gives the shared value a meaningful identity and helps keep the value consistent wherever it is used.
Common mistake
No common mistake is linked to this question yet.
