C - Question Paper Quark Media House India Pvt. LTD.: 1. What Is The Output of The Following Code
The document contains a question paper with 20 multiple choice questions related to C programming. The questions test various concepts in C like operator precedence, data types, function calls, pointers, macros, arrays etc. The answers and explanations provided give details about the logic and evaluation order to arrive at the output in each case.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
67 views9 pages
C - Question Paper Quark Media House India Pvt. LTD.: 1. What Is The Output of The Following Code
The document contains a question paper with 20 multiple choice questions related to C programming. The questions test various concepts in C like operator precedence, data types, function calls, pointers, macros, arrays etc. The answers and explanations provided give details about the logic and evaluation order to arrive at the output in each case.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9
C - Question Paper
Quark Media House India Pvt. Ltd.
Note : There are 20 questions and no negative marking. Time allotted is 30 minutes 1. What is the output of the following code main() { printf("Hello %d",printf("QUARK test? ")); } a. Compile time error. . Hello QUARK test? !. R"n time error. d. #one of t$e ao%e. e. Q"ar& 'est ?Hello. Ans. d. t$e o"tp"t is QUARK test? Hello () '$is is e!a"se t$e e%al"ation of t$e parameters in a f"n!tion !all is done from ri*$t to left, e!+ t$e parameters ,ere passed %ia a sta!& $en!e t$e first parameter (t$e leftmost one) is at t$e ottom of t$e sta!& and t$e ri*$tmost parameter (if it is an e-presseion, it ,ill e e%al"ated efore p"ttin* it on t$e sta!&) is on t$e top of t$e sta!&, $en!e ,$ile poppin* t$e parameters from t$e sta!&, t$e f"n!tion printf (or an. ot$er f"n!tion) *ets t$em in t$e re%erse order, i.e., from ri*$t to left, $en!e t$e statement printf(/Q"ar& test? /) *ets e%al"ated first ,$ile p"s$in* it as a parameter on to t$e sta!&, and t$en t$e statement printf(/Hello %d0) is e-e!"ted. '$e 1()2 is t$e res"lt of t$e ret"rn of printf(/Q"ar& test? /) ,$i!$ ret"rns t$e n"mer of !$ara!ters printed. .! "ut put of the following code is main() { int i,3,A; for (A 4 5(;A64(; A77) printf("%d8t",99A); } a. ( : ( . ;<<=> : ;<<=> !. 5( : ( d. 5;<<=> : ;<<=> e. #one of t$e ao%e #ns. 1 $ 1 %! What is the out put of the following code& main() { int i4)<<; printf("%d8t",77(i77)); } a. Compilation error . R"ntime error !. )<; d. : e. #one of t$e ao%e Ans. Compile 'ime ?rror 1@%al"e ReA"ired '! What shall (e the output of the following code& main() { !$ar i 4 BaB; printf("%! 8t %! 8t", i ,(77i)); } a. a . Compile time error !. d. a a e. ;< ;; Ans. )! What shall (e the output of the following code& main() { int i,3; printf(/QUARK %s8n0,main()); } a. Compilation error. . R"n5time error !. Contin"o"s s!rollin* Q"ar& on t$e s!reen. d. #one of t$e ao%e. Ans. '$ere is not$in* on t$e s!reen and pro* ,aits till t$e memor. lasts and t$en o"t of memor. r"n time error, so ans is . *! What shall (e the output of the following code & Cdefine f(-) -D-D- main(){ printf("8n%d",f()7))); } a. E . ;> !. (: d. () Ans. f()7)) ,ill e-pand to )7)D)7)D)7) 4 )7>7>7) 4 () +! What shall (e the output of the following code & main() { %oid f"n((%oid D); !$ar aFG 4 "A"ar&"; %oid Dtemp; temp 4 a; f"n((temp);} %oid f"n((%oid Dtemp( ) { int t( 4 :; ,$ile(D((!$arD)temp(7 t(77 )94B8:B) { printf("%!",D((!$arD)temp( 7 t()); } } a. Compilation error . ar& !. A"ar& d. "ar& Ans, "ar& ,. What will (e the out put of the following code& %oid main() { int -4=; printf("%d8t %d",-HH(, -66=); } a. ( and > . ( and )> !. ( and )I d. #one of t$e ao%e #ns. 1 and ' '$is is e!a"se = in inar. is :::::::: ::::::(( in t,o .tes (inte*er). A*ain, t$e ri*$t to left e%al"ation r"le of parameters is appli!ale and so -66= *ets e-e!"ted first, it means left s$ift = times, "t t$is operator does not !$an*e t$e %al"e of - itself, it simpl. ret"rns a %al"e, so - retains its %al"e after t$is operation $as een !arried o"t, so ,e *et :::::::: :::((::: ,$i!$ is )>, so )> is p"s$ed onto t$e sta!&, and t$en -HH(, ri*$t s$ift (, :::::::: ::::::((, ,$i!$ is ( in de!imal, so ( is p"s$ed onto t$e sta!&, t$en printf("%d8t %d") *ets e-e!"ted displa.in* ( )>. -. What will (e the result of the following code& int D-; - 4(int D) (<; a. Compilation error . Compiles "t *i%es a r"ntime error !. Asol"te lo!ation (< in t$e memor. spa!e s$all e assi*ned to pointer -; d. @o!ation (< in t$e pro*ram spa!e is assi*ned to pointer -; e. @o!ation (< !ontains t$e address to an inte*er. #ns d 1$. Which of the following functions cannot (e called fro. another file& a. !onst %oid f"n!(){ JJ..} . e-tern %oid f"n!(){JJJ} !. %oid f"n!(){JJJ} d. stati! %oid f"n!(){JJJ.} Ans. stati! 11. What will (e the out co.e of the following code& Cin!l"de6stdio.$H int D f"n!(){ stati! int -4:; -77; ret"rn K-; } int main() { int D . 4 f"n!(); printf("%d",(D.)77); f"n!(); printf("%d8n",D.); ret"rn :; } a. Compilation error. . Lrints ( and = !. Lrints ( and = "t it is not *ood pra!ti!e. d. Lrints ( and ( e. '$e !ode ,ill not e-e!"te properl. e!a"se . points to a %ariale ,$ose life span is limited to e-e!"tion of t$e f"n!tion f"n!(); Ans. Lrints ( and = "t it is not a *ood pra!ti!e 1. /eferring to the a(ove code 0 which of the following would (e the correct i.ple.entation for .12unc & !$ar Dformat 4 /%d0; int main() { int -; m.M"n!(s!anf,K-); printf(/%d8n0,-); ret"rn(:); } a. %oid m.M"n!(int(D.)(!onst !$arD,J),int D3! 456.)(format,K-);} . %oid m.M"n!(int(D.)(!onst !$arD,J),int D3! 456.)(format,D-);} !. %oid m.M"n!(intD.(!onst !$arD,J),int D3! 456.)(format,K-);} d. %oid m.M"n!(D(int .(!onst !$arD,J)),int D3! 456.)(format,-);} e. %oid m.M"n!(int(D.)(!onst !$arD,J),int D3! 456.)(format,-);} 1%. What shall (e the output of the following C code& %oid main() { "nsi*ned int -4 5(; int . 4:; if(.64-) printf(/A is tr"e8n0); if (. 4 4(- 4 5(:)) printf(/N is tr"e8n0); if ((int) -H4.) printf(/C is tr"e8n0); } a. A is tr"e. . N is tr"e. !. C is tr"e. d. #one of t$e ao%e. #ns. # is true e!a"se - !ontains O(, i.e., in inar. it is ffff, i.e., all (s, so ein* "nsi*ned, all (s are interpreted as t$e %al"e ;<<=< and not as O( ($o,e%er, all (s are interpreted as O( if it is 3"st an int), $en!e .64- ret"rns tr"e. 1'. In the following code what is the correct wa1 to incre.ent the varia(le ptr to point to the ne3t .e.(er of the arra1 "nion intfloat { int intArra.F <G; float floatArra.F <G; }; "nion intfloat arrF):G; %oid Dptr 4arr; a. 77(intD)ptr; . ptr 4 ptr7<; !. ptr 4 ptr 7si+eof(Dptr); d. ptr 4 ptr7si+eof(intfloat.floatArra.); e. ptr 4 (%oidD)(("nion intfloatD)ptr 7(); #ns. e. ptr 4 (%oidD)(("nion intfloatD)ptr 7(); 1).What shall (e the output of the following progra.&
Cdefine LRP#'QRS(-,.,+) printf (C- "4%d8t" C+ "4%d8n", -, .) %oid main() { int -, ., +; -4:; .4(; +4); - TT 77. TT77+; LRP#'QRS(-,.,+); 77- TT 77. KK 77+; LRP#'QRS(-,.,+); 77- KK 77. TT 77+; LRP#'QRS(-,.,+); } a. Compilation error. . R"ntime error. !. -4: +4) -4( +4= -4) +4> d. -4: +4) -4( +4) -4) +4= e. #one of t$e ao%e. Ans. d. 1*. What shall (e the output of the following code & main() { printf(/%d %d0, si+eof(#U@@), si+eof(/0)); } a. ( and :. . : and ( !. ) and ( d. > and ( e. #one of t$e ao%e #ns. Uepends on t$e ma!$ine and !ompiler. A!t"all. it is t$e si+eof(int) and si+eof(!$ar) as a strin* is stored as a !$ar arra. terminated ,it$ :, so si+eof(/0) *i%es (, ,$ereas si+eof(/adsf0) *i%es < (in!l"din* t$e terminatin* :). Vo in '"roC ,e *et ! as t$e ans,er, on WC ,e *et d as t$e ans,er, so P *"ess e is t$e ans, i.e., #one of t$e ao%e. 1+. What shall (e the output of the following code& int D!$e!& ( int,int); %oid main() {int c0d; ! 4 !$e!&(((,)X); d4 !$e!&():,=:); printf("8n!4%"",!); } int D !$e!&(int i,int 3 ) { int Dp, DA; p4Ki; A4K3; if(iH4X<) ret"rn(A); else ret"rn(p); } a. (( . )X !. Compilation error d. R"ntime error e. #one of t$e ao%e. #ns. e. #one of t$e ao%e. t$e statement ! 4 !$e!&(((,)X) is assi*nin* an int ptr to an int, so ! $as an address of an int (,$i!$ $as *one o"t of s!ope, sin!e t$e f"n!tion ret"rns t$e address of a %ariale ,$i!$ $ad its s!ope onl. inside t$e f"n!tion, sin!e t$e parameters ,ere passed . %al"e) so t$e %al"e printed !an e an.t$in*. Pnstead, if t$e statement ,as ! 4 D(!$e!&(((,)X)) t$en ! ,o"ld $a%e t$e %al"e stored at t$e address ret"rned . t$e f"n!tion, ,$i!$ ,o"ld most proal. e ((, "t it !annot e *"aranteed sin!e t$e %ariale i $as fallen o"t of s!ope. 1,. What shall (e the output of the following code& %oid main() {int aF=GF)G4{ (,), <,I, ;,E}; printf("8n%d",((a7()5(Ka7())); } a. : . 5(; !. 5) d. 5E e. #one of t$e ao%e. #ns. 7. P $a%en2t een ale to fi*"re t$is one o"t. a is t$e address of t$e )5d arra., $ere a, Ka, Da all *i%e t$e same %al"e, i.e., address of t$e arra.. (a7() *i%es t$e address of t$e se!ond ro,, it is t$e same as aF(G. D(a7() *i%es t$e address of t$e first !ell of t$e se!ond ro,. DD(a7() *i%es t$e %al"e of t$e element stored in t$e first !ell in t$e se!ond ro,. (D(a7()7() *i%es t$e address of t$e se!ond !ell of t$e se!ond ro,. D(D(a7()7() *i%es t$e %al"e of t$e element stored in t$e se!ond !ell in t$e se!ond ro,. 1-.What shall (e the output of the following code& main() { !$ar str(FG4"Hello"; !$ar str)FG4"Hello"; if(str(4 4str)KK (D(str(7;)4 4D(str)7;))) printf("8n ?A"al"); else printf("8n "neA"al"); } a. ?A"al . UneA"al !. Compilation error. d. R"ntime error. e. #one of t$e ao%e. Ans. . UneA"al, e!a"se t$e addresses of t$e t,o strin*s are str( and str) and t$e. are different. $. 8iven that si9eof5int! is 0 what is the output of the following code main() { int a, 4)<<,!4()I; a4Y; !4!Z(Ya K T:);8 !4!Z(Y(Y)); printf("%d8n",!); } a. ?rror e!a"se of o%erflo,; . )<< !. O)<; d. ()I e. #one of t$e ao%e Ans. d. ()I If u want previous year quark papers also u can mail me at lacement0!2002"yahoo.com #r $shish%mca&23"rediffmail.com #r contact '('33&&023 after (pm #:;W</; 1. = . # %. # '. C ). > *. = +. = ,. > -. # 1$. = 11. C 1. < 1%. # 1'. < 1). = 1*. < 1+. C 1,. C 1-. > $. =