From 431558b5e9fa01c53815cb3ec11a9a82080f5d2b Mon Sep 17 00:00:00 2001 From: lzy Date: Sat, 13 Apr 2024 17:40:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E5=85=AB=E7=AB=A0=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Chapter8/C8-构造类型.md | 6 +++++ Chapter8/typedef.c | 57 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 Chapter8/typedef.c diff --git a/Chapter8/C8-构造类型.md b/Chapter8/C8-构造类型.md index 443a5a2..091a6c0 100644 --- a/Chapter8/C8-构造类型.md +++ b/Chapter8/C8-构造类型.md @@ -17,6 +17,7 @@ - [函数传参(值,地址)](#函数传参值地址-1) - [位域](#位域) - [枚举](#枚举) + - [typedef](#typedef) # 构造类型 @@ -224,3 +225,8 @@ enum 标识符 }; ``` +## typedef + +为已有的数据类型改名。 + +`typedef 已有的数据类型 新名字;` \ No newline at end of file diff --git a/Chapter8/typedef.c b/Chapter8/typedef.c new file mode 100644 index 0000000..e7a7e16 --- /dev/null +++ b/Chapter8/typedef.c @@ -0,0 +1,57 @@ +#include +#include + +// #define INT int; + +typedef int INT; + +/** + * #define IP int *; + * IP p,q; -> int *p, q; + * + * typedef int *IP; + * IP p,q; -> int *p, *q; + * + */ + +/** + * typedef int ARR[6]; --> int [6] -> ARR + * + * ARR a; -> int a[6]; + * + */ + +#if 0 +typedef struct node_st +{ + int i; + float p; +} NODE, *NODEP; + +NODE a; // struct node_st a; +NODE *p; + +NODEP p; // struct node_st *p; +#endif + + +/** + * typedef int FUNC(int); --> int(int) FUNC; + * FUNC f; --> int f(int); + * + * typedef int *FUNCP(int); + * FUNCP p; --> int *p(int); + * + * typedef int *(*FUNCP)(int); + * FUNCP p; --> int *(*p)(int); + * + */ + +int main() +{ + INT i = 100; // int i; + + printf("%d\n", i); + + exit(0); +} \ No newline at end of file