WHAT IS A COMPUTER PROGRAM ?
A computer is nothing but a very dumb machine that has the ability to perform mathematical operations very rapidly and very accurately, but it can do nothing without the aid of a program written by a human being. Moreover, if the human being writes a program that turns good data into garbage, the computer will very obediently, and very rapidly, turn the good data into garbage. It is possible to write a computer program with one small error in it that will do that very thing,
and in some cases appear to be generating good data. It is up to the human programmer to design a program to achieve the desired results. A computer program is simply a "recipe" which the computer will use on the input data to derive the desired output data. It is similar to the recipe for baking a cake. The input data is comparable to the ingredients, including the heat supplied by the oven. The program is comparable to the recipe instructions to mix, stir, wait, heat, cool, and all
other possible operations on the ingredients. The output of the computer program can be compared to the final cake sitting on the counter ready to be cut and served. A computer program is therefore composed of two parts, the data upon which the program operates, and the program that operates on the data. The data and program are inseparable as implied by the last sentence.
WHAT ARE CONSTANTS ?
Nearly any computer program requires some numbers that never change throughout the program. They can be defined once and used as often as needed during the operation of the program. To return to the recipe analogy, once you have defined how big a tablespoon is, you can use the same tablespoon without regard to what you are measuring with it. When writing a computer program, you can define the value of PI = 3.141592, and continue to use it wherever it makes sense knowing that
it is available, and correct.
WHAT ARE VARIABLES ?
In addition to constants, nearly every computer program uses some numbers that change in value throughout the program. They can be defined as variables, then changed to any values that make sense to the proper operation of the program. An example would be the number of eggs in the above recipe. If a single layer of cake required 2 eggs, then a triple layer cake would require 6 eggs. The number of eggs would therefore be a variable.
HOW DO WE DEFINE CONSTANTS OR VARIABLES ?
All constants and variables have a name and a value. In the last example, the name of the variable was "eggs", and the value was either 2 or 6 depending on when we looked at the stored data. In a computer program the constants and variables are given names in much the same manner, after which they can store any value within the defined range. Any computer programming language has a means by which constants or variables can be first named, then assigned a value.
more on this subject to follow ....