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 *

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM