Constant

In mathematics, a constant is a specific number or a symbol that is assigned a fixed value. For example, in the equation below, "y" and "x" are variables, while the numbers 2 and 3 are constants.

y = 2x - 3

Constants are also used in computer programming to store fixed values. They are typically declared at the top of a source code file or at the beginning of a function. Constants are useful for defining values that are used many times within a function or program. For example, in the C++ code below, min and max are declared as constants.

const int min = 10;
const int max = 100;

By using constants, programmers can modify multiple instances of a value at one time. For example, changing the value assigned to max in the example above will modify the value wherever max is referenced. If the number 100 was used instead of max, the programmer would have to modify each instance of "100" individually. Therefore, it is considered good programming practice to use constants whenever a fixed value is used multiple times.

Updated May 3, 2012 by Per C.

quizTest Your Knowledge

When something occurs live, it is said to happen in what?

A
Livetime
0%
B
Realtime
0%
C
Microtime
0%
D
Millitime
0%
Correct! Incorrect!     View the Real-Time definition.
More Quizzes →

The Tech Terms Computer Dictionary

The definition of Constant on this page is an original definition written by the TechTerms.com team. If you would like to reference this page or cite this definition, please use the green citation links above.

The goal of TechTerms.com is to explain computer terminology in a way that is easy to understand. We strive for simplicity and accuracy with every definition we publish. If you have feedback about this definition or would like to suggest a new technical term, please contact us.

Sign up for the free TechTerms Newsletter

How often would you like to receive an email?

You can unsubscribe or change your frequency setting at any time using the links available in each email.

Questions? Please contact us.