typedef的用法

typedef的语法定义就是:typedef existing-type-name new-type-name;也就是给一个已经存在的数据类型起一个别名。

#include <stdio.h> typedef struct Student { int id; char name; char sex; }ST;//一般要大写 int main(void) { struct Student st1;//等价于ST st1; struct Student* pst;//等价于ST* pst; ST st2; st2.id=99; printf("%d/n",st2.id); return 0; } 

#include <stdio.h> typedef struct Student { int id; char name; char sex; }* PST;//PST等价于struct Student* int main(void) { struct Student st; PST pst=&st; pst->id=99; printf("%d/n",pst->id); return 0; } 

#include <stdio.h> typedef struct Student { int id; char name; char sex; }* PST,ST;//等价于PST代表struct Student*,而ST代表了struct Student; int main(void) { ST st;//等价于struct Student st; PST pst=&st;//struct Student pst=&st; pst->id=99; printf("%d/n",pst->id); return 0; } 


你可能感兴趣的:(struct)