以下程序在VC环境下运行:
#include
<
stdio.h
>
typedef struct
{
int age;
char * name;
} Person;
struct card
{
char * face;
char * suit;
} * pCard;
typedef struct card Card;
int main()
{
Person empA;
empA.age = 20 ;
empA.name = " Lisi " ;
struct card MyCard;
MyCard.face = " Ace " ;
MyCard.suit = " Heart " ;
pCard = & MyCard;
Card card;
card.face = " Deuce " ;
card.suit = " Club " ;
printf( " Info of employee: Name: %d, Age: %s \n " , empA.age, empA.name);
printf( " Info of MyCard: face: %s, suit: %s \n " , MyCard.face, MyCard.suit);
printf( " Info of *pCard: face: %s, suit: %s \n " , pCard -> face, pCard -> suit);
printf( " Info of card: face: %s, suit: %s \n " , card.face, card.suit);
return 0 ;
}
typedef struct
{
int age;
char * name;
} Person;
struct card
{
char * face;
char * suit;
} * pCard;
typedef struct card Card;
int main()
{
Person empA;
empA.age = 20 ;
empA.name = " Lisi " ;
struct card MyCard;
MyCard.face = " Ace " ;
MyCard.suit = " Heart " ;
pCard = & MyCard;
Card card;
card.face = " Deuce " ;
card.suit = " Club " ;
printf( " Info of employee: Name: %d, Age: %s \n " , empA.age, empA.name);
printf( " Info of MyCard: face: %s, suit: %s \n " , MyCard.face, MyCard.suit);
printf( " Info of *pCard: face: %s, suit: %s \n " , pCard -> face, pCard -> suit);
printf( " Info of card: face: %s, suit: %s \n " , card.face, card.suit);
return 0 ;
}
输出:
Info of employee: Name: 20, Age: Lisi
Info of MyCard: face: Ace, suit: Heart
Info of *pCard: face: Ace, suit: Heart
Info of card: face: Deuce, suit: Club
注意:结构体的声明方法,结构变量,结构指针的声明方法