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.
Copyright © 2026 eLLeNow.com All Rights Reserved.