answersLogoWhite

0

Say you put into your program the formula to calculate the area of a circle given its radius R asA = 3.141592 * R * R

Computer science teachers will usually mark you down for this, saying you should instead write it as

PI = 3.141592

...

A = PI * R * R

Because that way, should the value of pi ever change, you can just change it in the header and anywhere you've used the value in the program will automatically change with it.


Okay, that's not super likely, but suppose instead you had formulas to calculate the area of the circle, and the volume of a sphere, and the circumference of a circle, and the surface area of a sphere, and you run your program and notice that the answers you're getting are just slightly off what they should be. You look, and eventually find that the book you used to look up the value of pi had a typo and you've been using 3.145192 instead. Now you have to find everywhere it occurs in the program and fix it. If you had defined it in the header, you make the change in one spot, and its instantly fixed everywhere in the program.

User Avatar

Wiki User

9y ago

Still curious? Ask our experts.

Chat with our AI personalities

SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra

Add your answer:

Earn +20 pts
Q: How the use of constants rather than literals can simplify software maintenance.?
Write your answer...
Submit
Still have questions?
magnify glass
imp