Array
Information about Array
An array is a data structure used to store collections of similar values under a given
name. They are also called subscripted variables. Elements of array are stored in the
contiguous memory locations.
These elements are accessed by their name of the
array followed by the subscript number within brackets.
Like variable, array(s) must also be declared before they are used.
Data_type array_name [number of elements in array]
Where data type is a valid type (like int, float...), name is a valid identifier and the
elements field (which is always enclosed in square brackets [ ]), specifies how many
of these elements the array has to contain.
Entering Data into an Array
Since array represents a collection of values, so to input data into the individual
elements of the array, we make use of loop statements. If the actual size of the array
is known in advance, then for loop is preferred to while loop or do–while loop.
Accessing the Values of an Array
In any point of a program in which an array is visible, we can access the value of any
of its elements individually as if it was a normal variable, thus being able to both read
and modify its value. The format is as simple as:
name[index];
There are two types of arrays: (1) one dimension and (2) multi dimensional arrays
One pair of square brackets is used for each (1) one dimensional array dimension.
For example one dimensional arrays has only one subscript, and it is viewed as row
matrix or column matrix,
But, multidimensional arrays have more than one subscript, hence the name twodimensional
array three dimensional arrays and so on. C does not support strings
data type but strings are handled as an array of characters.
There is rich library of functions for manipulating strings.
Declaration of Two Dimensional Arrays
In C language, the syntax used to define 2-D or Dim array is :
data type array _ name [row] [columns]:
Where the Row → represents the no. of elements processed in the Subscript 1
and
the column → represents the no. of elements processed in the Subscript 2.
Comments
Post a Comment