C Tutorial/Structure/structure pointer

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Using the structure member and structure pointer operators

#include <stdio.h>
struct card {                           
   char *face; 
   char *suit; 
};
int main()
{ 
   struct card aCard; 
   struct card *cardPtr;
   aCard.face = "Ace";   
   aCard.suit = "Spades";
   cardPtr = &aCard;
   printf( "%s%s%s\n%s%s%s\n%s%s%s\n", aCard.face, " of ", aCard.suit,
      cardPtr->face, " of ", cardPtr->suit,                           
      ( *cardPtr ).face, " of ", ( *cardPtr ).suit );                 
   
   return 0;
}
Ace of Spades
Ace of Spades
Ace of Spades