结构体指针 : 指向结构体类型的指针.

示例:

#include <iostream>
#include <string.h>
using namespace std;
//定义结构体
struct Student{
    string name;
    int age;
    int score;
};
int main(){
    //定义结构体变量
    Student student;
    //结构体类型的指针并指向结构体
    Student * p = &student;
    
    p->name = "陈陈菌";
    p->age = 20;
    p->score = 99;
    cout <<"姓名: "<< student.name <<endl;
    cout <<"年龄: "<< student.age <<endl;
    cout <<"成绩: "<< student.score <<endl;
}

指针指向结构体

Student * p = &student;

解引用

p->name = "陈陈菌";
p->age = 20;
p->score = 99;

运行结果:

姓名: 陈陈菌
年龄: 20
成绩: 99




文章目录