Definition of Structure, Declration of Structure, Initalization of Structure
struct information
A struct cannot contain an instance of itself
Can contain a member that is a pointer to the same structure type
A structure definition does not reserve space in memory
Instead creates a new data type used to declare structure variables
Declarations
Declared like other variables:
card oneCard, deck[ 52 ], *cPtr;
Can use a comma separated list:
struct card {
char *face;
char *suit;
} oneCard, deck[ 52 ], *cPtr;
Valid Operations
Assigning a structure to a structure of the same type
Taking the address (&) of a structure
Accessing the members of a structure
Using the sizeof operator to determine the size of a structure
Initializer lists
Example:
card oneCard = { "Three", "Hearts" };
Assignment statements
Example:
card threeHearts = oneCard;
Could also declare and initialize threeHearts as follows:
card threeHearts;
threeHearts.face = “Three”;
threeHearts.suit = “Hearts”;