本例来自c++ primer plus 第六版 的 119页
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int MAXN=1e3; typedef long long LL; char str[MAXN]; struct antarctica_years_end { int year; }; int main() { antarctica_years_end s01, s02, s03; s01.year=1998; antarctica_years_end *pa=&s02; pa->year=1999; antarctica_years_end trio[3]; trio[0].year=2003; cout<<(trio)->year<<endl;//此时的trio是一个指针指向&trio[0],可以通过加减(trio+1)->year访问下一个元素 const antarctica_years_end *arp[3]={&s01, &s02, &s03};//数组指向了三个地址 cout<<arp[1]->year<<endl; const antarctica_years_end **ppa=arp;//二维指针指向&arp auto ppb = arp;//c++ 11 下运行 自动类型转换 cout<<(*ppa)->year<<endl;//*ppa为结构体指针 cout<<(*(ppb+1))->year<<endl; return 0; }