VOOZH about

URL: https://www.geeksforgeeks.org/c/advantages-and-disadvantages-of-array-in-c/

⇱ Advantages and Disadvantages of Array in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Advantages and Disadvantages of Array in C

Last Updated : 23 Jul, 2025

An array is a data structure that stores a collection of elements, all of the same data type, in a contiguous block of memory. Each element in the array is identified by an index, which is a numerical value that represents the position of the element in the array. The first element in the array has an index of 0, the second element has an index of 1, and so on.

Arrays can be used to store a variety of data types, including integers, floats, characters, and even user-defined types. They are commonly used to store collections of similar data, such as a list of numbers, a list of strings, or a list of objects.

πŸ‘ Image

Though, the array got its own set of advantages and disadvantages.

Below are some advantages of the array:

  • In an array, accessing an element is very easy by using the index number.
  • The search process can be applied to an array easily.
  • 2D Array is used to represent matrices.
  • For any reason a user wishes to store multiple values of similar type then the Array can be used and utilized efficiently.
  • Arrays have low overhead.
  • C provides a set of built-in functions for manipulating arrays, such as sorting and searching.
  • C supports arrays of multiple dimensions, which can be useful for representing complex data structures like matrices.
  • Arrays can be easily converted to pointers, which allows for passing arrays to functions as arguments or returning arrays from functions.

Now let’s see some disadvantages of the array and how to overcome it:

: The array is static, which means its size is always fixed. The memory which is allocated to it cannot be increased or decreased. Below is the program for the same:


Output
Element at index 0 is 5
Element at index 11 is -1176897384

: In the above program the array of size 10 is declared and the value is assigned at a particular index. But when the value at index 11 is printed then it prints the garbage value because the array was accessed out of the bound index. In some compiler, it gives error as "Array Index Out Of Bound.".

: To overcome that problem use Dynamic Memory Allocation like malloc(), calloc(). It also helps us to deallocates the memory using the free() method which helps to reduce wastage of memory by releasing it. Below is the program for the same:


Output
The elements are: 1 2 3 4 5 6 7 8 9 10

:The array is homogeneous, i.e., only one type of value can be store in the array. For example, if an array type "int", can only store integer elements and cannot allow the elements of other types such as double, float, char so on. Below is the program for the same:


Output
100
547.000000
Ram

Output:

πŸ‘ Image

: The above code gives "Compilation Error" as an integer type array is assigned value to a string and float type.

: To overcome that problem, the idea is to structure, where it can store non-homogeneous (heterogeneous) value. Below is the program for the same:


Output
100
547.000000
Ram

: The array stores data in contiguous(one by one) memory location. Below is the representation of the same:

πŸ‘ Image

To overcome the sequential access to the array, the idea is to use the Linked list. In a Linked list, the elements are not stored in contiguous memory locations. Below is the representation of the same:

πŸ‘ Image

: The operation insertion and deletion over an array are problematic as to insert or delete anywhere in the array, it is necessary to traverse the array and then shift the remaining elements as per the operation. This operation cost is more.

Example: For inserting 22 in 3rd position of the array then below are the steps:

πŸ‘ Image

Below is the program to illustrate the same:


Output
1 2 3 4 5 6 7 8 9 10 
Array after inserting 50 at position 5
1 2 3 4 50 5 6 7 8 9 10

To overcome the above problem using a Linked List. Below is the representation of the same:

πŸ‘ Image

Below is the program to implement the same:


Output
Current Linked List is: 3 1 5 7 

 Linked List after insert 6 in 4th position: 3 1 5 6 7
Comment
Article Tags: