有以下程序: #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() {

admin2021-04-28  20

问题 有以下程序:
    #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,30,
B、30,17
C、15,30,
D、20,15,

答案D

解析 本题考查的是指针和结构的应用。首先定义的数组tt中有两个成员,一个整型变量,一个结构指针。当i=1时,p指针指向结构数组的第一个元素,并输出此元素的第一个成员x.即20;当i=2时,p指针指向结构数组的第二个元素的第一个成员,所以输出15。
转载请注明原文地址:https://kaotiyun.com/show/N3tp777K
0

相关试题推荐
最新回复(0)