www.gibmonks.com

Main Page




Previous Page
Next Page

[Page 1061 (continued)]

22.3. Initializing Structures

Structures can be initialized using initializer lists, as is done with arrays. For example, the declaration

Card oneCard = { "Three", "Hearts" };

creates Card variable oneCard and initializes member face to "Three" and member suit to "Hearts". If there are fewer initializers in the list than members in the structure, the remaining members are initialized to their default values. Structure variables declared outside a function definition (i.e., externally) are initialized to their default values if they are not explicitly initialized in the external declaration. Structure variables may also be set in assignment expressions by assigning a structure variable of the same type or by assigning values to the individual data members of the structure.


Previous Page
Next Page