I come, I see, I conquer

                    —Gaius Julius Caesar

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

以下程序在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;
}

 

输出:

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

注意:结构体的声明方法,结构变量,结构指针的声明方法

 

posted on 2008-09-17 11:34  jcsu  阅读(536)  评论(0)    收藏  举报