Re: LZ: array's


[Prev][Next][Index][Thread]

Re: LZ: array's



On Fri, 26 Jul 1996, Peter Cordes wrote:


> I am just wondering, how are arrays used in programs because I want to
> use them in my programs but don't understand how to


An array is like a collection of things.  When you have more
than one of something you can store them in an array.  One
example is an array of month names.  You might have an array
that has the names "Jan", "Feb", "Mar", etc.  The first item
in an array is always the 0 item.  The second item is the 1
item.  That's because you would add 0 to the address of the
array to get "Jan".  So you would subtract 1 from the month
number to get the element in the array.  if the date is
2/21/96 you would use 2 as the month number, subtract 1 and
that gives you a 1 for the element number and that means it's
"Feb".   In an assembly program you would use a formula like
E = A + (N-1) * L
where E is the address of the element, A is the address of
the array, N is the number (the month) and L is the length
of a single element.  All of the elements have to have the
same length.


Another use for an array is to contain a list of addresses
that you might jump to in response to certain commands.  This
is called a jump table but it's really just a special kind of
an array.


I hope this helps.


Barry


References: