0%

数据结构 | C 语言的 typedef

这个可以简化代码量,提供更好的阅读方式。

经典

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# include <stdio.h>
typedef int SHUZI;


typedef struct Student{
int sid;
char name[100];
char sex;
}ST;

int main(void){
SHUZI i = 10;
ST st;
}

指针方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# include <stdio.h>
typedef int SHUZI;


typedef struct Student{
int sid;
char name[100];
char sex;
}* PST; //PST 等价于 struct Student*

int main(void){
struct Student st;
PST ps = &st;
ps->sid = 99;
}

多命名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# include <stdio.h>

typedef int SHUZI;


typedef struct Student {
int sid;
char name[100];
char sex;
} *PST, ST; //PST 等价于 struct Student*

int main(void) {
ST st;
PST ps = &st;
ps->sid = 99;
}
请我喝杯咖啡吧~