60.2k views
3 votes
Assume a program uses the named constant PI to represent the value 3.14159. What is the advantage of using the named constant instead of the actual value 3.14159 in each statement?

a) Reduces memory usage
b) Makes the code run faster
c) Easier to change the value in one place
d) Makes the code clearer to read

1 Answer

5 votes

Final answer:

Using a named constant, such as PI, instead of the actual value 3.14159 in each statement has the advantage of making the code easier to change in one place and clearer to read.

Step-by-step explanation:

The advantage of using a named constant, such as PI, instead of the actual value 3.14159 in each statement is that it makes the code easier to change in one place. This means that if the value of PI ever needs to be updated, it can be done by modifying the named constant definition, instead of having to search for and update every instance of the actual value 3.14159 in the code. This can save time and reduce errors.

Additionally, using a named constant makes the code clearer to read and understand. When another person reads the code, they can easily see that the value being used is PI, and it eliminates any confusion or ambiguity.

User Hituptony
by
8.4k points