Software QA/Testing
Glossary and Technical FAQs
|
|
Q: What is a constant?
A: In software or software testing, a constant is a meaningful name that represents a number, or string, that does not change.
Constants are variables whose value remain the same, i.e. constant, throughout the execution of a program.
Why do developers use constants? Because if we have code that contains constant values that keep reappearing, or, if we have code that depends on certain numbers that are difficult to remember, we can improve both the readability and maintainability of our code, by using constants.
To give you an example, let's suppose we declare a constant and we call it Pi. We set it to 3.14159265 and use it throughout our code.
Constants, such as Pi, as the name implies, store values that remain constant throughout the execution of our program.
Keep in mind that, unlike variables which can be read from and written to, constants are read-only variables.
Although constants resemble variables, we cannot modify or assign new values to them, as we can to variables.
But we can make constants public, or private.
We can also specify what data type they are.
[Continued on next page...]
Click on a link!
|
______________________________________________________
|