How to Create an Array of Structs in C? Last Updated : 11 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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 structs, we first need to define the struct type and then declare an array of that type using the below syntax. Syntax to Create an Array of Structure in C// Define the structstruct StructName { dataType1 member1; dataType2 member2; // more members...};// Declare an array of structsstruct StructName arrayName[arraySize];Here, StructName is the name of the struct.dataType1, dataType2 are the data types of the members of the struct.member1, member2 are the names of the members of the struct.arrayName is the name of the array of structs.arraySize is the size of the array.C Program to Create an Array of StructsThe below program demonstrates how we can create an array of structs in C. C // C program to demonstrate how to create an array of // structs #include <stdio.h> // Define the struct struct Student { int id; char name[50]; }; int main() { // Declare the size of the array int size = 5; // Declare an array of structs struct Student myArray[size]; // Initialize data to structs present in the array for (int i = 0; i < size; i++) { myArray[i].id = i + 1; snprintf(myArray[i].name, sizeof(myArray[i].name), "Student%d", i + 1); } // Print the data of structs present in the array printf("Array Elements:\n"); for (int i = 0; i < size; i++) { printf("Element %d: ID = %d, Name = %s\n", i + 1, myArray[i].id, myArray[i].name); } return 0; } OutputArray Elements: Element 1: ID = 1, Name = Student1 Element 2: ID = 2, Name = Student2 Element 3: ID = 3, Name = Student3 Element 4: ID = 4, Name = Student4 Element 5: ID = 5, Name = Student5 Time Complexity: O(N), here N is the number of elements present in the arrayAuxiliary Space: O(N) Comment More infoAdvertise with us Next Article How to Create an Array of Structs in C? S syam1270 Follow Improve Article Tags : C Programs C Language c-array C-Arrays C Examples +1 More Similar Reads How to Dynamically Create Array of Structs in C? In C, an array is a data structure that stores the collection of elements of similar types. Structs in C allow the users to create user-defined data types that can contain different types of data items. In this article, we will learn how we can create an array of structs dynamically in C. Dynamicall 2 min read How to Create a Dynamic Array of Structs? In C, we have dynamic arrays in which we can allocate an array of elements whose size is determined during runtime. In this article, we will learn how to create a dynamic array of structures in C. Create a Dynamic Array of Structs in CA dynamic array of structs in C combines dynamic arrays and struc 2 min read How to Create a Dynamic Array of Strings in C? In C, dynamic arrays are essential for handling data structures whose size changes dynamically during the program's runtime. Strings are arrays of characters terminated by the null character '\0'. A dynamic array of strings will ensure to change it's size dynamically during the runtime of the progra 3 min read How to Add an Element to an Array of Structs in C? In C, a struct is a user-defined data type that allows the users to group related data in a single object. An array of structs allows to store multiple structs in contiguous memory locations. In this article, we will learn how to add an element to an array of structs in C. Example: Input: structArra 3 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 Delete an Element from an Array of Structs in C? 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 }, }; Ta 2 min read How to Pass Array of Structure to a Function in C? An array of structures in C is a data structure that allows us to store multiple records of different data types in a contiguous memory location where each element of the array is a structure. In this article, we will learn how to pass an array of structures from one function to another in C. Passin 2 min read 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 Create a Dynamic Array Inside a Structure? In C, the structure can store the array data types as one of its members. In this article, we will learn how to create a dynamic array inside a structure in C. Creating a Dynamic Array Inside a Structure in CTo create a dynamic array inside a structure in C, define a structure that contains a pointe 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 Like