**** 注意:typedef定义的是类型,给类型取别名:
typedef和基本类型配合使用:
typedef int myint;
myint myi=40000;
printf("%d\n",myi);
typedef结构体配合使用:
typedef void (*cloneP)(int a,int b); // 定义函数指针、
struct person{
int age;
char* name;
cloneP rp; //使用函数指针定义类型
};
void cloneP1(int a,int b){
int c=a+b;
printf("运算结果是:%d\n",c);
}
typedef struct person pp;
void main(){
pp pn={40,"小明"};
pn.rp= cloneP1;
pn.rp(4,6);
}
typedef枚举使用:
enum gender{
MAN,
WOMAN
};
typedef enum gender gendertype;
gendertype g1=WOMAN;
enum gender g=WOMAN;
switch (g1) {
case MAN:
printf("我是man\n");
break;
default:
printf("我是woman\n");
break;
}
c中typedef的使用typedef和基本类型配合使用: typedef int myint; myint myi=40000; printf("%d\n",myi); typedef结构体配
猜你喜欢
转载自blog.csdn.net/dreams_deng/article/details/82872249
今日推荐
周排行