第9章 结构体
一、单项选择题
1. 若有以下说明语句: struct student { int num; char name[ ]; float score; }stu;
则下面的叙述不正确的是: ( )
A) struct是结构体类型的关键字 B) struct student 是用户定义的结构体类型 C) num, score都是结构体成员名 D) stu是用户定义的结构体类型名 2. 若有以下说明语句: struct date { int year; int month; int day; }brithday;
则下面的叙述不正确的是_____.
A) struct是声明结构体类型时用的关键字 B) struct date 是用户定义的结构体类型名 C) brithday是用户定义的结构体类型名 D) year,day 都是结构体成员名
3. 已知:(设整型2字节,字符型1字节,浮点型4字节)
struct { int i; char c; float a; }test;
则sizeof(test)的值是 。 A) 4 B) 5 C) 6 D) 7
4. 以下对结构变量stul中成员age的非法引用是 。
struct student { int age; int num; }stu1,*p; p=&stu1;
A) stu1.age B) student.age C) p->age D) (*p).age 5. 有如下定义
struct person{char name[9]; int age;}; struct person class[10]={“Tom”,17,“John”,19,
“Susan”,18,“Adam”,16,};
根据上述定义,能输出字母A的语句是
A) printf(“%c\\n”,class[3].name); B) printf(“%c\\n”,class[3].name[0]);
C) printf(“%c\\n”,class[3].name[1]); D) printf(“%c\\n”,class[2].name[3]); 6. 存放100个学生的数据、包括学号、姓名、成绩。在如下的定义中,不正确的是( )。
A.struct student
{int sno; char name[20]; float score; } stu[100];
B. struct student stu[100]
{int sno; char name[20]; float score}; C. struct { int sno; char name[20]; float score;} stu[100]; D. struct student
{int sno; char name[20]; float score;}; struct student stu[100];
7. 设有定义语句“struct {int x; int y;} d[2]={{1,3},{2,7}};” 则“printf(“%d\\n”,d[0].y/d[0].x*d[1].x);”输出的是( )。
A.0 B)1 C)3 D)6 8. 设有如下定义,则对data中的a成员的正确引用是( )。 struct sk{ int a; float b;} data,*p=&data;
A)(*p))data.a B)(*p).a C)p->data.a D)p.data.a 9、已知: struct sk { int a;
float b;
}data, *p;
若有p=&data,则对data中的成员a的正确引用是( )。 A、(*p).data.a B、p->data.a C、(*p).a D、p.data.a 10. 设有如下定义:
struck sk { int a; float b; }data; int *p;
若要使P指向data中的a域,正确的赋值语句是 A) p=&a; struct student { int age;
B) p=data.a; C) p=&data.a;
D)*p=data.a;
11. 以下对结构变量stu1中成员age的非法引用是( )。
int num; }stu1,*p; p=&stu1;
A、 stu1.age B、 student.age C、 p->age D、 (*p).age 12、设有以下说明语句:
typedef struct stu { int a; float b; } stutype;
则下面叙述中错误的是( )。
A、struct是结构类型的关键字 C、a和b都是结构成员名
二、阅读程序,写出运行结果
1.
#include
} a[2]={5, 7, 2, 9} ; main() {
printf(\}
运行结果是: 14 2.
#include
{struct stu {int no;
char a[5]; float score;
}m={1234,”wang”,89.5};
printf(“%d,%s,%f”,m.no,m.a,m.score); }
运行结果是:
1234,wang,89.500000
B、struct stu是用户定义的结构类型 D、stutype是用户定义的结构体变量名
3.
#include
}cnum[2]={1, 3, 2, 7}; main( ) {
printf(“%d\\n”, cnum[0].y * cnum[1].x ); }
运行结果是: 6 4.
#include
{ struct abc s[2]={{1,2,3},{4,5,6}}; int t;
t=s[0].a+s[1].b; printf(\}
运行结果是: 6 5.
#include
} pt[]={1,4,6, 8,3,5}; main()
{ struct point *p; p=pt;
printf(“%d”,p->y *(p+1)->x); }
运行结果是: 24 6.
#include
float score;
}stu[3]={{1,\main() { int i;
float total=0.0; for(i=0;i<3;i++)
total=total+stu[i].score;
printf(\ }
运行结果是:
The total scores is:260.5