C Programming Interview Questions and Answers - C in Depth PDF
C Programming Interview Questions and Answers - C in Depth PDF
Clanguageinterviewquestionssolutionforfreshersbeginnersplacementtrickygoodpointersanswersexplanationoperatorsdatatypesarraysstructuresfunctions
recursionpreprocessorsloopingfilehandlingstringsswitchcaseifelseprintfadvancelinuxobjectivemcqfaqonlinewrittentestprimenumbersArmstrongFibonacci
seriesfactorialpalindromecodeprogramsexamplesonc++tutorialsandpdf
Ctutorial
CProgrammingQuestions
CInterviewQuestions
CPrograms
CTest
Cprogrammingpdf
Programofc++
SqlServer
StartDownload
Search
ConvertAnyFiletoaPDF.GettheFreeFromDoctoPdfToolbar!
Adsby Google
DownloadPDF
FreePDFBooks
JavaPDF
StartDownload
ConvertAnyFiletoaPDF.GettheFreeFromDoctoPdfToolbar!
Adsby Google
PDFFiletoWord
eBookFreeDownload
VBNetPDF
Cindepthpdf
Page1of25
Adsby Google
8/26/2011
CQUESTIONSANDANSWERS
Cprogramexamples
Cinterviewquestionsandanswers
Datatypequestions
Variablenamingrulequestions
Operatorsquestions
Controlflowquestions
Switchcasequestions
CPROGRAMMINGQUESTIONSAND
ANSWER
PDFPDF
comPDF
UploadPDF
Loopingquestions
Pointerquestions
Stringquestions
Printf,Scanfquestions
Preprocessorquestions
Structurequestions
Commadlineargument
CquestionsinLinux
http://cquestionbank.blogspot.com|Riteshkumar
Conlinetest
Cmixedpracticesets
Ctrickyquestions
Exampleofrecursioninc
Cprogrammingforums
Page2of25
(1)Whatwillbeoutputifyouwillcompileandexecute
thefollowingccode?
#include<stdio.h>
structmarks{
intp:3
intc:3
intm:2
}
LABELS
Advancenc(14)
intmain(){
structmarkss={2,6,5}
printf("%d%d%d",s.p,s.c,s.m)
return0
Arrayinc(27)
Cprograms(48)
C++(21)
Datatypes(55)
Exact(6)
(a)265
FileHandling(30)
(b)261
Functiontutorialinc(78)
(c)221
Java(53)
(d)Compilererror
linuxquestions(4)
(e)Noneofthese
Loopinginc(6)
Answer:(c)
MemoryMapping(15)
Explanation:
Operators(19)
Binaryvalueof2:00000010(Selectthreetwobit)
pdf(11)
Binaryvalueof6:00000110
Pointers(31)
Binaryvalueof6:11111001+1=11111010
Pointersonc(147)
(Selectlastthreebit)
Preprocessor(24)
Binaryvalueof5:00000101(Selectlasttwobit)
SQL(6)
Completememoryrepresentation:
PAGEVIEWSLASTMONTH
5 4 5 1 9 6
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page2
CLOVERCOMMUNITY
Jointhissite
withGoogleFriendConnect
Members(3386) More
Page3of25
Alreadyamember?Signin
SUBSCRIBEVIAEMAIL
CTUTORIAL
Memorymappingtutorialinc
(2)Whatwillbeoutputifyouwillcompileandexecute
thefollowingccode?
Enteryouremailaddress:
Variablestutorialinc
Datatypestutorialinc
Storageclassestutorialinc
#include<stdio.h>
Subscribe
intmain(){
inthuge*p=(inthuge*)0XC0563331
Loopingtutorialinc
Pointerstutorialinc
inthuge*q=(inthuge*)0xC2551341
*p=200
printf("%d",*q)
Functiontutorialinc
DeliveredbyFeedBurner
return0
STANDARDOFQUESTIONS
?
Arraytutorialinc
}
Preprocessortutorialinc
Excellent
1011(45%)
Good
626(27%)
Avg
129(5%)
470(21%)
Advancedctutorial
(a)0
(b)Garbagevalue
Worst
POPULARPOSTS
(c)null
(d)200
Votessofar:2236
Pollclosed
Cprogramexamples|Interview
CompleteList
(e)Compilererror
Answer:(d)
Cinterviewquestionsandanswers
Checkgivennumberisprimenumber
ornotusingcprogram
Programtoconvertdecimaltobinaryin
c
TOFINDFACTORIALOFANUMBER
USINGCPROGRAM
Explanation:
Physicaladdressofhugepointerp
Hugeaddress:0XC0563331
Offsetaddress:0x3331
Segmentaddress:0XC056
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page3
Findouttheperfectnumberusingc
program
TOFINDFIBONACCISERIESUSING
CPROGRAM
Page4of25
MULTIPLICATIONOFTWOMATRICES
USINGCPROGRAM
Cquestionsandanswers
Physicaladdress=Segmentaddress*0X10+Offset
Primenumberprogramincusing
recursion
address
=0XC056*0X10+0X3331
CPROGRAMMINGQUESTIONSAND
ANSWER
Cquestionsandanswers
Cinterviewquestionsandanswers
Pointerstopointersincprogramming
language
Debuggingquestionsincwithanswers
Aptitudequestionsandanswersinc
Therewasanerrorinthisgadget
=0XC0560+0X3331
=0XC3891
Physicaladdressofhugepointerq
Hugeaddress:0XC2551341
Offsetaddress:0x1341
Segmentaddress:0XC255
Physicaladdress=Segmentaddress*0X10+Offset
address
=0XC255*0X10+0X1341
=0XC2550+0X1341
=0XC3891
Sincebothhugepointerspandqarepointingsame
physicaladdresssocontentofqwillalsosameas
contentofq.
contentofq.
148
(3)Writecprogramwhichdisplaymousepointerand
positionofpointer.(Inxcoordinate,ycoordinate)?
Answer:
#include<dos.h>
#include<stdio.h>
intmain(){
unionREGSi,o
intx,y,k
//showmousepointer
i.x.ax=1
int86(0x33,&i,&o)
while(!kbhit())//itsvaluewillfalsewhenwehit
keyinthekeyboard
{
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page4
Page5of25
i.x.ax=3//getmouseposition
x=o.x.cx
y=o.x.dx
printf("(%d,%d)",x,y)
delay(250)
int86(0x33,&i,&o)
}
return0
}
(4)Writeacprogramtocreatedoscommand:dir.
Answer:
Step1:Writefollowingcode.
Step1:Writefollowingcode.
#include<stdio.h>
#include<dos.h>
intmain(intcount,char*argv[]){
structfind_tq
inta
if(count==1)
argv[1]="*.*"
a=_dos_findfirst(argv[1],1,&q)
if(a==0){
while(!a){
printf("%s\n",q.name)
a=_dos_findnext(&q)
}
}
else{
printf("Filenotfound")
}
return0
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page5
Page6of25
}
Step2:Savetheaslist.c(Youcangiveanyname)
Step3:Compileandexecutethefile.
Step4:WriteclickonMycomputerofWindowXP
operatingsystemandselectproperties.
Step5:SelectAdvanced>EnvironmentVariables
Step6:Youwillfindfollowingwindow:
Clickonnewbutton(Buttoninsidetheredbox)
Step7:Writefollowing:
Variablename:path
Variablevalue:c:\tc\bin\list.c(Pathwhereyouhave
saved)
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page6
Page7of25
Step8:Opencommandpromptandwritelistandpress
enter.
(5)Whatwillbeoutputifyouwillcompileandexecute
thefollowingccode?
#include<stdio.h>
intmain(){
inti
floata=5.2
char*ptr
ptr=(char*)&a
for(i=0i<=3i++)
printf("%d",*ptr++)
return0
}
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page7
Page8of25
(a)0000
(b)GarbageGarbageGarbageGarbage
(c)102568032
(d)1021029064
(e)Compilererror
Answer:(d)
Explanation:
Incfloatdatatypeisfourbytedatatypewhilechar
pointerptrcanpointonebyteofmemoryatatime.
Memoryrepresentationoffloata=5.2
ptrpointerwillpointfirstfourthbytethenthird
bytethensecondbytethenfirstbyte.
Contentoffourthbyte:
Binaryvalue=01100110
Decimalvalue=64+32+4+2=102
Contentofthirdbyte:
Binaryvalue=01100110
Decimalvalue=64+32+4+2=102
Contentofsecondbyte:
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page8
Page9of25
Binaryvalue=10100110
Decimalvalue=128+32+4+2=90
Contentoffirstbyte:
Contentoffirstbyte:
Binaryvalue=01000000
Decimalvalue=64
Note:CharacterpointertreatsMSBbitofeachbyte
i.e.leftmostbitofabovefigureassignbit.
(6)Whatwillbeoutputifyouwillcompileandexecute
thefollowingccode?
#include<stdio.h>
intmain(){
inti
doublea=5.2
char*ptr
ptr=(char*)&a
for(i=0i<=7i++)
printf("%d",*ptr++)
return0
}
(a)5152525252522064
(b)5152525252522064
(c)Eightgarbagevalues.
(d)Compilererror
(e)Noneofthese
Answer:(a)
Explanation:
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page9
Page10of25
Incdoubledatatypeiseightbytedatatypewhile
charpointerptrcanpointonebyteofmemoryata
time.
Memoryrepresentationofdoublea=5.2
ptrpointerwillpointfirsteighthbytethenseventh
bytethensixthbytethenfifthbytethenfourthbyte
thenthirdbytethensecondbytethenfirstbyteas
showninabovefigure.
Contentofeighthbyte:
Binaryvalue=11001101
Decimalvalue=128+64+8+4+1=51
Contentofseventhbyte:
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page10
Page11of25
Binaryvalue=11001100
Decimalvalue=128+64+8+4=52
Contentofsixthbyte:
Binaryvalue=11001100
Decimalvalue=128+64+8+4=52
Contentoffifthbyte:
Binaryvalue=11001100
Decimalvalue=128+64+8+4=52
Contentoffourthbyte:
Binaryvalue=11001100
Decimalvalue=128+64+8+4=52
Contentofthirdbyte:
Binaryvalue=11001100
Decimalvalue=128+64+8+4=52
Contentofsecondbyte:
Binaryvalue=000010100
Decimalvalue=16+4=20
Contentoffirstbyte:
Binaryvalue=01000000
Decimalvalue=64
Note:CharacterpointertreatsMSBbitofeachbyte
i.e.leftmostbitofabovefigureassignbit.
(7)Whatwillbeoutputifyouwillcompileandexecute
thefollowingccode?
#include<stdio.h>
intmain(){
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page11
Page12of25
Page12of25
printf("%s","c""question""bank")
return0
}
(a)cquestionbank
(b)c
(c)bank
(d)cquestionbank
(e)Compilererror
Answer:(d)
Explanation:
Incstringconstantxyissameasxy
(8)Whatwillbeoutputifyouwillcompileandexecute
thefollowingccode?
#include<stdio.h>
intmain(){
char*str="cpointer"
printf("%*.*s",10,7,str)
return0
}
(a)cpointer
(b)cpointer
(c)cpoint
(d)cpointernullnull
(e)cpoint
Answer:(e)
Explanation:
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page12
Page13of25
Meaningof%*.*sintheprintffunction:
First*indicatesthewidthi.e.howmanyspaceswill
taketoprintthestringandsecond*indicateshow
manycharacterswillprintofanystring.
Followingfigureillustratesoutputofabovecode:
(9)Whatwillbeoutputifyouwillcompileand
executethefollowingccode?
#include<stdio.h>
intmain(){
inta=12
a=a>>3
printf("%d",a)
return0
}
(a)4
(b)3
(c)2
(d)96
(e)Compilererror
Answer:(c)
Explanation:
Binaryvalueof12is:0000000000001100
Binaryvalueof12wills2scomplementof12i.e.
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page13
Page14of25
Sobinaryvalueof12is:1111111111110100
Rightshiftingrule:
Rule1:Ifnumberispositivethefillvacantspacesin
theleftsideby0.
Rule2:Ifnumberisnegativethefillvacantspacesin
theleftsideby1.
Inthiscasenumberisnegative.Sorightshiftallthe
binarydigitsbythreespaceandfillvacantspaceby1
asshownfollowingfigure:
Sinceitisnegativenumbersooutputwillalsoa
negativenumberbutits2scomplement.
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page14
Page15of25
Hencefinaloutputwillbe:
Anditsdecimalvalueis:2
Henceoutputwillbe:2
(10)Whatwillbeoutputifyouwillcompileand
executethefollowingccode?
#include<stdio.h>
#include<string.h>
intmain(){
printf("%d%d",sizeof("string"),strlen("string"))
return0
}
(a)66
(b)77
(c)67
(d)76
(e)Noneofthese
Answer:(d)
Explanation:
Explanation:
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page15
Page16of25
Sizeofoperatorreturnsthesizeofstringincluding
nullcharacterwhilestrlenfunctionreturnslengthof
astringexcludingnullcharacter.
(11)Whatwillbeoutputifyouwillcompileand
executethefollowingccode?
#include<stdio.h>
intmain(){
staticmain
intx
x=call(main)
printf("%d",x)
return0
}
intcall(intaddress){
address++
returnaddress
}
(a)0
(b)1
(c)Garbagevalue
(d)Compilererror
(e)Noneofthese
Answer:(b)
Explanation:
Asweknowmainisnotkeywordofcbutisspecialtype
Asweknowmainisnotkeywordofcbutisspecialtype
offunction.Wordmaincanbenamevariableinthemain
andotherfunctions.
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page16
Page17of25
(12)Whatwillbeoutputifyouwillcompileand
executethefollowingccode?
#include<stdio.h>
intmain(){
inta,b
a=1,3,15
b=(2,4,6)
printf("%d",a+b)
return0
}
(a)3
(b)21
(c)17
(d)7
(e)Compilererror
Answer:(d)
Explanation:
Inccommabehavesasseparatoraswellasoperator.
a=1,3,15
b=(2,4,6)
Intheabovetwostatementscommaisworkingas
operator.Commaenjoysleastprecedenceandassociative
islefttoright.
Assigningthepriorityofeachoperatorinthefirst
statement:
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page17
Page18of25
Hence1willassigntoa.
Assigningthepriorityofeachoperatorinthesecond
statement:
(13)Whatwillbeoutputifyouwillcompileand
executethefollowingccode?
#include<stdio.h>
intexternx
intmain()
printf("%d",x)
x=2
return0
}
intx=23
(a)0
(b)2
(b)2
(c)23
(d)Compilererror
(e)Noneofthese
Answer:(c)
Explanation:
externvariablescansearchthedeclarationofvariable
anywhereintheprogram.
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page18
Page19of25
(14)Whatwillbeoutputifyouwillcompileand
executethefollowingccode?
#include<stdio.h>
intmain(){
inti=0
if(i==0){
i=((5,(i=3)),i=1)
printf("%d",i)
}
else
printf("equal")
}
(a)5
(b)3
(c)1
(d)equal
(e)Noneofabove
Answer:(c)
(15)Whatwillbeoutputifyouwillcompileand
executethefollowingccode?
intmain(){
inta=25
printf("%o%x",a,a)
return0
}
(a)2525
(b)0250x25
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page19
Page20of25
(c)1242
(d)3119
(e)Noneofthese
Answer:(d)
Explanation:
%oisusedtoprintthenumberinoctalnumberformat.
%xisusedtoprintthenumberinhexadecimalnumber
format.
Note:Incoctalnumberstartswith0andhexadecimal
numberstartswith0x.
(16)Whatwillbeoutputifyouwillcompileand
executethefollowingccode?
#include<stdio.h>
#definemessage"unionis\
powerofc"
intmain(){
printf("%s",message)
return0
}
(a)unionispowerofc
(b)unionispowerofc
(c)unionis
Powerofc
(d)Compilererror
(e)Noneofthese
Answer:(b)
Explanation:
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page20
Page21of25
Ifyouwanttowritemacroconstantinnewlinetheend
withthecharacter\.
(17)Whatwillbeoutputifyouwillcompileand
executethefollowingccode?
#include<stdio.h>
#definecall(x)#x
intmain(){
printf("%s",call(c/c++))
return0
}
(a)c
(b)c++
(c)#c/c++
(d)c/c++
(e)Compilererror
Answer:(d)
Explanation:
#isstringoperator.Itconvertsthemacrofunction
callargumentinthestring.Firstseetheintermediate
file:
test.c1:
test.c2:voidmain(){
test.c3:printf("%s","c/c++")
test.c4:return0
test.c4:}
test.c5:
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page21
Page22of25
Itisclearmacrocallisreplacedbyitsargumentin
thestringformat.
(18)Whatwillbeoutputifyouwillcompileand
executethefollowingccode?
#include<stdio.h>
intmain(){
if(printf("cquestionbank"))
printf("Iknowc")
else
printf("Iknowc++")
return0
}
(a)Iknowc
(a)Iknowc
(b)Iknowc++
(c)cquestionbankIknowc
(d)cquestionbankIknowc++
(e)Compilererror
Answer:(c)
Explanation:
Returntypeofprintffunctionisintegerwhichreturns
numberofcharacteritprintsincludingblankspaces.
Soprintffunctioninsideifconditionwillreturn13.
Inifconditionanynonzeronumbermeanstruesoelse
partwillnotexecute.
(19)Whatwillbeoutputifyouwillcompileand
executethefollowingccode?
#include<stdio.h>
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page22
Page23of25
intmain(){
inti=10
staticintx=i
if(x==i)
printf("Equal")
elseif(x>i)
printf("Greaterthan")
else
printf("Lessthan")
return0
(a)Equal
(b)Greaterthan
(c)Lessthan
(d)Compilererror
(e)Noneofabove
Answer:(d)
Explanation:
Staticvariablesareloadtimeentitywhileauto
variablesareruntimeentity.Wecannotinitializeany
loadtimevariablebytheruntimevariable.
Inthisexampleiisruntimevariablewhilexisload
timevariable.
(20)Whatwillbeoutputifyouwillcompileand
executethefollowingccode?
#include<stdio.h>
intmain(){
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page23
Page24of25
printf("%s",__DATE__)
return0
}
(a)Currentsystemdate
(b)Currentsystemdatewithtime
(c)null
(d)Compilererror
(e)Noneofthese
Answer:(a)
Answer:(a)
Explanation:
__DATE__isglobalidentifierwhichreturnscurrent
systemdate.
(21)Whatwillbeoutputifyouwillcompileand
executethefollowingccode?
#include<stdio.h>
voidstart()
voidend()
#pragmastartupstart
#pragmaexitend
intstatici
intmain(){
printf("\nmainfunction:%d",++i)
return0
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page24
Page25of25
voidstart(){
printf("\nstartfunction:%d",++i)
}
voidend(){
printf("\nendfunction:%d",++i)
}
(a)
mainfunction:2
startfunction:1
endfunction:3
(b)
startfunction:1
mainfunction:2
endfunction:3
(c)
mainfunction:2
endfunction:3
startfunction:1
(d)Compilererror
(e)Noneofthese
Answer:(b)
Explanation:
Everycprogramstartwithmainfunctionandterminate
withnullstatement.But#pragmastartupcancall
functionjustbeforemainfunctionand#pragmaexit
Copyright@riteshkumar:http://cquestionbank.blogspot.com/
Page25
ThisPDFdockeepscprogrammingquestionsandanswerwithexplanationin
depth.TofreedownloadthepdfdocgototheFile>DownloadOriginal
9comments:
GauravKumar 2/28/13,6:10PM
It'sgoodbuthowcandownloadthepdffile
Reply
Replies
riteshkumar
2/28/13,7:21PM
download the pdf click on top right corner of pdf(Open in new window) then go to the File >
DownloadOriginal
Reply
Bhuvan 6/4/13,9:15PM
Canuupload"CinDepth"bySrivastava..
Reply
Anonymous 6/27/13,11:42AM
yourgenuis,canyougivesomevb.netsampleprogramsorcodes?
Reply
rahulsati 7/10/14,11:09AM
ihavethisbook"cindepth"..nicebook.
Reply
Replies
NagaPrasad 6/4/16,10:51AM
hi...
canusendCINDEPTHsoftcopytomymail..id:bnprasad020@gmail.com
thanksinadvance.
Reply
DeepakMandal 3/20/15,3:08PM
itsgooducanunderstandeasily
Reply
rajarajeswari 4/18/15,8:58AM
plsuploadthefullbookinpdfformat
Reply
RameshThapa 2/29/16,10:00AM
PleaseUploadthefullbookinpdfformat
Reply
Enteryourcomment...
Commentas:
Publish
Selectprofile...
Preview
Linkstothispost
CreateaLink
NewerPost
Home
Subscribeto:PostComments(Atom)
Copyright@Priyanka.PictureWindowtemplate.PoweredbyBlogger.
OlderPost