文档详情

[2017年电大]《c语言程序设计》形成性考核作业()解答.doc

发布:2017-08-14约5.23千字共7页下载文档
文本预览下载声明
《C语言程序设计》作业4解答 一、选择题 1. 假定有“struct BOOK {char title[40]; float price;}; struct BOOK * book;”,则不正确的语句为 ( A )。 A. struct BOOK * x=malloc(book); B. struct BOOK x={C++ Programming,27.0}; C. struct BOOK * x=malloc(sizeof(struct BOOK)); D. struct BOOK **x=book; 2. 假定有“struct BOOK {char title[40]; float price;} book;”,则正确的语句为 ( B )。 A. struct BOOK x=book; B. struct BOOK * x=book; C. struct BOOK x=calloc(BOOK); D. struct BOOK *x=BOOK; 3. 表示文件结束符的符号常量为( C )。 A. eof B. Eof C. EOF D. feof 4. C语言中的系统函数fopen( )是( D )一个数据文件的函数。 A. 读取 B. 写入 C. 关闭 D. 打开 5. 从一个数据文件中读入以换行符结束的一行字符串的函数为( B )。 A. gets( ) B. fgets( ) C. getc( ) D. fgetc( ) 6. 向一个二进制文件中写入信息的函数fwrite( )带有( D )个参数。 A. 1 B. 2 C. 3 D. 4 二、填空题 1. 假定一个结构类型的定义为“struct A {int a, b; struct A * c;};”,则该类型的大小为 12 字节。 2. 假定一个结构类型的定义为“struct B {int a[5]; char * b;};”,则该类型的大小为 24 字节。 3. 假定一个结构类型的定义为“struct D {int a; union {int b; double c}; struct D * d[2];};”,则该类型的大小为 20 字节。 4. 假定要动态分配一个类型为struct Worker的具有n 个元素的数组,并由r指向这个动态数组,则使用的语句表达式为struct Worker * r= calloc(n, sizeof(struct Worker)); 。 5. 假定要访问一个结构x中的由a指针成员所指向的对象,则表示方法为 *(x.a) 。 6. 假定要访问一个结构指针p所指对象中的b指针成员所指的对象,则表示方法为 *(p-b) 。 7. 与结构成员访问表达式(*fp).score等价的表达式是 fp-score 。 三、写出下列每个程序运行后的输出结果 1. #include stdio.h struct Worker { char name[15]; // 姓名 int age; // 年龄 float pay; // 工资 }; void main( ) { struct Worker x={wanghua, 52, 2350}; struct Worker y, * p; y=x; p=x; printf(%s %d %6.2f\n,y.name, y.age, y.pay); printf(%s %d %6.2f\n,p-name, p-age, p-pay);d资 } 程序的运行结果是: wanghua 52 2350.00 wanghua 52 2350.00 2. #include stdio.h #include string.h struct Worker { char name[15]; // 姓名 int age; // 年龄 float pay; /
显示全部
相似文档