标签: ,

一、选择题(共30分,每小题2分)

1.

假定有“struct BOOK{char title[40]; float price;}; struct BOOK book;”,则不正确的语句为(    )。

单选题 (2 分) 2
  1. struct BOOK *x=malloc(book);

  2. struct BOOK x={“C++ Programming”,27.0};

  3. struct BOOK *x=malloc(sizeof(struct BOOK));

  4. struct BOOK *x=&book;

2.

假定有“struct BOOK{char title[40]; float price;} book;”,则正确的语句为(    )。

单选题 (2 分) 2
  1. struct BOOK x= &book;

  2. struct BOOK *x=&book;

  3. struct BOOK x=calloc(BOOK);

  4. struct BOOK *x=BOOK;

3.

在结构类型的定义中,不同数据成员的定义项之间采用的分隔符是(    )。

单选题 (2 分) 2
  1. 句点

  2. 冒号

  3. 分号

  4. 逗号

4.

假定一个结构类型的定义为 “struct A{int a,b; double c;};”,则该类型的长度为(    )。

单选题 (2 分) 2
  1. 8

  2. 10

  3. 12

  4. 16

5.

假定一个结构类型的定义为 “struct D{int a; D* next;};”,则该类型的长度为(    )。

单选题 (2 分) 2
  1. 4

  2. 8

  3. 12

  4. 16

6.

假定要访问一个结构指针变量x中的数据成员a,则表示方法为(    )。

单选题 (2 分) 2
  1. a

  2. x->a

  3. x(a)

  4.  x{a}

7.

与结构成员访问表达式x.name等价的表达式为(    )。

单选题 (2 分) 2
  1. x->name

  2. &x->name

  3. (&x)->name

  4. (*x)->name

8.

假定一个链表中结点的结构类型为“struct AA{int data, struct AA *next;};”,则next数据成员的类型为(    )。

单选题 (2 分) 2
  1. struct AA

  2. struct AA*

  3. AA

  4. int

9.

假定一个链表的表头指针为f,结点中包含有data和next域,则向该链表的表头插入一个地址为p的结点时,应执行的操作为(    )。

单选题 (2 分) 2
  1. p->next=f

  2. p->next=f和f=p

  3. f=p->next

  4. f->next=p和f=p

10.

标准输入设备键盘的文件流标识符是(    )。

单选题 (2 分) 2
  1. stdin

  2. stdout

  3.  stderr

  4. stdio

11.

表示文件结束符的符号常量为(    )。

单选题 (2 分) 2
  1. eof

  2. Eof

  3. EOF

  4. feof

12.

C语言中打开一个数据文件的系统函数为(    )。

单选题 (2 分) 2
  1. fgetc()

  2.  fputc()

  3. fclose()

  4. fopen()

13.

从一个数据文件中读入以换行符结束的一行字符串的系统函数为(    )。

单选题 (2 分) 2
  1. gets()

  2. fgets()

  3. getc()

  4. fgetc()

14.

向一个二进制文件中写入信息的函数fwrite()带有的参数个数为(    )。

单选题 (2 分) 2
  1. 1

  2. 2

  3. 3

  4. 4

15.

在C语言中,为只写操作打开一个文本文件的方式为(    )。

单选题 (2 分) 2
  1. “a”

  2. “r+”

  3. “r”

  4. “w”

二、判断题(共40分,每小题2分。叙述正确则回答“是”,否则回答“否”)

16.

在结构类型的定义中,其中的数据成员可以是本身类型的直接对象。

判断题 (2 分) 2
17.

在结构类型的定义中,允许出现结构类型不完整的超前定义。

判断题 (2 分) 2
18.

定义结构类型的变量时,不能够同时进行初始化。

判断题 (2 分) 2
19.

使用一个结构类型时,必须一起使用关键字struct和类型标识符。

判断题 (2 分) 2
20.

假定一个结构类型的定义为 “struct A{int a,b; A* c;};”,则该类型的长度为12。

判断题 (2 分) 2
21.

假定一个结构类型的定义为 “struct B{int a[5]; char* b;};”,则该类型的长度为20。

判断题 (2 分) 2
22.

执行calloc(n,8)函数调用时,将动态分配得到8*n个字节的存储空间。

判断题 (2 分) 2
23.

执行malloc(sizeof(struct BB))函数调用时,得到的动态存储空间能够保存具有struct BB结构类型的一个对象。

判断题 (2 分) 2
24.

假定要访问一个结构对象x中的由a指针成员所指向的对象,则表示方法为x.a。

判断题 (2 分) 2
25.

假定要访问一个结构指针p所指对象中的b指针成员所指的对象,则表示方法为p->b。

判断题 (2 分) 2
26.

与结构成员访问表达式(*fp).score等价的表达式是fp->score。

判断题 (2 分) 2
27.

在C语言中,对二进制文件的所有不同打开方式共有6种。

判断题 (2 分) 2
28.

C语言中的标准输入和输出设备文件都属于字符文件。

判断题 (2 分) 0
29.

在一个磁盘数据文件的文件名中,文件主名和扩展名都是必须的,不可省略。

判断题 (2 分) 2
30.

在数据文件打开方式字符串中,字符r、w和a具有确定的含义,分别代表读、写和追加方式。

判断题 (2 分) 2
31.

一个磁盘数据文件的文件名由文件主名和扩展名所组成,其中间用圆点分开。

判断题 (2 分) 2
32.

C语言系统中提供一个用来描述文件属性的类型标识符为FILE。

判断题 (2 分) 2
33.

每次只能向文本文件中写入一个字符,不能一次写入一个字符串。

判断题 (2 分) 2
34.

对二进制文件进行读和写操作将使用相同的系统函数。

判断题 (2 分) 2
35.

在C语言中,系统函数fseek()用来移动数据文件中的文件位置指针。

判断题 (2 分) 2

三、写出下列每个程序运行后的输出结果(共15分,每小题5分)

36.

#include<stdio.h>

       struct Worker {

           char name[15];  //姓名

           int age;        //年龄

           float pay;      //工资

       };

       void main() {

           struct Worker x={“wanghua”,52,4300};

           struct Worker y, *p;

           y=x; p=&x;

           printf(“%s  %d  %6.2f\n”,x.name,y.age,p->pay);

       }

简答题 (5 分)

wanghua 52 4300

37.

#include<stdio.h>

       #include<string.h>

       struct Worker {

           char name[15];  //姓名

           int age;        //年龄

           float pay;      //工资

       };

       void main() {

           struct Worker x;

           char *t=”liouting”;

           int d=38; float f=3493;

           strcpy(x.name,t);

           x.age=d; x.pay=f;

           printf(“%s  %d  %6.0f\n”,x.name,x.age,x.pay);

       }

简答题 (5 分)

liouting 39 2493

38.

#include<stdio.h>

       struct Worker {char name[15]; int age; float pay;};

       int Less(struct Worker r1, struct Worker r2) {

           if(r1.age<r2.age) return 1; else return 0;

       }

       void main() {

           struct Worker a[4]={{“abc”,25,2420},{“def”,58,4638},

                        {“ghi”,49,4260},{“jkl”,36,3750}};

           struct Worker x=a[0];

           int i;

           for(i=1; i<4; i++)

               if(Less(x,a[i])) x=a[i];

           printf(“%s  %d  %6.0f\n”,x.name,x.age,x.pay);

       }

简答题 (5 分)

def 58 4638

四、写出下列每个函数的功能(共15分,每小题5分)

39.

void QA(struct Worker a[], int n) {

           int i;

           for(i=1; i<n; i++)

               scanf(“%s %d %f”,&a[i].name,&a[i].age,&a[i].pay);

       }

    假定结构类型struct Worker 的定义如下:

       struct Worker { char name[15]; int age; float pay;};

简答题 (5 分)

从键盘输入n个Worker类型的记录到一维数组a中。

40.

int Count(struct IntNode *f)

        {      //f为指向一个单链表的表头指针

            int c=0;

            while(f) {

                c++;

                f=f->next;

            }

            return c;

        }

    假定struct IntNode的类型定义为:

        struct IntNode {int data; IntNode* next;};

简答题 (5 分)

统计出以表头指针为f的链表中的结点个数。

41.

void xw1(char* fname) {

           FILE* fout=fopen(fname,”w”);

           char a[20];

           printf(“每个字符串长度小于20,字符串end作为结束标志\n”);

           while(1) {

               scanf(“%s”,a);

               if(strcmp(a,”end”)==0) break;

               fputs(a,fout);

               fputc(‘\n’,fout);

           }

           fclose(fout);

       }

简答题 (5 分)

把从键盘上输入的若干个字符串保存到由fname参数所指定的文本文件中。