結構體指針:通過指針訪問結構體中的成員。
具體實現:
#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;
}