第九章习题及答案

  • 格式:doc
  • 大小:58.50 KB
  • 文档页数:10

下载文档原格式

  / 10
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

第九章习题

一、选择题

1.以下选项中不能正确把cl定义成结构体变量的是( )

A)typedef struct B)struct color cl

{ int red; { int red;

int green; int green;

int blue; int blue;

} COLOR; COLOR cl; };

C)struct color D)struct

{ int red; { int red;

int green; int green;

int blue; int blue;

} cl; } cl;

2.有以下说明和定义语句

struct student

{ int age; char num[8];};

struct student stu[3]={{20,"200401"},{21,"200402"},{10\9,"200403"}};

struct student *p=stu;

以下选项中引用结构体变量成员的表达式错误的是( )

A) (p++)->num B)p->num C)(*p).num D)stu[3].age

3.有以下结构体说明、变量定义和赋值语句

struct STD

{char name[10];

int age;

char sex;

}s[5],*ps;

ps=&s[0];

则以下scanf函数调用语句中错误引用结构体变量成员的是( )。

A)scanf(“%s”,s[0].name);B)scanf(“%d”,&s[0].age);

C)scanf(“%c”,&(ps->sex)); D)scanf(“%d”,ps->age);

4.以下叙述中错误的是()

A)可以通过typedef增加新的类型

B)可以用typedef将已存在的类型用一个新的名字来代表

C)用typedef定义新的类型名后,原有类型名仍有效

D)用typedef可以为各种类型起别名,但不能为变量起别名

5.有以下程序段()

typedef struct node { int data; struct node *next; } *NODE;

NODE p;

以下叙述正确的是(C)

A)p是指向struct node结构变量的指针的指针

B)NODE p;语句出错

C)p是指向struct node结构变量的指针

D)p是struct node结构变量

6.若有以下定义和语句

union data

{ int i; char c; float f;}x;

int y;

则以下语句正确的是( )。

A)x=;B)=101; C)y=x;D)printf(“%d\n”,x);

7.有以下程序

main()

{ union { unsigned int n;

unsigned char c;

}u1;

=`A`;

printf("%c\n",;

}

执行后输出结果是()

A) 产生语法错 B) 随机值C) A D) 65

8.有以程序

#include <>

#include <>

typedef struct { char name[9]; char sex; float score[2]; } STU;

void f( STU a)

{ STU b={“Zhao” ,’m’,,} ; int i;

strcpy,;

=;

for(i=0;i<2;i++) [i]=[i];

}

main()

{ STU c={“Qian”,’p’,,};

f(c); printf(“%s,%c,%2.0f,%2.0f\n”,,,[0],[1]);

}

程序的运行结果是

A)Qian,p,95,92 B) Qian,m,85,90

C)Zhao,p,95,92 D) Zhao,m,85,90

9.现有以下结构体说明和变量定义,如图所示,指针p,q,r分别指向一个链

表中连续的三个结点。

struct node

{

char data;

struct node *next;

}*p,*q,*r;

现要将q和r所指结点交换前后位置,同时要保持链表的连续,以下不能完成此操作的语句是

A)q->next=r->next; p->next=r; r->next=q;

B) p->next=r; q->next=r->next; r->next=q;

C) q->next=r->next; r->next=q; p->next=r;

D) r->next=q; p->next=r; q-next=r->next;

10.有以下程序段

struct st

{ int x; int *y;}*pt:

int a[]={1,2},b[]={3,4};

struct st c[2]={10,a,20,b};

pt=c;

以下选项中表达式的值为11的是( )

A) *pt->y B) pt->x C) ++pt->x D) (pt++)->x

二、填空题

1.设有说明

struct DATE{int year;int month; int day;};

请写出一条定义语句,该语句定义d为上述结构体变量,并同时为其成员year、month、day 依次赋初值2006、10、1。

2.已有定义如下:

struct node

{ int data;

struct node *next;

} *p;

以下语句调用malloc函数,使指针p指向一个具有struct node类型的动态存储空间。请填空。

p = (struct node *)malloc( );

3.以下程序中函数fun的功能是:统计person所指结构体数组中所有性别(sex)为M的记录的个数,存入变量n中,并做为函数值返回。请填空: