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 *