上机运行结果是1 2,求解释struct har{ int x, y; struct har *p;} h[2];main(){
h[0].x=1; h[0].y=2; h[1].x=3; h[1].y=4; h[0].p=h[1].p=h; printf("%d %d \n",(h[0].p)->x,(h[1].p)->y); system("pause"); return 0;
}
光阴似箭催人老,日月如移越少年。
h == &h[0]h[1].p == h == &h[0]h[0].p == h[1].p == &h[0 ] points to the same address h, namely &h[0], the result is obvious
Assigning h[0].p=h+0; h[1].p=h+1; like this, the poster may give you the answer you want.
p points to the front of the structure array, and of course prints the content of h[0].
p
h[0]
h == &h[0]
h[1].p == h == &h[0]
h[0].p == h[1].p == &h[0 ]
points to the same address h, namely &h[0], the result is obvious
Assigning h[0].p=h+0; h[1].p=h+1; like this, the poster may give you the answer you want.
p
points to the front of the structure array, and of course prints the content ofh[0]
.