Saturday, May 10, 2008

Array And string(Introduction of Array )

Introduction of Array

Whenever there is need to store a group of data of the
same type in the memory, arrays are used. Two terms has
been described here Array and String.

Strings in C are represented by the array only therefore
it would be convenient to describe strings separately in
the same block but in the different section.

Arrays are the contiguous memory location used to store
similar data type or in other terms we can say Arrays are
a data structure which holds multiple variables of the same
data type.

Consider the case where a programmer needs to keep track
of a number of people within an organization. So far, our
initial attempt will be to create a specific variable for each user.


This might look like:

int name1 = 101;
int name2 = 232;
int name3 = 231;

It becomes increasingly more difficult to keep track of this as
the number of variables increases. Arrays offer a solution
to this problem.

An array is a multi-element box, a bit like a filing
cabinet, and uses an indexing system to find each variable stored within it.

In C, indexing starts at zero. Arrays, like other
variables in C, must be declared before they can be used.

The replacement of the above example using arrays looks like:

int names[4];
names[0] = 101;
names[1] = 232;
names[2] = 231;
names[3] = 0;

We created an array called names, which has space for four
integer variables. You may also see that we stored 0 in the last space of the array.

This is a common technique used by C programmers to
signify the end of an array.

An image showing internal stucture and location
distribution method of array >

Array And string



0 comments:

Copyright

Copyright © 2008 C Tutorial, All rights are reserved