1、结构体指针的引用
#include<iostream>
using namespace std;struct Student
{int num;char name[32];
};
int main()
{struct Student stu = {1,"张三"};struct Student* p = &stu;system("pause"); return 0;
}
2、通过结构体指针访问结构体
#include<iostream>
using namespace std;struct Student
{int num;char name[32];
};
int main()
{struct Student stu = {1,"张三"};struct Student* p = &stu;cout << "结构体访问:" <<"\n" << p->name << "\n"<<p->num << endl;system("pause"); return 0;
}
访问结果如下所示: