typedef的用法

 typedef的用法

#include <stdio.h>

typedef int ZHANGSAN; //为int再重新多取一个名字,ZHANGSAN等价于int

typedef struct Student
{
   int sid;
   char name[100];
   char sex;
}ST; //为struct Student重新多取一个名字,叫ST

int main()
{
    //int i = 10;  //等价于 ZHANGSAN i = 10;
    //ZHANGSAN j = 20;
    ST st2;
    st2.sid = 200;
    printf("%d\n", st2.sid);
}

 

#include <stdio.h>

typedef int ZHANGSAN; //为int再重新多取一个名字,ZHANGSAN等价于int

typedef struct Student
{
   int sid;
   char name[100];
   char sex;
}* PST; //PST 等价于strut Student *

int main()
{
   struct Student st;
   PST ps = &st;
   ps->sid = 98;
   printf("%d\n", ps->sid);
}

 

#include <stdio.h>

typedef int ZHANGSAN; //为int再重新多取一个名字,ZHANGSAN等价于int

typedef struct Student
{
   int sid;
   char name[100];
   char sex;
}* PSTU, STU; //PSTU 等价于strut Student *, STU代表了struct Student

int main()
{
    STU st; //struct Student st;
    PSTU ps = &st; // struct Student * ps = &st;
    ps->sid = 99;
    printf("%d\n",ps->sid);
    return 0;
}

 

typedef struct Node
{
    int data; //数据域
    struct Node * pNext; //指针域;
}NODE, *PNODE; //NODE等价于 struct Node,  PNODE等价于struct Node *

 

posted @ 2019-06-23 21:07  小孢子  阅读(1086)  评论(0编辑  收藏  举报