帮忙看看指针地址输出问题
#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;
}
[解决办法]
#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; }