C Array Applications

In the previous tutorials we have learnt more about array and type of arrays. In this example we will be learning different array applications in c programming.

C Programming Array Application :

Array is used for different verities of applications. Array is used to store the data or values of same data type. Below are the some of the applications of array –

A. Stores Elements of Same Data Type

Array is used to store the number of elements belonging to same data type.

int arr[30];

Above array is used to store the integer numbers in an array.

arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
arr[3] = 40;
arr[4] = 50;

Similarly if we declare the character array then it can hold only character. So in short character array can store character variables while floating array stores only floating numbers.

B. Array Used for Maintaining multiple variable names using single name

Suppose we need to store 5 roll numbers of students then without declaration of array we need to declare following –

int roll1,roll2,roll3,roll4,roll5;
  1. Now in order to get roll number of first student we need to access roll1.
  2. Guess if we need to store roll numbers of 100 students then what will be the procedure.
  3. Maintaining all the variables and remembering all these things is very difficult.

Consider the Array :

int roll[5];

So we are using array which can store multiple values and we have to remember just single variable name.

C. Array Can be Used for Sorting Elements

We can store elements to be sorted in an array and then by using different sorting technique we can sort the elements.

Different Sorting Techniques are :

  1. Bubble Sort
  2. Insertion Sort
  3. Selection Sort
  4. Bucket Sort

D. Array Can Perform Matrix Operation

Matrix operations can be performed using the array.We can use 2-D array to store the matrix.
[box]Matrix can be multi-dimensional[/box]

E. Array Can be Used in CPU Scheduling

CPU Scheduling is generally managed by Queue. Queue can be managed and implemented using the array. Array may be allocated dynamically i.e at run time. [Animation will Explain more about Round Robin Scheduling Algorithm | Video Animation]

F. Array Can be Used in Recursive Function

When the function calls another function or the same function again then the current values are stores onto the stack and those values will be retrieve when control comes back. This is similar operation like stack.