(21)有如下程序:
#include
void fun(int& x, int y) { int t = x; x = y; y = t; }
int main( )
{
int a[2] = {23, 42};
fun(a[1], a[0]);
std::cout << a[0] << ", " << a[1] << std::endl;
return 0;
}
执行后的输出结果是
A)42, 42
B)23, 23
C)23, 42
D)42, 23
(22)有如下类声明:
class Foo { int bar; };
则Foo类的成员bar是
A)公有数据成员
B)公有成员函数
C)私有数据成员
D)私有成员函数
(23)有如下类声明:
class MyBASE{
int k;
public:
void set(int n){ k=n;}
int get( )const{ return k; }
};
class MyDERIVED: protected MyBASE{
protected:
int j;
public:
void set(int m, int n){ MyBASE::set(m); j=n;}
int get( )const{ return MyBASE::get( )+j; }
};
则类MyDERIVED中保护的数据成员和成员函数的个数是
A)4
B)3
C)2
D)1
(24)已知在一个类体中包含如下函数原型: VOLUME operator-(VOLUME)const;,下列关于这个函数的叙述中,错误的是
A)这是运算符-的重载运算符函数
B)这个函数所重载的运算符是一个一元运算符
C)这是一个成员函数
D)这个函数不改变类的任何数据成员的值
(25)有如下函数模板定义:
template
T func(T x, T y) { return x*x+y*y; }
在下列对func的调用中,错误的是
A)func(3, 5);
B)func(3.0, 5.5);
C)func (3, 5.5);
D)func
(26)有如下程序:
#include
using namespace std;
int main( )
{
cout.fill('*');
cout.width(6);
cout.fill('#');
cout << 123 << endl;
return 0;
}
执行后的输出结果是
A)###123
B)123###
C)***123
D)123***
(27)在下列函数原型中,可以作为类AA构造函数的是
A)void AA(int);
B)int AA( );
C)AA(int)const;
D)AA(int);
(28)下列关于this指针的叙述中,正确的是
A)任何与类相关的函数都有this指针
B)类的成员函数都有this指针
C)类的友元函数都有this指针
D)类的非静态成员函数才有this指针
(29)有如下程序:
#include
using namespace std;
class Test {
public:
Test( ) { n+=2; }
~Test( ) { n-=3; }
static int getNum( ) { return n; }
private:
static int n;
};
int Test::n = 1;
int main( )
{
Test* p = new Test;
delete p;
cout << "n=" << Test::getNum( ) << endl;
return 0;
}
执行后的输出结果是
A)n=0
B)n=1
C)n=2
D)n=3
(30)有如下程序:
#include
using namespace std;
class A {
public:
A( ) { cout << "A"; }
};
class B { public: B( ) { cout << "B"; } };
class C : public A {
B b;
public:
C( ) { cout << "C"; }
};
int main( ) { C obj; return 0; }
执行后的输出结果是
A)CBA
B)BAC
C)ACB
D)ABC
责任编辑:cyth