Saturday, 3 September 2016

characteristics of an array


  • ARRAY TERMINOLOGY
  • CHARACTERISTICS OF AN ARRAY 
 

                                               ARRAY TERMINOLOGY

SIZE : Number of elements or capacity to store elements in an array is called its size . It is always                    mentioned in brackets([ ]).


TYPE: Types refer to data type.It decides which type of element is stored in the array .It also instructs              the compiler to reserve memory according to data type .

BASE: The address of the first element (0th) is a base address . The array name itself stores address                of the first  element.

INDEX: The array name is used to refer to the array element. For example , num[x] , num is array                       name and x is index.The value of x begins from 0 to onwards depending on the size of the                   array .The index value is always an integer .

RANGE: Index of an array i.e value of x varies from lower bound to upper bound while writing or                     reading elements from an array . For example  in  num[100]  the range of index is 0 to 99.

WORD: It includes the space required for an element. in each memory location,computer can store a                  data piece.The space occupation varies from machine to machine.If the size of element is                     more than word (one byte) then it occupies two successive locations.The variables of data                    type  int,float,long need more than one byte in memory.

                                  CHARACTERISTICS OF AN ARRAY

  1. The declaration int a[5]  is nothing but creation of five variables of integer type in memory instead of declaring five variables for five values, the programmer can define them in an array .
  2. All the elements of an array share the same name,and they are distinguished from one another with the help of the element number.
  3. The element number in an array play a major role for calling each element.
  4. Any particular element of an array can be modified separately without disturbing the other elements.
                    int a[5]={1,2,3,4,8};
            If a programmer needs to replace  8 with 10,then it need not require changing all other                         numbers except 8.To carry out this task the statement  a[4]=10 can be used. Here,other four               elements are not disturbed.

      5. Any element of an array  a[ ]  can be assigned/equated to another ordinary variable or array                 variable of its type.
   

  EXAMPLE:
   
       b=a[2];
      a[2]=a[3];
  •   In the statement   b=a[2]  or vice versa,the value of a[2]  is asigned to 'b',where 'b' is an integer.
  • In the statement  a[2]=a[3]or vice versa ,the value of a[2] is assigned to  a[3],where both the elements are of the same array .
  • The array elements are stored in continuous memory locations.
     6. Array elements are stored in contigious memory locations.
 
     7. Once the arrays is declared,its lowest boundary cannot be changed but upper boundary can be               expanded .The array name itself is  a constant pointer and we cannot modify it.Therefor, the                 lowest boundary of an array cannot be expanded.In other words ,even if the boundary exceeds             then specified,nothing happens.the compiler throws no errors. 
     8. We know that an array name itself is a pointer . Though it is a pointer , it does not need '*'                    operator.The brackets([ ]) automatically denote that the variable is a pointer.
     9. All the elements of an array share the same name, and they are distinguished from one another            with the help of the element number.
   10. The amount of memory required for an array depends upon the data type and the number of                elements.The total size in bytes for a single dimensional array is computed as shown below:
               total bytes=sizeof(data type)  x size of array 
   11. The  operation such as insertion,deletion of an element can be done with the list  but cannot be            done with an array .Once an array is created we cannot remove or insert memory location. An              element can be deleted,replaced but the memory location as it is.

No comments:

Post a Comment