typedef是用来给类型去别名的
用法:
typedef 原类型 新类型
#include<stdio.h> #include<stdlib.h> //typedef变量取别名 int main (void) { int a = 10; typedef int u32; //typedef 原类型名 新类型名 u32 b = 20; printf("u32 is %d \n",b); printf("the sizeof u32 is %d\n", sizeof(u32)); printf("int is %d\n",a); }
u32 is 20
the sizeof u32 is 4
int is 10
#include<stdio.h> #include<stdlib.h> //typedef 结构体取别名 struct stu { int a; int b; }; typedef struct stu ST; int main (void) { struct stu T1 = {1,2}; printf("T1.a %d T1.b %d \n", T1.a, T1.b); ST T2 = {12,34}; // ST == struct stu printf("T2.a %d T2.b %d \n", T2.a, T2.b); } T1.a 1 T1.b 2 T2.a 12 T2.b 34
标签:typedef,--,T2,别名,T1,int,u32,printf From: https://www.cnblogs.com/shunguo/p/16840551.html