C'Language - [One Dimensional Array]

♠ Posted by Unknown in at 00:35

One Dimensional Array:

An array is a group of related data items that share a common name and common data type. In the array every data item are differentiated with its subscript number. A particular value is indicated by writing a number called index number or subscript in the bracket after the array name.

A list of items can be given one variable name using only one subscript and such a variable is called a single-subscripted variable or a one-dimensional array. In C, Single-subscripted variable xi can be expressed as,

                             x[1], x[2], x[3]…………… x[n]

The subscript can begin with number 0. That is x[0] is allowed.

Declaration of Arrays :

Like any other variable, arrays must be declared before they are used. The general form of array declaration is       
                             type variable-name[size];

The type specifies the type of element that will be contained in the array, such as int, float, or char and the size indicates the maximum number of elements that can be stored inside the array.

For example, if we want to represent a set of five number, say (35, 40, 20, 57, 19) by an array variable number, then we may declare the variable number as follows
  
                           int number[5];

and the computer reserves five storage locations as shown below:         

Image: One Dimensional Array

These elements may be used in the programs just like any other C variable. The subscript of an array can be integer constants, integer variables like i, or expressions that yield integers. C performs no bounds checking and, therefore, care should be exercised to ensure that the array indices are within the declared limits.


0 comments:

Post a Comment