Sei sulla pagina 1di 8

1/23/2015

00:19:45

Like

Share

C Programming Test Random


CProgramming

1.

Result&Statistics

Inthefollowingcodewhatis'P'?

Marks:10/20

typedefchar*charp
constcharpP
A.

Pisaconstant

B.

Pisacharacterconstant

C.

Pischaractertype

D.

Noneofabove

Totalnumberofquestions

: 20

Numberofansweredquestions

: 17

Numberofunansweredquestions :

Feedback
Answer:OptionA

QualityoftheTest

Select

Learnmoreproblemson:Typedef

DifficultyoftheTest

Select

Discussaboutthisproblem:DiscussinForum

Comments:
...

2.

Whatwillbetheoutputoftheprogram?
#include<stdio.h>
intfun(int,int)
typedefint(*pf)(int,int)
intproc(pf,int,int)

SubmitFeedback

TakeanAnotherRandomTest!

intmain()
{
printf("%d\n",proc(fun,6,6))
return0
}
intfun(inta,intb)
{
return(a==b)
}
intproc(pfp,inta,intb)
{
return((*p)(a,b))
}

GotoOnlineTestPage
GotoHomePage

A.

B.

C.

D.

Answer:OptionB
Learnmoreproblemson:Functions
Discussaboutthisproblem:DiscussinForum

3.

Pointouttheerrorintheprogram?
#include<stdio.h>
#include<string.h>
voidmodify(structemp*)
structemp
{
charname[20]
intage
}
intmain()
{
structempe={"Sanjay",35}
modify(&e)
printf("%s%d",e.name,e.age)

http://www.indiabix.com/onlinetest/cprogrammingtest/random

1/8

1/23/2015

00:19:45
return0
}
voidmodify(structemp*p)
{
p>age=p>age+2
}
A.

Error:instructure

B.

Error:inprototypedeclarationunknownstructemp

C.

Noerror

D.

Noneofabove

Answer:OptionB
Explanation:
Thestructempismentionedintheprototypeofthefunctionmodify()beforedeclaringthe
structure.Tosolvethisproblemdeclarestructempbeforethemodify()prototype.
Learnmoreproblemson:Structures,Unions,Enums
Discussaboutthisproblem:DiscussinForum

4.

Whatwillbetheoutputoftheprogram?
#include<stdio.h>
intmain()
{
charhuge*near*far*ptr1
charnear*far*huge*ptr2
charfar*huge*near*ptr3
printf("%d,%d,%d\n",sizeof(**ptr1),sizeof(ptr2),sizeof(*ptr3))
return0
}
A.

4,4,4

B.

2,2,2

C.

2,8,4

D.

2,4,8

Answer:OptionA
Learnmoreproblemson:ComplicatedDeclarations
Discussaboutthisproblem:DiscussinForum

5.

ApointerunionCANNOTbecreated
A.

Yes

B.

No

Answer:OptionB
Learnmoreproblemson:Structures,Unions,Enums
Discussaboutthisproblem:DiscussinForum

6.

Whichofthefollowingcannotbecheckedinaswitchcasestatement?
A.

Character

B.

Integer

C.

Float

D.

enum

Answer:OptionC
Explanation:
Theswitch/casestatementintheclanguageisdefinedbythelanguagespecificationtousean
intvalue,soyoucannotuseafloatvalue.
switch(expression)
{
caseconstantexpression1:statements1

http://www.indiabix.com/onlinetest/cprogrammingtest/random

2/8

1/23/2015

00:19:45
caseconstantexpression2:statements2
caseconstantexpression3:statements3
...
...
default:statements4
}
Thevalueofthe'expression'inaswitchcasestatementmustbeaninteger,char,short,long.
Floatanddoublearenotallowed.
Learnmoreproblemson:ControlInstructions
Discussaboutthisproblem:DiscussinForum

7.

Afilewrittenintextmodecanbereadbackinbinarymode.
A.

Yes

B.

No

Answer:OptionB
Explanation:
Thedifferenceisthattextfilescontainlines(orrecords)oftextandeachofthesehasanend
oflinemarkerautomaticallyappendedtotheendofitwheneveryouindicatethatyouhave
reachedtheendofaline.
Binaryfilesarenotbrokenupintoseparatelinesorrecordssotheendoflinemarkerisnot
writtenwhenwritingtoabinaryfile.
So,wecannotreadthecorrectthedatainbinarymode.
Learnmoreproblemson:Input/Output
Discussaboutthisproblem:DiscussinForum

8.

Whatwillbetheoutputoftheprogram?
#include<stdio.h>
intmain()
{
float*p
printf("%d\n",sizeof(p))
return0
}
A.

2in16bitcompiler,4in32bitcompiler

B.

4in16bitcompiler,2in32bitcompiler

C.

4in16bitcompiler,4in32bitcompiler

D.

2in16bitcompiler,2in32bitcompiler

Answer:OptionA
Explanation:
sizeof(x)returnsthesizeofxinbytes.
float*pisapointertoafloat.
In16bitcompiler,thepointersizeisalways2bytes.
In32bitcompiler,thepointersizeisalways4bytes.
Learnmoreproblemson:FloatingPointIssues
Discussaboutthisproblem:DiscussinForum

9.

WhichofthefollowingarecorrectpreprocessordirectivesinC?
1: #ifdef
2: #if
3: #elif
4: #undef

A.

1,2

B.

C.

1,2,4

D.

1,2,3,4

http://www.indiabix.com/onlinetest/cprogrammingtest/random

3/8

1/23/2015

00:19:45
Answer:OptionD
Explanation:
Themacros#ifdef#if#elifarecalledconditionalmacros.
Themacro#undefundefinetheprevioslydeclaredmacrosymbol.
Henceallthegivenstatementsaremacropreprocessordirectives.
Learnmoreproblemson:CPreprocessor
Discussaboutthisproblem:DiscussinForum

10. Pointouttheerrorinthefollowingprogram.
#include<stdio.h>
#include<stdarg.h>
voiddisplay(char*s,...)
voidshow(char*t,...)
intmain()
{
display("Hello",4,12,13,14,44)
return0
}
voiddisplay(char*s,...)
{
show(s,...)
}
voidshow(char*t,...)
{
inta
va_listptr
va_start(ptr,s)
a=va_arg(ptr,int)
printf("%f",a)
}
A.

Error:invalidfunctiondisplay()call

B.

Error:invalidfunctionshow()call

C.

Noerror

D.

Error:Rvaluerequiredfort

Answer:OptionB
Explanation:
Thecalltoshow()isimproper.Thisisnotthewaytopassvariableargumentlisttoafunction.
Learnmoreproblemson:VariableNumberofArguments
Discussaboutthisproblem:DiscussinForum

11. Unionelementscanbeofdifferentsizes.
A.

True

B.

False

Answer:OptionA
Learnmoreproblemson:Structures,Unions,Enums
Discussaboutthisproblem:DiscussinForum

12. Afunctionmayhaveanynumberofreturnstatementseachreturningdifferentvalues.
A.

True

B.

False

Answer:OptionA
Explanation:
True,Afunctionmayhaveanynumberofreturnstatementseachreturningdifferentvalues

http://www.indiabix.com/onlinetest/cprogrammingtest/random

4/8

1/23/2015

00:19:45
andeachreturnstatementswillnotoccursuccessively.
Learnmoreproblemson:Functions
Discussaboutthisproblem:DiscussinForum

13. Pointouttheerror,ifanyintheprogram.
#include<stdio.h>
intmain()
{
inti=1
switch(i)
{
printf("Thisiscprogram.")
case1:
printf("Case1")
break
case2:
printf("Case2")
break
}
return0
}
A.

Error:Nodefaultspecified

B.

Error:Invalidprintfstatementafterswitchstatement

C.

NoErrorandprints"Case1"

D.

Noneofabove

Answer:OptionC
Explanation:
switch(i)becomesswitch(1),thenthecase1:blockisgetexecuted.Henceitprints"Case1".
printf("Thisiscprogram.")isignoredbythecompiler.
Hencethereisnoerrorandprints"Case1".
Learnmoreproblemson:ControlInstructions
Discussaboutthisproblem:DiscussinForum

14. Whatwillbetheoutputoftheprogram?
#include<stdio.h>
intmain()
{
enumcolor{red,green,blue}
typedefenumcolormycolor
mycolorm=red
printf("%d",m)
return0
}
A.

B.

C.

D.

red

Answer:OptionB
Learnmoreproblemson:Typedef
Discussaboutthisproblem:DiscussinForum

15. Whatwillbetheoutputoftheprogram?
#include<stdio.h>
intmain()
{

http://www.indiabix.com/onlinetest/cprogrammingtest/random

5/8

1/23/2015

00:19:45
inti=3,j=2,k=0,m
m=++i&&++j&&++k
printf("%d,%d,%d,%d\n",i,j,k,m)
return0
}
A.

2,3,1,1

B.

2,3,1,2

C.

1,2,3,1

D.

3,3,1,2

Answer:OptionA
Explanation:
Step1:inti=3,j=2,k=0,mherevariablei,j,k,maredeclaredasanintegertypeand
variablei,j,kareinitializedto3,2,0respectively.
Step2:m=++i&&++j&&++k
becomesm=2&&3&&1
becomesm=TRUE&&TRUEHencethisstatementbecomesTRUE.Soitreturns'1'(one).
Hencem=1.
Step3:printf("%d,%d,%d,%d\n",i,j,k,m)Inthepreviousstepthevalueofi,j,kare
increementedby'1'(one).
Hencetheoutputis"2,3,1,1".
Learnmoreproblemson:Expressions
Discussaboutthisproblem:DiscussinForum

16. Whatwillbetheoutputoftheprogram?
#include<stdio.h>
intmain()
{
inti=4,j=1,k=0,w,x,y,z
w=i||j||k
x=i&&j&&k
y=i||j&&k
z=i&&j||k
printf("%d,%d,%d,%d\n",w,x,y,z)
return0
}
A.

1,1,1,1

B.

1,1,0,1

C.

1,0,0,1

D.

1,0,1,1

Answer:OptionD
Explanation:
Step1:inti=4,j=1,k=0,w,x,y,zherevariablei,j,k,w,x,y,zaredeclaredasaninteger
typeandthevariablei,j,kareinitializedto4,1,0respectively.
Step2:w=i||j||kbecomesw=4||1||0.HenceitreturnsTRUE.So,w=1
Step3:x=i&&j&&kbecomesx=4&&1&&0HenceitreturnsFALSE.So,x=0
Step4:y=i||j&&kbecomesy=4||1&&0HenceitreturnsTRUE.So,y=1
Step5:z=i&&j||kbecomesz=4&&1||0HenceitreturnsTRUE.So,z=1.
Step6:printf("%d,%d,%d,%d\n",w,x,y,z)Hencetheoutputis"1,0,1,1".
Learnmoreproblemson:Expressions
Discussaboutthisproblem:DiscussinForum

17. Whatwillbetheoutputoftheprogram?
#include<stdio.h>
intmain()
{
inti
chara[]="\0"
if(printf("%s",a))

http://www.indiabix.com/onlinetest/cprogrammingtest/random

6/8

1/23/2015

00:19:45
printf("Thestringisempty\n")
else
printf("Thestringisnotempty\n")
return0
}
A.

Thestringisempty

B.

Thestringisnotempty

C.

Nooutput

D.

Answer:OptionB
Explanation:
Thefunctionprintf()returnsthenumberofcharectersprintedontheconsole.
Step1:chara[]="\0"Thevariableaisdeclaredasanarrayofcharactersanditinitialized
with"\0".Itdenotesthatthestringisempty.
Step2:if(printf("%s",a))Theprintf()statementdoesnotprintanything,soitreturns
'0'(zero).Hencetheifconditionisfailed.
Intheelsepartitprints"Thestringisnotempty".
Learnmoreproblemson:Strings
Discussaboutthisproblem:DiscussinForum

18. Declarethefollowingstatement?

"Apointertoanarrayofthreechars".
A.

char*ptr[3]()

B.

char(*ptr)*[3]

C.

char(*ptr[3])()

D.

char(*ptr)[3]

Answer:OptionD
Learnmoreproblemson:ComplicatedDeclarations
Discussaboutthisproblem:DiscussinForum

19. AcharvariablecanstoreeitheranASCIIcharacteroraUnicodecharacter.
A.

True

B.

False

Answer:OptionA
Explanation:
Yes,wecanstoreeitheranASCIIcharacteroraUnicodecharacterinacharvariable.
Learnmoreproblemson:ControlInstructions
Discussaboutthisproblem:DiscussinForum

20. Howwillyoufreethememoryallocatedbythefollowingprogram?
#include<stdio.h>
#include<stdlib.h>
#defineMAXROW3
#defineMAXCOL4
intmain()
{
int**p,i,j
p=(int**)malloc(MAXROW*sizeof(int*))
return0
}
A.

memfree(intp)

B.

dealloc(p)

C.

malloc(p,0)

D.

free(p)

Answer:OptionD
Learnmoreproblemson:MemoryAllocation

http://www.indiabix.com/onlinetest/cprogrammingtest/random

7/8

1/23/2015

00:19:45
Discussaboutthisproblem:DiscussinForum

SubmitTest

20082014byIndiaBIXTechnologies.AllRightsReserved|Copyright|TermsofUse&PrivacyPolicy

Contactus:info@indiabix.com
Bookmarkto:

http://www.indiabix.com/onlinetest/cprogrammingtest/random

Followusontwitter!

8/8

Potrebbero piacerti anche