Sunteți pe pagina 1din 9

C How to Program, 7/e Multiple Choice Test Bank

1 of 9

2.1 Introduction
(Noquestions.)

2.2 A Simple Program: Printing a Line of Text


2.1WhichofthefollowingmusteveryCprogramhave?
(a)main
(b)#include
(c)/*
(d)<stdio.h>
ANS:(a)
2.2EverystatementinCmustendwitha
(a)period(.)
(b)semicolon(;)
(c)colon(:)
(d)backslash(/)
ANS:(b)
2.3Whichofthefollowingisnotavalidescapesequence?
(a)\n
(b)\\
(c)\~
(d)\
ANS:(c)
2.4Whichstatementaboutcommentsisfalse?
a)Commentsbeginandendwith/*and*/,respectively.
b)Programmersinsertcommentstodocumentprogramsandimproveprogram
readability.
c)Commentsdonotcauseanymachinelanguageobjectcodetobegenerated.
d)Lengthycommentscancausepoorexecutiontimeperformance.
ANS:(d)
2.5Linesbeginningwitha#areprocessed
a)atexecutiontime.
b)atcompiletime.
c)atpreprocessortime.
d)atpostprocessortime.
ANS:(c)
ScholarStock

C How to Program, 7/e Multiple Choice Test Bank


2 of 9

2.6Whichofthefollowingstatementsabouttheinclusionof<stdio.h>isfalse?
a)Itisrequired.
b)Thisheaderfilecontainsinformationanddeclarationsusedbythecompilerwhen
compilingstandardinput/outputlibraryfunctionssuchasprintf.
c)Thisheaderfilecontainsinformationthathelpsthecompilerdetermineifcallsto
libraryfunctionshavebeenmadecorrectly.
d)Thisheaderhelpslocatebugsinyourprogramatcompiletime,ratherthanat
executiontime(whenerrorsareusuallymorecostlytocorrect).
ANS:(a)
2.7Intheline
int main()
theparenthesesindicatethatmainisaprogrambuildingblockcalleda
a)module
b)statement
c)directive
d)function
ANS:(d)
2.8Thepairofbracesthatdelineatethebodyofmainandtheportionoftheprogram
betweenthesebracesiscalleda__________.
a)function
b)block
c)statement
d)header
ANS:(b)
2.9WhichofthefollowingisnotasynonymforaCstring?
a)message
b)characterstring
c)character
d)literal
ANS:(c)
2.10Thefollowinglineismostproperlyanexampleofa__________.
puts( "Welcome to C!" );
a)function
b)block
ScholarStock

C How to Program, 7/e Multiple Choice Test Bank


3 of 9

c)statement
d)header
ANS:(c)
2.11Inaprintf,abackslashisprintedbyenclosinginquotes
a)\
b)\\
c)/\
d)//
ANS:(b)
2.12Alinkedprogramisoftencalleda(n)__________.
a)chain
b)library
c)object
d)executable
ANS:(d)
2.13Theescapesequenceforhorizontaltabis__________.
a)\tab
b)\t
c)\horizontaltab
d)\T
ANS:(b)

2.3 Another Simple Program: Adding Two Integers


2.14Whichofthefollowingisnotavalidintegervalue?
(a)-3
(b)0
(c)2134859
(d)1.1
ANS:(d)
2.15Whichofthefollowingisaninvalididentifier(variablename)?
(a)_Test
(b)TEST
(c)5test
(d)test1
ScholarStock

C How to Program, 7/e Multiple Choice Test Bank


4 of 9

ANS:(c)
2.16Whichstatementprintshionthescreen?
(a)puts("hi");
(b)put "hi";
(c)puts "hi";
(d)noneoftheabove
ANS:(a)
2.17The__________signisalsoknownasthe__________operator.
(a)+,assignment
(b)=,assignment
(c)*,streammanipulator
(d)&,streaminsertion
ANS:(b)
2.18A(n)__________isalocationinthecomputer'smemorywhereavaluecanbe
storedforusebyaprogram.
a)unknown
b)name
c)variable
d)declaration
ANS:(c)
2.19Whichstatementisfalse.
a)Variablesmaybedefinedanywhereinthebodyofmain.
b)Allvariablesmustbedefinedbeforetheyareused.
c)Allvariabledefinitionsmustincludethenameanddatatypeofeachvariable.
d)Severalvariablesofthesamedatatypemaybedefinedinonedefinition.
ANS:(a)
2.20Whichoftheseisnotavalididentifier?
a)a_valid_identifier
b)a1_valid_identifier
c)a_valid_identifier_
d)1_valid_identifier
ANS:(d)
2.21Whichofthefollowingstatementsisfalse?
a)Ciscasesensitive.
b)UppercaseandlowercaselettersaredifferentinC.
c)identifierandIdEnTiFiErareidenticalidentifiersinC.
d)Identifierscanbeofanylength
ScholarStock

C How to Program, 7/e Multiple Choice Test Bank


5 of 9

ANS:(c)
2.22Whichofthefollowingmultiplewordvariablenamesdoesnotconformtothegood
programmingpracticesinthetext?
a)multiple_word_variable_name
b)multipleWordVariableName
c)multiplewordvariablename
d)aReallyReallyLongMultipleWordVa
ANS:(c)
2.23Theaddressoperatoris
a)&&
b)%
c)@
d)&
ANS:(d)
2.24Whichstatementisfalse?
a)inthestatement
sum = integer1 + integer2;
both=and+arebinaryoperators.
b)Thestatementinparta)isanexampleofanassignmentstatement.
c)Thespacesaroundeachofthebinaryoperatorsinthestatementofparta)arerequired.
d)Inparta),the=operatorstwooperandsaresumandthevalueoftheexpression
integer1 + integer2.
ANS:(c)
2.25Whichofthefollowingisfalse?
a)Eachvariablebeinginputinascanfstatementisgenerallyprecededbyan&.
b)Eachvariablebeingoutputinaprintfstatementisgenerallynotprecededbyan&.
c)Inaprintfstatement,thecommathatseparatestheformatcontrolstringfromthe
expressionstobeprintedisplacedinsidetheformatcontrolstring.
d)Calculationscanbeperformedinsideprintfstatements.
ANS:(c)

2.4 Memory Concepts


2.26Variablenamesactuallycorrespondto__________.
(a)locationsinthecomputer'smemory
ScholarStock

C How to Program, 7/e Multiple Choice Test Bank


6 of 9

(b)operators
(c)integers
(d)datatypes
ANS:(a)
2.27Whenanumbergetsassignedtoavariablethatalreadyhasavalue__________.
(a)thenewnumberoverwritesthepreviousvalueatthatmemorylocation
(b)thenewnumbergetsassignedtoaneighboringmemorylocation
(c)thecomputerissuesanerror
(d)thenewvalueisdestroyedandtheoldvalueremains
ANS:(a)
2.28Everyvariablehasalltheattributesbelow,except
a)name
b)value
c)alias
d)type
ANS:(c)
2.29Whichofthefollowingisfalse?
a)Readingavalueintoamemorylocationdestroysthepreviousvalue.
b)Readingavalueoutofamemorylocationdestroysthatvalue.
c)sum = integer1 + integer2;involvesdestructivereadin.
d)Thestatementinpartc)alsoinvolvesnondestructivereadout.
ANS:(b)

2.5 Arithmetic in C
2.30Whichoperationwillfindtheremainderwhen15isdividedby6?
(a)15 / 6
(b)15 % 6
(c)15 ^ 6
(d)15 * 6
ANS:(b)
2.31Evaluatetheexpression
3 * 4 % 6 + 4 * 5
(a)20
(b)26
(c)12
ScholarStock

C How to Program, 7/e Multiple Choice Test Bank


7 of 9

(d)32
ANS:(a)
2.32Whichstatementisfalse?
a)Inalgebra,wewriteabtomultiplyatimesb.
b)InC,wewriteabtomultiplyatimesb.
c)InC,theremainderoperatoris%.
d)InC,integerdivisionyieldsanintegerresult.
ANS:(b)
2.33WhichstatementaboutCarithmeticisfalse?
a)6/3yields2
b)5/2yields2.5
c)7%3yields1
d)6%3yields0
ANS:(b)
2.34a * ( b + c )mayalsobewritteninCas
a)ab + ac
b) (a * b ) + c
c)a * b + c
d)a * b + a * c
ANS:(d)
2.35Whichstatementaboutprecedenceisfalse?
a)Parenthesesmaybeusedtoforcetheorderofevaluationtooccurinanysequence
desiredbytheprogrammer.
b)Nested,orembeddedparenthesesareevaluatedlast.
c)Multiplicationhasahigherprecedencethanaddition.
d)Subtractionhasalowerprecedencethandivision.
ANS:(b)
2.36Whichexpressionistrue?
a)Theexpressiona * (b + c) + c * (d + e)containsnestedparentheses.
b)Theexpressiony = a * x * x + b * x + cdoesexponentiationwithoutan
exponentiationoperator.
c)TheCstandardlibraryprovidesfunctionpowertoperformexponentiation.
d)Whenwesayevaluationofanexpressionproceedsfromlefttorightwearereferring
totheadditivityoftheoperators.
ANS:(b)

ScholarStock

C How to Program, 7/e Multiple Choice Test Bank


8 of 9

2.6 Decision Making: Equality and Relational Operators

2.37C'sifstatementexecutesthestatementinsideitsbodyifaspecified__________is
__________.
(a)condition,true
(b)condition,false
(c)equalityoperator,true
(d)relationaloperator,true
ANS:(a)
2.38Whichofthefollowingisanequalityoperator?
(a)==
(b)=
(c)>
(d)>=
ANS:(a)
2.39Whichstatementisfalse?
a)ExecutableCstatementseitherperformactionsormakedecisions.
b)Iftheconditioninanifstatementismet,thestatementinthebodyoftheifstatement
isexecuted.
c)Alltherelationaloperatorshavethesamelevelofprecedence.
d)Theequalityoperatorshaveahigherlevelofprecedencethantherelationaloperators.
ANS:(d)
2.40Whichstatementisfalse?
a)Whitespacecharacterssuchastabs,newlinesandspacesaregenerallyignoredbythe
Ccompiler.
b)Thestatementsinanifstatementmustbeindented.
c)Placingablanklinebeforeandaftereverycontrolstructurecanimproveprogram
readability.
d)Therecanbe(butshouldnotbe)morethanonestatementperline.
ANS:(b)
2.41Whichstatementisfalse?
a)Itisnotcorrecttosplitanidentifierwithaspace,ataboranewline.
b)Statementsandcommentsmaybesplitoverseverallines.
c)Theequalssign(=)isnotanoperator.
d)Agoodprogrammingpracticeistobreakalineafteracommainalengthycomma
separatedlist.
ANS:(c)

ScholarStock

C How to Program, 7/e Multiple Choice Test Bank


9 of 9

2.42Whichofthefollowingisnotakeyword?
a)int
b)return
c)if
d)main
ANS:(d)
2.43Whichstatementisfalse?
a)Theassignmentoperatorassociatesfromlefttoright.
b)Thearithmeticoperatorsassociatefromlefttoright.
c)Theequalityoperatorsassociatefromlefttoright.
d)Therelationaloperatorsassociatefromlefttoright.
ANS:(a)
2.44Theorderinwhichstatementsare__________iscalledflowofcontrol.
a)enteredinasourcefile
b)preprocessed
c)compiled
d)executed
ANS:(d)

2.7 Secure C Programming


2.45WhichofthefollowingstatementsistrueinsecureCprogramming?
(a)Youshouldavoidusingprintftodisplayasinglestringargument.
(b)Youshouldalwaysuseprintftodisplayasinglestringargument.
(c)Youshouldalwaysuseputstodisplayasinglestringargument.
(d)Noneoftheabove.
ANS:(a)
2.46WhichofthefollowingstatementsshouldbeusedinsecureCprogrammingto
displaythestring"Welcome"notfollowedbyanewlinecharacter?
(a) printf( "Welcome" );
(b)puts( "Welcome" );
(c)printf( "%s", "Welcome" );
(d)Noneoftheabove.
ANS:(c)

ScholarStock

S-ar putea să vă placă și