第九章单元测试
有以下结构体定义:
struct example
{ int x;
int y; }v1;
则正确的引用或定义是( ) 。
对于如下结构体定义,若对变量person的出生年份进行赋值,正确的赋值是( )。
struct date
{ int year,month,day;
};
struct worklist
{ char name[20];
char sex;
struct date birth;
}person;
根据下述定义,可以输出字符'A'的语句是( )。
struct person
{ char name[11];
struct
{ char name[11];
int age;
}other;
};
struct person man[10]={ {"Jone",{"Paul",20}},{"Paul",{"Mary",18}},
{"Mary",{"Adam",23}},{"Adam",{"Jone",22}}
};
若有以下程序段:
struct st
{ int n;
struct st *next; };
struct st a[3]={5,&a[1],7,&a[2],9, '\0'} ,*p=a;
则值为6的表达式为( )。
运行下列程序段,输出结果是( ) 。
struct country
{ int num;
char name[10];
}x[5]={1,"China",2,"USA",3,"France",4, "England",5, "Spanish"};
struct country *p;
p=x+2;
printf("%d,%c",p->num,(*p).name[2]);
定义以下结构体数组
struct c
{ int x;
int y;
}s[2]={1,3,2,7};
语句printf("%d",s[0].x*s[1].x)的输出结果为( )
定义以下结构体类型
struct student
{char name[10];
float score[50];
double average;
}stud1;
则stud1占用内存的字节数是( )。
能在一个存储区内处理不同的类型的数据叫结构体。
在编译时对结构体类型不分配空间,只能对结构体变量分配空间。
结构体一旦定义,系统就给它分配所需的内存单元。
A:struct example v2={10}; B: v1.x=10; C:example v2; v2.x=10; D:struct v2; v2.x=10;
答案: v1.x=10;
A:birth.year=1976 B:person.birth.year=1976 C: year=1976 D:person.year=1976
A:printf("%c",other.name[0]); B:printf("%c",man[3].name); C:printf("%c",man[2].(* other[0])); D:printf("%c",man[2].other.name[0]);
A: (*p).n++ B:++p->n C:p++->n D:p->n++
A:2,USA B:4,g C: 5,Spanish D:3,a
A: 6 B:21 C:2 D:14
A:7 B:228 C:64 D:218
A:对 B:错
A:错 B:对
A:错 B:对