有以下程序 #include struct tt { int x; struct tt *y; } *p; struct tt a[4]={20,a+1,15,a+2,30,a+3,17,a}; main() { int i; p=a; for(i=1;

admin2015-07-28  22

问题 有以下程序
#include
struct tt
{ int x; struct tt *y; } *p;
struct tt a[4]={20,a+1,15,a+2,30,a+3,17,a};
main()
{ int i;
p=a;
for(i=1; i<=2; i++) { printf("%d,", p->x ); p=p->y; }
}
程序的运行结果是( )。

选项 A、20,15,
B、30,17
C、15,30,
D、20,30,

答案A

解析 语句"p=a;"将指针p指向了结构体数组a的首地址,此时p->x与a[0].x等价,值为20,执行语句"p=p->y;"则将指针p指向了a+1,即数组a第二个元素的地址,此时p->x与a[1].x等价,值为15,所以答案选A。
转载请注明原文地址:https://jikaoti.com/ti/DMn0FFFM
0

最新回复(0)