How to Initialize Array of Structs in C? Last Updated : 28 Feb, 2024 Comments Improve Suggest changes Like Article Like Report 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 using list initialization where each of the nested lists corresponds to the members of a single structure element. Syntax to Initialize Array of Structs in Cstruct Str str[] = { {structure1_value1, structure1_value2}, {structure2_value1, structure2_value2}, {structure3_value1, structure3_value2} };C Program to Initialize an Array of StructsThe below example demonstrates how we can initialize an array of structures in C. C // C Program to Initialize an Array of Structs #include <stdio.h> // Define the struct struct Student { char name[50]; int roll; float marks; }; int main() { // Initialize an array of structs struct Student students[] = { { "John", 1, 85.5 }, { "Emma", 2, 90.6 }, { "Harry", 3, 92.7 } }; // Print the array of structs printf("Students: \n"); for (int i = 0; i < 3; i++) { printf("Name: %s, Roll: %d, Marks: %.2f\n", students[i].name, students[i].roll, students[i].marks); } return 0; } OutputStudents: Name: John, Roll: 1, Marks: 85.50 Name: Emma, Roll: 2, Marks: 90.60 Name: Harry, Roll: 3, Marks: 92.70 Time Complexity: O(N), where N is the size of the array.Space Complexity: O(1) as no extra space for utilization is required. Comment More infoAdvertise with us Next Article How to Initialize Array of Structs in C? fizakhatoon947 Follow Improve Article Tags : C Programs C Language C-Arrays C-Structure & Union C Examples +1 More Similar Reads 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 Initialize Char Array in Struct in C? In C++, we can also define a character array as a member of a structure for storing strings. In this article, we will discuss how to initialize a char array in a struct in C. Initialization of Char Array in Struct in CWhen we create a structure instance (variable) in C that includes a char array, we 2 min read How to Initialize Array to 0 in C? Initializing an array to zero is a common practice in programming to ensure that all elements start with a known value. In C, there are several ways to initialize an array to zero. In this article, we will explore different methods to do so. Initialize Array to 0 in CThere are mainly two ways to ini 2 min read How to Iterate Through Array of Structs in C? 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 o 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 Initialize a 2D Array in C? In C, a 2D Array is a type of multidimensional array in which data is stored in tabular form (rows and columns). It has two dimensions so it can store the data and can expand in two directions. In this article, we will learn how to initialize a 2D array in C.There are three main ways to initialize t 4 min read How to Initialize a 3D Array in C? In C, a 3D array is a type of multidimensional array that stores data in a three-dimensional grid. It has three dimensions, allowing it to store data in three directions: rows, columns, and depth. In this article, we will learn how to initialize a 3D array in C.There are three ways in which a 3D arr 4 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 Initialize a Dynamic Array in C? In C, dynamic memory allocation is done to allocate memory during runtime. This is particularly useful when the size of an array is not known at compile time and needs to be specified during runtime. In this article, we will learn how to initialize a dynamic array in C.Initializing a Dynamic Arrays 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 Like