![]() |
In C, an array of structs refers to the array that stores the structure variables as its elements. In this article, we will learn how to delete an element from an array of structures in C. For Example, Input: struct Person persons[3] = { { "Person1", 25 }, { "Person2", 30 }, { "Person3", 22 }, }; TargetToDelete= "Person2" Output: Array of Persons after deletion: Name: Person1, Age: 25 Name: Person3, Age: 22 Remove an Element from an Array of Structure in CWe cannot directly remove the element for an array in C so to remove an element from an array of structures, we need to overwrite the target element that we want to remove by shifting all elements after the target element one position toward the beginning of the array. C Program to Delete an Element from an Array of StructureThe below example demonstrates how we can remove the element from an array of structures in C. C
Output
Array of Persons after deletion: Name: Person1, Age: 25 Name: Person3, Age: 22 Time Complexity: O(N), where N is the size of the array.
|
Reffered: https://www.geeksforgeeks.org
C Language |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |