struct date { int month; int day; int year; }; Here,
date is a structure (user-defined) that has three
members, called
month, day, and year. The
definition of
date here defines a new data type in the language in the sense that the variables may
subsequently be declared to be of type
struct date as follows:
struct date today; However, unlike variables of type int, float, or char, a special syntax is needed when dealing with structure variables.
A member function is accessed by specifying the variable name, followed by a period (.) or dot operator, and then the member name. For example, today.day = 24; Note that there are no spaces allowed between the variable name, the period, and the
member name. So to set the year of the date, the expression is: