c++ - C语言有关结构体的问题
大家讲道理
大家讲道理 2017-04-17 14:55:04
0
3
390

上机运行结果是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;

}

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(3)
黄舟

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].

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template