首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

帮忙看看指针地址输出有关问题

2012-04-08 
帮忙看看指针地址输出问题#include iostreamusing namespace std/*按照我的想法输出后P1=P5,P2P6,P3P

帮忙看看指针地址输出问题
#include <iostream>
using namespace std;
/*按照我的想法输出后P1=P5,P2=P6,P3=P7,P4=P8,但是输出却有些不同,请帮忙看看谢谢!*/
int main()
{
int a(1),b[1],c[2][2],d[3][3][3];
int *p1=&a;
int *p2=&b[1];
int *p3=&c[1][1];
int *p4=&d[1][1][1];

int *p5=&a;
int *p6=(int*)(b+1);
int *p7=(int*)((int*)(c+1));
int *p8=(int*)((int*)((int*)(d+1)+1)+1);

cout<<p1<<","<<p2<<","<<p3<<","<<p4<<","<<p5<<","<<p6<<","<<p7<<","<<p8<<endl;

return;
}

[解决办法]

C/C++ code
#include  <iostream> using namespace std; /*按照我的想法输出后P1=P5,P2=P6,P3=P7,P4=P8,但是输出却有些不同,请帮忙看看谢谢!*/ int main() {     int a(1),b[1],c[2][2],d[3][3][3];     int *p1=&a;     int *p2=&b[0];     int *p3=&c[1][1];     int *p4=&d[1][1][1];         int *p5=&a;     int *p6=(int*)(b);     int *p7=(int*)(*(c+1) + 1);     int *p8=(int*)(*(*(d+1)+1)+1);         cout <<p1 <<"," <<p2 <<"," <<p3 <<"," <<p4 <<"," <<p5 <<"," <<p6 <<"," <<p7 <<"," <<p8 <<endl;         return; } 

热点排行