VOOZH about

URL: https://www.geeksforgeeks.org/c/how-to-initialize-array-of-structs-in-c/

⇱ How to Initialize Array of Structs in C? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Initialize Array of Structs in C?

Last Updated : 23 Jul, 2025

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 C

We 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 C

struct Str str[] = {
 {structure1_value1, structure1_value2},
 {structure2_value1, structure2_value2},
 {structure3_value1, structure3_value2}
};

C Program to Initialize an Array of Structs

The below example demonstrates how we can initialize an array of structures in C.


Output
Students: 
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