结构和类有什么区别?如果把程序中定义结构的关键字struct直接改成class,会有什么问题?用教材上的一个例程试一试,想一想做什么修改能使程序正确运行?
第1题:
已知有结构体: struct sk { int a; float b; }data,*p; 若有p=&data,则对data的成员a的正确引用是( )。
A.struct是结构体类型的关键字
B.st是结构体类型名
C.x、y、z都是结构体成员名
D.struct str是结构体类型名
第2题:
设有以下语句: struct SS { int no; char name[10];}PERSON; 则下面叙述中错误的是 ( )
A.struct是结构体类型的关键字
B.struct SS是结构体类型
C.PERSON是结构体类型名
D.name是结构体成员名
第3题:
设有以下说明语句
struct ex
{ int x ; float y; char z ;} example;
则下面的叙述中不正确的是
A.struct结构体类型的关键字
B.example是结构体类型名
C.x,y,z都是结构体成员名
D.struct ex是结构体类型名
第4题:
A.struct是结构体类型的关键字
B.structteacher是用户定义的结构体类型
C.num,sex,age都是结构体变量teacher1的成员
D.teacher1是结构体类型名
第5题:
设有以下说明语句: struct stu { int a; float b; }stutype; 则下面叙述不正确的是( )。
A.struct是结构体类型的关键字
B.structstu是用户定义的结构体类型
C.stutype是用户定义的结构体类型名
D.a和b都是结构体成员名
第6题:
在C++语言中,关于类(class)和结构体(struct)的说法中,正确的是______。
A.结构体不允许有成员函数
B.结构体与类没什么区别,可以替换
C.类定义中成员在默认情况下是private
D.类定义中成员在默认情况下是public
A.
B.
C.
D.
第7题:
若有如下说明,则_______的叙述是正确的。 struct st { int a; int b[2]; }a;
A.结构体变量a与结构体成员a同名,定义是非法的
B.程序只在执行到该定义时才为结构体st分配存储单元
C.程序运行时为结构体st分配6个字节存储单元
D.类型名struct st可以通过extern关键字提前引用(即引用在前,说明在后)
第8题:
设有以下说明语句
struct stu
{int a;
float b;
} stutype;
则下面的叙述不正确的是
A.struct是结构体类型的关键字
B.struct stu是用户定义的结构体类型
C.stutype是用户定义的结构体类型名
D.a和b都是结构体成员名
第9题:
若有如下说明,且int类型占两个字节,则正确的叙述为( )。 struct st {int a; int b[2]; }a;
A.结构体变量a与结构体成员a同名,定义是合法的
B.程序只在执行到该结构体时才为结构体st分配存储单元
C.程序运行时为结构体st分配8字节存储单元
D.类型名struct st可以通过extern关键字提前引用
第10题:
a)Can a struct inherit from another struct?
(结构体能继承结构体吗)
b)Can a struct inherit from another class?
(结构体能继承类吗)
c)Can a struct be the base of another class?
(结构体可以作为一个类的基类吗)
d)Can a struct implement an interface?
(结构体可以实现一个接口吗)
e)What’s the difference between struct and class?
(结构体与类有什么区别)