Storage Concept
When working with programming languages, i.e., those computer languages that "do something", a central concept is how information is stored. Programming languages essentially "fetch" information from storage, designate what is to be done with this information, and in turn store the result so it can be used later or displayed. It is not the details of how the storing is done, but the fact that it is stored which is the essential concept. Perhaps the easiest way to develop this concept is in terms of what is today everyday items: a telephone and a calculator.
Buy a telephone and install it and normally it will be found that pressing "Redial" does nothing. The phone was never used so there is no number to redial. Make a phone call, though, press "Redial", and a phone call to the same number will be made. The number was entered and stored, so it was available for the "Redial". Dial another number and press "Redial". The number just dialed, not the one entered previously, is the call that will be made. The storage location that was initially empty, then contained the first dial-up, had its number replaced by the number dialed for the second. So it is with storage locations, what is in them can be "fetched", but they cannot be used to contain something else without losing what was there.
| --> | | --> | |
"Fresh" | | 1st No. | | 2nd No./td> |
What about a phone with memory storage? Consider one with just 3 storage locations where a number has already been dialed. The "Redial" storage has a number in it but there are none in any of the memory locations.
To store a number with this phone a button, say "Program", is pressed to designate that the number entered in the "Redial" location is not to be called but is to be placed in a memory location, say M2. The memory location is specified by keying in "M" then "2" followed by "Store". The content of the memory locations may thus be represented:
The number from the "Redial" location has not been lost, it was just duplicated in the specified memory location. To dial a number from a memory location a button "Recall" is pressed designating something from memory is to be put in the location that enables dialing, and that something is specified by entering, say "M" and then "2". Whatever was in the "Redial" area is lost, just as if a new number is entered, but the memory location is left unchanged.
With a computer, it is not necessary to specify a memory location as such. It is only necessary to assign a name, which is termed a variable, to what is entered. A memory location is then assigned automatically. To regain what the computer put into a memory location that name must be used somewhere in the body of the program or code. If the same name is used for a new value, the previous value is lost.