C Programming MCQ
C Programming MCQ
fn(int arr[4][10]) fn(int arr[][10]) fn(int arr[4][]) none of the above Correct Ans : 1,2 2/439
W h a ti sf u n c t i o nt oc o n c a t e n a t et w os t r i n g s ?
fputc() fprintf() fwrite() fputs() Correct Ans : 2 4/439 What would be printed on the standard output as a result of the following code snipper?
m a i n ( ) { e n u m { r e d , g r e e n , b l u e = 0 , w h i t e } ; p r i n t f ( " % d% d% d% d " , r e d , g r e e n , b l u e , w h i t e ) ; r e t u r n0 ; }
control passes to the initialization of the loop control passes o the condition of the loop control passes to the beginning of the loop control passes to the change expression of the loop. Correct Ans : 4 6/439
W h i c hs t a n d a r df u n c t i o ni su s e dt oc l e a rt h em e m o r ya l l o c a t e db yt h em a l l o c ( ) f u n c t i o n ?
free()
calloc delete release Correct Ans : 1 7/439 Choose the correct answer from given options about the given source code in C Language :
# i n c l u d e < s t d i o . h > # d e f i n eC1/ /L i n e1 m a i n ( )
Compile time Error on Line 2: can't create case using variable value Compile time error on Line 3: can't use macro in the place of case declration Print on standard output : GOOD Print on standard output : GOOD but BAD Correct Ans : 1 8/439 What will be printed on the standard output as a result of the following code snippest?
v o i dm a i n ( ) { c h a ra r r [ ] = { ' R ' , ' A ' , ' M ' , \ 0 ' } ; p r i n t f ( " % d " , s t r l e n ( a r r ) ; }
It is a storage-class specifier It guarantees that the variable is kep in the CPU register for maximum speed. It requests that the variable be kept in the CPU register for maximum speed. It does not guarantee that variable value is kep in CPU regiser for maximum speed Correct Ans : 1,3,4 11/439
G i v e nt h ef o l l o w i n ga r r a y i n ta [ 2 ] [ 3 ] [ 4 ] ; W h a tw o u l db et h en u m b e ro fe l e m e n t si na r r a ya ?
24 22 20 12 Correct Ans : 1 12/439 What would be printed on the standard output as a result of the following code snipper?
# d e f i n em a x ( a , b ) ( ( a ) > ( b )? ( a ) : ( b ) ) m a i n ( ) { i n ta = 4 ; f l o a tb = 4 . 5 ; p r i n t f ( " % . 2 f \ n " , m a x ( a , b ) ) ; }
T h ed e c l r a t i o ni n t* ( * p ) [ 1 0 ]i n d i c a t e st h a t:
p is an array of pointers to functions the return type of which is an integer p is a pointer to a function that returns a pointer to an integer p is a pointer to an array of integer pointers p is a pointer to a character string Correct Ans : 2
strlen() strcmp() strcpy() strcomp() Correct Ans : 4 15/439 What will be printed on the standard output as a result of the following code snippest?
v o i dm a i n ( ) { i n ta r r [ ] [ 2 ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; p r i n t f ( " % d " , a r r [ 2 ] [ 1 ] ) ; }
1313
1313 1311 1300 3131 Correct Ans : 3 17/439 What will happen when the following code is executed?
{ i n tn u m ; n u m = 0 ; d o { n u m ; p r i n t f ( " % d" , n u m ) ; n u m + + ; } w h i l e ( n u m > = 0 ) ; }
The loop will run infinitely The program will no enter the loop There will be a copilation error A runtime error will be reported Correct Ans : 1 18/439
W h i c hf u n c t i o nw i l ly o uu s et op o s i t i o nt h ef i l ep o i n t e ra tt h eb e g i n n i n go ft h e f i l e ?
rewind() fseek() fscanf() a or b Correct Ans : 2 19/439 What will be printed on the standard output as a result of the following code snippest?
m a i n ( ) { i n tn u m = 4 2 5 ; p r i n t f ( " % d " , p r i n t f ( % d " , n u m ) ) ; }
Will result in compilaion error? 4425 4253 none of the above Correct Ans : 3 20/439
20/439
W h i c hf u n c t i o na l l o c a t e sm e m o r ya n di n i t i a l i z e se l e m e n t st o0 ?
assign() calloc() malloc() allocate() Correct Ans : 2 21/439 What would be printed on the standard output as a result of the following code snipper?
m a i n ( ) { s i g n e dc h a ri = 1 ; f o r ( ; i < = 2 5 5 ; i + + ) p r i n t f ( " % d " , j ) ; r e t u r n0 ; }
copilation error 1 2 3 .255 1 2 3 127 1 2 3..127-1280 1 2 3.(infinite times) Correct Ans : 4 22/439
W h i c ho ft h ef o l l o w i n gi sn o tav a l i dm o d ef o ro p e n i n gaf i l e ?
The element will be set to 0 Nothing ; it is commonly done it is undefined behaviour you will get an error message from the compiler Correct Ans : 2 24/439
W h a ti st h er e t u r nt y p eo ft h ef o l l o w i n gf u n c t i o nd e c l r a t i o n ? F u n c ( c h a rc ) ;
== != <> >= Correct Ans : 3 26/439 What would be printed on the standard output as a result of the following code snipper?
m a i n ( ) { c h a ro p t i o n = 5 ; s w i t c h ( o p t i o n ) { c a s e' 5 ' : p r i n t f ( " c a s e1 " ) ; b r e a k ; c a s e5 : p r i n t f ( " c a s e2 " ) ; b r e a k ; d e f a u l t : p r i n t f ( " c a s e3 : " ) ; b r e a k ; } r e t u r n0 ; }
case 1
W h a td o e st h ef o l l o w i n gf u n c t i o nd o ? i n tf n ( u n s i g n e di n tx ) { i n tc o u n t = 0 ; f o r ( ; x ! = 0 , x & = ( x 1 ) ) c o u n t + + ; r e t u r nc o u n t ; }
Returns the minimum number of bits required to represent the number x Returns the number of zero bits present in the number x Returns the number of 1 bits in the number x Returns the square root of the number Correct Ans : 3 29/439
I no r d e rt or e a ds t r u c t u r e s / r e c o r d sf r o maf i l e ,w h i c hf u n c t i o nw i l ly o uu s e ?
fscanf()
W h i c ho ft h ef o l l o w i n gs t a t e m e n t sw i l lr e s u l ti nac o m p i l a t i o ne r r o r ?
int n=5, x; x=n++; int n=5,x; x=++n++; int n=5,x; x=(n+1)++; int n=5, x=6; x=(n+x)++ Correct Ans : 2,3,4 32/439
# i n c l u d e < s t d i o . h > i n tm a i n ( ) { i n ti = 1 ; f o r ( i = 0 ; i = 1 ; i = 1 ){ p r i n t f ( " % d" , i ) ; i f ( i ! = 1 )b r e a k ; } r e t u r n0 ; }
The first command line parameter has been passed to the program The program name The number of command line parameters None of the Above a static array hold arg information Correct Ans : 2 34/439
521 752
752 52 compile time error in : conditional part of loop Correct Ans : 3 36/439
W h a tw o u l db ep r i n t e do nt h es t a n d a r do u t p u ta sar e s u l to ft h ef o l l o w i n gc o d e s n i p p e s t ? m a i n ( ) { i n tn = 5 , x ; x = n + + ; p r i n t ( " % d " , x ) ; x = + + n ; p r i n t f ( " % d " , x + + ) ; p r i n t f ( " % d " , x ) ; r e t u r n0 ; }
d a t a?
int i; char c; i=c; c=i; int i; char c; c=i; i=c; int i; float f; i=f; f=i; None of the Above Correct Ans : 2,3 39/439
# i n c l u d e < s t d i o . h > i n tm a i n ( ) { f o r ( ; ; ){ p r i n t f ( " % d" , 1 0 ) ; } r e t u r n0 ; }
10 10 10 10 .. Infinite time It will not print anything on the screen syntax error in for loop Correct Ans : 2 40/439
W h a ti so u t p u to ff o l l o w i n gp r o g r a mw h e nw ec o m p i l ea n dr u ni t ? v o i dm a i n ( ) { i n t c o n s t*p = 5 ; p r i n t f ( " % d " , + + ( * p ) ) ; }
print 6 on standard output Compile time error in pointer declration Can't Say (Pointer dangling) None of the above Correct Ans : 2 41/439
W h a ti so u t p u to ff o l l o w i n g v o i dm a i n ( ) { c h a rc h ; f o r ( c h = 0 ; c h < = 1 2 7 ; c h + + ) p r i n t f ( " % c % d\ n " ,c h ,c h ) ; }
Compile time Error because : Can't apply ++ on char data type Will print 128 characters with corresponding ASCII code Loop execute infinite
Error in printf statement : i[s] is not valid, you can't put array name in subscript Print the following output : man man man man Print ouptut : m m m m a a a a n n n n None of the above Correct Ans : 3 43/439
W h a ti so u t p u to ff o l l o w i n g ? ? m a i n ( ) { f l o a tf 1=1 . 0 ; d o u b l ef 2=1 . 0 ; i f ( f 1 = = f 2 ) p r i n t f ( " Il o v eU " ) ; e l s e p r i n t f ( " Ih a t eU " ) ; }
Print : HELLO Print only : H Error in printing Error in String initialization Correct Ans : 4 45/439
W h a ti so u t p u to ff o l l o w i n g ? m a i n ( ) { i n ta = 1 0 , * j ; v o i d* k ; j = k = & a ; / /L i n e: 1 j + + ; k + + ; / /L i n e:2 p r i n t f ( " \ n% u% u" , j , k ) ; }
Error on Line 1 : can't assign value from k to j Error on Line 2: can't apply ++ unary operator on void * pointer Print the same value for both k & j None of the above Correct Ans : 3 46/439
W h a tv a l u e sa r ep r i n t e dw h e nw er u nf o l l o w i n g ?
Output will be : 2 2 2 2 2 2 3 4 5 7 Error on Line 1: can't copy or assign int[] array to pointer Output will be : 2 3 4 5 6 7 2 3 4 5 6 7 Error on Line 1: Can't initialize int type of array with double type of literal in braces data set. Correct Ans : 1 48/439
m a i n ( ) { i n ti = 1 , j = 1 , k = 0 , l = 2 , a ; a = i + + & & j + + & & k + + | | l + + ; p r i n t f ( " % d% d% d% d% d " , i , j , k , l , a ) ; }
0 -1 2 1 3 00131 Error in expression assigned to a on Line 1 Output : -1, -1, 0, 3, 4, Correct Ans : 2 49/439 What will be printed on the standard output as a result of the following code snippest?
10 10 2 10 2 2 10 2 10 10 10 10 Correct Ans : 2 50/439 What will be printed on the standard output as a result of the following code snippest?
m a i n ( ) { i n ti = 1 ; w h i l e( i < = 5 ) { p r i n t f ( " % d " , i ) ; i f( i > 2 ) g o t oh e r e ; i + + ; } } f u n ( ) { h e r e : p r i n t f ( " P P " ) ; }
1 2 3 PP 4 PP 5 PP 1 2 3 4 5 PP PP PP PP PP Compile time error in program : Undefined label here : Compiler Error : Can't transfer label control using goto outside function. Correct Ans : 3 51/439
51/439
Compile time error Warning : possibly incorrect assignment in if statement 2 24 Correct Ans : 2,3 53/439
# i n c l u d e < s t d i o . h > i n tm a i n ( ) { i n ti , j ; i = j = 2 , 3 ; w h i l e ( i & & j + + ) p r i n t f ( " % d% d " , i , j ) ; r e t u r n0 ; }
12 13 will not print anything print value of i & j infinite Correct Ans : 2
Start End Start Start Start Start Start Start Start it will print anything on the screen Correct Ans : 2 56/439 What will be the output of following code when execute ?
# d e f i n eC U B E ( x )( x * x * x ) # d e f i n eM5 # d e f i n eNM + 1 # d e f i n eP R I N Tp r i n ( " H . G y a n " ) ; v o i dm a i n ( ) { i n tv o l u m e= C U B E ( 3 + 2 ) ; c l r s c r ( ) ; p r i n t f ( " % d% d" , v o l u m e , N ) ; P R I N T g e t c h ( ) ; }
125 6 H. Gyan 17 6 H. Gyan 125 5 H. Gyan None of the above Correct Ans : 2
57/439
# i n c l u d e < s t d i o . h > i n tm a i n ( ) { i n ti = 2 , j = 2 ; w h i l e ( i + 1 ? i : j + + ) p r i n t f ( " % d " , i ) ; r e t u r n0 ; }
10 11 12 1
Compile time error : Multiple declration of a 8 2 None of the above Correct Ans : 1 62/439
# i n c l u d e < s t d i o . h > v o i dm a i n ( ) { s w i t c h ( 2 ) { c a s e1 L : p r i n t f ( " N o " ) ; c a s e2 L : p r i n t f ( " % s " , " I " ) ; g o t oL o v e ; c a s e3 L : p r i n t f ( " P l e a s e " ) ; c a s e4 L : L o v e : p r i n t f ( " H i " ) ; } }
I IPleaseHi IHi
www.gvcjaipur.co.in Compile time error : nested switch is not allowed Compile time error : loop can't be inside switch case None of the above Correct Ans : 1 64/439
# i n c l u d e < s t d i o . h > v o i dm a i n ( ) { s t a t i ci n ti ; i n tj ; f o r ( j = 0 ; j < = 5 ; j + = 2 ) s w i t c h ( j ) { c a s e1 :i + + ; b r e a k ; c a s e2 :i + = 2 ; c a s e4 :i % = 2 ; j = 1 ; c o n t i n u e ; d e f a u l t :i ; c o n t i n u e ; } p r i n t f ( " % d " , i ) ; }
Compile time error on Line #1 : misplaced continue; It will print garbadge value , because i is not initlized 0 6 Correct Ans : 1 66/439
# i n c l u d e < s t d i o . h > # d e f i n eT R U E1 v o i dm a i n ( ) { s w i t c h ( T R U E ) { p r i n t f ( " w w w . g v c j a i p u r . c o . i n " ) ; } }
Compiler Error : at least one case required in switch control It will print nothing on console print : www.gvcjaipur.co.in None of the above Correct Ans : 2 67/439
# i n c l u d e < s t d i o . h > v o i dm a i n ( ) { u n s i g n e dc h a rc = 2 8 0 ; s w i t c h ( c ) { p r i n t f ( " S t a r t \ t " ) ; / /L i n e# 1 c a s e2 8 0 : p r i n t f ( " A " ) ; c a s e2 4 :p r i n t f ( " B " ) ; d e f a u l t : p r i n t f ( " C " ) ; p r i n t f ( " E n d " ) ; } }
Will Print : B C End Compile time error on Line #1 Compiler will show warning message on Line#1 : unreachable code Start B C End Correct Ans : 1,3 68/439
# i n c l u d e < s t d i o . h > i n tm a i n ( ) { i n ti = 5 ; i n ta = + + i++ + i++ + i ; p r i n t f ( " % d " , a ) ; r e t u r n0 ; }
rem = 3.14 % 2.1; rem = modf(3.14, 2.1); rem = fmod(3.14, 2.1); Remainder can't be obtain in floating point values Correct Ans : 3 70/439
W h i c ho ft h ef o l l o w i n gs p e c i a ls y m b o la l l o w e di nav a r i a b l en a m e ?
71/439
B yd e f a u l tar e a ln u m b e ri st r e a t e da sa
1 1 and 3 1 and 2 2 Correct Ans : 2 74/439 In the following program where is the variable a getting defined and where it is getting declared?
extern int a is declaration, int a = 20 is the definition int a = 20 is declaration, extern int a is the definition int a = 20 is definition, a is not defined a is declared, a is not defined Correct Ans : 1 75/439
W h e nw em e n t i o nt h ep r o t o t y p eo faf u n c t i o n ?
float, double short int, double, long int float, double, long double double, long int, float Correct Ans : 1 77/439
W h i c hs t a t e m e n tw i l ly o ua d di nt h ef o l l o w i n gp r o g r a mt ow o r ki tc o r r e c t l y ? # i n c l u d e < s t d i o . h > / /a d ds t a t e m e n th e r eL i n e:2 i n tm a i n ( ) { p r i n t f ( " % f \ n " ,l o g ( 3 6 . 0 ) ) ; r e t u r n0 ; #include "dos.h" }
#include"math.h" #include"dos.h"