下面代码执行后,正确的输出是( )
char *a ="Hello";
char b[6]="Hello";
if (a==b) {
if (*a == *b)
printf(“AA”);
else
printf(“BB”);
}
else {
if (*a == *b)
printf(“CC”);
else
printf(“DD”);
}
A) AA B) BB C) CC D) DD
设有如下 class 定义:
class CA
{
public:
CA(void) { std::cout << 'a'; }
~CA(void) { std::cout << 'b'; }
};
class CB : private CA
{
public:
CB(void) { std::cout << 'c'; }
~CB(void) { std::cout << 'd'; }
};
则,
{
CB obj;
}
以上代码的执行结果是( )
A) abcd B) acbd
C) cadb D) acdb
设有如下 class 定义:
class CA
{
public:
virtual void foo(int i)
{ cout << "void CA::foo(int i)" << endl; }
};
class CB : public CA
{
public:
virtual void foo(int i)
{ cout << "void CB::foo(int i)" << endl; }
virtual void foo(double d)
{ cout << "void CB::foo(double d)" << endl; }
};
则,
CB b;
CA & a = b;
a.foo(5.0);
b.foo(5.0);
以上代码的执行结果是( )
A) void CA::foo(int i)
void CB::foo(double d)
B) void CA::foo(int i)
void CB::foo(double d)
C) void CB::foo(int i)
void CB::foo(double d)
D) void CB::foo(double d)
void CB::foo(double d)
设有如下 class 定义:
class CA
{
public:
CA(void) { ++CA::ms_iCounter; }
~CA(void) { --CA::ms_iCounter; }
static int ms_iCounter;
}
int CA::ms_iCounter = 0;
则,
CA a[2];
CA b = a[1];
cout << CA::ms_iCounter;
以上代码的执行结果是( )
A) -1 B) 0 C) 2 D) 3
如下代码:
class CInner
{
public:
CInner();
~CInner();
};
class CBase
{
Public:
CBase();
~CBase();
};
class CChild : public CBase
{
public:
CChild ();
~ CChild ();
private:
CInner m_inner;
};
他们的构造函数的调用顺序是( )
A) CInner::CInner()
CBase::CBase()
CChild:: CChild()
B) CChild::CChild()
CBase::CBase()
CInner::CInner()
C) CBase::CBase()
CChild::CChild()
CInner::CInner()
D) CBase::CBase()
CInner::CInner()
CChild::CChild()
下面函数中,参数 a 的实际类型是( )
void foo(int a[5][6])
{
...
}
A) 数组的数组;
B) 指针的指针;
C) 指针的数组;
D) 数组的指针;
下面的程序的输出结果为:s
#include<iostream>
#include<list>
using namespace std;
class CBaseClass
{
public:
CBaseClass()
{
Init();
}
~CBaseClass(void){};
virtual int Init(void)
{
m_iInitVar = 1;
return 0;
}
int GetResult(void)
{
return m_iInitVar;
}
int m_iInitVar;
};
class CDerivedClass : public CBaseClass
{
public:
CDerivedClass(void) {};
~CDerivedClass(void) {};
virtual int Init(void)
{
m_iInitVar = 2;
return 0;
}
};
int main()
{
CBaseClass * pCBaseA = new CBaseClass();
CBaseClass * pCBaseB = new CDerivedClass();
CDerivedClass * pCDerivedClass = new CDerivedClass ();
int i = pCBaseA->GetResult();
int j = pCBaseB->GetResult();
int k = pCDerivedClass ->GetResult();
cout<<i<<","<<j<<","<<k<<endl;
delete pCBaseA;
delete pCBaseB;
delete pCDerivedClass;
return 0;
}
A) 1,1,1
B) 1,2,1
C) 1,2,2
D) 2,2,2