What are the various operations you can perform on an Array?

An array supports the following operations:

  • Traversal
  • Insertion
  • Deletion
  • Search

Other operations include sorting ascending, sorting descending, etc. Let’s follow up on these individually.

Traversal:

Visiting every element of an array once is known as traversing the array.

It is important for use cases like:

  • Storing all elements – Using scanf()
  • Printing all elements – Using printf()
  • Updating elements.

An array can easily be traversed using a for loop in C++

Array Size:

If we create an array of length 100 using a[100]. It is possible for a program to use just 60 elements out of these 100. (But we cannot go beyond 100 elements).

Insertion:

An element can be inserted in an array at a specific position. For this operation to succeed, the array must have enough capacity.

Sorting:

Sorting means arranging an array in an orderly fashion (ascending or descending). We have different algorithms to sort arrays. In the upcoming videos, we will explore these in much more detail.

Also, you will learn how to debug possible errors related to arrays. This video will also revise for loops and iteration methods to dynamically determine array size during traversal.

Syntax:

//Initialization Operation 
Int Arr1; 
Arr1[0] = -10; 

// Access an Element 
printf("%d\n", arr[2]); 

//Modify Operation 
Arr1 [0] = 15;