C++基础之结构体指针

    技术2025-09-15  28

    结构体指针:通过指针访问结构体中的成员。

    具体实现:

    #include <iostream> using namespace std; #include<string> /* 定义一个结构体 */ struct Student { string name; int age; int score; }; int main() { /* 创建结构体变量 */ struct Student s1 = {"小红",12,68}; /* 指针指向结构体变量 */ struct Student *p = &s1; /* 指针访问结构体变量中的数据 */ cout << p->age << p->name << p->score << endl; system("pause"); return 0; }
    Processed: 0.019, SQL: 9