一、 选择题
14.1 根据以下定义,能输出字母M的语句是
A) printf("%c\\n",class[3].name);
B) printf("%c\\n",class[3].name[1]);
C) printf("%c\\n",class[2].name[1]);
D) printf("%c\\n",class[2].name[0]);
struct person { char name[9]; int age; };
struct person class[10]={ "John", 17,
"Paul", 19,
"Mary", 18,
"Adam", 16, };
答案: D
14.2 以下程序的输出结果是
A) 0
B) 1
C) 3
D) 6
main()
{ struct cmplx { int x; int y; } cnum[2]={1,3,2,7};
printf("%d\\n",cnum[0].y/cnum[0].x*cnum[1].x); }
答案:D
14.3 若有以下说明和语句,则值为6的表达式是
A) p++->n
B) p->n++
C) (*p).n++
D) ++p->n
struct st
{ int n;
struct st *next;
};
struct st a[3],*p;
a[0].n=5; a[0].next=&a[1];
a[1].n=7; a[1].next=&a[2];
a[2].n=9; a[2].next=\'\\0\';
p=&a[0];
答案:D
14.4 已知字符0的ASCII代码值的十进制数为48,且数组的第0个元素元素在低位,以下程序的输出结果是
A) 39
B) 9
C) 38
D) 8
main()
{ union { int i[2];
long k;
char c[4];
} r,*s=&r;
s->i[0]=0x39; s->i[1]=0x38;
printf("%x\\n",s->c[0]);
}
答案:A
14.5 以下程序的输出结果是
A) 32
B) 16
C) 8
D) 24
typedef union { long x[2];
int y[4];
char z[8];
} MYTYPE;
MYTYPE them;
main()
{ printf("%d\\n",sizeof(them)); }
答案:C
14.6 以下程序的输出结果是
A) 10
B) 50
C) 51
D) 60
20 60 60 70
20 21 11 31
struct st
{ int x;
int *y;
} *p;
int dt[4]={10,20,30,40};
struct st aa[4]={50,&dt[0],60,&dt[0],60,&dt[0],60,&dt[0],};
main()
{ p=aa;
printf("%d\\n",++p->x);
printf("%d\\n",(++p)->x);
printf("%d\\n",++(*p->y));
}
答案:C