(21)有如下函数定义:
void func (int a,int&b) {a++; b++;}
若执行代码段:
int x=0 ,y=1
func(x,y);
则变量x和y值分别是
A)0和1
B)1和1
C)0和2
D)1和2
(22)有如下程序:
#include
using namespace std;
class A{
public
static int a;
void init(){a=1;}
A(int a=2) {init();a++;}
};
int A:;a=0
A obj;
Int main()
{
cout<
}
运行时输出的结果是
A)0
B)1
C)2
D)3
(23)下列有关继承和派生的叙述中,正确的是
A) 派生类不能访问基类的保护成员
B)作为虚基类的类不能被实例化
C)派生类应当向基类的构造函数传递参数
D)虚函数必须在派生类中重新实现
(24)下列运算符中,不能被重载的是
A)&&
B)!=
C).
D)++
(25)下列函数模板的定义中,合法的是
A) template
B)template class
C)template T
D)template T abs(T x){returm x<0 -x;x;}
(26)在语句cin>>data;中,cin是
A)C++的关键字
B)类名
C)对象名
D)函数名
(27)有如下程序:
#include
using namespace std;
class test {
private:
int a;
public:
test(){cout<<”constructor”<
{
a=_testa;
cout<<”copy constructor”<
test(){cout<<”destructor”<
int main()
}
test A(3)
return0;
运行时输出的结果是
A)3
B)constructor
destruclor
C)copy constructor
D)3
dstructor destruclor
(28)若有如下类声明
class My Class {
public:
MyClass() {cout<<1;}
};
执行下列语句
MyClass a,b[2],*P[2];
以后,程序的输出结果是
A)11
B)111
C)1111
D11111
(29)有如下程序:
#include
using namespace std;
class point {
public:
static int number;
public:
point(){number++;
~point(){number-;}
};
imt point::number=0;
void main(){
point*ptr;
printA,B;
{
point*ptr_point=new point{3};
ptr=ptr_point;
}
pointC;
cout<
}
运行时输出的结果是
A)3
B)4
C)6
D)7
#include
using namespace std;
class Base{
int a,b;
public:
Bace(int x ,int y) { a=x; b=y;}
Void show(){ cout< }
clsaa Derived:public Base {
int c ,d;
public:
Derived(int x,int y,int z,int m):Base(x,y){c=z; d=m;}
Void show(){ cout<
int main()
{
Base B1(50,50),*pb;
Derived DI(10,20,30,40);
Pb=&D1;
Pb->show();
Return 0;
}
运行时输出的结果是
A)10,20
B)30,40
C)20,30
D)50,50
责任编辑:cyth