如:
int a = 10;
int* pt = &a;
指针是对普通变量的操作;
等同与:
int* a = 10;
int** pt = &a;
二级指针是对指针的操作。
void test()
{
int a = 10;
int* pt = &a;
int** ppt = &pt;
cout << "a = " << a << endl;
cout << "*pt = " << *pt << endl;
cout << "**ppt = " << **ppt << endl;
cout << "change the Value : a= 20" << endl<<endl;
a = 20;
cout << "a = " << a << endl;
cout << "*pt = " << *pt << endl;
cout << "**ppt = " << **ppt << endl;
cout << "change the Value : *pt= 30" << endl<<endl;
*pt = 30;
cout << "a = " << a << endl;
cout << "*pt = " << *pt << endl;
cout << "**ppt = " << **ppt << endl<<endl;
cout << "change the Value : **ppt= 40" << endl;
**ppt = 40;
cout << "a = " << a << endl;
cout << "*pt = " << *pt << endl;
cout << "**ppt = " << **ppt << endl<<endl;
}a = 10
*pt = 10
**ppt = 10
change the Value : a= 20
a = 20
*pt = 20
**ppt = 20
change the Value : *pt= 30
a = 30
*pt = 30
**ppt = 30
change the Value : **ppt= 40
a = 40
*pt = 40
**ppt = 40
本文通过具体的C++代码示例,详细介绍了指针与二级指针的概念及其使用方法。通过实例演示了如何利用指针及二级指针来操作变量,并展示了不同级别的指针在内存中指向的不同层次。
3597

被折叠的 条评论
为什么被折叠?



