Once a structure is defined, we can declare variables of that type. The variables of that structure type must be initialized before use. C gives us a number of ways to do this, depending on the needs of the situation.
Given the definition of struct Card, we can initialize a variable of that type in one of three ways:
- At the time of declaration: The first way of initializing a structure variable is at declaration time, as follows:
struct Card c1 = { heart , (int) heart , king, (int)king , false };
The structure component values are enclosed between {and }, separated by commas. The order is significant. c1is a card of the heart suit with suitValue of the heart enumeration and face of king with faceValue of the king enumeration, which is not a wildcard. In this form of initialization, we must be careful to get the order exactly correct within the definition of struct Card...