C-數據結構-typedef的用法
阿新 • • 發佈:2019-04-01
main har struct printf 結構 等價 zhang stdio.h span
1.typedef的用法 # include <stdio.h> typedef int zhang; //為數據類為int從新取名為zhang 等價於int typedef struct Student { int sid; char name[100]; char sex; }ST; int main(void) { int i = 10; //等價於 zhang i = 10; struct Student st; //等價於 ST st; struct Student * ps = &st; //等價於ST * ps;zhang j = 20; printf("%d\n", j); ST st2; st2.sid = 200; printf("%d\n", st2.sid); return 0; }
2.typedef的用法2 # include <stdio.h> typedef struct Student { int sid; char name[100]; char sex; }* PST; //等價於struct Student * intmain(void) { struct Student st; PST ps = &st; ps->sid = 99; printf("%d\n", ps->sid); return 0; }
3.typedef的用法3 # include <stdio.h> typedef struct Student { int sid; char name[100]; char sex; }* PSTU, STU; //等價於STU代表了 struct Student, PSTU 代表了struct Student *int main(void) { STU st; //等價於 struct Student st; PSTU ps = &st; //等價於 struct Student * ps = &st; ps->sid = 99; printf("%d\n", ps->sid); return 0; }
C-數據結構-typedef的用法