Initializing Structures
-
A structure can be initialized at the time it is declared
by assigning it a list of member values separated by commas and enclosed in braces.
-
For example, with the structure type for the date:
struct Date
{
int month;
int day;
int year;
};
a structure variable of type Date can be declared and initialized as follows:
Date due_date = {12, 31, 2000};
The first value in the list is assigned to the first member, the second value is assigned to the second member, etc.