C Programming ACE
C Programming ACE
Programming Languages
04 . main()
Level-1 Questions
{
printf("\nab");
Basics: printf("\bsi");
printf("\rha");
0 1. main() }
(a) hai (b) ab
(c) ha (d) si
extern int i;
(a) 0 (b) I
(a) 10 (b) 0
(c) 14 (d) I 0
(c) I (d) None of these
India '• Beet Online Coachln& Platfo rm for OATlt, ltBlt, PSUe, 88C-Jlt, SBC, Banke, Groupe a, PBC bame
{ }
ex tern out; (a) 1 = = l is TRUE
printf("¾d", out); (b) l = =l is FALSE
} (c) l= = l
Recular Live Doubt clearln1 Se-■lon• I Free Online Teat Serles I ASK an expert
ace Affordable Fee I Available lM I 3M I 6M 112M I 18M and 24 Month• Sub■crlptlon Packages
online
;u@YhhhhihMMIIIYihi~
15. inti ; 19. main()
main()
{
regi ster int a=2;
int t ;
printf("Address of a = ¾d", &a);
for(t=4 ;scanf("%d" ,&i)-t;printf(" ¾ d\n" ,i))
printf("¾ d--" ,t--); printf("Value of a = ¾d", a);
} }
If the inputs are 0, 1,2,3 then what is the output? (a) 2
(a) 4--0, 3--1 , 2--2 (b) 0--4, 2--2, 3--2 (b) Compiler Error
(c) 2--2, 3--3, 0--4 (d) 4--0, 2--0, 2--3 ( c) Runtime Error
(d) None of the above
16. main()
{
20. main()
int a= 0;int b = 20 ;char x = 1;
chary =10; {
if(a,b,x,y) extern i;
printf("hello"); printf(" ¾d\n", i);
} {
(a) hello (b) 0
inti= 20;
(c) 20 (d) 10
printf(" ¾d\n", i);
5 ;p@@hhhhldWl®m~
{ i = 20;
printf("¾d", sizeof( i));
int i = -1 , j = - 1, k = 0 / = 2 m ·
' ' ' }
m = i++&& j++ && k++11 /++·
II '
(a) 20 (b) Linker E rror
printf(" ¾d ¾d ¾d ¾d ¾d" i J. k / m)·
' ' ' ' ' , ( d) Runtime E rror
(c) Compiler Error
}
(a) 0 0 l 3 l (b) 0 1 0 3 l
27. main()
(c) 0 0 1 1 1 (d) 0 0 l l 3
{
char not; not= !2;
23 . main()
printf("¾d", not);
{
}
printf(" ¾x", - 1 <<4);
(a) I (b) 2
}
(c) 0 (d) No output
(a) 0fff (b) 0123
(c) fffO (d) fffl
2 8. int i=l0;
main()
24. main()
{
{
extern inti;
inti = 5 ;
printf("%d%d% d% d%d", i++,i--,++i,--i, i);
int i= 20;
}
(a) 54545 (b) 65545
( d) Compiler Error const volatile unsigned i= 30;
(c) 45545
printf("¾d" ,i);
25 . enum color{BLACK, BLU E, GREEN };
main() printf("¾d" ,i);
{ }
printf("¾d ..¾ d .. ¾ d" ,BLACK,BLUE, GREEN);
printf("¾d" ,i);
return() ) ;
}
(a) 30,20 , I 0 (b) I 0,20,30
(a) 2 .. 1..0 (b) 0 .. 1..2
(c) 20, 10,30 (d) 20,30, I 0
(c) 1..2 .. 3 (d) Runtime Error
Recular Ll•e Doubt cleartn1 8eeel o n• I F ree Online Teet Berle• I ABK an expert
ace Affordable Fee I Available lM f I 6M I 12 M I 18M and 24 Montha S ub•~rt
online 3M ~ p t i on p ackqe■
•AIP@hhhhhiiiiQ~
2 9 . # include<stdio.h>
32. void main()
main()
static int i= 5;
const int i=4 ; if(- - i)
float j; {
j = ++i; main();
}
(a) 4 }
(b) 5
(a) 0 0 0 0 (b) 5 5 5 5
(c) Runtime Error ( d) Compiler Error
(c)4444 (d) 2 2 2 2
30. main()
33. void main()
{
{
inti= l_ abc(IO);
unsigned giveit= - 1;
printf(" ¾d\n", - -i);
int gotit;
}
printf("¾u" ,++giveit);
int I a bc(int i) printf("¾u \n", gotit = - -giveit);
{ }
return( i++); Assume that unsigned int range is O to 65535
} (a) l 65535
(a) 10 (b) 9 (b) I 65534
(c) 8 (d) 11 (c) 0 65535
( d) None of these
31. main()
{ 34. void main( )
{
int i =O;j =O;
static int i=i++, j =j ++, k=k++;
if(i && j ++)
printf("i = ¾d, j = ¾ d, k = ¾ d", i, j , k);
printf("¾d .. ¾ d",i++,j);
printf("¾d .. ¾ d" ,i,j);
(a) i = 1, j = 2, k = 3
(b) i = 2, j = I, k = 2
(a) 0..0 (b) 1..0
(c)i = 1, j = l ,k = 1
(c) o.. J (d) I.. I
(d) None of these
ace India'■ Be■t Onllne Coachlnc Platform for OATlt, 11:81!:, PSU■, SSC-JE, SSC, Bank■, Group■ & PSC Eu ~
onllne Eajoy a ■ mooth onUne learnlnc e•perlence lo vulou■ lanllJ ■jle■ at your convenience
-
7 iQi@000iOIOiMli@@~
35. What is the output for the program given below. 39. main()
typedef enum errorType {warning, error,
exception} error;
int i=4,j=7;
main()
j = j :: i++ && printf(" YOU CA N") ;
{
error gl ; printf("¾d ¾d", i, j);
gl=l ;
printf("¾d" ,g l );
} (a) YOU CAN
(a) l (b) Compiler Error (b) 4 7
( c) Runtime Error (d) Garbage value (c) 4 1
(d) Compiler Error
36. typedef struct error {int waming,error, exception;}
error;
40 . main()
main()
{ {
{ {
inti =5; int day,month,yea r;
printf ("¾d", i= ++i = = 6); };
}
scanf("¾s ¾ d ¾ d ¾ d", stud.rollno,
(a) l (b) O (c) 6 (d) 5
&studen t.dob.day,&studen t.dob. month,
{
int i= 10,j =20;
j = i, j?(i,j)? i:j :j ; (a) Runtime Error
printf("¾d ¾ d", i,j); (b) Compiler Error
} (c) Linker Error
(a) l O 20 (b) 10 10
(d) No output
(c) 20 30 (d) 20 20
Re1ular Live Doubt clearln1 Se ■■ lon• Free Online Teet Be rl e■ I ASK • n exp o rt
ace I I I 6M j 12M I 18M and 24 Month■ S ubacrlptlo n Pa ckag es
online Affordable Fee Available lM 3M
r ,
8 iFMliliillili4MINY~
Functio ns: 44. main()
{
41. #define square(x) x*x show();
main() }
{
void show()
inti;
{
i = 64/square( 4);
printf("I'm the great~st");
printf("¾d " ,i);
}
}
(a) I'm the greatest (b) Compiler Error
(a) 64 (b) 4
( c) Runtime Error ( d) None of these
(c) 16 (d) None of these
} main()
(a) 5 (b) PP
( c) Compiler Error ( d) Runtime Error int (*ptr[3])( );
ptr[0]=aaa;
43. #define f(g,g2) g##g2 ptr[ l ]=bbb;
main()
ptr[2]=ccc;
{ int var! 2 = I 00;
ptr[2]();
printf("¾d ", f(var, 12));
}
(a) 100 (b) 90 (a) aaa (b) bbb
(c) 95 (d) None of these (c) he llo (d) bye
!Yace India'• Beat Online Coachl n1 Platform for GATE, ESE, P8Ua, 88C-J£, 88C , Banke, Groupe & PSC E:a:ama
~ online En.Joy a •moo tb o nlln e leamln1 ea:porience tn varioua lan&u•1•• at your convenience
jalEA_.C~ - 9 ;QHM60000i410Nid~
47. vo id main()
50. int DIM(int array[ ])
{
{
int k= ret(sizeof(floa t));
return sizeof(array)/ sizeof(int );
printf("\n here value is % d", ++k);
}
}
main( )
int ret(int ret)
{
int arr[l0] ;
ret + = 2 .5;
printf("The dimension of the array is % d",
return(ret);
DIM(arr)) ;
} }
(a) 2 .5 (b) 6 (a) 0 (b) 1
(c) 7 (d) 5 (c) 3 (d) 5
Re1 ular Llve Doubt clearln1 Seaalon■ I Free Online Te ■t Berle ■ I ASK an ezpert
ace Affordable Fee I Available lM I 3M I 6M I l~M I 18M and ~4 Month■ &ub■crlpj:lon Packace■
online
10
iiNY@ihhOOAMO@h~
auto inti, j ; {
i = reset ( ); printf(" ¾d" ,n);
fo r (j = 1; j <=3; j + +)
{ else
printf(i, j); {
printf(next(i)); f(n/2) ;
printf(last(i)); printf(" ¾d" ,n%2);
printf(new( i + j));
}
} }
} What does f ( l 73) print?
int reset (void)
(a) 010110101
{
(b) 010101101
return (i);
(c) 10110101
(d) 10 10 11 01
N Tace India'• Be■ t
Online Coachln1 Platform fo r GATE, ESE, PSUa, SS C-J E, SSC, Banlu, Group• & PS C Exam•
'---~---=-_o,!_!n~ll!n
!. . !.:e~ _ J_____E_:nj....:oy:.....__a_• m_ o_o_th_ on1_1_n_e _le_ar_n_ln-=''-e_xp:_e_rt_e_nc_e_l_n _• a_rl_o_u_. _1a_n:::..._
cuai .=.e_•_•_t _;_
yo_ u_r_c_o n
_ v....:.
e....:.
nl_e_n c_e_ _ __
11 iQdN@i!OOOiYiiiMihM~
rvr ace India'• Beat Online Coachln1 Platrorm (or GATE, ESE, PSUa, 8SC-JE, SSC, Banke, Groupe Ill PSC Exam•
~ online Enjoy a amooth onllne learnln1 ezperlence In v arioua Iancu•1•• at your co nvenJence
13 •Pi@Bhhhiii4MiiNlh~
63. Assume that base address of array is 100 and 65 . main( )
integer occupies '2' bytes then the output is {
main() static int a[]= {0,1,2,3,4};
{ int *p[] = {a,a+l ,a+2 ,a+3,a+4 };
int a[2][3][2]={ { {2,4}, {7,8}, {3,4 } },{ {2,2}, int **ptr= p;
{2,3}, {3,4} }}; ptr++;
printf("%u%u%u%d\n" a *a **a ***a)· printf("\n¾d¾d¾ d", ptr-p, *ptr-a, * *ptr); *ptr++;
' ' ' ' '
printf("%u%u%u%d\n" a+ 1 *a+l **a+l printf("\n¾d¾d¾ d", ptr-p, *ptr-a, **ptr);*++ptr;
' ' ' '
printf("\n¾d¾ d¾ d", ptr-p, *ptr-a, **ptr);++*ptr;
***a+l);
} printf("\n ¾d ¾d ¾d", ptr- p, *ptr-a, **ptr);
}
(a) I 00, 100, 100, 2
(a) 111 , 222,333, 444 (b) 444, 333, 222, 111
112, 104, 102, 3
(c) 111,222, 333 , 344 (d) Compiler Error
(b) 2, 100, 108, 100
104, 110, 100, 3
66 . main()
(c) 100, 2, 100, 2
{
3, 114, 104, 100 vo id *vp ;
(d) 100, 100, 2, 100 char ch = ' g' , *cp = " goofy";
114, 104, I 02, 3 int j = 20;
vp = &ch;
64. main() printf("¾c", *(char *)vp);
{ vp = &j ;
int a[] ={ 10, 20, 30, 40, 50}j,*p; printf("¾d", *(int *)vp );
for (j=0 ; j < 5; j ++) vp = cp ;
{ printf("¾s",(char *)vp + 3);
printf("%d", *a); }
(a) g20fy (b) goofy
a+ +;
(c) goofy20 (d) goo20
}
p = a;
67. main()
for(j = 0; j <5; j++)
{
{ char *strl = " abed";
printf("%d", *p );
char str2[ ] = "abed";
p++; printf("¾d ¾ d¾ d", sizeof(strl ), sizeof(str2),
} sizeof("abcd"));
} }
(a) 10 (b) 50 (a) 2 5 5 (b) 5 2 5
(c) Compiler Error ( d) Runtime Error (c) 5 5 2 (d) Compiler Error
Regular Live Doubt clearing Se-■lon■ I Free Online Te■t Serie■ I ASK an ezpert
ace Affordable Fee I Available lM I 3M I 6M I l2M I 18M and 24 Month■ Sub■crlptlon Package■
online
•PiiMFhi!w\h◄Mii@Ft~
68 . ma in() (a) 3 (b) Compiler Error
{ (c) Runtime Error (d) Garbage value
int *j;
{ 71. main()
int i = 10 ; {
j = &i ; char *p;
}
p="¾d\n";
printf("¾d" ,*j);
p++;
}
p++;
(a) 10 (b) Compiler Error
printf(p - 2,300);
( c) Runtime Error (d) None of these
}
(a) 302 (b) 300
69. struct point
(c) 304 (d) 298
{
int x;
int y; 72. void main( )
}; {
struct point origin, *pp; void *v;
main() int integer= 2;
{ int *i = &integer;
pp=&origin;
V = i;
printf("origin is (¾ d, ¾d)\n",(*pp).x,(*pp ).y);
printf("¾d" ,(int*)*v );
printf("origin is (%d,%d)\n", pp-x, pp-y);
}
}
(a) originis(0; l) (b) origin is (0,0) (a) 2
ptr+==3; }
printf("¾d", *ptr); (a) 1 (b) 2
(c) 3 (d) 4
,-Y, a ce India' ■ Be■ t Online Co achin& Platform for GATE, ESE, PSU■ , SSC-JE, SSC, Bank ■ , Group ■ & PSC Exams
~ online Enjoy a ■mooth o nllne learnln& experience In varlou■ lanpa&e■ at your convenience
15 iQIMFIOhih!AMO@w~
74. What is the output for the following program? (a) Garbage value, zeros
main()
(b) Compiler Error
{ (c) Runtime Error
int arr2D[3][3] ; (d) None of the above
printf("%d\n" ,((arr2D== *arr2D)&&
(*arr2D = = arr2D[0]))) ; 78 . main()
} {
(a) 0 (b) I int a = 2, *fl, *£2;
(c) 2 (d) 3 fl= f2 = &a;
*f2+=*f2+=a+ =2.5;
75. main() printf("\n¾d ¾d ¾d", a, *fl , *£2);
{ }
}
79. main()
(a) b (b) ayqm
(c) d (d) Compiler error
char *p="GOOD";
char a[ ]="GOOD";
76. main()
printf("\n sizeof(p) = ¾ d,
{
sizeof(*p) = ¾ d,
char P[ ] = "ayqm";
strlen(p) = ¾ d",
char c; sizeof(p ), sizeof(*p), strlen(p));
C = ++*P; printf("\n sizeof(a) = ¾ d, strlen(a) = ¾ d",
printf("%c", c ) ; sizeof(a), strlea(a));
} }
(a) aygm (b) g The output of the above program is _ _ .
(c) b (d) y
80. main()
77. void main( ) {
{ int i = 257;
int *mptr, *cptr; int *iPtr = &i;
mptr = (int*)malloc( sizeof(int)); printf("%d%d" , *(( char*)iPtr), *(( char*)iPtr+ I));
printf("%d", *mptr); }
int *cptr = (int*)calloc(s izeof(int), I);
printf("%d", *cptr); (a) 1 I (b) 1 2
(c) 2 I (d) None of the above
}
Recular Liv e Doubt c l earl n&Se ■■ lon• I P'ree Online Teat Serie• I ASK an eapert
ace Affordable P'ee I Available lM I 3M I 6M I llM I 18M and l4 Mo n t h• S ubacrlptlon Packae:e•
online
•PdMFl!OhhiMMi@ih~
84. What is the suitable error in the following code typedef struct a a Type;
segment? struct a
{ int x;
int *p = O; aType *b;
inti = O; };
while(i++<n)
p = &arr[i] ;
(a) Yes (b) No
*p = 0;
India '■ Beat Online Coachln,: Platform for GATE, ES E, PSU■ , SSC-JE, SSC, Bank■ , Group ■ & PSC Exam•
!Y ace
~ online Eajoy a ■mooth o nline l earhln,: ~erlence In varlou■ lan,:uar;e• at your conveD.ience
17 •PdMiihOOOMMh@h~
88. Is the following code legal? 91. Is this code legal?
void main() int *ptr;
{ ptr = (int *) 0x400;
typedef struct a a Type;
aType someVariable; (a) Yes (b) No
struct a
{ 92 . main()
int x;
aType *b; int a= 10,*j;
}; void *k;
} j = k = &a;
(a) Yes (b) No j++;
k++;
89. void main() printf("\n %u %u", j, k);
} 93 . char *somefun()
If the pointer size is 2 bytes then the output of the
above program is _ _ . char *temp = "string constant";
return temp;
int i= l 0, j =2 ;
int *ip= &i, *jp = &j ; puts( somefun() );
int k = *ip/*jp;
printf(" ¾ d",k); (a) Error
(b) Runtime error
}
(b) 10 (c) Compiler Error
(a) 5
(d) 2 ( d) String constant
( c) Compiler Error
Re&ular Live Doubt clearln& Be■■lon1 I Fre e Online Te1t Serie ■ I AS K an expert
ace Affordable Fee I Available 111 I 3M I 6M I 12 M I 1 8M and 2 4 Month■ Bu b1crlptlon Paclr.acee
online
iPMiiidliiiiMIIAli~
94. main() 96. main()
{ {
int num[ ] = {24, 34, 12, 44, 56, 17}; int stud[5][2] = {
{1234, 56},
inti = 0, *j ;
{1212,33},
j = &num[0] ;
{1434, 80} ,
while (i <= 5)
{1312, 78} ,
{
{1203, 75},
printf("\n address= %u", &num[i]);
};
printf("element = %d", *j);
int i,j;
i ++ ; for (i = 0; j<=4; i ++)
j++; printf("\n Address of %dth 1-D array =
} %u" , i, stud[i]);
} }
If base address of array is 65514 and integer Assume that base address of array is 65506 and
occupies '2' bytes then output of the above integer occupies '2' bytes then output of the
program is _ _ __ above program is
97. main()
95. main()
{
{
int stud[5)[2] = {
int num[ ] = {24, 34, 12, 44, 56, 17};
{1234, 56},
display(&num[0], 6);
{1212, 33 },
}
{1434, 80},
display(int *j, int n)
{1312, 78 },
{1203, 75 },
inti = I ; };
w hile (i <=n) int i,j ;
{ fo r (i = 0; i<=4 ; i ++)
[ 1',11 ace l ndla'a Beat On lin e Coaching Platform for GATE , ESE, PSUa, S SC-J E, SSC , Banke, Groupe • P SC Eaam a
~ online Enjo y a amoolh onUne learnl n & cnrp e rle nce In varlo ua lancua &• • a t :,o ur c onYenJence
~
;;,aqaoo,,0,11+1,mw~
98. main() 101. main()
{ int a[3][4] = { {
5, 7, 5, 9, int arr[]= {O, 1, 2, 3, 4 };
4, 6, 3, 1,
int *ptr;
2, 9,0, 6
for (ptr = &arr[O]; ptr<=&arr[4]; ptr++)
};
int *p; printf (" ¾d" , *ptr);
int (*q)[ 4]; }
p = (int *) a ; Output of the above program is _ _ .
q = a;
printf("\n ¾ u ¾ u", p,q) ; 102. main()
p++; {
q++; int arr[]= {0, 1, 2, 3, 4 };
printf("\n ¾ u ¾ u", p,q) ; int i, *ptr;
}
for (ptr = &arr[0] , i = 0; i <= 4; i++)
If the base address of array is 65502 then output
printf (" ¾d" , ptr[ i]);
of the above program is _ _ .
}
99. main() Output of the above program is _ _ .
{
static int a[]= {0, 1, 2, 3, 4 }; 103. main( )
static int *p[ ] = {a, a+ 1, a+2, a+ 3, a+4}; {
printf("\n ¾u ¾ u ¾d", p, *p, *(*p)); int arr[]= {O, 1, 2, 3, 4} ;
} int *ptr;
If base address of 'a' is 170, base address of 'p' is for(ptr = arr + 4, ptr >= arr; ptr- - )
180 then output is _ _ __ printf ("¾d", arr[ptr-arr]) ;
(a) 0l70180 (b) 180 170 0 }
(c) 170 0 180 (d) 0 180 170 Output of the above program is - - -
106. main( )
L
{ 108. main()
a
static int a[3] [3] = { {
I, 2, 3, int c[] = {2.8, 3.4,4, 6.7, 5};
4, 5, 6,
int j, *p = c, *q = c;
7, 8, 9
forU = 0;j<5;j + +)
};
static int *ptr[3] = {a[0], a[l], a[2]} ; {
int **ptrl = ptr; printf("%d", *c);
inti; ++ q;
for(i = 0; i<= 2; i++) }
I
printf ("%d" , *ptr[i]);
forU = 0; j < 5;j + +)
printf ("\n");
{
for (i = 0; i<=2; i++)
printf ("%d", *a[i]); printf("%d", *p );
printf ("\n"); + + p;
for (i = 0; i<=2; i++) }
{ }
printf(" %d", **ptrl);
(a) 2 2 2 2 2 3 3 4 6 5
ptrl ++ ;
(b) 2 2 2 2 2 2 3 4 6 5
}
(c) 2 2 2 2 5 5 3 4 6 5
}
Output of the abo ve program is _ _ (d) 2 2 2 2 3 3 3 4 6 5 I
tv, ace India 's Beat Onlin e Co a c hing Platform for GATE, ESE , PSUa, SSC-JE, SSC, Banka, Group• & PSC £llama
~ online EnJoy a smooth onllne learning ellperl ence In varloua lancuace• at your convenience
iPMIOOIOOAMOM!h~
120. main()
(a) I (b) 2
{
(c) - I (d) 0
inti= 3;
for (;i++ =0;) printf("¾d",i);
I I 7 . What is the output of the program given
below? }
s igned char i= 0;
for(;i >=O;i++) ; 121 . void main( )
printf("¾d\n" ,i);
static int i;
(a) - 128 (b) 128 while(i <= 10)
(c) 127 (d) - 127
(i > 2)? i++: i- - ;
printf("¾d", i) ;
I 18. ma in()
}
(a) 32767
unsigned char i=0;
(b) 32768
fo r( ;i>=0 ;i++) ;
(c) 32770
rrintf("%d\n" ,i );
(d) None of the above
A_;,; QCe - lµdla'a Be■t Online Coachlnc Platform for GATE, ESE, PSU■ , SSC-JE, SSC , Banks, Groupe & PSC Esam•
l
- - ~ - Q~n.:::;l:.:.in..;.=
e-_...,_____E_rtj:__o.::_y_a_•_m_oo_ t_b_o_nU_ n_e_le_•_rni
___:
n,
=-e- •-=-
P_e rl
_ e_n_ce_ l_n_v_u_lo
_ u_•_la_n.=
c_ua-=':_
e•_ •_t..:..y_ou
_ r_c_o_n v_e_n_le_nc_ e_ _ __ ,
iMi@?IMhhi4ii,M1&'"°9
l .::!2. main() Paramete r passing techniqu es:
{
float i= l. 5 ; 124. Aliasing in the content of programming languages
switch(i) refer to
{ (a) Multiple variables having the same memory
} write(a);
Replar Lh•e Do ubt c learlA& Seulo.,. I Free OnUne Teat Serlea I ASK an u :pert
ace Affordable Fee I AY&ilabl e 114 I 314 f 611 I 12M I l 8M and :J4 Month.a Subac rlpt l on p ac-.ace•
._
online
;Uh@hihhhhAl!iMI~
K = 3; return (y);
}
L = 5;
funcg (int x)
return (X + Y);
}
static int y = IO;
If the function P were invoked by the following
y += l ;
program fragment
return (y + x);
K := I;
}
L = I; (a) 43 80 (b) 42 74
Z = P(K, L); (c) 33 37 (d) 32 32
Then the value of Z would be equal to
(a) 2 (b) 3 (c) 4 (d) 8 02. void func(void);
int main (void)
{
Level-2 Questions
printf ("Lucknow\n");
goto ab;
return 0;
Functions:
}
void func (void)
0 I . What is the output of the following program?
{
#include <stdio.h>
ab:
int funcf (int x);
printf ("Bareilly\n");
int funcg (i nt y);
}
main ( )
{
03 . void func (int a, int b);
int x = 5, y = 10, count;
for (coun t= I; count <= 2; ++count) int main (void)
{
ace India' ■ Be ■ t Online Coachln& Platform for GATE, 11:811:, PBU■, 88C-JII:, 88C, Bank■ , Group■ a. PSC Exam•
online Eajoy a ■mooth onllna leunln& upertence In 'Hriou■ lancuece■ at your con•Hnlence
25 •Ai®ihhhih@ih@lh1
Resular Ll•e Doubt clearln1 8e■-lon• I Free Online Te ■t 8■ rle• I ABK an ellpert
ace Affordable Fee I A•allable 111 I 3M I 6 M I 12 M 11811 and 24 Month■ Sub■crlptlon Packa&e■
online
ilM61161Miil@i1
08. int func (int x ,int y); 11 . void func (int x, int y);
int main (void)
int main(void)
{
{
int p=func (5 ,6);
int x;
printf ("%d" ,P);
x=func (5,6)+100;
return O;
printf ("%d",x);
}
int func (int x,int y) return O;
int z;
Z = X + y;
09 . int min (int a, int b) ;
int main(void)
{
12. int diff (int x, int y)
int a= IO, b=5;
printf ("%d\n" ,min(a,b )); {
~ ace lndla'■ Beat On lin e Coa chln1 Platform for GATE, £1111:, PIIU■, 8110-JS, 8110, Baaka, Group■ a, P8C Sa• 111•
~- ~~
L____:_:::== Online
=-=-.c..:=.- Enjoy
- - ' - -- - - - a ■mooth onllne leamln& eaperlence In 'Hrloua la.n&11a1ea at your conye aJence
iPMhiiiiiiidG~
08. int func (int x,int y); 11 . void func (int x, int y);
int main (void)
int main(void)
{
{
int p=func (5,6);
int x;
printf ("¾ d" ,p);
x=func (5,6)+100;
return O;
} pn·ntf ("¾od" , x) ,·
rYt ace India'■ Be■t Online Coachln& Platform for GATE, EBE, PBU■, SSC-.JE, SSC, Bank■, Group■ • PSC EZ&JD•
~ online Enjoy a ■mooth onllne lea.mine eKperlence In varlou■ languace1 at your convalllence
►
27 ;;o@hihhiihi441•~
{ y = square3 (x);
int x= 1, y=2, z=3, resu lt; printf ("% 1f\t", y);
result = func (x,y,(z=S, z+ lO)); y = square4 (x);
printf ("x=¾d, y=¾d, z=¾d", x, Y, z); printf ("% 1f\t", y );
printf ("result=¾d\n", result); return O;
return O; }
} int squarel (int a)
func (int a, int b, int c) {
{ return a*a;
return 2* (a+b+c);
}
Re ,;ular Live Doubt c learln,; SeHlone Free Online Te at S e rie • I ASK an exp ert
~ ace Affordable Fe e I Available lM I 3M I 6M I 12M I 18M and 24 Mon th• Subacription Packages
~ online
iFIIMl@dfhPMiii ~
ace lndla'■ BHt Onllne Coachlnc Platform for GATE, ESE, PSU■, SSC-J S , SSC, Bank■ , Group•• PSC ham•
online Enjoy • amooth onllne lea.min& e,rpertence In vartou■ tanaua1e• at yow convenlence
►
29 ;;1@@ihhhhiih@h~
int func (int a, int b, int c) 24. int func (int x, int y);
int main (void)
return a, b, c;
{
}
int a=2, b=5;
a= func (a+b, a - b);
22. void func (int a, int b );
printf ("%d\n", a);
int main (void)
return O;
{
int i=5, j = l O;
int func (int x, int y)
func (i/2, j%3);
{
return O;
return x+y, x-y;
}
}
void func (int a, int b)
{
25 . int func (int k);
a/=2; int main (void)
b- - ; {
printf ("%d\t", a+b ); int i=O, k=3;
i+ = func (k);
i+= func (k);
23. int a=5; i+= func (k);
void func (void); printf ("%d\n", i);
int main (void) return O;
}
func( ); int func (int k)
printf ("%d\n", a) ; {
} m=m+k;
int a=2;
printf ("%d\t" , a);
Replar Live D oub t claarln& SeHlon• I Free Online Teat Serlea I ABK an eapert
ace Affordable Fee I Available IM I 3M I 6M I \ 2M I IBM and 2 4 Month• Subacrlption Packa&ea
online
;p;;@d\0000410~
} {
static int s=O;
inti;
27. void func (int a, static int b );
for (i=l ; i<=n ; i++)
int main (void)
s+=i;
{
func (1,2); returns ;
func (3 ,4) ; }
return O ;
30 . Rewrite the function func ( ) without using else
}
void func (int a, static int b) and variable x.
} {
int a, b ;
/Vf ace India' ■ Be ■t Online Coachlne Platform for GATE, ESE , PSU■ , SSC-JE , SSC, Banks, Orou a & PSC E•am•
~ online Enjoy a ■mooth oallne learnlne e:xperlence In vartou■ laneuaee• at your con ~eJtjen ce
•Ri@ihhhheAMi,Nlhij
int fl (int x, int y) Rewrite the following functions from Q32 to Q33
{ using a single return statement.
return x+y ;
} 32. int func (int n)
int t2 (int x, int y) {
{ if (n= =39)
return x - y ; {
} n+=5 ;
return n;
31. Rew rite the function func ( ) without using the }
variable flag. else
#include< math .h> return n;
int func (int n); }
int main (void)
{ 33 . int func (int x, int b)
int n;
printf ("Enter a number :"); if(x= = 5)
scanf ("¾d" , &n); return b+2;
printf ("¾d", func (n)) ; else if (x> 5)
return O; return b+ IO;
} else
int fun c (int n) return b;
int i, flag=O;
for (i=2, i<= sqrt (n); i++) Rewrite the following functions from Q34 to Q3 7
without using else.
{
if (n¾ i= =0)
34. int ispalindrome (int num)
{
flag= l ; {
ace India'• BHt Online Coachln1 Platform for OATII:, BBJE, P8Ue, 88C-JB, SSC, Banke, Groupe a. PSC Exam•
online Enjoy a amooth online learn1J11 eaperlence In variou■ lancua&ea at your conTellience
[•EA.C~
_ 33 _ _ _ _ _ __ _ _ __
_ _ _ _ _ _ _ _ _ _ _ _ _L__j_
.PMH@iihNiiiM:!1
Reiular Lin D o ubt olearla1 8eHloaa I f"rH Onllo• Tu t Serl ~J_ ~ ~ p ut~
Affordable Fee I Anilable lM I 311 I 611 I llM j 1911 an~ ~
--- --
Mouth. 81.Lhacrlptlou Pa.c:lr.aa;.. -
-
•P@hihhOOAMONih~
{
printf("%s", * - -*++p + 3);
(c) 7 5 (d) 65
I -~~ _
,Dc!!el~Q~_
aQ ___L_[n_d_l•_·•_ B
_•_• _
t 0
--=n
~ l:....
ln_• _C_o_•c_h_lD
_'_ P_l_
• t_fo_r_
m_r..:::
or_ O....:A
:....T_E_, -E-B E
_ ,_p_s_u_••_s_s_c ...:-J:....
Eajoy a amooth onllno learnin1 oxpertonco In vartoue tancua1ea at your con•entenca
S...:,:....
ss _ c_,..:
B_•n
_ ...
_·_· -0 -r o_"_P•_ •_ P_B_
C _Es
_ •_m
__•
iMhiillbliiiMHF~
4 7. int main( void)
51. int main (void)
Replar Live Doubt clearlnt: BeHlone Free Online Teat Serie ■ I ASK an expe rt
ace Affordable Fee I Anllable lM I 3M I 6M I 12M I 18M and 24 Month ■ Subacrlptlon Packages
online
•PMhibibii!Ail!&·h~
55. int main (void) 59. int main(void)
{
{
int a=9;
int a=5,b=6;
char ch= ' A' ;
printf("¾d\t" ,a=b);
a = a+ch+24;
printf("¾d\t" ,a==b);
printf("¾d,%c\t%d,¾ c\n", ch,ch,a,a);
return O; printf("¾d ¾ d\n", a,b);
} return O;
}
56. int main (void)
{ 60. int main(void)
int a,b,c,d;
{
a=b=c=d=4;
int a=3, b=4, c=3,d=4, x,y;
a*=b+l;
x= (a=5) && (b=7);
c+=d*=3 ;
printf("a=¾d, c=¾d\n" ,a,c); y= (c=5) :: (d=8);
return O; printf("a=¾d, b=¾d, c=¾d, d=¾ d, x=¾d,
} y=¾d\n" ,a,b,c,d,x,y);
x= (a == 6) && (b=9);
57. int main (void)
y = (c = =6) :: (d= lO);
{
printf(''a=%d,b=%d,c=%d,d=%d,x=%d,
int a = 5, b = 10, temp;
y=¾d\n", a, b, c, d, x, y);
temp = a, a = b, b = temp;
printf("a=¾d, b=¾d\n", a,b); return O;
return O; }
}
6 1. int main (void)
{
58. int main (void)
int a = 10;
{
a = a++;
int a = 10, b = 3, max;
a = a++ * a--;
a> b ? max = a : max = b;
printf("¾d\n",a);
printf("¾d\n", max);
printf("¾d\n" ,a++ * a++);
return O; return O;
}
ace India'• BHt Online Coachlnc Platform for GATE, ESE, PSUa, S8C-JE, SSC, Banka, Group• • PSC Saam•
online EnjoJ a amooth onllne Jea.rnlllc experience In • arloua lanpace• at Jow- c on•enience
►
tEUNibhhMAMONld~
62. int main (void)
65 . int main(void)
{
int a= 2, b=2, x,y;
inti= IO;
X = 4*(++a * 2+3);
i == 50;
y = 4* (b++ * 2+3);
if (i==50)
printf("a=¾ d, b=¾d, x=¾d, y=¾d\n",
printf (" i is fifty\n ");
a, b, x, y);
return O; else
printf (" i is not fifty\n");
return O;
Control Stateme nts: }
int a = O; i=j+2 ;
printf("¾d\n" ,i);
if (a = O)
return O;
printf ("a is zero\t");
}
else
printf ("a is not zero\t");
68. Write this statement using an if-else.
printf (" value of a is ¾ d\n" ,a);
x+= a < b ? (- x) : 100;
return O;
Regular Live Doubt clearln1 Senion■ Free Online Te1t Serie• I ASK an expert
ace Affordable Fee I Available lM I 3M I 6M I l2M I 18M and 24 Month• Sub■criptJon Pacllace■
online
;u@Fhhhhhiih@~
69. Rewrite the follo wing else ... .if chains using z- -;
switch. break;
(i) if(x== l) case 30:
y=x+ l ; switch(y)
else if(x= =2) {
{ case 2:
y=0; z =z+3 ;
x=0; break;
} case 4:
else if (x= =3 :: x= =4 :: x= =5) case 5:
y++;
z = z+l0;
else if (x= =6)
break;
y+=4;
default:
else
z = z-2 ;
y--;
}
(ii) if(x= = I) break;
y=x+ l; default:
else if(x= =2 :: x= =3 :: x= =4) z = 0;
y++;
}
else if (x= =5)
y- - ;
71 . What is the output of the following programs.
else if (x= = 6)
(i) int main (void)
y=0;
int a=5;
. ' ..
{
I ' ' ,
begin:
70. Write equivalent if .. . else statements for the
if(a)
fo ll owing nested switch statements.
{
int x,y; printf ("¾ d\n",a);
x=30, y=5, z; a - -·
'
switch(x) goto begin;
}
case 10: return 0;
z++; }
break;
case 20:
~ ace India' ■ Be ■ t Online Coacbln1 Pla tform for GATE, EBE, PBU■ , SSC-JE, SSC, Ba nk■ , Group ■ & PSC Esaall
I_~ online J!)ajoy a ■mootb onlln• learnln& ezperlen c e In varlou■ lancua1e■ at your c o nve nie nce
t
►
iPdN@lhhhiiAMhMld~
(ii) int main ( void)
(v) for (i=O; i<=IO; i - -)
{ printf ("¾d", i);
inta=5·,
begin: (vi) for (i=lO; i>= l ; i - - )
if (a) printf ("¾d",i);
if (i + + = = 3) }
break;
printf ("¾d", i); 81 . What is the output of the following for loops.
ace lndla'• BHt Online Coachln1 Platform for GATE, EBE, PBU■, BSC-JE, SBC, Bank■ , Group ■ 8t PSC E:u ui•
onllne Enjoy a amooth onllne leamln1 ~•rlence In varlou■ lanl\l-AIH at your convenJe nce
pa
41 iPd@hOO!OhAMOM!d~
(ii) for (j=l; j<=5; j++) break;
for (i=l; i<=6; i++) printf ("%d",i++, j- -);
printf ("*" );
}
printf ("\n"); (iii) for (i=2; i<==sqrt (n); i++)
if(n¾i = =0)
(iii) for (j= 1; j<=5; j++) break;
{
for (i=l ; i<=6; i++) 83. Will the two programs given below give same
printf("*"); output.
printf("\n"); (i) int main (void)
} {
inti = l,j=3 ;
(iv) for (k=l; k<=3; k++) while (i<5)
{ {
for (j=l; j<=5; j++) i++;
{ if G = =O)
for (i= l; i<=6; i++) break;
printf("*"); j - -;
printf("\n"); }
printf("\n"); return O;
}
}
82. Write the following loops without break (ii) int main (void)
{
statement.
int i= l , j=3;
(i) for(i= l;; i++)
while (i<5 && j !=0)
{
if (i> 5) {
break; i++;
printf ("%d",i); j - -;
}
(ii) i= l , j =3; printf ("¾d ¾ d\n" ,ij);
{ }
if (j= ==0)
Replar LIY• Doubt o learlDI Se■ -lon • J'ree Onllne Teat Serie■ I ASK an ••pert
ace Affordable Fee I AYailabl• 111 I 3M I 611 I l::IM 11811 and ::14 Month■ Subacrlpt!on Packacea
online
i◄hllMiiiiAMIIQ~
84 . Rewrite these for loops so that the initialization, 86. Write these pieces of code using while loops.
test and update expressions are inside the
parenthesis of for statement. (i) i=l, z=O;
do
(i) i= I ; if (i<5)
for ( ; ; ) {
{ printf ("¾d", i++);
if (i= =5) z = z + 2;
break; }
printf('"¾d\n" ,i); }while(i<5);
i++;
} (i i) do
{
} i=] ;
wh ile (i<=5)
!Y ace India'• BHt Online Coachln1 Platform for OATlt, lt81t, PSU■ , BIIC-JI!:, SIIC , Danila, Group■ & PBC Ea&lll 1
~ online E,tjoy a ■mooth onlln• leamlnc eaperlence ln Tarloua lan1U•1•• at your c onyenlence
I• ~:£~_. _. ._______________L4:3::_L_ ___________:_•A='=;;='=o=o=n=o=••=•='=.;=-l
= :=J
88 . Wi 11 these three loops g ive the samc output?
(ii) i=0;
ror 0 -- 1; i<a..:5 ; i++)
do
{
i++;
i f( i= =3)
printf("¾d", i);
co n tinue;
while(i<=5);
printf ("%d\ n" , i) '·
program to compiler looks like this: stack overflows at runtime. So it terminates the
{
100; 12. Ans: (b)
printf("%d\n", I 00); Sol: The input program to the compiler after
processing by the preprocessor is,
Note: I 00; is an executable statement but with no
action . So it doesn't give any problem.
ace India' ■ Be■ t Online Coachln& Platform for GATE, ESE, PSU■ , 88C-JE, SBC, Bank■ , Group■ & PSC EJtasn•
online Eajoy • ■mooth onllne learning experience In varlou■ lansua1•• at :,our con,renience
•PMHIOIMI04Miii9!6~
main ()
16. Ans: (a)
{ Sol: The comma operator has associativity from left
if(O)
to right. Only the rightmost value is returned and
puts("NULL"); the other values are evaluated and ignored. Thus
else if(- 1) the value of last variable y is returned to check in
puts("TRUE"); if. Since it is a non zero value it becomes true so,
else "hello" will be printed.
puts("FALSE");
} 17. Ans:(b)
Preprocessor doesn' t replace the values given Sol: The char array ' a' will hold the initialized string,
inside the double quotes. If condition is Boolean whose length will be counted from O till the
value false so it goes to else. In second if null character. Hence the ' i' will hold the value
' -1' is Boolean value true hence "TRUE" ts equal to 5, after the pre-increment in the printf
printed. statement, the 6 will be printed.
i value may be stored either in register or in Sol: The identifier 1 1s available in the inner block
and so using extern has no use in resolving it.
memory.
21. Ans: (d)
15. Ans: (a)
Sol: The character array has the memory just enough to
Sol: Let us assume some x= scanf("¾d", &i)-t the
hold the string "HELL" and doesn't have enough
values duri ng execution will be, space to store the terminating null character. So it
t X prints the HELL correctly and continues to print
4 0 -4 garbage values till it accidentally comes across a
3 -2 NULL character.
2 2 0
I Free Online Teat Serlea I ASK an eapert
a ce Re1ular Live Doubt cleutn& Senion•
I I I I 12M I 18M and 24 Montba Subacrlptton PacJu&ea
online Am>rdable ll'H An.l.lable lM 3M 6M
◄
iP@FihhOhAMh@ih~
values of other variables are also incremented by volatile unsigned which is a valid declaration.
I. 'i' is assumed of type int. So printf prints 30.
In the next block, ' i ' has value 20 and so printf
23. Ans: (c) prints 20. In the outermost block , ' i' is declared
Sol: -1 is internally represented as all l's. When left
as extern, so no storage space is allocated fo r it.
shifted four times the least significant 4 bits are
After compilation is over the linker resolves it to
filled with O's. The %x format specifiers specifies
that the integer value be printed as a hexadecimal global variable 'i ' (since it is the only variable
~ ace India' • BHt Online Coechlnl Platform fo r GAT E , El!IE, PSUa , SSC -JE, S S C, Ba nka, Group s & PSC Exaai•
~ online Eajoy a amooth onllne lea rnln1 expe r ie nce In v a rloua la.npa ce• at yow: c o nvenien c e
►
iPUM010iMh4iib4161~
32. Ans: (a)
36. Ans: (a)
sol: The variable " i" is declared as stati·c, h ence
Sol: The three usages of name errors can be
memory for 'i' will be allocated tor on 1y once
distinguishable by the compiler at any instance,
as it encounters the statement· Th e funchon . '
so valid (they are in different namespaces).
main() will be called recursively unless
Typedef struct error{int warning, error,
'i' becomes equal to O, and since main() is
exception;}error;
recursively called, so the value of static 'i'
ie., 0 will be printed every time the control is This error can be used only by preceding the error
returned. by struct keyword as in:
struct error someError;
33. Ans: (c) typedef struct error{int warning, error,
exception;} error; This can be used only after
34. Ans: (c) . (dot) or - (arrow) operator preceded by the
Sol: Since static variables are initialized to zero by variable name as in :
default.
gl.error = l ;
printf("o/od" ,g 1.error);
35. Ans: (b)
Sol: The name error is used in the two meanings. One typedef struct error {int warning, error,
means that it is a enumerator constant with value exception;}error;
1. The another use is that it is a type name ( due This can be used to define variables without using
to typedef) for enum errorType. Given a situation the preceding struct keyword as in:
the compiler cannot distinguish the meaning of error gl ;
error to know in what sense the error is used:
Since the compiler can perfectly distinguish
error gl; between these three usages, it is perfectly legal
g l =error; and valid.
// which error it refers in each case? Note: This code is given here to j ust explain the
concept. In real programming don't use such
When the compiler can diSt inguish between
overloading of names. It reduces the readab ility
usages then it will not issue error (in pure
of the code. Possible doesn' t mean that we should
ly be overloaded in
technical terms, names can on use it!
different namespaces).
. th declaration, enum 37. Ans: (a)
Note: The extra comma ID e
. ception,} is not an Sol: The expression can be treated as i = ( ++i= 6),
error Type {wammg, error, ex .
. 11·d and is provided because == is of higher precedence than =
error. An extra comma is va
, onvenience. operator. In the inner expression, ++i is equal to
Just for programmer s c
6 yielding true( l ).
Reaular Ll•e Doubt clearln& Se■-lon■ Free Online Teat Serie■ I ASK an expert
I A•allabl• UI I 3JI I 6M I l:IM I 18M and 2 4 Month■ Sub■crlptlon Package■
ace Affordable Fee
online
lk@Ahhhlhiih&!h~
ace lndla'a But Online Coaohlnl Platform for OATE • ESE • PSU ■, SSC -JE, SSC, Banke , Groupe • PSC Eaaaa•
online Ito.Joy a ■mooth onUne learnlo1 eaperlence to varloua l■ncu•&•• at your con•entence
iQl@dh,hhhMMl,§mj
l~
56. Ans: (a)
31
Sol: pis a pointer to a "constant integer' '. But we tried
Pf(173 %2)
f(86) to change the value of the "constant integer".
l~
f(43)
Pf(86%2)
0
57. Ans: (c)
Sol: s[i], *(i+s), *(s+i), i[s] are all different ways of
l~
f(21)
Pf(43%2)
expressing the same idea. Generally array name
is the base address for that array. Here s is the
base address. i is the index number/displacement
I~
f(l0)
Pf(21%2)
1
from the base address. So, indirecting it with •
is same as s[i]. i[s] may be surprising. But in the
case of C it is same as s[i].
I~
f(5)
Pf(10%2)
0
58. Ans: (a)
Sol: The sizeof() operator gives the number of bytes
I~
f(2)
Pf(5%2)
taken by its operand. p is a character pointer,
which needs one byte for storing its value (a
character). Hence sizeof(*p) gives a value of I.
I~
f( l)
Pf(2%2)
0
Since it needs two bytes to store the address of
the character pointer sizeof(p) gives 2.
52 ,u&YhihhHOPIIIM!h~
'¾d\n' and 300 is printed. true the result is true( 1) and the same is printed.
a. P8C
~ ace lndla'• Beet Online Coachln& Platform (or OATJI:, 11:8£, P8U■ , 88C-JJI:, 88C, Dank■ , Group ■ 11:•am ■
~ online Enjoy • emooth onUne learnln1 e11pertence lo Yarlou ■ lansu•1•• at your convenience
53 IPM§iiiOO@NMi@W~
75. Ans: (d) When sizeof operator is applied to an array
Sol: it returns the sizeof the array and it is not the
'y' same as the sizeof the pointer variable. Here the
'q' 'm' '\O'
sizeof(a), where a is the character array and the
00 101 102 103 104
size of the array is 5 because the space necessary
for the terminating NULL character should also
time error.
80. Ans: (a)
Sol: The integer value 257 is stored in the memory
76. Ans: (c)
as, 10000000 I .
Sol:
I 00000001, so the individual bytes are taken by
'y' 'q' ' m' ' \O' casting it to char * and get printed.
00 101 102 103 104
ace India's Best Online Coaching Platform for GATE, E8E, PBUs, S8C-JE, 88c, Banks, Groups & PSC Exams
aler e emooth online learning experlence in various languages at your convenience
online
jiiiLP
55 •A@§@hiiiihi!IMib§i@~
96.
102.
~ol: address of 0 th 1-D array=65506
Sol: 0 I 2 3 4
address of ph 1-D array=655 l O
address of 2 th 1-D array=65514 103.
address of 3 th 1-D array=65518 Sol: 4 3 2 I 0
address of 4 th 1-D array=65522
104.
97.
Sol: 170, 0
Sol: 1234 56
180, 170, 0
1212 33
180,170, 0
1434 80
1312 78
105. Ans: 1, l, 1
1203 75 2,2,2
3, 3, 3
98. Ans: 65502 65502 3, 4, 4
65504 65510 Sol:
Sol: a
0 2 3 4
a Is 7 5 91 4 6 3 1 2 0 9 61 I
100 102 104 106 108
D 65502 4 6 8 10 12 14 16 18 20 22 24
100. 106.
Ans: 10 20 30 40 50 Sol: 4 7
4 7
101. I 4 7
Sot: 0 1 2 3 4
e ular Live Doubt clearln& 8e■■lon■ Free Onlln ■ Te ■t Berle ■ I ABK an eape rt
ace R I Available lM I 3M I 6M I l~M I lBM and ~4 Montha 8ub■crtptlon Packace■
Affordable Fee I
online
•Ed@hi!Ohh!NIOK!i~
In the first loop, since only 'q' is incremented Sol: The value of y%2 is 0. This value is assigned
and not 'c' , the value 2 will be printed 5 times. to x . The condition reduces to if(x) or in other
In second loop 'p' itself is incremented. So the words if(0) and so z goes uninitialized.
values 2 3 4 6 5 will be printed. Thumb Rule: Check all control paths to write
bug free code.
111. A ns: (a) it has no effect on the expression and now the
Sol: Printf will return how many characters it prints. while loop is, while(i--!=0) which is false and so
Hence printing a null character returns I which breaks out of while loop. The value - I is printed
makes the if statement true, thus "Ok here" is due to the post-decreme nt operator.
printed.
~ ace 1nd la'• Be■t Online Co ■ohlnc Platform for OATlt, EBlt, PBU•, BBC-Jlt, SBC, Ba nk•, Group• & PSC Exam•
~ online Enjoy • •moolb onllne learntnc experience In v arlou• lan au aae • a t your oon;enle noe
57
ikd@Fhhhii!MiiiM!d~
Sol: The difference between the previous question (fprintf (stderr, "assertion failed: \ %s, file %s,
and this one is that the char is declared to be line %d \n",#cond, FILE , LINE), abort()))
unsigned. So the i++ can never yield negative Note: However this problem of "matching with
value and i>=0 never becomes false so that it nearest else" cannot be solved by the usual
cannot come out of the for loop. method of placing the if statement inside a
block like this, #define assert(cond) { \ if(!(cond))
\ (fprintf(stderr, "assertion failed: %s, file %s,
119. Ans: (d)
Sol: Ending the string constant with \0 explicitly line %d \n",#cond,\ FILE_,_ LINE_), abort())\
I 58 I iPHl§hiiiiiiii144iiN~
03.
Level 2- Solutions
Sol: Function is declared as void, so the function call
can't used in assignment expression.
Functions:
04.
01. Ans: (a) Sol: If no value is returned through return statement
'
Sol:x =5 , y=10 and the function is not declared of type void then
return( I 1 + 5 )
⇒ y= 16 06.
funcf(5) return 16 Sol: Since function declaration is absent and the
h !Y ace lndla'1 But Online Coachlnc Platform for OATJt, IJBI!:, PBU1, BBC-JIJ, BBC, Bank,, Group, a, PSC balD1
~ online Enjoy a 1mooth onllne learntnc experience In vartou, lancua&H at your connn.lenca
~
159 I iilMZiliii,ii!4¥U~
11. 23. Ans: 2 5
Sol: fu nc ( ) is vo id, so it can ' t be used as an operand Sol: In func( ), the local variable will be accessed
of ' + ' operator. because whenever there is a conflict between the
local and global variables the local variable gets
12. Ans: 24 11 the priority.
24. Ans: 10
13. Ans : 22
25. Ans: 24
14. Ans: x = I , y = 2, z = 15 result = 36 Sol: main ()
k
[Q] m
15. Ans: Sum is 3 Pf(i)-+ 24
Sol: If the value of non void function is not to be used, L= j_+ func(3)
5 0 5 m L= j_+ func(3)
then this can be made explicit by converting the Ci] 24 I 3 II
function call expression to void with the help of
L= j_+ func(3)
a cast. 13 5 8
function. Sol:
i= 1
k func( )
18. Ans: 15 290
~ 112
19. Ans: 2 2 i=2
func()
20. Ans: 7
2b 11=i 3
4
Re1ular Live Doubt clearln1 8e■alona Free Online Teat Serle a I ASK an expe rt
ace Affordable Fee I Available lM I 3M I 611 I 1:2MI 1811 and :24 Month■ S ubacrlption Packages
online
iPMIIOOOOMMh@ih~
30. {
if (x= = 5)
Sol: int funcl(int a, int b) b+=2;
{ else if (x>5)
if(a==b) b+ = 10;
35.
31.
Sol: int funcl (int a, int b)
Sol: int funcl (int n)
{
{ a= a- b;
inti; if (a! = 2)
for (i=2; i<=sqrt (n); i++) {
a++;
if (n¾i= = 0)
return a;
return 1; }
return 0; a=a+b;
} printf("¾d", a);
return b;
}
32.
Sol: int funcl (int n) 36.
Sol: int func 1 (int m, int n)
if (n = = 39) {
n+=5;
if (m = = 5)
return n-10;
return n;
if(m>5)
return n+ I0;
return n;
!Y ace lndla'a Beet Online Coaching Platform for GATE, ESE, PSUa, SSC-JE, SSC, Banka, Oroupa & PSC Eaam•
~ onllne Enjoy a emooth onllne learning experience in vuloue language• at your con~pnience
61
IMFililH'iP!IEH141ii1
48. Ans: a = 36
60. Ans: a= 5, b = 7, c = 5, d = 4, x = I , y = I
a= 5, b = 7 , c = 5, d = 10, x = 0 , y = I
49. Ans: 6 ,5 6,4 7,4 7,5
61.
50.
Sol: Result of these type of expression is undefined.
Sol: Error, expressions like
8++, ++x++, (x+y) - - are not valid.
62. Ans: a= 3, b = 3, x = 36, y =2
51. Ans: a= 4, b = l, c = 0
r"Vf ace Jndla'1 Beet Online Coachlnc Platform for GATE, E8E, P8Ua, 88C-JE, BBC, Banke, Group• a, PBC E:u111•
~ online Enjoy a 1mooth onllne leamlnc experience In varlou1 lancuac•• at your con,tenlence
i&FiiiiiHN+ieiimj
i = j + 2; y- - ;
So the statement i=j +2 will always be executed. break
case 6:
68. y = O;
Sol: if (a< b) }
X = O; In (ii), the last else is not present, so there is no
else
default in the switch.
x+= I00;
Re1ular Liv• Doubt olurtn1 leu lona I Free On llne Te■t lerle ■ I ASK an eapert
Affordable Fee I A•allable UI I 3M I 611 112M I 1111 lllld 24 Mon th• Subacrtptlon Packqea
iANiliiiiliilii#Q.g
70.
(f) Variabl e a is assigne d value of b which is
1
Sol: if (x= = t O)
and so the value of expres sion a= b is I, thus
z++; the loop will iterate infinite ly.
else if (x = = 20)
(g) Variabl e a is assigne d value of b which is o,
z--·,
and so the value of express ion a= b is 0, thus
else if (x = = 30)
the loop will not iterate even once.
{
if (y = = 2) 73.
z = z + 3; Sol: (i) 0 l 2 3456789
else if (y = =4 ::y = = 5)
(ii) 1234 5678 910
z=z+ 10;
(iii) 0 l 2 3 4 5 6 7 8 9 10
else
(iv) l 2 3 4 5 6 7 8 9
z = z - 2;
(v) This loop will run infinite ly. Value of i is
}
else initially O and it is decrem ented in each
printf("¾d\n'', i); The other two loops will iterate infinitely after
printing I and 2. In for loop, the continue
statement transfers the control to the update
(ii) for (sum=0; sum<= 100; sum+=n)
expression, in while and do - while loops the
scanf(" ¾d", &n);
control is transferred to the test expression. In the
while and do-while loops given in the exercise
85.
the expression that changes the value of i is after
Sol: for (i=0, j=I0, k=6; i!=j && k>=0; i++,j- -,
continue statement. Once the continue statement
k=k-2)
is encountered, test expression is checked and
printf("%d%d%d\n", i, j, k);
again continue is executed and this process goes
on infinitely
86.
Sol: (i) Here the loop condition is checked inside the
89.
loop before executing the body of loop, so this Sol: (i) 6
can be written using while loop as. (ii) syntax error
i= l, z= 0;
while (i<5) 90.
Sol: (i) for (i=l ; i<6; i++)
printf (" ¾d", i++); { if (i!=3)
z=z+2; printf ("¾ d", i);
} }
ace Iud la'• 8 ••t Online Coachla& Platform for GATE, ESE, PSU•, SSC-JE, SSC, Bank■ , Group• a, PSC Eiam■
onllne 11:ajoy a ■mooth oaline leanu.aI •Ipe rt ■nee I n variou■ laD,uaae■ at your convenience