Once we've allocated dynamic memory, we can access it via the pointer that's returned by the allocation functions, as we would with any other pointer. With each of the previous examples, we could use that dynamic memory as follows:
InitializeCard( pCard1 , spade , ace , kNotWild );
InitializeCard( pCard2 , heart , queen , kNotWild );
pCard1 and pCard2 are pointers to individual Card structures. Therefore, we can use them just like we used the pointers in carddeck.c using automatic variables.
However, consider the following:
pHand1[3].suit = diamond;
pHand1[3].face = two;
for( int i = 0 ; i < kCardsInHand , i++ ) {
PrintCard( &(pHand[i]) );
}
Both pHand1 and pHand2 point to a contiguous block of memory that is equivalent to the size of five Card structures. Using array notation, we set the suit and face structure members of the fourth element via pHand1. The PrintCard() function takes a pointer to...