**What is an Array?**

Whenever we want to work with large number of data values, we need to use that much number of different variables. As the number of variables are increasing, complexity of the program also increases and programmers get confused with the variable names. There may be situations in which we need to work with large number of similar data values. To make this work more easy, C programming language provides a concept called "Array".

An array is a variable which can store multiple values of same data type at a time.An array can also be defined as follows...

"Collection of similar data items stored in continuous memory locations with single name".To understand the concept of arrays, consider the following example declaration.

###
**int a, b, c;**

Now consider the following declaration...

### int a[3];

Here, the compiler allocates total 6 bytes of continuous memory locations with single name 'a'. But allows to store three different integer values (each in 2 bytes of memory) at a time. And memory is organized as follows...
That means all these three memory locations are named as 'a'. But "how can we refer individual elements?" is the big question. Answer for this question is, compiler not only allocates memory, but also assigns a numerical value to each individual element of an array. This numerical value is called as "Index". Index values for the above example are as follows...

The individual elements of an array are identified using the combination of 'name' and 'index' as follows...

### arrayName[indexValue]

For the above example the individual elements can be referred to as follows...If I want to assign a value to any of these memory locations (array elements), we can assign as follows...

### a[1] = 100;

The result will be as follows...**Basic Operations**

Following are the basic operations supported by an array.

**Traverse**− print all the array elements one by one.**Insertion**− Adds an element at the given index.**Deletion**− Deletes an element at the given index.**Search**− Searches an element using the given index or by the value.**Update**− Updates an element at the given index.

**Arrays can of following types:**

**1. One dimensional (1-D) arrays or Linear arrays**

**2. Multi dimensional arrays**

**(a) Two dimensional (2-D) arrays or Matrix arrays**

**(b) Three dimensional arrays**

**1. One dimensional (1-D) arrays or Linear arrays:**

In it each element is represented by a single subscript. The elements are stored in consecutive memory locations. E.g. A [1], A [2], ….., A [N].

**2. Multi dimensional arrays:**

**(a) Two dimensional (2-D) arrays or Matrix arrays:**

In it each element is represented by two subscripts. Thus a two dimensional m x n array A has m rows and n columns and contains m*n elements. It is also called matrix array because in it the elements form a matrix. E.g. A [2] [3] has 2 rows and 3 columns and 2*3 = 6 elements.

**(b) Three dimensional arrays:**

In it each element is represented by three subscripts. Thus a three dimensional m x n x l array A contains m*n*l elements. E.g. A [2] [3] [2] has 2*3*2 = 12 elements.

**INDEX**

## No comments:

## Post a Comment