A)&p=f(10,&i,p,p1); B)p1=f(i++,(int *)p1,p,&p); C)p=f(i+1,&(i+2),*p,p); D)f(i+1,&i,p,p); 考生答案: 正确答案: B
11.22 下面函数的功能是将指针t2所指向的线性链表,链接到t1所指向的链表的末端。假定t1所指向的链表非空
struct node{ float x;struct node *next;}; connect(struct node *t1, struct node *t2) { if(t1->next==NULL)t1->next=t2; else connect(______ ,t2); }
要实现此功能则应该添入的选项是
A)t1.next B)++t1.next C)t1->next D)++t1->next 考生答案: 正确答案: C
11.23 阅读如下程序段,则执行后程序的输出结果是 #include
{ structa{int x; int y; } num[2]={{20,5},{6,7}};
printf(\\n\[0].x/num[0].y*num[1].y); }
A)0 B)28 C)20 D)5 考生答案: 正确答案: B
11.24 阅读程序段,则执行后的输出结果为 #include \
typedef union{ long x[2]; [4];
char z[8];} atx;
typedef struct aa{ long x[2]; int y[4];
char z[8]; } stx; main()
{ printf(\\n\(atx),sizeof(stx)); } A)union=8,struct aa=8 B)union=8,struct aa=24 C)union=24,struct aa=8 D)union=24,struct aa=24 考生答案: 正确答案: B 11.25 阅读下列程序段 #include \typedef struct aa { int a;
struct aa *next; } M;
void set(M *k,int i,int *b) { int j,d=0;
for(j=1;j
{ k[j-1].next=&k[j];
k[j-1].a=b[d++]; }
k[j].a=b[d]; }
main()
{ M k[5],*p;
int d[5]={23,34,45,56,67}; set(k,5,d); p=k+1;
printf(\\n\); }
则下面的表达式在table处,能使程序执行后,打印输出数据45的是 A)p->next->a B)++p->a C)(*p).a++ D)p++->a 考生答案: 正确答案: A
二、填空题(请将每一个空的正确答案写在答题卡相应序号后。)
11.26 以下定义的结构体类型拟包含两个成员,其中成员变量info用来存入整形数据;成员变量link是指向自身结构体的指针,请将定义补充完整。 struct node { int info; 【1】link; };
考生答案: 正确答案: struct node * 11.27 设有以下结构体类型: struct st
{ char name[8]; int num; float s[4]; }student[50];
并且结构体数组student中的元素都已有值,若要将这些元素写到硬盘文件fp中,请将以下fwrite语句补充完整:
fwrite(student,【2】,1,fp);
考生答案: 正确答案: sizeof(struct st)*50
11.28 使用结构体处理数据的场合是【3】 。
考生答案: 正确答案: 把不同类型的数据作为整体处理。
11.29 以下程序的功能是:处理由学号和成绩组成的学生记录,N名学生的数据已在主函数中放入结构体数组s中,它的功能是:把分数最高的学生数据放在h所指的数组中,注意:分数高的学生可能不只一个,函数返回分数最高学生的人数。请填空。 #include
{ char num[10];
int s ; } STREC;
int fun (STREC *a, STREC *b) { int i,j=0,max=a[0].s; for(i=0;i if(max main () { STREC s[N]={{\{\{\{\STREC h[N]; int i, n;FILE *out; n=fun(s,h); printf(\\n\); for (i=0; i printf(\\n \[i].num,h[i].s); printf(\\n\); out=fopen(\); fprintf(out, \\n\); for(i=0; i fprintf(out, \\n \[i].s); fclose(out); } 考生答案: 正确答案: max==a[i].s 11.30 若有以下说明和定义语句,则变量w在内存中所占的字节数是 【5】 。 union aa {float x; float y; char c[6]; }; struct st{ union aa v; float w[5]; double ave; } w; 考生答案: 正确答案: 34 11.31 阅读下列程序,则程序的输出结果为【6】。 #include \struct ty { int data; char c; }; main() { struct ty a={30,′x′}; fun(a); printf(\); } fun(struct ty b) { b.data=20; b.c=′y′; } 考生答案: 正确答案: 30x 11.32 现有如下定义:struct aa{int a;float b;char c;}*p;现需用malloc函数动态的申请一个struct aa类型大小的空间(由p指向),则定义的语句为: 【7】 。 考生答案: 正确答案: p=(struct aa *) malloc (sizeof(struct aa)); 11.33 阅读下列程序,则程序实现的功能是 【8】 。 #include \struct node { char data; struct node *next; } *head; fun(struct node *q) { if(head == NULL) { q->next=NULL; head=q; } else { q->next=head; head=q; } } main() { char ch; struct node *p; head = NULL; while((ch=getchar())!=′\n′) { p=(struct node *)malloc(sizeof(struct node)) p->data=ch; fun(p); } p=head; while(p!=NULL) { printf(\); p=p->next; } } 正确答案: 从键盘输入一行字符串,调用函数建立反序的链表,然后输出整个链表 11.34 以下函数set用来建立一个带头结点的单向链表,新产生的结点总是插入在链表的末尾。单向链表的头指针作为函数值返回,请填空。 struct node{char data; struct node *next; }; struct node *set() { struct node *t1,*t2,*t3; char ch; t1=(struct node*)malloc(sizeof(struct node)); t3=t2=t1; ch=getchar(); while(ch!=′\n′) { t2= 【9】 malloc(sizeof(struct node)); t2->data=ch; t3->next=t2; t3=t2; ch=getchar(); } t3->next=′\0′ ; 【10】 } 正确答案: (struct node *) 正确答案: return(t1)