若有以下程序段: struct st { int n; int*m;}; int a=2,b=3,c=5; struct st s[3]=({101,&a},{102,&c),{103,&b)}; m

admin2021-02-25  21

问题 若有以下程序段:
    struct st
    { int n;
      int*m;};
    int a=2,b=3,c=5;
    struct st s[3]=({101,&a},{102,&c),{103,&b)};
      main()
     {  struct st*p;
        p=s;
        …}
    则以下表达式中值为5的是(    )。

选项 A、(p++)->m
B、*(p++)->m
C、(*p).m
D、*(++p)->m

答案D

解析 本题考查如何通过指针引用数组元素。首先定义了一个结构体,然后定义了一个结构体变量s[3],并赋了初值。在主程序中,定义了一个指向结构体变量s的指针p,要使表达式的值为5,就应该引用s[1].m的值,使指针p指向s[1],++p可以实现将p指针加1,指向s[1]。
转载请注明原文地址:https://kaotiyun.com/show/notp777K
0

最新回复(0)