若有以下程序段 struct st{int n;struct st*next;}; struct st a[3]={5,&a[1],7,&a[2],9,’\0’},*p; P=&a[0]; 则以下选项中值为6的表达式是

admin2017-04-26  34

问题 若有以下程序段
    struct st{int n;struct st*next;};
    struct st a[3]={5,&a[1],7,&a[2],9,’\0’},*p;
    P=&a[0];
则以下选项中值为6的表达式是

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

答案A

解析 选项A)中表达式++(p->n)为前缀自加表达式,p->n和a[0].n等价,其值为5,前缀自加后值为6。选项B)中表达式(*p).n和选项D)的表达式p->n含义相同,表示取结构指针p所指向的成员,因此值为5。选项C)中表达式p->n++为后缀自加表达式,相当于(p->n)++,表达式值为5。
转载请注明原文地址:https://kaotiyun.com/show/5eDp777K
0

最新回复(0)