1.作用:给已经存在的类型起一个新的名字
2.适用场合
a.基本数据类型
b.指针
c.结构体
d.枚举
e. 指向函数的指针
#include <stdio.h>
typedef int MyInt ;
typedef MyInt MyInt2;
// 给指针类型char *起一个新的类型名称String
typedef char * String ;
struct Student
{
int age ;
};
typedef struct Student MyStu ;
typedef enum Sex
{
Man;
Woman ;
} MySex ;
typedef int (* Mypoint ) (int , int );
int minus (int a, int b)
{
return a- b;
}
int sum (int a , int b)
{
return a+b;
}
typedef struct Person
{
int age ;
} * PersonPoint ;
int main ()
{
//定义结构体变量
struct Person p = {20};
PersonPoint p2 =&p;
return 0 ;
}
3.typedef 使用注意
#define Integer int 和 typedef int Integer;意思是一样的