#include <iostream>
using std::cout;
using std::endl;
//当const修饰的是指针的时候
//
//int(*p)[5] int * p[5]
//数组指针 指针数组
//int (*p)(void) int * p()
//函数指针 指针函数
//
//常量指针 指针常量
void test0()
{
int number = 1;
int number2 = 10;
int * p1 = &number;
*p1 = 2;
p1 = &number2;
cout << "&number = " << &number << endl;
cout << "&number2 = " << &number2 << endl;
cout << "&p1 = " << &p1 << endl;
cout << "p1 = " << p1 << endl << endl;
const int * p2 = &number;//常量指针(pointer to const)
//*p2 = 11;//error, 不能通过p2指针修改所指变量的值
p2 = &number2;//ok
cout << "p2 = " << p2 << endl;
cout << "*p2 = " << *p2 << endl << endl;
int const * p3 = &number;
//*p3 = 11;//error, 不能通过p3指针修改所指变量的值
p3 = &number2;//ok
cout << "p3 = " << p3 << endl;
cout << "*p3 = " << *p3 << endl << endl;
int * const p4 = &number;//指针常量(const pointer)
*p4 = 11;//ok, 不能通过p4指针修改所指变量的值
p4 = &number2;//error, 不能改变指针p4的指向
cout << "p4 = " << p4 << endl;
cout << "*p4 = " << *p4 << endl << endl;
const int * const p5 = &number; //两者都不能进行修改
}
int main(void)
{
test0();
return 0;
}