#include<iostream>
using namespace std;
int main()
{
int a = 1;
int *p1 = &a; //p1是一个指针,指向变量a
int &p2 = a; //p2是a的引用
int * &p3 = p1; //p3是一个引用,是指针p1的引用
int * *p4 = &p1; //p4是一个指针,指向整数指针的地址 (int*)(*p4)
cout << "*p1 = " << *p1 << endl;
cout << "p1 = " << p1 << endl;
cout << "&p1 = " << &p1 << endl;
cout << "p2 = " << p2 << endl;
cout << "*p3 = " << *p3 << endl;
cout << "p3 = " << p3 << endl;
cout << "p4 = " << p4 << endl;
cout << "*p4 = " << *p4 << endl;
cout << "**p4 = " << **p4 << endl;
cout << "&p4 = " << &p4 << endl;
return 0;
}
运算符*和&自右向左结合,因此从右向左看,就能知道变量是什么类型了。