结构体03:结构体指针
#include<iostream>
#include<string>
using namespace std;
//结构体指针
//定义结构体
struct Student{
string name;
int age;
int score;
};
int main(){
//以下struct可以省略
//创建学生结构体变量
struct Student stu={
"张三",18,100};
//通过指针指向结构体变量
struct Student *p =&stu;
//通过指针访问结构体变量中的数据 使用 指针变量->结构体中的属性
cout<<p->name<<" "<<p->age<<" "<<p->score<<endl;
}
还没有评论,来说两句吧...