关与地址,变量,指针的运用 C++

#include<iostream>
using namespace std;
int main()
{
	int a=2,b=3;
	cout<<&a<<"\n"<<endl;
	cout<<&b<<"\n"<<endl;
	int *p;
	p=&a;
	*p--;
	cout<<*p<<endl;
}

为什么这样可以输出b???下面是输出

&a是取a的地址

p=&a;让p指向a的地址

*p--让p移动,移动一个int的大小,这个地址放的什么东西不确定,输出3可能只是碰巧了,你多运行几次看看结果还是不是3。

测试代码:

 

#include<iostream>
using namespace std;
int main()
{
	int a=2,b=3;
	cout<<&a<<"\n"<<endl;
	cout<<&b<<"\n"<<endl;
	int *p;
	p=&a;
	cout << "p=" << p<< endl;
	*p--;
	cout << "p=" << p<< endl;
	cout<<*p<<endl;
	system("pause");
	return 0;
}

打印内容: