Array Declaration


Array Declaration









Declaration is an important process for a variable so that the compiler will know what kind of variable , containing which type of value and of what size is required by the user .
    
   Therefore , an array is also declared as other variables. In declaration we provides the name and the size of array.

Syntax of array declaration is as follows : - 

          Int - N  [a];

  • Int : Type of Data
  • N : Name of Variable
  • [a] : Size of Length

Type of Data or data type defines the type or category of element's can be stored in the arrays .

Like - int type only store number's, Name (n) specifies the name of array or variable.














[a] Size or Length specifies the capacity of storing elements.
Like [10] means it can only store 10 elements. For example - 
    
           int N [10].

In the above example, the name of array is N and it can accept only 10 integer (number) type of elements.

The Array as an ADT : 











We can represent an array as an abstract data type. We assume the function type (arg) , which returns the type of its argument, arg . But , such a function cannot exist in C , since C  cannot  dynamically determine the type of a variable. However, since we are not concerned here with implementation, but rather with specification, the use of such a function is permissible.

      










Let ARR TYPE (ub , el type) denote the ADT corresponding to the C array type el type array  [ub] .  In this case, ub and el type are the parameters. Note that el type is a type indicator, not a value we may now view any one - dimensional array as an entity of the type ARR TYPE.

For example,

ARR TYPE (05, int) would represent the type of the array x in the declaration int x [05]. 


The specification follows - 













abstract store (a, i, elt)
ARR TYPE ( ub, el type) a;
int i;
el type elt;
precondition 0 <=I<ub;
post condition a[i]==elt;

/* written a[i]=elt*/


The store operation is the first operation that modifies one of its parameters, like in the array a. This is indicated in the post condition by specifying the value of the array element to which elt is being assigned. Unless a modified value is specified in a post condition,we assume that all parameters retain the same value after the operation is applied in a post condition as before. It is not necessary to specify that such values remain unchanged In this example, all array elements other than the one to which elt is assigned retain the same values.
     
        







Once the operation extract has been defined, together with its bracket notation, a[i] , that  notation can be used for the subsequent store operation specification . Within the post condition of extract , however, subscripted sequence notation must be used , since the array bracket notation itself is being defined.










Thank You.........





   

Comments

Popular posts from this blog

Data Structure and C

Description of Various Data Structures