Loading, please wait...

Arrays

Arrays are the data structure having the linear relationship between the elements represented by means of sequential memory locations. Arrays contained the similar kind of elements (values or variables). Arrays are useful when the number of elements to be stored is fixed. Operations like traversal, searching and sorting can easily be performed on arrays.

 

Element- The values or data stored in an array is known as the elements of an array.

 

Index- For recognizing an element in the array each value is associated with a numerical key value known as Index of the element in the array. Index value in the array is starts with 0 for the first element.

 

 

Array Representation:

An array can be represented just as any other variable in C, i.e. data followed by array name. The only modification in the declaration is the subscript in the bracket which indicates the number of elements it will hold. By declaring an array, the specified number of memory locations (size of array) are allocated in the memory.

 

For example,

int no_animals[50];

float commissions[25];

char colors[15];

The first example is of an integer type array where each element will hold an integer value, second one is the floating type array and the third is the character type array.

 

The elements of an array can be easily processed as they are stored in contiguous memory locations.

For example,

int my_array[5];

 

This is stored as

 

500

501

502

503

504

my_array[0] my_array[1] my_array[2] my_array[3] my_array[4]



Basic Operations: Following are some operations performed on array.

Traversal: It involves processing each element in the list.

Searching: Searching or finding any element with a given value or the record with a given key.

Insertion: Adding a new element to the array.

Deletion: Removing an element from the array.

Sorting: Arranging the elements in some order.

Merging: Combining two lists into a single list.

Updating: Updating an element at the defined index.



Array Initialization

Arrays can be initialized at the time of declaration. For Example

int age[5] = [12, 45, 54, 21, 36];

float salary[3] = [25000, 35000, 45000];