-->

Arrays of Structures

Arrays of Structures
Arrays of Structures
We can use structures to describe the format of a number of related variables
We may also declare arrays of structure. Each element of an array represents a structure variable.

Example:
struct marks student[100];
defines an array called student, that consists of 100 elements. Each element is said to be of the type struct class
struct marks
{
int sl;
int s2;
int s3;
};
main()
{
struct marks student[3]= { {45,68,81}, {75,53,69}, {57,36,71}};
}

This declares the student as an array of three elements student 0, student 1 and student 2 and initialize their members as follows
student[0].s1=45;
student[0].s2=68;
student[0].s3=81;
----------------------
----------------------
student[2].s3=71;
A Since student is an array, we usually use array-accessing methods to access individual elements and then the member operator to access the members.
Remember, each element of a student array, is a structure variable with three members.
An Array of structures is stored inside the memory in the same way as a multidimensional array
45
68
81
75
53
69
57
36
71

The array student inside memory

Related Posts

Subscribe Our Newsletter