If you are familiar with the variables in Mathematics’ algebra. They are used to represent unknown or in explicitly defined fields of an equation. Similarly, a constant is a term whose value never changes.

If we look over this example: 7x+ 8, the value of x can be anything, where are the remaining digits remains the same.

So, the digits 7 and 8 are termed as constant and x is a digit.

If you are new to programming language, this is the first thing you are going to hear.

Thus in programming the same scenario of algebra is applied. A variable is just a location in a memory where data can be stored. A programming language makes a computer to carve out a piece of memory and assign it a unique name.

The value in variable can change during a runtime, where as constant, as name implies remains the same.

Lets say I am a labor. I work for Rs. 100/day. and I can get some bonus based on the work I do.

So my daily income will be something like 100+bonus.

If I do good work my bonus can be any numeric value. (Let’s say 10). So my earning per day will be 100+10 = 110.

If you carefully look over the above equation. Rs. 100 remains the same, where as bonus can vary.  Thus due to the varying nature, it is termed as variable. Where as due to the fixed nature, 100 is termed as constant.

In some programming language any kind of data can be stored variable and constant, where as in some programming language, the type of data must be defined first.

Share:


About the Author


Leave a Reply

Your email address will not be published. Required fields are marked *

Premium WordPress Themes