These test questions are fill in the blank, multiple choice, and true-false. The multiple
choice questions may have more than one correct answer. There is one matching
question. Mark all of the correct answers for full credit.
True False questions require an explanation in addition to the true/false response, and, if
false, also require a correction.
True False:
Comment required.
1. OOP is an acronym that means Object Oriented Programming.
Answer: True.
Explanation: OOP is currently popular and is a powerful programming technique for a
large class of problems.
2. C++ not only supports OOP but also supports other programming styles.
Answer: True.
Explanation: C++ supports OOP and traditional procedure oriented programming.
3. The namespace facility is a tool used that assists in the study of genealogy.
Answer: False.
Explanation: The namespace facility helps prevent the libraries from “preempting all the
good names,” and allows us to use names we want whether the library has used them.
4. In C++ the variables Alpha, ALPHA and AlphA are the same identifier.
Answer: False.
Explanation: C++ is case sensitive, these are different identifiers.
5. In C++ the compiler will infer the type intended for a variable from the context in
which the variable occurs.
Answer: False.
Explanation: C++ requires every identifier to be declared prior to use. The type is
specified in the declaration.
6. A C++ declaration introduces only an identifier's spelling and specifies its type.
Answer: True.
Explanation: A declaration introduces the spelling and type, whereas a definition is a
TestBanksAdept
, Test #xzBank #xzfor #xzSavitch #xzAbsolute Page #xz
#xzC++ #xz6e 2
declaration #xzthat #xzalso #xzallocates #xzmemory.
7. A #xzC++ #xzdeclaration #xzis #xza #xzdefinition #xzthat #xzalso #xzallocates #xzstorage #xzfor #xzan
identifier's #xzvalue #xz(or #xzfunction's #xzbody #xzetc.).
#xz
Answer: # x z True.
Explanation: #xzA #xzdeclaration #xzintroduces #xzthe #xzspelling #xzand #xztype, #xzwhereas #xza #xzdefinition #xzis
a #xzdeclaration #xzthat #xzalso #xzallocates #xzmemory.
#xz
8. The #xzrange #xzof #xzvalues #xzfor #xzan #xzint #xzvariable #xzis #xzfrom #xzabout
0 #xzto #xz+2 #xzbillion. #xzAnswer: #xzFalse:
Explanation: #xzThe #xzcorrect #xzrange #xzis #xzabout #xz–2 #xzBillion #xzto #xz+2 #xzBillion.
9. The #xznames #xzx, #xzy, #xzand #xzz #xzare #xzsatisfactory #xzvariable #xznames #xzfor #xzthe #xzlengths
#xz of #xzthe #xzlegs #xzand #xzhypotenuse #xzof #xza #xztriangle.
Answer: # x z False.
Explanation: #xzNames #xzshould #xzcommunicate #xzto #xzthe #xzhuman #xzreader #xzthe #xzmeaning #xzof
the #xzvalue. #xzThese #xzidentifiers #xzdo #xznot #xzcommunicate #xzthe #xzmeaning #xzof #xztheir
#xz
#xz values..
10. In #xzC++ #xzyou #xzcan #xzassign #xzan #xzexpression #xzof #xztype #xzint #xzto #xza #xzvariable #xzof #xztype
#xz double #xzwith #xzno #xzproblem.
Answer: # x z True.
Explanation: #xzAssignment #xzfrom #xzan #xzinteger #xztype #xzto #xza #xzfloating #xzpoint #xztype #xzcan
#xz lose #xzinformation #xzand #xzshould #xzbe #xzavoided. #xzSome #xzcompilers #xzwill #xzwarn, #xzothers
may #xzgive #xzan #xzerror #xzmessage, #xzbut #xzyou #xzshould #xzavoid #xzthis.
#xz
11. In #xzC++ #xzyou #xzcan #xzassign #xzan #xzexpression #xzof #xztype #xzdouble #xzto #xza #xzvariable #xzof
type #xzint #xzwith #xzno #xzproblem.
#xz
Answer: # x z False.
Explanation: #xzIn #xzgeneral #xzassigning #xza #xzfloating #xzpoint #xzvalue #xzto #xzan #xzinteger
#xz variable #xzmostly #xzloses #xzinformation. #xzA #xzwarning #xzmessage #xz(or #xzan #xzerror #xzmessage)
is #xzissued #xzby #xzC++ #xzcompilers.
#xz
12. To #xzput #xza #xzcharacter #xzinto #xza #xzcstring #xzconstant #xzthat #xzcauses #xzthe #xzoutput #xzto
#xz continue #xzon #xzthe #xznext #xzline, #xzinsert #xzthe #xzescape #xzsequence #xz\t #xzinto #xzthe #xzstring
#xz constant.
Answer: # x z False.
Explanation: #xz\t # x z is #xzthe #xztab #xzescape #xzsequence. #xzUse #xz\n #xzinstead.
©2016 # x z Pearson # x z Education, #xz Inc. # x z Upper # x z Saddle # xz River, # x z NJ. # x z All
# x z Rights # x z Reserved.
,Test #xzBank #xzfor #xzSavitch #xzAbsolute Page #xz
#xzC++ #xz6e 3
13. If #xzwe #xzexecute #xzthis #xzcode #xzin #xzan #xzotherwise #xzcorrect #xzand #xzcomplete #xzprogram:
n # x z = # x z 1;
©2016 # x z Pearson # x z Education, #xz Inc. # x z Upper # x z Saddle # xz River, # x z NJ. # x z All
# x z Rights # x z Reserved.
, Test #xzBank #xzfor #xzSavitch #xzAbsolute Page #xz
#xzC++ #xz6e 4
n # x z = # x z (n++) # x z + # x z (n++);
the #xzvalue #xzof #xzn #xzis #xzguaranteed #xzto #xzbe #xz3 #xzafter #xzthe #xzsecond
#xz line #xzexecutes. #xzAnswer: #xzFalse.
Explanation: #xzSome #xzcompilers #xzmay #xzgive #xzthe #xzvalue #xz3. #xzThe #xzresult #xzof #xzsuch #xzcode
is #xzdependent #xzon #xzthe #xzcompiler #xzimplementation. #xzThe #xzC++ #xzStandard #xzsays #xzsuch
#xz
#xz code #xzis #xzillegal, #xzand #xzthe #xzStandard #xzsays #xzthe #xzresults #xzare #xzundefined, #xzmeaning
#xz the #xzcompiler #xzcan #xzdo #xzanything #xzwith #xzit #xzthat #xzsuits #xzthe #xzcompiler #xzwriter. #xzOne
#xz of #xzmy #xzcompilers #xzgives #xzthe #xzvalue #xz4 #xzto #xzn.
14. If #xzwe #xzexecute #xzthe #xzcode #xzfragment #xzin #xzan #xzotherwise #xzcomplete, #xzcorrect #xzprogram:
n # x z = # x z 1;
cout # x z << # x z n++ # x z << # x z " # x z " # x z << # x z n++ # x z << # x z " # x z "
# x z << # x z n++ # x z << # x z endl;
the #xzoutput #xzis #xzguaranteed #xzto #xzbe #xz1 # x z 2
# x z 3. #xzAnswer: #xzFalse.
Explanation: #xzThe #xzcode #xzis #xzillegal #xzbecause #xzits #xzexecution #xzdepends #xzon #xzthe #xzorder #xzof
#xz evaluation #xzof #xzarguments. # x z Various #xzcompilers #xzgive #xzdifferent #xzanswers. #xzOne
#xz compiler #xzthis #xzwriter #xzuses #xzgives #xz3 #xz2 #xz1.
15. C++ #xzuses #xzonly #xz/* # x z */ #xzfor
#xz comments. #xzAnswer: #xzFalse.
Explanation: #xzC++ #xzuses #xz/* # x z */ #xzcomments #xzand # x z // #xz“here #xzto #xzthe #xzend #xzof #xzthe
#xzline”
comments.
16. A #xzprogram’s #xzcomments #xzshould #xzconnect #xzthe #xzprogram #xzcode #xzto #xzthe #xzproblem #xzbeing
solved.
#xz Answer:
True.
#xz
Explanation: #xzThe #xzpurpose #xzof #xzcomments #xzin #xza #xzprogram #xzis #xzto #xzhelp #xzthe #xzhuman
#xz reader #xzof #xzthe #xzcode #xzto #xzconnect #xzthe #xzprogram #xzto #xzthe #xzproblem #xzbeing #xzsolved.
#xz Comments #xzare #xzso #xzimportant #xzthere #xzis #xzan #xzaphorism, #xzoften #xzquoted #xzby #xzexpert
#xz programmers: #xz“If #xzthe #xzcomments #xzand #xzthe #xzcode #xzdisagree, #xzthen #xzboth #xzare
#xz probably #xzwrong.
17. A #xzprogram #xzshould #xzhave #xza #xzcomment #xzon
#xz every #xzline. #xzAnswer: #xzFalse.
©2016 # x z Pearson # x z Education, #xz Inc. # x z Upper # x z Saddle # xz River, # x z NJ. # x z All
# x z Rights # x z Reserved.