Microsoft Store
 

Variable


 

In computer science and mathematics, a variable is a symbol denoting a quantity or symbolic representation. In mathematics, a variable often represents an unknown quantity; in computer science, it represents a place where a quantity can be stored. Variables are often contrasted with constants, which are known and unchanging.

Why are variables useful?

Variables are useful in mathematics and computer programming because they allow instructions to be specified in a general way. If one were forced to use actual values, then the instructions would only apply in a more narrow, and specific set of situations. For example:

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

specify a mathematical definition for finding the square of ANY number: square(x) = x · x.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

Now, all we need to do to find the square of a number is replace x with any number we want.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  • square(x) = x · x = y
  • square(1) = 1 · 1 = 1
  • square(2) = 2 · 2 = 4
  • square(3) = 3 · 3 = 9
  • etc...

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    In the above example, the variable x is a "placeholder" for ANY number. One important thing we are assuming is that the value of each occurrence of x is the same -- that x does not get a new value between the first x and the second x.

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    In computer programming languages without referential transparency, such changes can occur.

    Related Topics:
    Computer - Programming language - Referential transparency

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~