不允许循环包含,比如a.h包含b.h,b.h又包含a.h
◆知识点14:typedef 只是给类型起了个别名并不是定义新类型
struct Student{ int age; char *name; }; typedef struct Student Student; 等价于typedef struct Student{ int age; char *name; }Student; 也等价于typedef struct { int age; char *name; }Student;
typedef enum Sex { Man,Women }Sex;
//下面是函数指针类型的自定义数据类型,返回值类型和参数类型要匹配
#include typedef int (*TypeFuncPointer)(int, int); int add(int a, intb) { return a + b; } int minus(int a, intb) { return a - b; } int main() { TypeFuncPointer p = add;//使用自定义类型Î TypeFuncPointer p2 = minus;//使用自定义类型Î printf("add = %d\n",p(1, 2)); printf("minus = %d\n",p2(1, 2)); return 0; }
typedef struct Student{ int age; char *name; }*PtrStu; //使用方式 Student stu ={18, "zhangsan"}; PtrStu p = &stu;
#define Integer int 相当于typedef int Integer