36
OBJECTIVE TYPE QUESTIONS Choose correct or the best alternative in the following: Q.1 What is the output of the following program? main ( ) { int x = 2, y = 5; if (x < y) return (x = x+y); else printf (“z1”); printf(“z2”); } (A) z2 (B) z1z2 (C) Compilation error (D) None of these Ans: D There is no compilation error but there will no output because function is returning a value and if statement is true in this case. Q.2 Choose the correct one (A) Address operator can not be applied to register variables (B) Address operator can be applied to register variables (C) Use of register declaration will increase the execution time (D) None of the above Ans: D A register access is much faster than a memory access, keeping the frequently accessed variables in the register will lead to faster execution of programs. Q.4 What is the output of the following program? main ( ) { 1

MCQs

Embed Size (px)

DESCRIPTION

MCQ on C

Citation preview

OBJECTIVE TYPE QUESTIONS Choose correct or the best alternative in the following Q!" What is the output of the following program? main ( ) { int x = 2, y = 5;if (x < y) return (x = x+y); else printf (z1);printf(z2); } #$%z2#B%z1z2 #C% Compilation error#&%None of these $ns & There is no compilation error but there will no output because function is returning avalue and if statement is true in this case. Q!' Choose the correct one #$% Address operator can not be applied to register variables #B% Address operator can be applied to register variables #C% se of register declaration will increase the e!ecution time #&% None of the above $ns & A register access is much faster than a memor" access# $eeping the fre%uentl"accessed variables in the register will lead to faster e!ecution of programs. Q!(What is the output of the followingprogram? main ( ) {extern int x; x = 20; printf(n!", x); } #$%B%2& #C% error#&%garbagevalue $ns C 'utput of the given program will be ()in$er error*undefined s"mbol !+. ,!ternalvariables are declared outside a function. Q!)-f ! is one dimensional arra"# then pic$ up the correct answer 1 #$% ./! 0 i1 is same as 2!3i4#B%.2!3i4 is same as ! 0 i #C%./! 0 i1 is same as !3i4 01#&%./! 0 i1 is same as .!3i4 $ns $ num3i4 is same as ./num0i1 Q!*Consider the following declarationint a, #$ = %a, ##& = %$;The following program fragment a = '; ##& = 5;#$% does not change the value of a #B%assigns address of c to a #C%assigns the value of b to a #&%assigns 5 to a $ns & The given statements assigns 5 to a Q!+Choose the correct answer #$%enumvariable can not be assigned newvalues #B% enum variable can be compared #C% enumeration feature increase the power of C #&% None of the above $ns C Theenumerateddatat"pesgiveanopportunit"toinventourowndatat"peanddefine what value the variable of this data t"pe can ta$e. Q!, The content of file will be lost if it is opened in#$% w mode#B%w0 mode #C%a mode#&%a0 mode

$ns $ When the mode is writing# the contents are deleted and the file is opened as a newfile. Q!- Consider thefollowingcodesegment6inta(10), #p1, #p2; p1 = %a('); p2 = %a(*); Which of the following statements is incorrect w.r.t. pointers? #$%p1 0 2#B%p2 7 2 #C%p2 0 p1#&%p2 7 p1 $ns C Addition of two pointers is not allowed. Q!". The second e!pression /8 7 $1 in the following e!pression will be evaluated2 (i + 5) %% (+ , -) #$% if e!pression /i 0 51 is true. #B% if e!pression /i 0 51 is false. #C% irrespective of whether /i 0 51 is true or false.#&%will not beevaluated in an" case. $ns $ -n a compound logical e!pression combined with 22# the second e!pressionis evaluated onl" if first is evaluated in true. Q!"" -n the for statement6 f.r (exp1; exp2; exp/) { 0 } where e!p1# e!p2and e!p9 are e!pressions. What is optional? #$% None of the e!pressions is optional. #B% 'nl" e!p1 is optional. #C% 'nl" e!p1 and e!p9 are optional. #&% All the e!pressions are optional. $ns & All the e!pressions are optional. :or /;;1 is a valid statement in C. Q!"'The output of the following code segment will be &1ar x = 234;s5it&1 (x) {&ase 2647 printf(a);&ase 2347 printf($);&ase 2847 printf(&); } #$%&) #$% A5#B%C #C%*1C#&%*15 $ns $ the value of the arithmetic e!pression is A5 as 2.909./DE51?C09.19?C09B?A5 Q!'" A global variable is a variable#$% declared in the main / 1 function. #B% declared in an" function other than the main / 1 function. #C% declared outside the bod" of ever" function. #&% declared an" wherein the C program. $ns C A global variable is declared outside the bod" of ever" function. Q!'' main / 1 is an e!ample of #$%librar" function #B%user defined function #C%header#&%statement $ns $ main/1 is a special function used b" C s"stem to tell the computer where theprogram starts. Q!'/ While incrementing a pointer# its value gets increased b" the length of thedata t"pe to which it points. This length is called #$%scale factor #B%length factor #C%pointer factor#&%increment factor $ns & While incrementinga pointer# its value gets increased b" the length of thedata t"pe to which it points. Q!'( The first digit of a decimal constant must be #$%a zero#B%a non zero number #C%a negative number#&%an integer $ns & Fecimal constants consist of a set of digit# & to B# preceded b" an optional 7or 0 sign. Q!')What is the output of the following statement6printf (!>/",12/'5); #$%1 2 9#B%*1 2 9#C%1 2 9 A 5#&%12 $ns C printf statement would print 129A5. Q!'* A single character input from the $e"board can be obtained b" using the function. #$% printf / 1#B% scanf / 1 C #C% putchar / 1#&% getchar / 1 $ns & Geading a single character can be done b" using the function getchar/ 1. Q!'+ The function ftell/ 1 #$% reads a character from a file #B% reads an integer from a file #C% gives the current position in the file #&% sets the position to the beginning of the file. $ns C ftell/ 1 ta$es a file pointer and returns a number of t"pe long# thatcorresponds to the current position. Q!', -f the variables i# 8 and $ are assigned the values 5#9 and 2 respectivel"# thenthe e!pression i = + + ( - + + = * ) + A #$%gives an error message#B%assigns a value 1C to i #C%assigns a value 1D to i#&%assigns a value 1B to i $ns $ -t gives an error message*)value re%uired. Q!'- -f an integer needs two b"tes of storage# then the ma!imum value of a signed integer is #$%21C*1#B%215*1 #C%21C#&%215 $ns B -f we use a 1C bit word length# the size of the integer value is limited to the range *215 to 215*1 Q!/. )iteral means #$%a string#B%a string constant #C%a character#&%an alphabet $ns B )iteral means a string constant. Q!/" -f H"> is of integer t"pe then the e!pressions 9(" D)IB and (" D)IB9#$% must "ield the same value. #B% must "ield different values. #C% ma" or ma" not "ield the same value. #&% none of the above. J $ns C The e!pression ma" or ma" not "ield the same value. Q!/'-n the following code fragment int x, y = 2, z, a;x=(y#=2) + (z=a=y);printf (2!"4,x); /A1 prints D /1) n l.D n = N(n l.D n) Q!,+The result of evaluating the following postfi! e!pression is 5# J# B# .# 0# A# B# 9# I# 0# * #$%5B%C5 #C%C1#&%CB $ns (C) Q!,, A graph with n vertices will definitel" have a parallel edge or self loop if the total numberofedges are #$%more than n#B%more than n6" #C%more than #n6"%7' $ns (D) #&%morethann#n8"%7' Q!,- 'ut of the following# the slowest sorting procedure is #$%Suic$ =ort#B%@eap =ort #C%=hell =ort#&%