All computer languages have subscripted variables, although the subscripts are often
given as values enclosed in parentheses or square brackets following the base name, as
in x(2) or y[z]. One of the first things to learn about a
new language is the syntax for using subscripted variables.
The importance of subscripted variables in programming cannot be stressed enough. One of the
most powerful features of the computer is that it can handle and manipulate huge
amounts of data. We use subscripted variables to reference lists of that data and
we use the subscripts to select individual items in that list.
Not only should you learn how to reference a subscripted variable in
the computer language that you are using, you should also be aware of the
lower (and upper) limits on the indexing of those subscripts. Some languages
start with the subscript 1 and move on to 2, 3, 4, and so on. Other languages
start with the subscript 0 and move on to 1, 2, 3, and so on.
There are languages that allow you to choose the lowest allowed subscript, not requiring it
to be either or 1.
In computer languages that have subscripts starting at 1 then the length
of a list of values is also the index of the last value. In computer
languages that have subscripts starting at 0 then the length
of a list of values is one more than the index of the last value.
Not only do we have extensive use for lists of values, we also have tremendous use for
arrays of values (a matrix or table of values). Just consider image processing where an image
is merely an array of picture elements (pixels). The computer I am using
to write this has a screen with 1920x1080 resolution; that is an array of 1920 by 1080
pixels. The Samsung Galaxy S4 smartphone has the same resolution. The old iPhone had a
resolution of 320x480 and the iPhone 5 has a resolution of 640x1136. All of the processing of
images on these screens is done by reference to the array of pixels available to them.
Memory on computers is arranged as one long list. Computer languages allow us to
think of that memory as an array, but really, behind the scenes, the language
takes care of translating the row and column subscript values to a subscript of the list in
memory.
For some types of problems, we want to extend the use of arrays to more than 2 dimensions.
Just for purposes of discussion it might be worth noting that I have personally had the "need" to
use five dimensional arrays. Again, languages that support these multi-dimensional arrays
take care of translating array subscripts to a subscript of the list of memory locations in memory.
"Need" in such situations is really just a statement that having such a feature, a five-dimensional
array, made conceptualizing and even programming the problem much easier than it would have been if I did
not have the feature.
Understanding "storage order" and the related translation of multiple dimension
subscripts to a subscript of a long list of memory locations allows a programmer to
improve the efficiency of a program in many situations. [This is especially true of
programs that will be run on systems that use cached memory and even more so on systems that are
multi-tasking with virtual memory on a disk system. This improved efficiency
may not be noticeable in an environment that has huge amounts of available memory and/or so little
demand on a processor that the program is essentially running by itself with no competition for resources.]