@(C語言)
[toc]
typedef
作用
設置別名,并沒有創建新的類型
使用
定義一個二叉樹:
struct Tnode{
char * word;
int count;
struct Tnode * left;
struct Tnode * right;
}
現在可以寫成這樣:
typedef struct Tnode* Treeptr;
typedef struct Tnode{
char * word;
int count;
Treeptr left;
Treeptr right;
} BinaryTreeNode;
int main(){
BinaryTreeNode * node;
node =(BinaryTreeNode *)malloc(sizeof(BinaryTreeNode *));
return 0;
}
這樣就很有面向對象的感覺
union
將不同的數據類型放到同一個內存中。
內存大小以最大的為準
union MyUnion{
int a;
char b;
float c;
};
int main(){
union MyUnion unio;
unio.a =10;
unio.b ='a';
unio.c =22.2f;
return 0;
}
enum
//自動升值
enum{
monday=10 ,
wenday,
};
int main(){
printf("wenday : %d\n",wenday);
return 0;
}
輸出:
wenday : 11