A. 对数据类型定义“别名"
int main(int argc, const char * argv[]) {
typedef int integer;
integer i = 5;
printf("print the int: %d\n", i);
return 0;
}
区别于宏定义的概念,typedef相当于定义了一种新的数据类型,而不是简单的别名
在”别名“的基础上再定义一个别名
typedef int integer;
typedef integer mytype;
B. typedef与指针
typedef char * String;
String name = "Simon”;
C. typedef与结构体
typedef struct MyPoint
{
int x;
int y;
} Point;
Point p = {10, 10};
D. typedef 结构体指针
typedef struct
{
int age;
char *name;
} * PP;
PP per1 = {11, "Tom"};//Running Error
shoulde be:
PP per1;
per1->age = 17;
(*per1).name = "Tom";
E. typedef 指向函数的指针
F. #define 与 typedef 的区别
typedef char * String1
#define String2 char *
String1 s1,s2;
String2 s3,s4;
==> 其中,s1,s2,s3是char指针,s4仅仅是普通的char变量