An array of structures is an array whose elements are structure variables of the same structure type. It is useful for storing multiple records of the same kind.
An array of structures is an array whose elements are structure variables of the same structure type. It is useful for storing multiple records of the same kind.
Here, students can store records of 50 students.
A single structure variable stores one record, while an array of structures can store many similar records together. This is useful for student, employee, book, and product records.
Instead of creating s1, s2, and
s3 separately, an array can store all three student
records as students[0], students[1],
and students[2].
An array of structures is declared by placing the array name and size after the structure type.
This creates an array that can store three
struct Student records.
An individual structure in the array is accessed using its index, and its member is then accessed using the dot operator.
The index selects the required student record and the dot operator accesses its member.
A loop can be used to read or display all records in an array of structures. This avoids writing the same statements repeatedly.
The loop accesses the roll number of each student one by one.
A college system may need to store information for many students. An array of structures can keep all student records under one common structure type.
students[0] → Student 1
students[1] → Student 2
students[2] → Student 3
Write a C program to store the roll number and percentage of three students using an array of structures and display all the records.
Create a Student structure and declare an array of
three students. Use a for loop to read and display
the values.
An array of structures combines the features of arrays and structures. Each array element is a complete structure record, and individual members are accessed using the index and dot operator.
Enter roll number for student 1: 101
Enter percentage: 82.5
Enter roll number for student 2: 102
Enter percentage: 76.0
Enter roll number for student 3: 103
Enter percentage: 88.5
Student Records:
Roll Number = 101, Percentage = 82.5
Roll Number = 102, Percentage = 76.0
Roll Number = 103, Percentage = 88.5
Each element of the array is a complete structure record.
For example, students[1].rollNo accesses the roll
number of the second student.
| Concept | Remember |
|---|---|
| Array of Structures | Stores multiple structure records of the same type. |
| Declaration | struct Student students[3]; |
| Array Element | Each element is one complete structure record. |
| Member Access | students[i].rollNo |
| Loop | Useful for processing multiple records. |
Watch a beginner-friendly explanation of arrays of structures in C programming.
A short handwritten-style revision sheet for arrays of structures will be provided here.
Use the mind map for quick revision of structure array, indexing, member access and loops.