个人博客
http://www.milovetingting.cn
C++中的常量指针和指针常量
常量指针
1 2 3 4 5 6 7 8 9 10 11 12
| int a = 1; int b = 2;
const int *p = &a; cout << *p << endl;
p = &b; cout << *p << endl;
|
指针常量
1 2 3 4 5 6 7 8 9 10 11 12
| int a = 1; int b = 2;
int * const p = &a; cout << *p << endl;
*p = 2; cout << *p << endl; cout << a << endl;
|