Arrays of Structures & Unions in C

Since structures are data types that are especially useful for creating collection items, why not make a collection of them using an array? Similarly, we can create array of Unions. The following code snippet shows how to create an array of structures and access a particular structure element’s member.

struct student
{
int rno;
char name[50];
}
std1[10];
struct student std2[5];
std1[0].rno = 10;
std2[4].name = “umar”;

The following code snippet shows how to create an array of unions and access a particular union element’s member.

union student
{
int rno;
char name[50];
}
std1[10];
union student std2[5];
std1[0].rno = 10;
std2[4].name = “umar”;