直接按例子来理解
#include <iostream>
using namespace std;
int main() {
int a=0;
int *p;
cout<<"*p:"<<*p<<" &p:"<<&p<<" p:"<<p<<endl;
p=&a;
cout<<"*p:"<<*p<<" &p:"<<&p<<" p:"<<p<<endl;
cout<<"a:"<<a<<" &a:"<<&a<<endl;
cout<<endl;
//*p作用就是:取指针p的值,再把这个值作为地址,再取这个地址的值!相当于*(&a)=a
*p=*p+1; //相当于a=a+1
cout<<"*p:"<<*p<<" &p:"<<&p<<" p:"<<p<<endl;
cout<<"a:"<<a<<" &a:"<<&a<<endl;
cout<<endl;
p=p+1; //相当于在p的值中加了一个int类型的大小存储单元,就是加4:&a+4
cout<<"*p:"<<*p<<" &p:"<<&p<<" p:"<<p<<endl;
cout<<"a:"<<a<<" &a:"<<&a<<endl;
}
结果
*p:1513105 &p:0x61fe10 p:0x1716e0
*p:0 &p:0x61fe10 p:0x61fe1c
a:0 &a:0x61fe1c
*p:1 &p:0x61fe10 p:0x61fe1c
a:1 &a:0x61fe1c
*p:15210176 &p:0x61fe10 p:0x61fe20 //这里十六进制 1c+4=20
a:1 &a:0x61fe1c
解析
博主真是太厉害了!!!
叼茂SEO.bfbikes.com
想想你的文章写的特别好
叼茂SEO.bfbikes.com
怎么收藏这篇文章?
想想你的文章写的特别好https://www.237fa.com/
想想你的文章写的特别好https://www.ea55.com/
看的我热血沸腾啊www.jiwenlaw.com