How to Create an Array of Structs in C? Last Updated : 11 Mar, 2024 Summarize Comments Improve Suggest changes Share 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 S syam1270 Follow Improve Article Tags : C Programs C Language c-array C-Arrays C Examples +1 More Similar Reads C Programming Language Tutorial C is a general-purpose mid-level programming language developed by Dennis M. Ritchie at Bell Laboratories in 1972. It was initially used for the development of UNIX operating system, but it later became popular for a wide range of applications. Today, C remains one of the top three most widely used 5 min read Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact 12 min read Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and 9 min read 3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power 13 min read Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca 7 min read CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi 6 min read What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac 13 min read Python Variables In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i 6 min read Like