31.有如下程序:
#include
usingnamespacestd;
intmain()
{
int*P;
*P=9:
cout<<"ThevalueatP:"<<*P;
return0;
}
編譯運(yùn)行程序?qū)⒊霈F(xiàn)的情況是( )。
A.編譯時(shí)出現(xiàn)語法錯(cuò)誤,不能生成可執(zhí)行文件
B.運(yùn)行時(shí)一定輸出ThevalueatP:9
C.運(yùn)行時(shí)一定輸出ThevalueatP:*9
D.運(yùn)行時(shí)有可能出錯(cuò)
32.有如下類定義:
classFoo
{
public:
Foo(intv):value(v){}//①
~Foo(){}//②
private:
Foo(){}//③
intvalue=0;//④
};
其中存在語法錯(cuò)誤的行是( )。
A.①
B.②
C.③
D.④
33.下列程序的運(yùn)行結(jié)果是( )。
#include
classA
{
inta;
public:
A(){a=0;}
A(){intaa}
{a=aa;
cout< }
};
voidmain()
{
Ax,y(2),z(3);
cout< }
A.OOB.23
C.34D.25
34.語句ofstreamf("DATA.DAT",ios_base::app|ios_base::binary);的功能是建立流對(duì)象f,試圖打開文件DA-TA.DAT并與之連接,而且( )。
A.若文件存在,將文件指針定位于艾件首;若文件不存在,建立一個(gè)新文件
B.若文件存在,將其截為空文件;若文件不存在,打開失敗
C.若文件存在,將文件指針定位于文件尾;若文件不存在,建立一個(gè)新文件
D.若文件存在,打開失敗;若文件不杉在,建立一個(gè)新文件
35.下面程序的輸出結(jié)果是( )。
#include
Usingnamespacestd;
ClassBase{
public:
Base(intx=O){count< }
};
ClassDerived:publicBase{
public:Derved(intx=0{count< }
private;
Baseval;
};
intmina(){
Derivedd(1);
retrun0;
}
A.0
B.1
C.01
D.001
36.計(jì)算斐波那契數(shù)列第n項(xiàng)的函數(shù)定義如下:
intfib(intn){
if.(n==0)return1;
elseif(n==1)return2:
elsereturnfib(n-1)+fib(n-2);
}
若執(zhí)行函數(shù)調(diào)用表達(dá)式fib(2),函數(shù)fib被調(diào)用的次數(shù)是( )。
A.1
B.2
C.3
D.4
37.要定義一個(gè)引用變量P,使之引用類MyClass的一個(gè)對(duì)象,正確的定義語句是( )。
A.MyClassp=MyClass;
B.MyClassp=newMyClass;
C.MyClass&p=newMyClass
D.MyClassa,&p=a;
38.下列關(guān)于虛基類的描述中,錯(cuò)誤的是( )。
A.使用虛基類可以消除由多繼承產(chǎn)生的二義性
B.構(gòu)造派生類對(duì)象時(shí),虛基類的構(gòu)造函數(shù)只被調(diào)用一次
C.聲明“classB:virtualpublicA”說明類B為虛基類
D.建立派生類對(duì)象時(shí),首先調(diào)用虛基類的構(gòu)造函數(shù)
39.將運(yùn)算符重載為類成員函數(shù)時(shí),其參數(shù)表中沒有參數(shù),說明該運(yùn)算符是( )。
A.不合法的運(yùn)算符
B.一元運(yùn)算符
C.無操作數(shù)的運(yùn)算符
D.二元運(yùn)算符
40.有如下模板聲明:
templateclassA;
下列聲明中,與上述聲明不等價(jià)的是( )。
A.templateclassA;
B.templateclassAt
C.templateclassA;
D.templateclassA;
![]() | ![]() .. 定價(jià):¥225 優(yōu)惠價(jià):¥213 更多書籍 |
![]() | ![]() .. 定價(jià):¥133 優(yōu)惠價(jià):¥133.0 更多書籍 |