c++ii习题及其解答(第1版).pdf
文本预览下载声明
习题及其解答
第 5 章 类与对象
5.1 选择题
第7章 1. 在下列结构变量的定义中,不正确的是 ( d )。
第8章
第9章
第10章 (a) struct employee (b) struct
{ char name[ 20 ] ; { char name[ 20 ] ;
long code ; long code ;
} emp ;
} emp ;
(c) struct employee (d) struct
{ char name[20]; { char name[20];
long code; long code;
} ; } employee;
employee emp; employee emp;
2.已知有职工情况结构变量emp定义为:
struct employee
{ char name[ 20 ] ;
long code ;
struct
{ int year ;
int month ;
int day ;
} birth ;
} emp ;
下列对 emp 的 birth 正确赋值方法是( d )。
(a) year = 1980 ; month = 5 ; day = 1 ;
(b) birth.year = 1980 ; birth.month = 5 ; birth.day = 1 ;
(c) emp.year = 1980 ; emp.month = 5 ; emp.day = 1 ;
(d) emp.birth.year = 1980 ; emp.birth.month = 5 ; emp.birth.day = 1 ;
3.假定有以下声明和定义,则下面引用形式错误的是( b )。
1
struct student
{ int num ;
float score ;
} stu[3] = {{1001,80},{1002,75},{1003,91}}, *p = stu ;
(a) p-num (b) (p++).num (c) (p++)-num (d) (*p).num
4.下列四个运算符中,优先级最低的是( a )。
(a) ++ (b) . (c) - (d) ()
5.若有以下声明和定义,则下列错误的引用是( d )。
struct worker
{ int no ;
char name[ 20 ] ;
} w, *p = w ;
(a) w.no (b) p-no (c) (*p).no (d) *p.no
6.若有以下声明和定义,则下列引用非法的是( d )。
struct data
{ int n;
float score;
data *q ;
};
data a[3] = {1001,87,a[1],1002,75,a[2],1003,90
显示全部