How to Iterate Through Array of Structs in C? Last Updated : 01 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. Iterate Over of an Array of StructuresTo 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. C Program to Iterate Over an Array of StructsThe below example demonstrates how we can iterate through an array of structs and access each struct in C. C // C program to illustrate how to iterate through array of // structs #include <stdio.h> // Define the Person struct struct Person { int id; char name[20]; int age; }; int main() { // Creating and initializing an array of Person structs struct Person people[] = { { 1, "Ram", 20 }, { 2, "Mohan", 25 }, { 3, "Ria", 30 } }; // Calculating the number of elements in the array of // struct int numPeople = sizeof(people) / sizeof(people[0]); // Iterating through the array of structs for (int i = 0; i < numPeople; i++) { printf("Person Id: %d, Name: %s, Age: %d\n", people[i].id, people[i].name, people[i].age); } return 0; } OutputPerson 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 (->). Comment More infoAdvertise with us Next Article How to Access Array of Structure in C? V vinod19ldr Follow Improve Article Tags : C Programs C Language c-array C-Arrays C-Structure & Union C Examples +2 More Similar Reads How to Initialize Array of Structs in C? In C, arrays are data structures that store the data in contiguous memory locations. While structs are used to create user-defined data types. In this article, we will learn how to initialize an array of structs in C. Initializing Array of Structures in CWe can initialize the array of structures usi 2 min read How to Search in Array of Struct in C? In C, a struct (short for structure) is a user-defined data type that allows us to combine data items of different kinds. An array of structs is an array in which each element is of struct type. In this article, we will learn how to search for a specific element in an array of structs. Example: Inpu 2 min read How to Access Array of Structure in C? In C, we can create an array whose elements are of struct type. In this article, we will learn how to access an array of structures in C. For Example, Input:myArrayOfStructs = {{'a', 10}, {'b', 20}, {'A', 9}}Output:Integer Member at index 1: 20Accessing Array of Structure Members in CWe can access t 2 min read How to Initialize Array of Pointers in C? Arrays are collections of similar data elements that are stored in contiguous memory locations. On the other hand, pointers are variables that store the memory address of another variable. In this article, we will learn how to initialize an array of pointers in C. Initialize Array of Pointers in CWe 2 min read How to Create an Array of Structs in C? In C, a structure is a user-defined data type that can be used to group items of different types into a single entity while an array is a collection of similar data elements. In this article, we will learn how to create an array of structs in C. Creating an Array of Structs in CTo create an array of 2 min read How to Declare a Pointer to a Struct in C? Structure (or structs) in the C programming language provides a way to combine variables of several data types under one name and pointers provide a means of storing memory addresses. In this article, we will learn how to declare such a pointer to a struct in C. Declaration of Pointer to Struct in C 2 min read Like