【正文】
} flag。 double rate。 structures, arrays, and pointers may be members of unions A First Book of ANSI C, Fourth Edition 29 Unions (continued) struct { char uType。 union DateTime first, second, *pt。 double time。 default : printf(Invalid type : %c, uType)。 case ‘d’: printf(%f, )。 case ‘i’: printf(%d, )。 – Each of these types, but only one at a time, can actually be assigned to the union variable – A union reserves sufficient memory locations to acmodate its largest member’s data type A First Book of ANSI C, Fourth Edition 27 Unions (continued) ? Individual union members are accessed using the same notation as structure members ? Typically, a second variable keeps track of the current data type stored in the union switch(uType) { case ‘c’: printf(%c, )。 double price。 – double calcNet(struct Employee *pt) – (*pt).idNum or *ptidNum A First Book of ANSI C, Fourth Edition 20 Passing and Returning Structures (continued) A First Book of ANSI C, Fourth Edition 21 Passing and Returning Structures (continued) A First Book of ANSI C, Fourth Edition 22 Passing and Returning Structures (continued) ? ++ and can be applied to structures – ++pthours – (pt++)hours – (++pt)hours A First Book of ANSI C, Fourth Edition 23 Passing and Returning Structures (continued) A First Book of ANSI C, Fourth Edition 24 Returning Structures A First Book of ANSI C, Fourth Edition 25 Returning Structures (continued) A First Book of ANSI C, Fourth Edition 26 Unions