For working professionals
For fresh graduates
More
5. Array in C
13. Boolean in C
18. Operators in C
33. Comments in C
38. Constants in C
41. Data Types in C
49. Double In C
58. For Loop in C
60. Functions in C
70. Identifiers in C
81. Linked list in C
83. Macros in C
86. Nested Loop in C
97. Pseudo-Code In C
100. Recursion in C
103. Square Root in C
104. Stack in C
106. Static function in C
107. Stdio.h in C
108. Storage Classes in C
109. strcat() in C
110. Strcmp in C
111. Strcpy in C
114. String Length in C
115. String Pointer in C
116. strlen() in C
117. Structures in C
119. Switch Case in C
120. C Ternary Operator
121. Tokens in C
125. Type Casting in C
126. Types of Error in C
127. Unary Operator in C
128. Use of C Language
Debugging C programs often reveals a recurring need—handling related data for multiple entities. Hardcoding each variable not only clutters the code but also makes maintenance harder. That’s where the Array of Structure in C becomes a crucial construct. It simplifies data grouping, boosts clarity, and makes managing multiple records straightforward. In this article, you’ll explore everything from syntax to examples, using a simple and practical student structure throughout.
Whether you're dealing with student details, product information, or grouped inputs, structuring your data effectively is key to writing clean and efficient programs. For beginners, understanding how arrays of structures work can bridge the gap between basic and modular C code. It helps reduce redundancy, streamlines logic, and makes the debugging process far more manageable.
Pursue our Software Engineering courses to get hands-on experience!
To create an array of structures in C, start by defining a structure. Use the struct keyword and group-related members under one name. Here's a simple structure for storing student details:
struct student {
char name[50];
char class[50];
int roll_number;
float marks[5];
};
This structure includes a student's name, class, roll number, and marks for five subjects. Once defined, you can create an array of this structure like so:
struct student s[3];
The array s can hold details for three different students. Each element in the array represents one student and holds its own set of member variables.
You can also declare structure variables in two ways:
struct student {
char name[50];
char class[50];
int roll_number;
float marks[5];
} s1;
This declares a structure and a variable s1 in one step.
Must Explore: Introduction to C Tutorial
struct student {
char name[50];
char class[50];
int roll_number;
float marks[5];
};
int main() {
struct student s1;
}
Here, the structure is defined first. The variable s1 is declared later inside the main function.
To handle multiple records efficiently, use an array instead of repeating structure variables. This keeps the code clean and manageable.
Do check out: Array in C
Working with multiple entities often demands better structure and organization. An array of structures solves this problem. Here’s why it’s a smart choice:
With one array, you can store multiple instances of a structure. This enables you to reuse code effectively. Instead of writing repetitive logic for each variable, loops let you handle all elements with ease.
You don’t need to create separate variables like student1, student2, and so on. A single array, such as s[10], is enough to manage all students.
Arrays of structures store all elements in contiguous memory locations. This improves cache performance and speeds up data access.
Loops simplify input and output operations. You can use one loop to populate all student records and another to display them:
for (int i = 0; i < 3; i++) {
// Access s[i].name, s[i].roll_number, etc.
}
If you need to handle more students, change the size of the array. The logic remains the same. You don’t have to modify your core program structure.
By using arrays of structures, your C programs become easier to scale, debug, and maintain.
Must Read: 29 C Programming Projects in 2025 for All Levels [Source Code Included]
An array of structure in C is a collection of structure variables, all grouped under a single name. Each element of the array is a full structure with its own data.
Take the student example again:
struct student {
char name[50];
char class[50];
int roll_number;
float marks[5];
};
To create an array of students:
struct student s[3];
Here, s[0], s[1], and s[2] are independent student records. You can access their members like this:
s[0].name
s[1].roll_number
s[2].marks[4]
Using arrays of structures lets you manage a collection of records without cluttering the program. Instead of defining separate structure variables, you use one array and index through it. This structure also simplifies passing grouped data to functions.
To initialize this array, use loops or direct assignment. For beginners, loops are usually easier and more flexible.
Must Explore : One Dimensional Array in C
Let’s walk through a complete example using the student structure. This will show how to input and display student records using an array.
#include <stdio.h>
struct student {
char name[50];
char class[50];
int roll_number;
float marks[5];
};
int main() {
struct student s[3];
// Input student data
for (int i = 0; i < 3; i++) {
printf("Enter details for student %d:\n", i + 1);
printf("Name: ");
scanf("%s", s[i].name);
printf("Class: ");
scanf("%s", s[i].class);
printf("Roll number: ");
scanf("%d", &s[i].roll_number);
printf("Enter marks for 5 subjects:\n");
for (int j = 0; j < 5; j++) {
printf("Subject %d: ", j + 1);
scanf("%f", &s[i].marks[j]);
}
printf("\n");
}
// Display student data
printf("Student Records:\n");
for (int i = 0; i < 3; i++) {
printf("Student %d:\n", i + 1);
printf("Name: %s\n", s[i].name);
printf("Class: %s\n", s[i].class);
printf("Roll number: %d\n", s[i].roll_number);
printf("Marks: ");
for (int j = 0; j < 5; j++) {
printf("%.2f ", s[i].marks[j]);
}
printf("\n\n");
}
return 0;
}
Enter details for student 1:
Name: Rishabh
Class: 10A
Roll number: 101
Enter marks for 5 subjects:
Subject 1: 85
Subject 2: 78
Subject 3: 92
Subject 4: 88
Subject 5: 91
...
Student 1:
Name: Rishabh
Class: 10A
Roll number: 101
Marks: 85.00 78.00 92.00 88.00 91.00
This code demonstrates how arrays of structures simplify storing and processing data for multiple students in C.
Also Explore : Two Dimensional Array in C
Understanding how control flows through a program that uses an array of structures can make it easier to debug and maintain. The following flowchart illustrates the key stages: defining the structure, accepting input using loops, and displaying the data.
Also Explore: What are Data Structures in C & How to Use Them?
You can also checkout : Array of Pointers in C
The Array of Structure in C is a must-know for anyone working with grouped data. It allows developers to:
Instead of creating separate variables for each entity, you use a single array. This approach works especially well in real-world programs—whether it's handling student records, employee data, or product listings.
With arrays of structures, your C code becomes more modular, reusable, and easy to debug.
Pursue DBA in Digital Leadership from Golden Gate University, San Francisco!
struct student {
char name[50];
char class[50];
int roll_number;
float marks[5];
};
struct student s[10]; // Array of 10 student structures
You can use a list of values during declaration:
struct student s[] = {
{"Ram", "10A", 101, {85, 90, 88, 92, 86}},
{"Shyam", "10B", 102, {75, 80, 78, 82, 79}},
};
Use the index with the dot operator:
printf("%s", s[1].name); // Name of second student
printf("%.2f", s[0].marks[2]); // 3rd mark of first student
Yes. You can pass it like any other array:
void display(struct student s[], int n);
Not mandatory, but highly recommended. Loops make input/output and processing more efficient and less repetitive.
Yes, pointers can be used to access and manipulate elements within the array. For example:
struct student *ptr = &s[0];
You can pass it by reference for better performance:
void display(struct student s[], int n);
Yes, use any sorting algorithm (like bubble sort) based on structure members such as roll_number or marks[0].
Use a loop and compare a member value (e.g., roll_number) with the search key:
if (s[i].roll_number == target) { /* found */ }
Yes, like this:
struct student s[2] = {
{"John", "10th", 1, {88, 76, 90, 85, 92}},
{"Amy", "10th", 2, {91, 87, 89, 93, 88}}
};
Access the index and update directly:
s[0].marks[2] = 95.0;
Yes, for single-word input. But use fgets() for reading full lines (e.g., names with spaces).
It causes undefined behavior. Always validate array bounds before accessing.
Yes. A structure can have members that are arrays of structures, depending on the program design.
Yes, they use contiguous memory which improves performance and cache locality.
Take a Free C Programming Quiz
Answer quick questions and assess your C programming knowledge
Author
Start Learning For Free
Explore Our Free Software Tutorials and Elevate your Career.
Talk to our experts. We are available 7 days a week, 9 AM to 12 AM (midnight)
Indian Nationals
1800 210 2020
Foreign Nationals
+918068792934
1.The above statistics depend on various factors and individual results may vary. Past performance is no guarantee of future results.
2.The student assumes full responsibility for all expenses associated with visas, travel, & related costs. upGrad does not provide any a.