VOOZH about

URL: https://www.geeksforgeeks.org/c/insert-element-into-array-of-structs-at-specific-position-in-c/

⇱ How to Insert an Element into an Array of Structs at a Specific Position in C? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Insert an Element into an Array of Structs at a Specific Position in C?

Last Updated : 23 Jul, 2025

In C, structs allow the users to create user-defined data types which can be used to store data of different types in a single unit. In many use cases, we might use an array of structs to store the structs in contiguous memory locations to access them sequentially. In this article, we will learn how we can insert an element into an array of structs at a specific position in C.

Insert an Element at a Specific Position into Array of Structs

In C, we have to manually insert the element in the array of structs at a specific position. We also need to create a space for the new elements by shifting all the elements to the left.

Approach

  1. Create the structure that you want to insert.
  2. Shift the elements of the array to make space for the new element.
  3. Insert the new element at the desired position in the array.

C Program to Insert an Element into an Array of Structs at a Specific Position


Output
Original array:
ID: 1, Name: Geeks
ID: 2, Name: for
ID: 3, Name: Geeks

Array after insertion:
ID: 1, Name: Geeks
ID: 4, Name: C++
ID: 2, Name: for
ID: 3, Name: Geeks

Time Complexity: O(N), where N is the total number of elements in the Array.
Space Complexity: O(1)


Comment