c

download c

of 8

description

c test

Transcript of c

  • 1/23/2015 00:19:45

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

    C Programming Test Random

    CProgramming Result&Statistics

    1. Inthefollowingcodewhatis'P'?

    typedefchar*charpconstcharpP

    A. Pisaconstant B. Pisacharacterconstant

    C. Pischaractertype D. Noneofabove

    Answer:OptionA

    Learnmoreproblemson:Typedef

    Discussaboutthisproblem:DiscussinForum

    2. Whatwillbetheoutputoftheprogram?

    #includeintfun(int,int)typedefint(*pf)(int,int)intproc(pf,int,int)

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

    A. 6 B. 1

    C. 0 D. 1

    Answer:OptionB

    Learnmoreproblemson:Functions

    Discussaboutthisproblem:DiscussinForum

    3. Pointouttheerrorintheprogram?

    #include#includevoidmodify(structemp*)structemp{charname[20]intage}intmain(){structempe={"Sanjay",35}modify(&e)printf("%s%d",e.name,e.age)

    Marks:10/20

    Totalnumberofquestions : 20

    Numberofansweredquestions : 17

    Numberofunansweredquestions : 3

    Feedback

    QualityoftheTest : Select

    DifficultyoftheTest : Select

    Comments:...

    SubmitFeedback

    TakeanAnotherRandomTest!

    GotoOnlineTestPage

    GotoHomePage

    Like Share

  • 1/23/2015 00:19:45

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

    return0}voidmodify(structemp*p){p>age=p>age+2}

    A. Error:instructure

    B. Error:inprototypedeclarationunknownstructemp

    C. Noerror

    D. Noneofabove

    Answer:OptionB

    Explanation:

    Thestructempismentionedintheprototypeofthefunctionmodify()beforedeclaringthestructure.Tosolvethisproblemdeclarestructempbeforethemodify()prototype.

    Learnmoreproblemson:Structures,Unions,Enums

    Discussaboutthisproblem:DiscussinForum

    4. Whatwillbetheoutputoftheprogram?

    #include

    intmain(){charhuge*near*far*ptr1charnear*far*huge*ptr2charfar*huge*near*ptr3printf("%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. ApointerunionCANNOTbecreatedA. 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/casestatementintheclanguageisdefinedbythelanguagespecificationtouseanintvalue,soyoucannotuseafloatvalue.

    switch(expression){caseconstantexpression1:statements1

  • 1/23/2015 00:19:45

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

    caseconstantexpression2:statements2caseconstantexpression3: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)oftextandeachofthesehasanendoflinemarkerautomaticallyappendedtotheendofitwheneveryouindicatethatyouhavereachedtheendofaline.

    Binaryfilesarenotbrokenupintoseparatelinesorrecordssotheendoflinemarkerisnotwrittenwhenwritingtoabinaryfile.

    So,wecannotreadthecorrectthedatainbinarymode.

    Learnmoreproblemson:Input/Output

    Discussaboutthisproblem:DiscussinForum

    8. Whatwillbetheoutputoftheprogram?

    #includeintmain(){float*pprintf("%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: #ifdef2: #if3: #elif4: #undef

    A. 1,2 B. 4

    C. 1,2,4 D. 1,2,3,4

  • 1/23/2015 00:19:45

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

    Answer:OptionD

    Explanation:

    Themacros#ifdef#if#elifarecalledconditionalmacros.

    Themacro#undefundefinetheprevioslydeclaredmacrosymbol.

    Henceallthegivenstatementsaremacropreprocessordirectives.

    Learnmoreproblemson:CPreprocessor

    Discussaboutthisproblem:DiscussinForum

    10. Pointouttheerrorinthefollowingprogram.

    #include#includevoiddisplay(char*s,...)voidshow(char*t,...)

    intmain(){display("Hello",4,12,13,14,44)return0}voiddisplay(char*s,...){show(s,...)}voidshow(char*t,...){intava_listptrva_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

  • 1/23/2015 00:19:45

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

    andeachreturnstatementswillnotoccursuccessively.

    Learnmoreproblemson:Functions

    Discussaboutthisproblem:DiscussinForum

    13. Pointouttheerror,ifanyintheprogram.

    #includeintmain(){inti=1switch(i){printf("Thisiscprogram.")case1:printf("Case1")breakcase2: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

    intmain(){enumcolor{red,green,blue}typedefenumcolormycolormycolorm=redprintf("%d",m)return0}

    A. 1 B. 0

    C. 2 D. red

    Answer:OptionB

    Learnmoreproblemson:Typedef

    Discussaboutthisproblem:DiscussinForum

    15.Whatwillbetheoutputoftheprogram?

    #includeintmain(){

  • 1/23/2015 00:19:45

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

    inti=3,j=2,k=0,mm=++i&&++j&&++kprintf("%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,maredeclaredasanintegertypeandvariablei,j,kareinitializedto3,2,0respectively.

    Step2:m=++i&&++j&&++kbecomesm=2&&3&&1becomesm=TRUE&&TRUEHencethisstatementbecomesTRUE.Soitreturns'1'(one).Hencem=1.

    Step3:printf("%d,%d,%d,%d\n",i,j,k,m)Inthepreviousstepthevalueofi,j,kareincreementedby'1'(one).

    Hencetheoutputis"2,3,1,1".

    Learnmoreproblemson:Expressions

    Discussaboutthisproblem:DiscussinForum

    16. Whatwillbetheoutputoftheprogram?

    #includeintmain(){inti=4,j=1,k=0,w,x,y,zw=i||j||kx=i&&j&&ky=i||j&&kz=i&&j||kprintf("%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,zaredeclaredasanintegertypeandthevariablei,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

    intmain(){intichara[]="\0"if(printf("%s",a))

  • 1/23/2015 00:19:45

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

    printf("Thestringisempty\n")elseprintf("Thestringisnotempty\n")return0}

    A. Thestringisempty B. Thestringisnotempty

    C. Nooutput D. 0

    Answer:OptionB

    Explanation:

    Thefunctionprintf()returnsthenumberofcharectersprintedontheconsole.

    Step1:chara[]="\0"Thevariableaisdeclaredasanarrayofcharactersanditinitializedwith"\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#include#defineMAXROW3#defineMAXCOL4

    intmain(){int**p,i,jp=(int**)malloc(MAXROW*sizeof(int*))return0}

    A. memfree(intp) B. dealloc(p)

    C. malloc(p,0) D. free(p)

    Answer:OptionD

    Learnmoreproblemson:MemoryAllocation

  • 1/23/2015 00:19:45

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

    Discussaboutthisproblem:DiscussinForum

    SubmitTest

    20082014byIndiaBIXTechnologies.AllRightsReserved|Copyright|TermsofUse&PrivacyPolicy

    Contactus:[email protected] Followusontwitter!

    Bookmarkto: