博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

关于数组地址的一道题

Posted on 2014-09-27 23:26  widy  阅读(125)  评论(0)    收藏  举报
#include<iostream>
using namespace std;

int main()
{
char a[2]={7,3};
char *p0=NULL,*p1=NULL;
p0=&a[0];
p1=&a[1];
cout<<p0<<endl; 
cout<<p1<<endl;
cout<<p0-p1<<endl;
cout<<"************"<<endl;
cout<<(int*)p0<<endl; 
cout<<(int*)p1<<endl; 
cout<<(int*)p0-(int*)p1<<endl; 

system("pause");
return 0;
}

结果:

 

 

分析:

p,p1是char型的指针,指向的是数组元素的地址,所以相差1。