![]() |
VOOZH | about |
In C, while working with an array of structs we have to iterate through each struct in an array to perform certain operations or access its members. In this article, we will learn how to iterate through an array of the structs in C.
To iterate through an array of the structures in C, we can simply use a loop (for loop or a while loop) and access each struct in the array using the array indexing, and then we can access every member using the member name.
The below example demonstrates how we can iterate through an array of structs and access each struct in C.
Person Id: 1, Name: Ram, Age: 20 Person Id: 2, Name: Mohan, Age: 25 Person Id: 3, Name: Ria, Age: 30
Time Complexity: O(N), here n is the number of elements in the array of structs.
Auxilliary Space: O(1)
Note: We can also use a pointer to iterate through the array and access each element's members using the arrow operator (
->).