用户自定义数据类型.doc
文本预览下载声明
用户自定义的数据类型复习题
选择题
1.下列程序的输出结果是( )。
A) 5 B) 6 C) 7 D) 8
struct abc
{ int a, b, c; };
main()
{ struct abc s[2]={{1,2,3},{4,5,6}}; int t;
t=s[0],a+s[1],b;
printf(%d \n,t);
}
2.下列程序执行后的输出结果是( )。
A) 6 B) 8 C) 10 D) 12
#define MA(x) x*(x-1)
main()
{ int a=1,b=2; printf(%d \n,MA(1+a+b));}
3. 有以下结构体说明和变量的定义,则不能把结点b连接到结点a之后的语句是( )。
A) a.next=q; ?B) p.next=b;
C) p-next=b; D) (*p).next=q;
struct node
{ char data;
struct node *next;
} a,b,*p=a,*q=b;
4.变量a所占内存字节数是( )。
A) 4 B) 5 C) 6 D) 8
union U
{ char st[4];
int i;
long l;
};
struct A
{ int c;
union U u;
}a;
5.有如下程序
#define N 2
#define M N+1
#define NUM 2*M+1
#main()
{ int i;
for(i=1;i=NUM;i++)printf(“%d\n”,i);
}
该程序中的for循环执行的次数是( )。
A) 5 B) 6 C) 7 D) 8
6.以下程序的输出结果是( )。
A) 16 B) 2 C) 9 D) 1
#define SQR(X) X*X
main()
{ int a=16, k=2, m=1;
a/=SQR(k+m)/SQR(k+m);
printf(“d\n”,a);
}
7.以下程序的输出是( )。
A) 10 B) 11 C) 51 D) 60
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));
}
8.以下程序的输出结果是( )。
struct HAR
{ int x, y; struct HAR *p;} h[2];
main()
{ h[0],x=1;h[0];y=2;
h[1],x=3;h[1];y=4;
h[0],p=h[1],p=h;
printf(“%d %d \n”,(h[0],p)-x,(h[1],p)-y);
}
A) 12 B) 23 C) 14 D) 32
9. 以下程序的输出结果是( )。
union myun
{ struct
{ int x, y, z; } u;
int k;
} a;
main()
{ a.u.x=4; a.u.y=5; a.u.z=6;
a.k=0;
printf(%d\n”,a.u.x);
}
A) 4 B) 5 C) 6 D) 0
10. 以下程序的输出结果是( )。
#define M(x,y,z) x*y+z
main()
{ int a=1,b=2, c=3;
printf(“%d\n”, M(a+b,b+c, c+a));
}
A) 19 B) 17 C) 15 D) 12
11. 若指针p已正确定义,要使p指向两个连续的整型动态存储单元,不正确的语句是( )。
A) p=2*(int*)malloc(sizeof(int));
B) p=(int*)malloc(2*sizeof(int));
C) p=(int*)malloc(2*2);
D) p=(int*)calloc(2,sizeof(int));
12. 若有下面的说明和定义:
struct test
{ int ml; char m2; float m3;
union uu {char ul[5]; int u2[2];} ua;
} myaa;
则sizeof(struct test )的值是( )。
A) 12 B) 16 C) 14 D) 9
1
显示全部