Thursday, February 28, 2013

Arrays

Array is a defined as collection of finite number of homogeneous elements(same type elements) or data item.It means an array can contain of type of data only, either all integers, all floating number etc. it is a group of contiguous or related data item that share a common name. it is basically a collection of  same data type is other words. declaration of arrays is as following:~
char a [5];
Where char specifies the data type or type elements array store. "a" is the name of array, and the number specified inside the square brackets is the number of elements is the number of elements as array can store, that is also called length of array.
length of size of array is the total number of elements.
Length of array = UB - LB + 1
 Here - UB- denotes upper bound
             LB- denotes lower bound
   Where under bound is the largest index and lower bound is the lowest index of the array.
If lower bound=1 then length of array is equal to upper bound.
Some important points about of array :
1.  The individual element of an array can be accessed by specifying name of the array follows by index inside the brackets for example to access third element of array a, we have to give the following statement :
a[2] 
2.  The first element of an array has index [0]. It means the first element and last element will be specified as:
a [0] and [n - 1]
3.  Array are normal like any other variable.
4.  Array can always be read or written through loop.If we study about one dimensional the requires one loop for reading and writing. 
For example
(a) reading an array :
for(i=0; i<=n; i++)
{
scanf("%d",&a[i]);
}
(b) for printing an array :
for (i=0;i<=n;i++)
{
printf("%d",a[i]);
}
similarly we are studying about two dimensional array then we require two loops. And similarly the array of n dimensional require n loops:
Example Let A be 10 element of linear array of integer such that
A[0]=1, A[1]=2, A[2]=3, A[3]=4, A[4]=5, A[5]=6, A[6]=7, A[7]=8, A[8]=9, A[9]=10
So length of array = UB-LB+1
=9-0+1
=10
Some command operation performed on array are as follows:
  1. Creating:Creating an array.
  2. Traversing:Processing every element of array.
  3. Searching:Finding the location of an element.
  4. Insertion:Insert a new element in given array.
  5. Deletion:Delete an item from  the array.
  6. Merging: Merging of an arrays.
So these are the some operation of an arrays. this was the brief description of an array.
TYPES OF ARRAY -CLICK HERE

No comments:

Post a Comment