```c
```c
```c
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct student {
char name[10]="abdce";
int age=10;
}students,*stu1;
//创建了一个变量student,和student类型的指针stu
typedef struct student *STU;
int main()
{
//stu2=&students;stu=&students;
//*stu=stu->students=students;
STU stu2=&students;
stu1=&students;
cout<<"输出地址"<<endl;
cout<<stu2<<endl;
cout<< stu1 <<endl;
cout<<&students<<endl;
printf("访问成员变量name\n");
cout<<(*stu1).name <<endl;
cout<<stu1->name<<endl;
cout<<students.name<<endl;
printf("输出类型\n");
cout<<typeid( stu1 ).name()<<endl;
cout<<typeid( (*stu1).name ).name()<<endl;
cout<<typeid(&students).name()<<endl;
}
其实结构体指针很简单,把结构体当作一种新的数据类型
1.定义结构体指针:
方式一:结构体名字 *指针名字=&指针指向的结构体类型的元素,与其他数据类型一致
方式二:
将结构体指针重新定义为一种数据类型
typedef int Position;
typedef struct Qnode *PtrToQNode;
Struct QNode {
ElementType *Data;
Position Front,Rear;
int MaxSize;
};
以后定义指针可以直接 PtrToNode p;而不需要加✳
2.访问结构体成员
两种方式
结构体指针->成员名
(*结构体).成员名