C++常见英文面试笔精彩试题Word格式文档下载.docx

上传人:b****1 文档编号:1478068 上传时间:2023-04-30 格式:DOCX 页数:20 大小:128.69KB
下载 相关 举报
C++常见英文面试笔精彩试题Word格式文档下载.docx_第1页
第1页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第2页
第2页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第3页
第3页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第4页
第4页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第5页
第5页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第6页
第6页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第7页
第7页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第8页
第8页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第9页
第9页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第10页
第10页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第11页
第11页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第12页
第12页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第13页
第13页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第14页
第14页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第15页
第15页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第16页
第16页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第17页
第17页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第18页
第18页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第19页
第19页 / 共20页
C++常见英文面试笔精彩试题Word格式文档下载.docx_第20页
第20页 / 共20页
亲,该文档总共20页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

C++常见英文面试笔精彩试题Word格式文档下载.docx

《C++常见英文面试笔精彩试题Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《C++常见英文面试笔精彩试题Word格式文档下载.docx(20页珍藏版)》请在冰点文库上搜索。

C++常见英文面试笔精彩试题Word格式文档下载.docx

Whatiscopyconstructor?

Constructorwhichinitializestheit'

sobjectmembervariables(byshallowcopying)withanotherobjectofthesameclass.Ifyoudon'

timplementoneinyourclassthencompilerimplementsoneforyou.

forexample:

BooObj1(10);

//callingBooconstructor

BooObj2(Obj1);

//callingboocopyconstructor

BooObj2=Obj1;

//callingboocopyconstructor

Whenarecopyconstructorscalled?

Copyconstructorsarecalledinfollowingcases:

a)whenafunctionreturnsanobjectofthatclassbyvalue

b)whentheobjectofthatclassispassedbyvalueasanargumenttoafunction

c)whenyouconstructanobjectbasedonanotherobjectofthesameclass

d)Whencompilergeneratesatemporaryobject

Whatisassignmentoperator?

Defaultassignmentoperatorhandlesassigningoneobjecttoanotherofthesameclass.Membertomembercopy(shallowcopy)

Whatarealltheimplicitmemberfunctionsoftheclass?

Orwhatareallthefunctionswhichcompilerimplementsforusifwedon'

tdefineone.?

defaultctor

copyctor

assignmentoperator

defaultdestructor

addressoperator

Whatisconversionconstructor?

constructorwithasingleargumentmakesthatconstructorasconversionctoranditcanbeusedfortypeconversion.

classBoo

{

public:

Boo(inti);

};

BooBooObject=10;

//assigningint10Booobject

Whatisconversionoperator?

classcanhaveapublicmethodforspecificdatatypeconversions.

doublevalue;

Boo(inti)

operatordouble()

{

returnvalue;

}

BooBooObject;

doublei=BooObject;

//assigningobjecttovariableioftypedouble.nowconversionoperatorgetscalledtoassignthevalue.

Whatisdiffbetweenmalloc()/free()andnew/delete?

mallocallocatesmemoryforobjectinheapbutdoesn'

tinvokeobject'

sconstructortoinitiallizetheobject.

newallocatesmemoryandalsoinvokesconstructortoinitializetheobject.

malloc()andfree()donotsupportobjectsemantics

Doesnotconstructanddestructobjects

string*ptr=(string*)(malloc(sizeof(string)))

Arenotsafe

Doesnotcalculatethesizeoftheobjectsthatitconstruct

Returnsapointertovoid

int*p=(int*)(malloc(sizeof(int)));

int*p=newint;

Arenotextensible

newanddeletecanbeoverloadedinaclass

"

delete"

firstcallstheobject'

sterminationroutine(i.e.itsdestructor)andthenreleasesthespacetheobjectoccupiedontheheapmemory.Ifanarrayofobjectswascreatedusingnew,thendeletemustbetoldthatitisdealingwithanarraybyprecedingthenamewithanempty[]:

-

Int_t*my_ints=newInt_t[10];

...

delete[]my_ints;

whatisthediffbetween"

new"

and"

operatornew"

?

workslikemalloc.

Whatisdifferencebetweentemplateandmacro?

Thereisnowayforthecompilertoverifythatthemacroparametersareofcompatibletypes.Themacroisexpandedwithoutanyspecialtypechecking.

Ifmacroparameterhasapost-incrementedvariable(likec++),theincrementisperformedtwotimes.

Becausemacrosareexpandedbythepreprocessor,compilererrormessageswillrefertotheexpandedmacro,ratherthanthemacrodefinitionitself.Also,themacrowillshowupinexpandedformduringdebugging.

Macro:

#definemin(i,j)(i<

j?

i:

j)

template:

template<

classT>

Tmin(Ti,Tj)

{

returni<

j;

}

WhatareC++storageclasses?

auto

register

static

extern

auto:

thedefault.Variablesareautomaticallycreatedandinitializedwhentheyaredefinedandaredestroyedattheendoftheblockcontainingtheirdefinition.Theyarenotvisibleoutsidethatblock

register:

atypeofautovariable.asuggestiontothecompilertouseaCPUregisterforperformance

static:

avariablethatisknownonlyinthefunctionthatcontainsitsdefinitionbutisneverdestroyedandretains=keepitsvaluebetweencallstothatfunction.Itexistsfromthetimetheprogrambeginsexecution

extern:

astaticvariablewhosedefinitionandplacementisdeterminedwhenallobjectandlibrarymodulesarecombined(linked)toformtheexecutablecodefile.Itcanbevisibleoutsidethefilewhereitisdefined.

WhatarestoragequalifiersinC++?

Theyare..

const

volatile

mutable

Constkeywordindicatesthatmemoryonceinitialized,shouldnotbealteredbyaprogram.

volatilekeywordindicatesthatthevalueinthememorylocationcanbealteredeventhoughnothingintheprogram

codemodifiesthecontents.forexampleifyouhaveapointertohardwarelocationthatcontainsthetime,wherehardwarechangesthevalueofthispointervariableandnottheprogram.Theintentofthiskeywordtoimprovetheoptimizationabilityofthecompiler.

mutablekeywordindicatesthatparticularmemberofastructureorclasscanbealteredevenifaparticularstructurevariable,class,orclassmemberfunctionisconstant.

structdata

charname[80];

mutabledoublesalary;

constdataMyStruct={"

SatishShetty"

1000};

//initlizedbycomplier

strcpy(MyStruct.name,"

ShilpaShetty"

);

//compilererror

MyStruct.salaray=2000;

//complierishappyallowed

Whatisreference?

referenceisanamethatactsasanalias,oralternativename,forapreviouslydefinedvariableoranobject.

prependingvariablewith"

&

symbolmakesitasreference.

inta;

int&

b=a;

读amp

Whatispassingbyreference?

Methodofpassingargumentstoafunctionwhichtakesparameteroftypereference.

voidswap(int&

x,int&

y)

inttemp=x;

x=y;

y=temp;

inta=2,b=3;

swap(a,b);

Basically,insidethefunctiontherewon'

tbeanycopyofthearguments"

x"

y"

insteadtheyrefertooriginalvariablesaandb.sonoextramemoryneededtopassargumentsanditismoreefficient.

Whendouse"

const"

referenceargumentsinfunction?

a)Usingconstprotectsyouagainstprogrammingerrorsthatinadvertently不经意的alterdata.

b)Usingconstallowsfunctiontoprocessbothconstandnon-constactualarguments,whileafunctionwithoutconstintheprototypecanonlyacceptnonconstantarguments.

c)Usingaconstreferenceallowsthefunctiontogenerateanduseatemporaryvariableappropriately.

WhenaretemporaryvariablescreatedbyC++compiler?

Providedthatfunctionparameterisa"

constreference"

compilergeneratestemporaryvariableinfollowing2ways.

a)Theactualargumentisthecorrecttype,butitisn'

tLvalue

doubleCube(constdouble&

num)

num=num*num*num;

returnnum;

doubletemp=2.0;

doublevalue=cube(3.0+temp);

//argumentisaexpressionandnotaLvalue;

b)Theactualargumentisofthewrongtype,butofatypethatcanbeconvertedtothecorrecttype

longtemp=3L;

doublevalue=cuberoot(temp);

//longtodoubleconversion

Whatisvirtualfunction?

Whenderivedclassoverridesthebaseclassmethodbyredefiningthesamefunction,thenifclientwantstoaccessredefinedthemethodfromderivedclassthroughapointerfrombaseclassobject,thenyoumustdefinethisfunctioninbaseclassasvirtualfunction.

classparent

voidShow()

cout<

<

"

i'

mparent"

<

endl;

classchild:

publicparent

mchild"

parent*parent_object_ptr=newchild;

parent_object_ptr->

show()//callsparent->

show()i

nowwegotovirtualworld...

virtualvoidShow()

show()//callschild->

show()

Whatispurevirtualfunction?

orwhatisabstractclass?

Whenyoudefineonlyfunctionprototypeinabaseclasswithoutimplementationanddothecompleteimplementation实现inderivedclass.Thisbaseclassiscalledabstractclassandclientwon'

tabletoinstantiateanobjectusingthisbaseclass.

Youcanmakeapurevirtualfunctionorabstractclassthisway..

voidfoo()=0;

BooMyBoo;

//compilationerror

WhatisMemoryalignment?

Thetermalignmentprimarilymeansthetendency趋向ofanaddresspointerva

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 医药卫生 > 预防医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2