What is the purpose of using constants over literal in code?
Mostly we use constants instead of using literals in code. Some of the reasons why we use them are:
- It will avoid the risky errors that might occur in the large programs beacause that type of programs may contains huge number like 3.14 or 3.07 if the numbers are repeated errors will occur so it will avoid those.
- If any number contains through out the program then any change is needed we have re write the number, y using this it will save the changes we need not change the every time in the program it automatically changes.
- The code becomes more readable because of this.
Get Answers For Free
Most questions answered within 1 hours.