【正文】
A First Book of ANSI C Fourth Edition Chapter 12 Structures A First Book of ANSI C, Fourth Edition 2 Objectives ? Single Structures ? Arrays of Structures ? Passing and Returning Structures ? Unions (Optional) ? Common Programming and Compiler Errors A First Book of ANSI C, Fourth Edition 3 Introduction ? Each data item listed in Figure is an entity by itself, called a data field ? Together, all the data fields form a single unit called a record – In C, a record is referred to as a structure A First Book of ANSI C, Fourth Edition 4 Introduction (continued) A First Book of ANSI C, Fourth Edition 5 Introduction (continued) ? A structure’s form consists of the symbolic names, data types, and arrangement of individual data fields in the record ? The structure’s contents consist of the actual data stored in the symbolic names A First Book of ANSI C, Fourth Edition 6 Introduction (continued) A First Book of ANSI C, Fourth Edition 7 Single Structures ? Structure definition in C: struct { int month。 int day。 int year。 } birth。 – Reserves storage for the individual data items listed in the structure – The three data items are the members of the structure ? Assigning actual data values to the data items of a structure is called populating the structure A First Book of ANSI C, Fourth Edition 8 spacing of a structure definition is not rigid Single Structures (continued) A First Book of ANSI C, Fourth Edition 9 Single Structures (continued) ? Multiple variables