0% found this document useful (0 votes)
234 views10 pages

Top 100 C Interview Questions & Answers

This document contains summaries of 25 questions and answers related to C programming. Some key topics covered include: increment and decrement operators, call by value vs call by reference, using comments for debugging, while loops, stacks, sequential access files, variable initialization, nested loops, relational operators, declaring string variables, header files, syntax errors, arrays, and data types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
234 views10 pages

Top 100 C Interview Questions & Answers

This document contains summaries of 25 questions and answers related to C programming. Some key topics covered include: increment and decrement operators, call by value vs call by reference, using comments for debugging, while loops, stacks, sequential access files, variable initialization, nested loops, relational operators, declaring string variables, header files, syntax errors, arrays, and data types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Top100CInterviewQuestions&Answers

1)HowdoyouconstructanincrementstatementordecrementstatementinC?

Thereareactuallytwowaysyoucandothis.Oneistousetheincrementoperator++anddecrementoperator.For
example,thestatementx++meanstoincrementthevalueofxby1.Likewise,thestatementxmeanstodecrement
thevalueofxby1.Anotherwayofwritingincrementstatementsistousetheconventional+plussignorminussign.In
thecaseofx++,anotherwaytowriteitisx=x+1.

2)WhatisthedifferencebetweenCallbyValueandCallbyReference?
WhenusingCallbyValue,youaresendingthevalueofavariableasparametertoafunction,whereasCallbyReference
sendstheaddressofthevariable.Also,underCallbyValue,thevalueintheparameterisnotaffectedbywhatever
operationthattakesplace,whileinthecaseofCallbyReference,valuescanbeaffectedbytheprocesswithinthe
function.
3)Somecodersdebugtheirprogramsbyplacingcommentsymbolsonsomecodesinsteadofdeletingit.How
doesthisaidindebugging?

Placingcommentsymbols/**/aroundacode,alsoreferredtoascommentingout,isawayofisolatingsomecodes
thatyouthinkmaybecausingerrorsintheprogram,withoutdeletingthecode.Theideaisthatifthecodeisinfact
correct,yousimplyremovethecommentsymbolsandcontinueon.Italsosavesyoutimeandeffortonhavingtoretype
thecodesifyouhavedeleteditinthefirstplace.

4)WhatistheequivalentcodeofthefollowingstatementinWHILELOOPformat?
1 for(a=1a&lt=100a++)
2
3 printf(&quot%d\n&quot,a*a)

Answer:
1 a=1
2
3 while(a&lt=100){
4
5 printf(&quot%d\n&quot,a*a)
6
7 a++
8
9 }

5)Whatisastack?

Astackisoneformofadatastructure.DataisstoredinstacksusingtheFILO(FirstInLastOut)approach.Atany
particularinstance,onlythetopofthestackisaccessible,whichmeansthatinordertoretrievedatathatisstoredinside
thestack,thoseontheupperpartshouldbeextractedfirst.StoringdatainastackisalsoreferredtoasaPUSH,while
dataretrievalisreferredtoasaPOP.

6)Whatisasequentialaccessfile?
Whenwritingprogramsthatwillstoreandretrievedatainafile,itispossibletodesignatethatfileintodifferentforms.A
sequentialaccessfileissuchthatdataaresavedinsequentialorder:onedataisplacedintothefileafteranother.To
accessaparticulardatawithinthesequentialaccessfile,datahastobereadonedataatatime,untiltherightoneis
reached.

7)Whatisvariableinitializationandwhyisitimportant?

Thisreferstotheprocesswhereinavariableisassignedaninitialvaluebeforeitisusedintheprogram.Without
initialization,avariablewouldhaveanunknownvalue,whichcanleadtounpredictableoutputswhenusedin
computationsorotheroperations.

8Whatisspaghettiprogramming?
Spaghettiprogrammingreferstocodesthattendtogettangledandoverlappedthroughouttheprogram.Thisunstructured
approachtocodingisusuallyattributedtolackofexperienceonthepartoftheprogrammer.Spaghettiprogramingmakes
aprogramcomplexandanalyzingthecodesdifficult,andsomustbeavoidedasmuchaspossible.

9)DifferentiateSourceCodesfromObjectCodes
Sourcecodesarecodesthatwerewrittenbytheprogrammer.ItismadeupofthecommandsandotherEnglishlike
keywordsthataresupposedtoinstructthecomputerwhattodo.However,computerswouldnotbeabletounderstand
sourcecodes.Therefore,sourcecodesarecompiledusingacompiler.Theresultingoutputsareobjectcodes,whichare
inaformatthatcanbeunderstoodbythecomputerprocessor.InCprogramming,sourcecodesaresavedwiththefile
extension.C,whileobjectcodesaresavedwiththefileextension.OBJ
10)InCprogramming,howdoyouinsertquotecharacters(and)intotheoutputscreen?

Thisisacommonproblemforbeginnersbecausequotesarenormallypartofaprintfstatement.Toinsertthequote
characteraspartoftheoutput,usetheformatspecifiers\(forsinglequote),and\(fordoublequote).
11)Whatistheuseofa\0character?
Itisreferredtoasaterminatingnullcharacter,andisusedprimarilytoshowtheendofastringvalue.

12)Whatisthedifferencebetweenthe=symboland==symbol?
The=symbolisoftenusedinmathematicaloperations.Itisusedtoassignavaluetoagivenvariable.Ontheotherhand,
the==symbol,alsoknownasequaltoorequivalentto,isarelationaloperatorthatisusedtocomparetwovalues.
13)Whatisthemodulusoperator?
Themodulusoperatoroutputstheremainderofadivision.Itmakesuseofthepercentage(%)symbol.Forexample:10%
3=1,meaningwhenyoudivide10by3,theremainderis1.

14)Whatisanestedloop?

Anestedloopisaloopthatrunswithinanotherloop.Putitinanothersense,youhaveaninnerloopthatisinsideanouter
loop.Inthisscenario,theinnerloopisperformedanumberoftimesasspecifiedbytheouterloop.Foreachturnonthe
outerloop,theinnerloopisfirstperformed.
15)Whichofthefollowingoperatorsisincorrectandwhy?(>=,<=,<>,==)

<>isincorrect.Whilethisoperatoriscorrectlyinterpretedasnotequaltoinwritingconditionalstatements,itisnotthe
properoperatortobeusedinCprogramming.Instead,theoperator!=mustbeusedtoindicatenotequaltocondition.
16)Compareandcontrastcompilersfrominterpreters.

Compilersandinterpretersoftendealwithhowprogramcodesareexecuted.Interpretersexecuteprogramcodesone
lineatatime,whilecompilerstaketheprogramasawholeandconvertitintoobjectcode,beforeexecutingit.Thekey
differencehereisthatinthecaseofinterpreters,aprogrammayencountersyntaxerrorsinthemiddleofexecution,and
willstopfromthere.Ontheotherhand,compilerscheckthesyntaxoftheentireprogramandwillonlyproceedto
executionwhennosyntaxerrorsarefound.
17)Howdoyoudeclareavariablethatwillholdstringvalues?
Thecharkeywordcanonlyhold1charactervalueatatime.Bycreatinganarrayofcharacters,youcanstorestring
valuesinit.Example:charMyName[50]declaresastringvariablenamedMyNamethatcanholdamaximumof50
characters.
18)Canthecurlybrackets{}beusedtoencloseasinglelineofcode?
Whilecurlybracketsaremainlyusedtogroupseverallinesofcodes,itwillstillworkwithouterrorifyouuseditfora
singleline.Someprogrammerspreferthismethodasawayoforganizingcodestomakeitlookclearer,especiallyin
conditionalstatements.

19)WhatareheaderfilesandwhatareitsusesinCprogramming?
Headerfilesarealsoknownaslibraryfiles.Theycontaintwoessentialthings:thedefinitionsandprototypesoffunctions
beingusedinaprogram.Simplyput,commandsthatyouuseinCprogrammingareactuallyfunctionsthataredefined
fromwithineachheaderfiles.Eachheaderfilecontainsasetoffunctions.Forexample:stdio.hisaheaderfilethat
containsdefinitionandprototypesofcommandslikeprintfandscanf.

20)Whatissyntaxerror?
Syntaxerrorsareassociatedwithmistakesintheuseofaprogramminglanguage.Itmaybeacommandthatwas
misspelledoracommandthatmustwasenteredinlowercasemodebutwasinsteadenteredwithanuppercase
character.Amisplacedsymbol,orlackofsymbol,somewherewithinalineofcodecanalsoleadtosyntaxerror.

21)Whatarevariablesanditwhatwayisitdifferentfromconstants?
Variablesandconstantsmayatfirstlooksimilarinasensethatbothareidentifiersmadeupofonecharacterormore
characters(letters,numbersandafewallowablesymbols).Bothwillalsoholdaparticularvalue.Valuesheldbya
variablecanbealteredthroughouttheprogram,andcanbeusedinmostoperationsandcomputations.Constantsare
givenvaluesatonetimeonly,placedatthebeginningofaprogram.Thisvalueisnotalteredintheprogram.Forexample,
youcanassignedaconstantnamedPIandgiveitavalue3.1415.YoucanthenuseitasPIintheprogram,insteadof
havingtowrite3.1415eachtimeyouneedit.
22)Howdoyouaccessthevalueswithinanarray?

Arrayscontainanumberofelements,dependingonthesizeyougaveitduringvariabledeclaration.Eachelementis
assignedanumberfrom0tonumberofelements1.Toassignorretrievethevalueofaparticularelement,refertothe
elementnumber.Forexample:ifyouhaveadeclarationthatsaysintscores[5],thenyouhave5accessibleelements,
namely:scores[0],scores[1],scores[2],scores[3]andscores[4].
23)CanIuseintdatatypetostorethevalue32768?Why?
No.intdatatypeiscapableofstoringvaluesfrom32768to32767.Tostore32768,youcanuselongintinstead.You
canalsouseunsignedint,assumingyoudontintendtostorenegativevalues.
24)Cantwoormoreoperatorssuchas\nand\tbecombinedinasinglelineofprogramcode?

Yes,itsperfectlyvalidtocombineoperators,especiallyiftheneedarises.Forexample:youcanhaveacodelikeprintf
(Hello\n\n\World\')tooutputthetextHelloonthefirstlineandWorldenclosedinsinglequotestoappearonthenext
twolines.
25)WhyisitthatnotallheaderfilesaredeclaredineveryCprogram?
ThechoiceofdeclaringaheaderfileatthetopofeachCprogramwoulddependonwhatcommands/functionsyouwillbe
usinginthatprogram.Sinceeachheaderfilecontainsdifferentfunctiondefinitionsandprototype,youwouldbeusingonly
thoseheaderfilesthatwouldcontainthefunctionsyouwillneed.Declaringallheaderfilesineveryprogramwouldonly
increasetheoverallfilesizeandloadoftheprogram,andisnotconsideredagoodprogrammingstyle.

26)Whenisthevoidkeywordusedinafunction?
Whendeclaringfunctions,youwilldecidewhetherthatfunctionwouldbereturningavalueornot.Ifthatfunctionwillnot
returnavalue,suchaswhenthepurposeofafunctionistodisplaysomeoutputsonthescreen,thenvoidistobe
placedattheleftmostpartofthefunctionheader.Whenareturnvalueisexpectedafterthefunctionexecution,thedata
typeofthereturnvalueisplacedinsteadofvoid.

27)Whatarecompoundstatements?
Compoundstatementsaremadeupoftwoormoreprogramstatementsthatareexecutedtogether.Thisusuallyoccurs
whilehandlingconditionswhereinaseriesofstatementsareexecutedwhenaTRUEorFALSEisevaluated.Compound
statementscanalsobeexecutedwithinaloop.Curlybrackets{}areplacedbeforeandaftercompoundstatements.

28)WhatisthesignificanceofanalgorithmtoCprogramming?

Beforeaprogramcanbewritten,analgorithmhastobecreatedfirst.Analgorithmprovidesastepbystepprocedureon
howasolutioncanbederived.Italsoactsasablueprintonhowaprogramwillstartandend,includingwhatprocessand
computationsareinvolved.
29)Whatistheadvantageofanarrayoverindividualvariables?
Whenstoringmultiplerelateddata,itisagoodideatousearrays.Thisisbecausearraysarenamedusingonly1word
followedbyanelementnumber.Forexample:tostorethe10testresultsof1student,onecanuse10differentvariable
names(grade1,grade2,grade3grade10).Witharrays,only1nameisused,therestareaccessiblethroughtheindex
name(grade[0],grade[1],grade[2]grade[9]).
30)Writealoopstatementthatwillshowthefollowingoutput:

12

123

1234

12345

Answer:
1 for(a=1a&lt=5i++){
2
3 for(b=1b&lt=ab++)
4
5 printf(&quot%d&quot,b)
6
7 printf(&quot\n&quot)
8
9 }

31)Whatiswronginthisstatement?scanf(%d,whatnumber)

Anampersand&symbolmustbeplacedbeforethevariablenamewhatnumber.Placing&meanswhateverintegervalue
isenteredbytheuserisstoredattheaddressofthevariablename.Thisisacommonmistakeforprogrammers,often
leadingtologicalerrors.
32)HowdoyougeneraterandomnumbersinC?
RandomnumbersaregeneratedinCusingtherand()command.Forexample:anyNum=rand()willgenerateanyinteger
numberbeginningfrom0,assumingthatanyNumisavariableoftypeinteger.

33)Whatcouldpossiblybetheproblemifavalidfunctionnamesuchastolower()isbeingreportedbytheC
compilerasundefined?

Themostprobablereasonbehindthiserroristhattheheaderfileforthatfunctionwasnotindicatedatthetopofthe
program.HeaderfilescontainthedefinitionandprototypeforfunctionsandcommandsusedinaCprogram.Inthecase
oftolower(),thecode#include<ctype.h>mustbepresentatthebeginningoftheprogram.
34)WhatarecommentsandhowdoyouinsertitinaCprogram?
Commentsareagreatwaytoputsomeremarksordescriptioninaprogram.Itcanservesasareminderonwhatthe
programisallabout,oradescriptiononwhyacertaincodeorfunctionwasplacedthereinthefirstplace.Comments
beginwith/*andendedby*/characters.Commentscanbeasingleline,orcanevenspanseverallines.Itcanbeplaced
anywhereintheprogram.

35)Whatisdebugging?

Debuggingistheprocessofidentifyingerrorswithinaprogram.Duringprogramcompilation,errorsthatarefoundwill
stoptheprogramfromexecutingcompletely.Atthisstate,theprogrammerwouldlookintothepossibleportionswherethe
erroroccurred.Debuggingensurestheremovaloferrors,andplaysanimportantroleinensuringthattheexpected
programoutputismet.

36)Whatdoesthe&&operatordoinaprogramcode?
The&&isalsoreferredtoasANDoperator.Whenusingthisoperator,allconditionsspecifiedmustbeTRUEbeforethe
nextactioncanbeperformed.Ifyouhave10conditionsandallbut1failstoevaluateasTRUE,theentirecondition
statementisalreadyevaluatedasFALSE.

37)InCprogramming,whatcommandorcodecanbeusedtodetermineifanumberofoddoreven?
ThereisnosinglecommandorfunctioninCthatcancheckifanumberisoddoreven.However,thiscanbe
accomplishedbydividingthatnumberby2,thencheckingtheremainder.Iftheremainderis0,thenthatnumberiseven,
otherwise,itisodd.Youcanwriteitincodeas:
1 if(num%2==0)
2
3 printf(&quotEVEN&quot)
4
5 else
6
7 printf(&quotODD&quot)

38)Whatdoestheformat%10.2meanwhenincludedinaprintfstatement?
Thisformatisusedfortwothings:tosetthenumberofspacesallottedfortheoutputnumberandtosetthenumberof
decimalplaces.Thenumberbeforethedecimalpointisfortheallottedspace,inthiscaseitwouldallot10spacesforthe
outputnumber.Ifthenumberofspaceoccupiedbytheoutputnumberislessthan10,additionspacecharacterswillbe
insertedbeforetheactualoutputnumber.Thenumberafterthedecimalpointsetsthenumberofdecimalplaces,inthis
case,its2decimalspaces.

39)Whatarelogicalerrorsandhowdoesitdifferfromsyntaxerrors?

Programthatcontainslogicalerrorstendtopassthecompilationprocess,buttheresultingoutputmaynotbethe
expectedone.Thishappenswhenawrongformulawasinsertedintothecode,orawrongsequenceofcommandswas
performed.Syntaxerrors,ontheotherhand,dealwithincorrectcommandsthataremisspelledornotrecognizedbythe
compiler.
40)Whatarethedifferenttypesofcontrolstructuresinprogramming?
Thereare3maincontrolstructuresinprogramming:Sequence,SelectionandRepetition.Sequentialcontrolfollowsatop
tobottomflowinexecutingaprogram,suchthatstep1isfirstperform,followedbystep2,allthewayuntilthelaststepis
performed.Selectiondealswithconditionalstatements,whichmeancodesareexecuteddependingontheevaluationof
conditionsasbeingTRUEorFALSE.Thisalsomeansthatnotallcodesmaybeexecuted,andtherearealternative
flowswithin.Repetitionsarealsoknownasloopstructures,andwillrepeatoneortwoprogramstatementssetbya
counter.
41)Whatis||operatorandhowdoesitfunctioninaprogram?

The||isalsoknownastheORoperatorinCprogramming.Whenusing||toevaluatelogicalconditions,anycondition
thatevaluatestoTRUEwillrendertheentireconditionstatementasTRUE.
42)Cantheiffunctionbeusedincomparingstrings?

No.ifcommandcanonlybeusedtocomparenumericalvaluesandsinglecharactervalues.Forcomparingstring
values,thereisanotherfunctioncalledstrcmpthatdealsspecificallywithstrings.
43)Whatarepreprocessordirectives?

PreprocessordirectivesareplacedatthebeginningofeveryCprogram.Thisiswherelibraryfilesarespecified,which
woulddependonwhatfunctionsaretobeusedintheprogram.Anotheruseofpreprocessordirectivesisthedeclaration
ofconstants.Preprocessordirectivesbeginwiththe#symbol.
44)Whatwillbetheoutcomeofthefollowingconditionalstatementifthevalueofvariablesis10?

s>=10&&s<25&&s!=12
TheoutcomewillbeTRUE.Sincethevalueofsis10,s>=10evaluatestoTRUEbecausesisnotgreaterthan10butis
stillequalto10.s<25isalsoTRUEsince10islessthen25.Justthesame,s!=12,whichmeanssisnotequalto12,
evaluatestoTRUE.The&&istheANDoperator,andfollowstherulethatifallindividualconditionsareTRUE,theentire
statementisTRUE.

45)DescribetheorderofprecedencewithregardstooperatorsinC.
Orderofprecedencedetermineswhichoperationmustfirsttakeplaceinanoperationstatementorconditionalstatement.
Onthetopmostlevelofprecedencearetheunaryoperators!,+,and&.Itisfollowedbytheregularmathematical
operators(*,/andmodulus%first,followedby+and).Nextinlinearetherelationaloperators<,<=,>=and>.Thisis
thenfollowedbythetwoequalityoperators==and!=.Thelogicaloperators&&and||arenextevaluated.Onthelast
levelistheassignmentoperator=.

46)Whatiswrongwiththisstatement?myName=Robin
Youcannotusethe=signtoassignvaluestoastringvariable.Instead,usethestrcpyfunction.Thecorrectstatement
wouldbe:strcpy(myName,Robin)
47)Howdoyoudeterminethelengthofastringvaluethatwasstoredinavariable?

Togetthelengthofastringvalue,usethefunctionstrlen().Forexample,ifyouhaveavariablenamedFullName,youcan
getthelengthofthestoredstringvaluebyusingthisstatement:I=strlen(FullName)thevariableIwillnowhavethe
characterlengthofthestringvalue.
48)Isitpossibletoinitializeavariableatthetimeitwasdeclared?

Yes,youdonthavetowriteaseparateassignmentstatementafterthevariabledeclaration,unlessyouplantochangeit
lateron.Forexample:charplanet[15]=Earthdoestwothings:itdeclaresastringvariablenamedplanet,then
initializesitwiththevalueEarth.
49)WhyisClanguagebeingconsideredamiddlelevellanguage?

ThisisbecauseClanguageisrichinfeaturesthatmakeitbehavelikeahighlevellanguagewhileatthesametimecan
interactwithhardwareusinglowlevelmethods.Theuseofawellstructuredapproachtoprogramming,coupledwith
Englishlikewordsusedinfunctions,makesitactasahighlevellanguage.Ontheotherhand,Ccandirectlyaccess
memorystructuressimilartoassemblylanguageroutines.
50)WhatarethedifferentfileextensionsinvolvedwhenprogramminginC?

SourcecodesinCaresavedwith.Cfileextension.Headerfilesorlibraryfileshavethe.Hfileextension.Everytimea
programsourcecodeissuccessfullycompiled,itcreatesan.OBJobjectfile,andanexecutable.EXEfile.

51)Whatarereservedwords?
ReservedwordsarewordsthatarepartofthestandardClanguagelibrary.Thismeansthatreservedwordshavespecial
meaningandthereforecannotbeusedforpurposesotherthanwhatitisoriginallyintendedfor.Examplesofreserved
wordsareint,void,andreturn.
52)Whatarelinkedlist?
Alinkedlistiscomposedofnodesthatareconnectedwithanother.InCprogramming,linkedlistsarecreatedusing
pointers.Usinglinkedlistsisoneefficientwayofutilizingmemoryforstorage.

53)WhatisFIFO?
InCprogramming,thereisadatastructureknownasqueue.Inthisstructure,dataisstoredandaccessedusingFIFO
format,orFirstInFirstOut.Aqueuerepresentsalinewhereinthefirstdatathatwasstoredwillbethefirstonethatis
accessibleaswell.
54)Whatarebinarytrees?
Binarytreesareactuallyanextensionoftheconceptoflinkedlists.Abinarytreehastwopointers,aleftoneandaright
one.Eachsidecanfurtherbranchtoformadditionalnodes,whicheachnodehavingtwopointersaswell.

55)Notallreservedwordsarewritteninlowercase.TRUEorFALSE?
FALSE.AllreservedwordsmustbewritteninlowercaseotherwisetheCcompilerwouldinterpretthisasunidentified
andinvalid.
56)Whatisthedifferencebetweentheexpression++aanda++?
Inthefirstexpression,theincrementwouldhappenfirstonvariablea,andtheresultingvaluewillbetheonetobeused.
Thisisalsoknownasaprefixincrement.Inthesecondexpression,thecurrentvalueofvariableawouldtheonetobe
usedinanoperation,beforethevalueofaitselfisincremented.Thisisalsoknownaspostfixincrement.

57)WhatwouldhappentoXinthisexpression:X+=15(assumingthevalueofXis5)
X+=15isashortmethodofwritingX=X+15,soiftheinitialvalueofXis5,then5+15=20.
58)InClanguage,thevariablesNAME,name,andNameareallthesame.TRUEorFALSE?
FALSE.Clanguageisacasesensitivelanguage.Therefore,NAME,nameandNamearethreeuniquelydifferent
variables.
59)Whatisanendlessloop?
Anendlessloopcanmeantwothings.Oneisthatitwasdesignedtoloopcontinuouslyuntiltheconditionwithintheloop
ismet,afterwhichabreakfunctionwouldcausetheprogramtostepoutoftheloop.Anotherideaofanendlessloopis
whenanincorrectloopconditionwaswritten,causingthelooptorunerroneouslyforever.Endlessloopsareoftentimes
referredtoasinfiniteloops.
60)Whatisaprogramflowchartandhowdoesithelpinwritingaprogram?
Aflowchartprovidesavisualrepresentationofthestepbystepproceduretowardssolvingagivenproblem.Flowcharts
aremadeofsymbols,witheachsymbolintheformofdifferentshapes.Eachshapemayrepresentaparticularentity
withintheentireprogramstructure,suchasaprocess,acondition,orevenaninput/outputphase.

61)Whatiswrongwiththisprogramstatement?void=10
ThewordvoidisareservedwordinClanguage.Youcannotusereservedwordsasauserdefinedvariable.

62)Isthisprogramstatementvalid?INT=10.50
AssumingthatINTisavariableoftypefloat,thisstatementisvalid.OnemaythinkthatINTisareservedwordandmust
notbeusedforotherpurposes.However,recallthatreservedwordsareexpressinlowercase,sotheCcompilerwillnot
interpretthisasareservedword.
63)Whatareactualarguments?
Whenyoucreateandusefunctionsthatneedtoperformanactiononsomegivenvalues,youneedtopassthesegiven
valuestothatfunction.Thevaluesthatarebeingpassedintothecalledfunctionarereferredtoasactualarguments.

64)Whatisanewlineescapesequence?
Anewlineescapesequenceisrepresentedbythe\ncharacter.Thisisusedtoinsertanewlinewhendisplayingdatain
theoutputscreen.Morespacescanbeaddedbyinsertingmore\ncharacters.Forexample,\n\nwouldinserttwo
spaces.Anewlineescapesequencecanbeplacedbeforetheactualoutputexpressionorafter.
65)Whatisoutputredirection?
Itistheprocessoftransferringdatatoanalternativeoutputsourceotherthanthedisplayscreen.Outputredirection
allowsaprogramtohaveitsoutputsavedtoafile.Forexample,ifyouhaveaprogramnamedCOMPUTE,typingthison
thecommandlineasCOMPUTE>DATAcanacceptinputfromtheuser,performcertaincomputations,thenhavethe
outputredirectedtoafilenamedDATA,insteadofshowingitonthescreen.

66)Whatareruntimeerrors?
Theseareerrorsthatoccurwhiletheprogramisbeingexecuted.Onecommoninstancewhereinruntimeerrorscan
happeniswhenyouaretryingtodivideanumberbyzero.Whenruntimeerrorsoccur,programexecutionwillpause,
showingwhichprogramlinecausedtheerror.
67)Whatisthedifferencebetweenfunctionsabs()andfabs()?
These2functionsbasicallyperformthesameaction,whichistogettheabsolutevalueofthegivenvalue.Abs()isused
forintegervalues,whilefabs()isusedforfloatingtypenumbers.Also,theprototypeforabs()isunder<stdlib.h>,while
fabs()isunder<math.h>.
68)Whatareformalparameters?
InusingfunctionsinaCprogram,formalparameterscontainthevaluesthatwerepassedbythecallingfunction.The
valuesaresubstitutedintheseformalparametersandusedinwhateveroperationsasindicatedwithinthemainbodyof
thecalledfunction.
69)Whatarecontrolstructures?
Controlstructurestakechargeatwhichinstructionsaretobeperformedinaprogram.Thismeansthatprogramflowmay
notnecessarilymovefromonestatementtothenextone,butrathersomealternativeportionsmayneedtobepassinto
orbypassedfrom,dependingontheoutcomeoftheconditionalstatements.

70)Writeasimplecodefragmentthatwillcheckifanumberispositiveornegative.
1 If(num&gt=0)
2
3 printf(&quotnumberispositive&quot)
4
5 else
6
7 printf(&quotnumberisnegative&quot)

71)Whenisaswitchstatementpreferableoveranifstatement?
Theswitchstatementisbestusedwhendealingwithselectionsbasedonasinglevariableorexpression.However,
switchstatementscanonlyevaluateintegerandcharacterdatatypes.
72)Whatareglobalvariablesandhowdoyoudeclarethem?

Globalvariablesarevariablesthatcanbeaccessedandmanipulatedanywhereintheprogram.Tomakeavariable
global,placethevariabledeclarationontheupperportionoftheprogram,justafterthepreprocessordirectivessection.
73)Whatareenumeratedtypes?
Enumeratedtypesallowtheprogrammertousemoremeaningfulwordsasvaluestoavariable.Eachiteminthe
enumeratedtypevariableisactuallyassociatedwithanumericcode.Forexample,onecancreateanenumeratedtype
variablenamedDAYSwhosevaluesareMonday,TuesdaySunday.
74)Whatdoesthefunctiontoupper()do?

Itisusedtoconvertanylettertoitsuppercasemode.Toupper()functionprototypeisdeclaredin<ctype.h>.Notethat
thisfunctionwillonlyconvertasinglecharacter,andnotanentirestring.
75)Isitpossibletohaveafunctionasaparameterinanotherfunction?
Yes,thatisallowedinCprogramming.Youjustneedtoincludetheentirefunctionprototypeintotheparameterfieldofthe
otherfunctionwhereitistobeused.

76)Whataremultidimensionalarrays?
Multidimensionalarraysarecapableofstoringdatainatwoormoredimensionalstructure.Forexample,youcanusea2
dimensionalarraytostorethecurrentpositionofpiecesinachessgame,orpositionofplayersinatictactoeprogram.
77)WhichfunctioninCcanbeusedtoappendastringtoanotherstring?
Thestrcatfunction.Ittakestwoparameters,thesourcestringandthestringvaluetobeappendedtothesourcestring.

78)Whatisthedifferencebetweenfunctionsgetch()andgetche()?
Bothfunctionswillacceptacharacterinputvaluefromtheuser.Whenusinggetch(),thekeythatwaspressedwillnot
appearonthescreen,andisautomaticallycapturedandassignedtoavariable.Whenusinggetche(),thekeythatwas
pressedbytheuserwillappearonthescreen,whileatthesametimebeingassignedtoavariable.

79)Dothesetwoprogramstatementsperformthesameoutput?1)scanf(%c,&letter)2)letter=getchar()
Yes,theybothdotheexactsamething,whichistoacceptthenextkeypressedbytheuserandassignittovariable
namedletter.

80)WhatarestructuretypesinC?
Structuretypesareprimarilyusedtostorerecords.Arecordismadeupofrelatedfields.Thismakesiteasiertoorganize
agroupofrelateddata.
81)Whatdoesthecharactersrandwmeanwhenwritingprogramsthatwillmakeuseoffiles?
rmeansreadandwillopenafileasinputwhereindataistoberetrieved.wmeanswrite,andwillopenafilefor
output.Previousdatathatwasstoredonthatfilewillbeerased.
82)Whatisthedifferencebetweentextfilesandbinaryfiles?

Textfilescontaindatathatcaneasilybeunderstoodbyhumans.Itincludesletters,numbersandothercharacters.On
theotherhand,binaryfilescontain1sand0sthatonlycomputerscaninterpret.

83)isitpossibletocreateyourownheaderfiles?
Yes,itispossibletocreateacustomizedheaderfile.Justincludeinitthefunctionprototypesthatyouwanttouseinyour
program,andusethe#includedirectivefollowedbythenameofyourheaderfile.
84)Whatisdynamicdatastructure?
Dynamicdatastructureprovidesameansforstoringdatamoreefficientlyintomemory.Usingdynamicmemory
allocation,yourprogramwillaccessmemoryspacesasneeded.Thisisincontrasttostaticdatastructure,whereinthe
programmerhastoindicateafixnumberofmemoryspacetobeusedintheprogram.

85)WhatarethedifferentdatatypesinC?
Thebasicdatatypesareint,char,andfloat.Intisusedtodeclarevariablesthatwillbestoringintegervalues.Floatis
usedtostorerealnumbers.Charcanstoreindividualcharactervalues.
86)WhatisthegeneralformofaCprogram?
ACprogrambeginswiththepreprocessordirectives,inwhichtheprogrammerwouldspecifywhichheaderfileandwhat
constants(ifany)tobeused.Thisisfollowedbythemainfunctionheading.Withinthemainfunctionliesthevariable
declarationandprogramstatement.

87)Whatistheadvantageofarandomaccessfile?
Iftheamountofdatastoredinafileisfairlylarge,theuseofrandomaccesswillallowyoutosearchthroughitquicker.If
ithadbeenasequentialaccessfile,youwouldhavetogothroughonerecordatatimeuntilyoureachthetargetdata.A
randomaccessfileletsyoujumpdirectlytothetargetaddresswheredataislocated.
88)Inaswitchstatement,whatwillhappenifabreakstatementisomitted?
Ifabreakstatementwasnotplacedattheendofaparticularcaseportion?Itwillmoveontothenextcaseportion,
possiblycausingincorrectoutput.

89)Describehowarrayscanbepassedtoauserdefinedfunction
Onethingtonoteisthatyoucannotpasstheentirearraytoafunction.Instead,youpasstoitapointerthatwillpointto
thearrayfirstelementinmemory.Todothis,youindicatethenameofthearraywithoutthebrackets.
90)Whatarepointers?
Pointerspointtospecificareasinthememory.Pointerscontaintheaddressofavariable,whichinturnmaycontaina
valueorevenanaddresstoanothermemory.
91)Canyoupassanentirestructuretofunctions?

Yes,itispossibletopassanentirestructuretoafunctioninacallbymethodstyle.However,someprogrammersprefer
declaringthestructureglobally,thenpassavariableofthatstructuretypetoafunction.Thismethodhelpsmaintain
consistencyanduniformityintermsofargumenttype.
92)Whatisgets()function?
Thegets()functionallowsafulllinedataentryfromtheuser.Whentheuserpressestheenterkeytoendtheinput,the
entirelineofcharactersisstoredtoastringvariable.Notethattheenterkeyisnotincludedinthevariable,butinsteada
nullterminator\0isplacedafterthelastcharacter.

93)The%symbolhasaspecialuseinaprintfstatement.Howwouldyouplacethischaracteraspartofthe
outputonthescreen?

Youcandothisbyusing%%intheprintfstatement.Forexample,youcanwriteprintf(10%%)tohavetheoutputappear
as10%onthescreen.
94)Howdoyousearchdatainadatafileusingrandomaccessmethod?
Usethefseek()functiontoperformrandomaccessinput/ouputonafile.Afterthefilewasopenedbythefopen()function,
thefseekwouldrequirethreeparameterstowork:afilepointertothefile,thenumberofbytestosearch,andthepointof
origininthefile.
95)ArecommentsincludedduringthecompilationstageandplacedintheEXEfileaswell?

No,commentsthatwereencounteredbythecompileraredisregarded.Commentsaremostlyfortheguidanceofthe
programmeronlyanddonothaveanyothersignificantuseintheprogramfunctionality.
96)IsthereabuiltinfunctioninCthatcanbeusedforsortingdata?
Yes,usetheqsort()function.Itisalsopossibletocreateuserdefinedfunctionsforsorting,suchasthosebasedonthe
balloonsortandbubblesortalgorithm.
97)Whataretheadvantagesanddisadvantagesofaheap?
Storingdataontheheapisslowerthanitwouldtakewhenusingthestack.However,themainadvantageofusingthe
heapisitsflexibility.Thatsbecausememoryinthisstructurecanbeallocatedandremoveinanyparticularorder.
Slownessintheheapcanbecompensatedifanalgorithmwaswelldesignedandimplemented.
98)HowdoyouconvertstringstonumbersinC?
Youcanwriteyouownfunctionstodostringtonumberconversions,orinsteaduseCsbuiltinfunctions.Youcanuse
atoftoconverttoafloatingpointvalue,atoitoconverttoanintegervalue,andatoltoconverttoalongintegervalue.
99)Createasimplecodefragmentthatwillswapthevaluesoftwovariablesnum1andnum2.
1 inttemp
2
3 temp=num1
4
5 num1=num2
6
7 num2=temp

100)Whatistheuseofasemicolon()attheendofeveryprogramstatement?
Ithastodowiththeparsingprocessandcompilationofthecode.Asemicolonactsasadelimiter,sothatthecompiler
knowswhereeachstatementends,andcanproceedtodividethestatementintosmallerelementsforsyntaxchecking.

You might also like