
1.指向结构体的指针的定义
struct Student *p;
2.利用指针访问结构体的成员
1> (*p).成员名称
2> p->成员名称
3.代码
1 #include <stdio.h>
2
3 int main()
4 {
5 struct Student
6 {
7 int no;
8 int age;
9 };
10 // 结构体变量
11 struct Student stu = {1, 20};
12
13 // 指针变量p将来指向struct Student类型的数据
14 struct Student *p;
15
16 // 指针变量p指向了stu变量
17 p = &stu;
18
19 p->age = 30;
20
21 // 第一种方式
22 PRintf("age=%d, no=%d\n", stu.age, stu.no);
23
24 // 第二种方式
25 printf("age=%d, no=%d\n", (*p).age, (*p).no);
26
27 // 第三种方式
28 printf("age=%d, no=%d\n", p->age, p->no);
29
30
31
32
33 return 0;
34 }