内容正文:
专题十七 结构体的定义和引用
1、 选择题
1. 设有一结构体类型变量定义如下:
struct date
{ int year;
int month;
int day;
};
struct worklist
{ char name[20];
char sex;
struct date birthday;
} person;
若对结构体变量person的出生年份进行赋值时,下面正确的赋值语句是( )
A. year=1976
B. birthday.year=1976
C. person.birthday.year=1976
D. person.year=1976
2.以下结构体类型变量的定义中,不正确的是( )
A. typedef struct aa { int n; float m; }AA; AA td1;
B. struct aa { int n; float m;} td1;
C. struct { int n; float m;}aa; struct aa td1;
D. struct{ int n; float m;}aa;
3.设有以下说明语句
struct stu { int a ;
float b ;
} stutype ;
则下面的叙述不正确的是( )。
A. struct 是结构体类型的关键字
B. struct stu 是用户定义的结构体类型
C. stutype 是用户定义的结构体类型名
D. a 和b 都是结构体成员名
4. 设有以下说明语句
struct date
{int x, y; }test1 = {10,20},test2;
则以下赋值语句中错误的是( )
A. test2= testl;
B. test2.x= testl.x;
C. test2.x= testl.y;
D. test2= {30,40};
二、程序填空题
1.编写一个程序,首先定义一个复数数据类型,即结构类型。然后按照复数的运算规则进行计算,并按照复数表示的格式进行输出。
#include <stdio.h>
main()
{ struct complex
{ (1) ;
int im;
}x,y,s,p;
scanf("%d%d",&x.re,&x.im);
scanf("%d%d", (2) );
s.re= (3) ;
s.im= (4) ;
printf("sum=%5d+i*%5d
",s.re,s.im);
p.re= (5) ;
p.im=x.re*y.im+x.im*y.re;
printf("product=%5d+i*%5d
",p.re,p.im);
}
(1)
(2)
(3)
(4)
(5)
三、编程题
定义一个结构体其中包括: 职工号、职工名、性别、年龄、工资、地址。按结构体类型定义一个结构体变量, 从键盘输入该结构体元素所需的数据,然后逐个输出这些元素的数据。
原创精品资源学科网独家享有版权,侵权必究!
$$
专题十七 结构体的定义和引用
1、 选择题
1. 设有一结构体类型变量定义如下:
struct date
{ int year;
int month;
int day;
};
struct worklist
{ char name[20];
char sex;
struct date birthday;
} person;
若对结构体变量person的出生年份进行赋值时,下面正确的赋值语句是( )
A. year=1976
B. birthday.year=1976
C. person.birthday.year=1976
D. person.year=1976
答案:C
解析:结构体变量的引用格式:结构体变量名.域名
2.以下结构体类型变量的定义中,不正确的是