【015】结构体指针

//指向结构体的指针

#include<iostream>

using namespace std;

struct date {

 int year;   

 int month;

 int day;

};

void main()

{

 date d1 = {1999, 9, 9}; //结构体变量初始化

 date *pd = &d1;

 cout<<"年份:"<<d1.year<<endl;

 cout<<"年份:"<<(*pd).year<<endl; //指针运算符*的优先级低于.(成员运算符)

 //cout<<"年份:"<<*pd.year<<endl; //错误写法

 cout<<"月份:"<<pd->month<<endl; //指向运算符“->”:用于访问所指向的结构体的成员。

 cout<<"日期:"<<pd->day<<endl;

原文地址:https://www.cnblogs.com/leopotter/p/4935626.html