Array

An Array is a collection of similar data type value in a single variable. An array is a derived data type in C, which is constructed from fundamental data type of C language.

download

  • Element − Each item stored in an array is called an element.

  • Index − Each location of an element in an array has a numerical index which is used to identify the element.

Array Representation

screenshot_20

Basic Operations:

Following are the basic operations supported by an array.

  • Traverse − print all the array elements one by one.

  • Insertion − add an element at given index.

  • Deletion − delete an element at given index.

  • Search − search an element using given index or by value.

  • Update − update an element at given index

Insertion Operation

Insert operation is to insert one or more data elements into an array. Based on the requirement, new element can be added at the beginning, end or any given index of array.

Here, we see a practical implementation of insertion operation, where we add data at the end of the array −

Algorithm:

Let Array is a linear unordered array of MAX elements.

Inserting Elements an Array

screenshot_21

Output

screenshot_22

Deletion Operation

Deletion refers to removing an existing element from the array and re-organizing all elements of an array.

Output

Search Operation

You can perform a search for array element based on its value or its index.

Output

Update Operation

Update operation refers to updating an existing element from the array at a given index.

Output