1.基本数据类型替换
typedef int INT;
INT a = 10; // int a = 10;
2.数组类型替换
typedef char ARR[6];
ARR str = ""; // char str[6] = "";
3.结构体类型替换
typedef struct student STU;
struct student {
int age;
char* name;
};
STU stu; //struct student stu;
typedef struct student* STUP;
struct student {
int age;
char* name;
};
STUP stu; //struct student* stu;
typedef struct {
int age;
char* name;
}STU;
int main(void) {
STU stu; //struct student stu;
typedef struct {
int age;
char* name;
}*STUP;
int main(void) {
STUP stu; //struct student* stu;
4.函数类型替换
#include <stdio.h>
#include <stdlib.h>
typedef int (*fun)(int,int);
int add(int a, int b) {
return a + b;
}
int main(void) {
fun myfun = add;
int result = myfun(1, 2);
printf("result = %d\n",result);
return 0;
}