Array Type Members of Structures:
The members of structure may be of different types. These can also be simple variables or array variables.
For example, in the following structure, the member “sub” is an array of int type. It has four elements. The member “name” is of string type and a string is also an array.
struct rec
{
char name [15];
int sub [4]
};
Method to access the elements of an array that is a member of a structure is the same as for other members. The dot operator is used. To access a specific element of an array of a member, its index value or subscript is used. The variable of a structure type that has an array member is initialized in the usual manner. The members of the array are initialized in the same sequence in which they are defined in the structure.
For example, in the following example, the member “sub” is initialized in the same way as an array variable is initialized.
struct result
{
char name [15];
int sub [4] ;
int total;
result student = {“John”, {62,69,70,40},0};
comment closed