Re: C programming Arrays

  • From: "Laura Eaves" <leaves1@xxxxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 9 Oct 2007 18:52:39 -0400

Hi John -- what would you like to do? and what concepts have you covered 
already? Do you have the definition of pointers and arrays down pat and a 
reasonably coherent idea of what they are? The thing to remember about 
arrays is that

1) an array addresses a block of contiguous or adjacent data in memory, so 
if you declare an array locally for example, you are guaranteed to have a 
list of adjacent data objects of the same type in memory.  For example,
    int a[100];
declares a block of int variables.

2) in the above example, you would grab the fifth int in the block by typing
or rather to get the i-th element, you type a[i-1].
Remember also that the elements are numbered from 0 to n-1 where n is the 
size of the array.

3) the array "a" above contains 100 ints, 0 through 99 -- and to initialize 
each element of the array, you type something like the following:
    int i, a[100];
    for (i = 0;  i < 100;  ++i) {
        a[i] = 0;

4) the name of the array is a special type of pointer which can't be 
assigned to, although its elements can be (see above).  This means the array 
name "a" above is constant, so if you type "a = something;" you will get a 
compile time error, because the array is a constant, but a[3] is not.
Also, the array name is a pointer and therefore can be used in pointer 
arithmetic as follows:

    x = a[5];
    x = *(a+5);

both of which assign a[5] to x.  Note that the subscript operator in C is 
defined to be equivalent to dereferencing the sum of the pointer and an 
int -- so the following are all equivalent:

    a[i]  *(a+5)  *(5+a)

5) there are as many examples of how to use arrays as there are problems to 
solve.  Think of a problem involving a list of anything and try to translate 
it into a C program.

I hope I'm not confusing you more; I just don't know what you have covered 
Good luck in any case; it isn't bad once you get the hang of it, it's just 
getting over the pointer hurdle.
Let me know if you need clarification before I type up a problem for you to 
solve.  I have one in mind that might be a good exercise.

----- Original Message ----- 
From: "John Miller" <n1umj@xxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, October 09, 2007 5:30 PM
Subject: C programming Arrays

Is there anyone that can give a good, actually reasonably understandable
explanation or example of an array in C programming? In my class, the book's
examples are horrible at best and confusing and the teacher should be fired
his is so bad. That or I should drop the class which I was actually about to
do but I looked and there is no other major completely online that holds my
interest so I guess I have to stick it out for another torturous 5 weeks or
what ever it is. I'm getting some of it, but not enough.
John Miller N1UMJ
AIM and yahoo messenger: N1UMJ Skype: n1umjjohn
home page:

View the list's information and change your settings at

View the list's information and change your settings at 

Other related posts: