C/C++ - 指针解引用,改变指针指向上的值
直接看代码:
#include<iostream> using namespace std; int main() { //定义一个整型数字a int a = 10; //1:定义指针 int* p; //让指针记录变量a的地址 p = &a; //打印一下 cout << "a的地址为:" << &a << endl; cout << "指针p为:" << p << endl; //2:使用指针 //可以通过指针解引用的方式来找到指针指向的内存 //即:指针前加*代表解引用,找到指针指向的内存中的数据 *p = 20;//将a的值变成20 //打印一下 cout << "a = " << a << endl; cout << "*p = " << *p << endl; system("pause"); return 0; }
输出:
作者:Jeremy.Wu
出处:https://www.cnblogs.com/jeremywucnblog/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。