1000 Ques

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 350

1.

typedef struct{
char *;
nodeptr next;
} * nodeptr;
what does nodeptr stand for?
ans:
2.int *x[](); means
ans:expl: Elments of an array can't be
functions.
3.struct list{
int x;
struct list *next;
}*head;
the struct head.x !""
#ns: a$o%e is correct & wron'
expl: Before using the ptr type struct variable
we have to give memory
to that .An also when ever the struct
variable is ptr then we access the
members by !"#! operator.
$.
main()
{
int i;
i!;
ii()*i((;
printf(*d+i);}
ans: $
%.main()
{
,-./ *fp!+*fp);
fp!fopen(0one0+0w0)
fp)fopen(0one0+0w0)
fputc(1#1+fp!)
fputc(121+fp))
fclose(fp!)
fclose(fp))}
a.error $. c. d.
ans: no error. But &t will over writes on same
file.
*****n
'.3include4malloc.h5
char *f()
{char *smalloc(6);
strcpy(s+0'ood$ye0);}
main()
{
char *f();
printf(0*c0+*f()1#1);}
o&p?
for strcpy function string.h heaer file
shoul be inclue
semicolon is missing in strcpy function
leftsie function call can come when it is
returning some pointer so (p)*A*+

7. 3define 8#x(x+y) (x)5(y)?(x):(y)
main()
{ int i!"+9:+;";
; 8#<(i((+((9);
printf(0*d *d *d 0+i+9+;);
}
ans. 12 ' 11
6. main()
{
int a!"+$:+ c=+d=;
if (a4$)>>(cd(()
printf(?*d *d *d *d@+ a+$+c+d);
else
printf(0*d *d *d *d@+ a+$+c+d);
}

ans: 1, % 3 3 -ote: if conition shoul be in
braces
A. main()
{
int i !";
printf(0 *d *d *d Bn0+ ((i+ i((+ ((i);
}

ans: 13 11 11
!". main()
{
int *p+ *c+ i;
i :;
p (int*) (malloc(siCeof(i)));
printf(0Bn*d0+*p);
*p !";
printf(0Bn*d *d0+i+*p);
c (int*) calloc());
printf(0Bn*dBn0+*c);
}
-ote: calloc function has less parameters
calloc.n/ elemsi0e1

main()
{
int *p+ *c+ i;
i :;
p (int*) (malloc(siCeof(i)));
printf(0Bn*d0+*p);
*p !";
printf(0Bn*d *d0+i+*p);
c (int*) calloc()+));
printf(0Bn*dBn0+*c);
}
ans: garbage/ %/ 1,/ , .malloc gives garbage an
calloc initiali0es with 0eros1
!!. 3define 8#<(x+y) (x) 5(y)?(x):(y)
main()
{
int i!"+9:+;";
; 8#<(i((+((9);
printf(0*d..*d..*d0+i+9+;);
}
ans: 12 ' 11
!). main()
{
enum Dta'{ left!"+ ri'ht+ front!""+ $ac;};
printf(0left is *d+ ri'ht is *d+ front is *d+ $ac; is
*d0+left+ri'ht+front+$ac;);
}
ans: left is 1,/ right is 11/ front is 1,,/ bac2
is 1,1
!=. main()
{
int a!"+$)";
a5:?$!"":$)"";
printf(0*dBn0+$);
}
ans: lvalue re3uire for ternary operator
!E. 3define FG-HI(int) printf(0int *d 0+int)
main()
{
int x+y+C;
x"=;y");C"!;
FG-HI(xJx);
C44=;FG-HI(x);
y55=;FG-HI(y);
}

ans: int ) , int ) 3 int ) ,
!:. main()
{
char s[] 02ouKuets and 2ric;$ats0;
printf(0Bn*c+ 0+*(>s[)]));
printf(0Bn*s+ 0+s(:);
printf(0Bn*s+0+s);
printf(0Bn*c0+*(s()));
}
ans: u/
ets an Bric2bats/
Bou3uets an Bric2bats/
u
!L. main()
{
struct s!
{
char *str;
struct s! *ptr;
};
static struct s! arr[] { {0Mydera$ad0+arr(!}+
{02an'alore0+arr()}+
{0Nelhi0+arr}
};
struct s! *p[=];
int i;
for(i";i4);i(()
p[i] arr[i].ptr;
printf(0*sBn0+(*p)O5str);
printf(0*sBn0+(((*p)O5str);
printf(0*sBn0+((*p)(()O5str);
}
ans: Bangalore
4elhi
4elhi
!7. main()
{
char *p 0hello worldP0;
p["] 1M1;
printf(0*s0+p);
}
ans: 5ello worl
!6. main()
{
int x!+y!;
while( (x 5 ") >> (y 5 ") )
{
printf(0*!Ld*!Ld0+x+y);
x ( y;
y ( x;
}
}
ans: here x ) x6y an y ) x62y when y goes
beyon 327'7 it falls in 8ve sie an loop
brea2s
!A. int f(int p)
{
int i "+ t !+ s !;
while( s 4 p)
{
i((;
t ( );
s ( s;
}
return i;
}
ans: this function gives the no. of bits
re3uire to represent a number in binary
form
)". remo%e the duplicate from a sorted array.
)!. fi$onacci series upto !"" recursi%ely.
)). main()
{
char c[]={ " enter" , "first" , "print" ,
"new" }.;
char **cp[]={c+3, c+2, c+1, c};
char ***cpp[]=cp;
printf("%s", ++*cp);
printf("%s",--*++cp);
}
ans: lvalue re3uire for secon printf
statement
)=. QRN and .R8 pro'rams
)E. Srite a pro'ram to print
!
) )
= = =
E E E E
: : : : :.
ans:
main.1
9
int i/:+
for.i)1+i;)%+i661
9
printf.!<n!1+
for.:)i+:#,+:""1
printf.!=!/i1+
>
):. dou$le what( dou$le C+ int y)
{
dou$le answer !;
while( y 5 " )
{
if( y*) !)
answer answer * C;
yy&);
CC*C;
}
return answer;
}
ans: 0 power y
)L. Fro'ram for sKuare root.
)7. Srite pro'ram to print
!
) =
E : L
7 6 A !"
!! !) != !E
ans:
main.1
9
int i/:/2+
2 ) 1+
for.i)1+i;)%+i661
9
for.:)i+:#,+:""1
printf.!=!/2661+
printf.!<n!1+
>
)6. write a function maxsu$strin'(str+alpha+theta) str is the
source strin' and ha%e to return maximum su$strin'
which starts with alpha and ends with theta.
ans:
main.1
9
int i/:),/2+
char st ) 'x'+
char en ) 'y'+
char p?@)!abxabcyxabcabcyabcxabyc!+
char (str+
for.i),+p?i@A)'<,'+i661
9
if.p?i@ )) st1
brea2+
>
if.p?i@))'<,'1
9
printf.!<n starting character not foun<n!1+
exit.,1+
>
str ) Bp?i@+
2)i+
while.p?66i@A)'<,'1
if.p?i@ )) en1
:)i+
if.:)),1
printf.! ening character not foun<n!1+
else
for.+2;):+2661
printf.!=c!/(str661+
>
)A. Mow do you write a pro'ram which produces its own
source code as its output?
Mow can - find the day of the wee; 'i%en the date?
Shy doesn1t R ha%e nested functions?
Shat is the most efficient way to count the num$er of
$its which are set in a %alue?
ans: C. Ditchie
Mow can - con%ert inte'ers to $inary or hexadecimal?
ans: C. Ditchie
Mow can - call a function+ 'i%en its name as a strin'?
ans: function pointers
Mow do - access commandOline ar'uments?
Mow can - return multiple %alues from a function?
ans: using pointer or structures
Mow can - in%o;e another pro'ram from within a R
pro'ram?
ans: using system function
Mow can - access memory located at a certain address?
Mow can - allocate arrays or structures $i''er than
LET?
Mow can - find out how much memory is a%aila$le?
Mow can - read a directory in a R pro'ram?
Mow can - increase the allowa$le num$er of
simultaneously open files?
Shat1s wron' with the call 0fopen(0c:BnewdirBfile.dat0+
0r0)0?
=". main()
{
int x!"+y!:;
xx((;
y((y;
printf(0*d *dBn0+x+y);
}
ans: 11 1'
=!. int x;
main()
{
int x";
{
int x!";
x((;
chan'eD%alue(x);
x((;
8odifyD%alue();
printf(0,irst output: *dBn0+x);
}
x((;
chan'eD%alue(x);
printf(0Uecond Vutput : *dBn0+x);
8odifyD%alue();
printf(0Ihird Vutput : *dBn0+x);
}
8odifyD%alue()
{
return (x(!");
}
chan'eD%alue()
{
return(x(!);
}
ans:
Eirst output : 12
Fecon output : 1
Ghir output : 1
=). main()
{
int x)"+y=:;
x y(( ( x((;
y ((y ( ((x;
printf(0*d *dBn0+x+y);
}
ans: %7 H$
==. main()
{
char *p!0Hame0;
char *p);
p)(char *)malloc()");
while(*p)((*p!(();
printf(0*sBn0+p));
}
ans: -o output since p2 is at null character to
get output moify the program given below.
.-ote: ;malloc.h# shoul be inclue1
{
char *p!0Hame0;
char *p)+*p=;
p)(char *)malloc()");
p=p);
while(*p)((*p!(();
printf(0*sBn0+p=);
}
=E. main()
{
int x:;
printf(0*d *d *dBn0+x+x44)+x55));
}
ans: % 2, 1
=:. 3define swap!(a+$) aa($;$aO$;aaO$;
main()
{
int x:+y!";
swap!(x+y);
printf(0*d *dBn0+x+y);
swap)(x+y);
printf(0*d *dBn0+x+y);
}
int swap)(int a+int $)
{
int temp;
tempa;
$a;
atemp;
return;
}
ans:
1, %
1, %
=L. main()
{ char *ptr 0Gamco Uystems0;
(*ptr)((;
printf(0*sBn0+ptr);
ptr((;
printf(0*sBn0+ptr);
}
ans:
Famco Fystems
amco Fystems
=7. main()
{ char s![]0Gamco0;
char s)[]0Uystems0;
s!s);
printf(0*s0+s!);
}
ans: lvalue re3uire .s1 is base aress of
array1
=6. main()
{
char *p!;
char *p);
p!(char *) malloc():);
p)(char *) malloc():);
strcpy(p!+0Gamco0);
strcpy(p)+0Uystems0);
strcat(p!+p));
printf(0*s0+p!);
}
ans: DamcoFystems .-ote: ;malloc.h#
shoul be inclue1
=A. # code li;e this is 'i%en.
a. for(i";i4num;i(()
$. for(inum;i5";iOO)
#ssumin' no code optimiCation and assume that the
microprocessor
has fla's etc. which one is faster.
Ans: b will execute faster.
E". main()
{
int a!+$)+c=;
printf(0*d+*d0+a+$+c);
}
ans: 1/ 2
E!. main()
{
struct
{
char a[=];
int $;
}x;
char *cp;
printf(?*d *d@+siCeof(cp)+siCeof(x));
}
ans: $ % since pointer cp stores
aress.32"bit1 $ bytes it ta2es an
an x ta2es % bytes.3 for character array a
an 2 for int b1
E). main()
{
int p=+KE;
K shw(>p);
printf(0*d *d0+p+K);
}
int shw(int *a)
{
*a !";
}
ans: 1, garbage
E=. write 7*a interms of (+O+44
ans: .x;;3"x1
EE. main()
{
char *s! 0hello0+*s) 0a$ce0;
strcpy(s!+00);
s)["] s!["];
printf(0*d*d0+strlen(s!)+strlen(s)));
}
ans: , ,
E:. main()
{
int i!";
printf(0*d*d*d0+i+i((+((i);
}
ans: 12 11 11 .compiler epenent1
EL. const char *
char * const
Shat is the differnce $etween the a$o%e two?
ans: const char ( pointer to a constant
character
char ( const constant pointer pointing
to a character
E7. main()
{
char *x0new0;
char *y0dictonary0;
char (t+
%oid swap (char * + char *);
swap (x+y);
printf(0(*s+ *s)0+x+y);
char (t+
tx;
xy;
yt;
printf(0O(*s+ *s)0+x+y);
}
%oid swap (char *x+char *y)
{
char *t;
yx;
xy;
yt;
}
ans: multiple eclaration of t an all
eclarations shoul be before executable
statement.errors1
E6. main()
{
char p[]0strin'0;
char t;
int i+9;
for(i"+9strlen(p);i49;i(()
{
tp[i];
p[i]p[9Oi];
p[9Oi]t;
}
printf(0*s0+p);
}
ans: will not print anything since p will be
pointing to a null string
EA. main()
{
int i!";
printf(0*d *d *d0+i+((i+i(();
}
ans: 12 12 1, .compiler epenent1
:". main()
{
%oid f(int+int);
int i!";
f(i+i(();
}
%oid f(int i+int 9)
{
if(i5:")
return;
i(9;
f(i+9);
printf(0*d+0+i);
}
ans: %1 $1 31 21 .i)11/ :)1, for function If*1
:!. main()
{
%oid f(int+int);
int i!";
f(i+((i);
}
%oid f(int i+int 9)
{
if(i5:")
return;
i(9;
f(i+9);
printf(0*d+0+i);
}
ans: %% $$ 33 22 .i)11/ :)11 for function If*1
:). main()
{
char *s0hello world0;
int i7;
printf(0*.*s0+i+s);
}
ans: hello w
:=. main()
{
int a+$;
printf(0enter two num$ers :0);
scanf(0*d*d0+a+$);
printf(0*d(*d*d0+a+$+a($);
}
ans: will generate run time error Jcore
ump
:E. main()
{
union{
int x;
char y;
struct {
char x;
char y;
int xy;}p;
}K;
printf(0Bn *d+*d0+siCeof(K)+siCeof(int));
}
ans: $/2
::. main()
{
char *x0Utrin'0;
char y[] 0add0;
char *C;
C(char *) malloc(siCeof(x)(siCeof(y)!);
strcpy(C+y);
strcat(C+x);
printf(0*s(*s*s0+y+x+C);
}
ans: a6Ftring)aFtring
:L. an arrey of n pointers to function returnin' pointers to
functions returnin' pointers to characters
ans: char ( .( .*x?n@1 .1 1 .1
pointer to array of int+ char etc.+ this is array
pointer
ans: int .(x1?@ char .(x1?@
array of pointer to int+ char etc.+ this is pointer
array
ans: int (x?@ char (x?@
function returnin' pointer to int+ char etc.+
ans: int (x.1 char (x.1
pointer to function returnin' int+ char etc.+
ans: int .(x1.1 char .(x1.1
function returnin' pointer to array of pointer to function
returnin' char
ans: char .(.(x.11 ?@1 .1
array of pointer to function returnin' pointer to array of
char
ans: char .(.(x?@1 .1 1 ?@
:7. main()
{
enum num$er { aO!+ $ E+c+d+e};
printf(0*d0+e);
}
ans: 7
:6. main()
{
int i";
for(i";i4)";i(()
{
switch(i)
{
case ":i(:;
case !:i();
case ::i(:;
default: i(E;
$rea;;}
printf(0*d+0+i);
}
}
ans: 1'/21 .after case an efault colon
shoul be there1
:A. main()
{
int i+ count+ x!;
for(i"+ count";i4!L;i(()
if( P(x>(!44i)) )
count((;
printf(0*d0+count);
}
ans: 1% .no. of 0eros1
L". main()
{
int i+ count+ x!;
for(i"+ count";i4!L;i(()
if(x>(!44i) )
count((;
printf(0*d0+count);
}
ans: 1 .no. of ones1
L!. which one will o%er flow 'i%en two pro'rams
pro' !: pro'):
main() main.1
{ {
int fact; int fact),
lon' int x; for.i)1+i;)n+i661
factfactoral(x); fact)fact(i+
} }
int factorial(lon' int x)
{
if(x5!) return(x*factorial(xO!);
}
ans: program 1 .program 2 is always 0ero since
fact ),1
L). main()
{
char str[:]0hello0;
if(strHW..) printf(0strin' null0);
else printf(0strin' not null0);
}
ans: string not null
L=. %oid f(int %alue)
{
for (i";i4!L;i(()
{
if(%alue >"x6"""55!) printf(0!0)
else printf(0"0);
}
}
ans: binary output of value
LE. %oid f(int *p)
{
static %al!"";
%al>p;
}
main()
{
int a!";
printf(0*d 0+a);
f(>a);
printf(0*d 0+a);
}
ans: nonportable pointer conversion .we
can*t store aress in integer variable/ we
have to ta2e pointer to store aress1
L:. main()
{
int x+ *y;
x y;
printf(?*d@+x);
}
ans: nonportable pointer conversion
LL. 3 define f(a+$) a($
3define '(c+d) c*d
find %alue of f(E+'(:+L))
ans: 3$
L7. main()
{
char a[!"]0hello0;
strcpy(a+1B"1);
printf(0*s0+a);
}
ans: arguments must be a string constant or
character array variable
here it is constat character not a string
constant. 5ence program error
L6. char a[:][!:];
int $[:][!:];
address of a "x!""" and $ is "x)""" find address of
a[=][E] and $[=][E]
inter'er ta;es =)O$its and character ta;es 6O$its
ans: a?3@?$@ ) ,x1,31 b?3@?$@ ) ,x2,K$
.-ote: aresses are in hexaecimal1
LA. Qi%en an inter'er in $inary form+find the num$er of
ones in
that num$er without countin' each $it.(Ihis Kuestin is
not
multiple choice Kuestion. Ihis Kuestion carries more
mar;s. Uo please ta;e care for this Kuestion.)
ans: C.Ditchie
7". main()
{
a);
$=;
xUW8(a+$)*);
printf(0x*dBn0+x);
}
ans: L
7!. num$er(int i)
{
num$er((;
printf(0*dBn0+num$er);
}
main()
{
static int i";
num$er(i);
}
ans: lvalue re3uire .function name is an
aress. Fo 66 operator shoul not be applie1
7). main()
{
unsi'ned char i;
int sum;
for(i"; i4=""; i(()
sum( i;
printf(0BnUum *dBn0+ sum);
}
ans: infinite loop
7=. %oid fn(int *p)
{
static int %al !"";
p >%al;
}
main()
{
int i!";
printf(0i*dBn0+ i);
fn(>i);
printf(0i*dBn0+ i);
}
ans: i)1,
i)1,
7E. Uwappin' without usin' a temporary %aria$les. (=
methods)
ans:
x ) x6y+
y ) x"y+
x ) x"y+
x ) xMy+
y ) xMy+
x ) xMy+
x ) x(y+
y ) xJy+
x ) xJy+
7:. Rode ! :
for(i"; i4!"""; i(()
for(9"; 94!""; 9(()
x y;
Rode ) :
for(i"; i4!""; i(()
for(9"; 94!"""; 9(()
x y;
Shich code will execute faster
ans: Koe2 .Koe 1 ) 1/,1,,, increment
operations1
.Koe 2 ) 1/,,1,, increment
operations1
7L. main()
{
int a[!"] {!+ )+ =+ E+ :+ L+ 7+ 6+ A+ !"}+ i+ x!"+
temp;
for(i"; i4x; i((){
temp a[i];
a[i] a[xOiO!];
a[xOiO!] temp;
}
ans: remains same
77. main("
{
int i !;
for;();
for;();
printf(0Bni *dBn0+ i(!);
}
ans: $ printfs will occur an i ) 2
76. 3define 8#<(a+ $) a5$ ? a:$
main()
{
int m+ n;
m = ( 8#<()+ =);
n ) * 8#<(=+ ));
printf(0m *d+ n *dBn0+ m+ n);
}
ans: m ) 2/ n ) 3
7A. main()
{
int i!";
for;();
for;();
for;();
printf(0*d@+i);
}
ans: L printfs will occur an i ) 1, .2 power
no. of for2s times printfs1
6". 3define f(a+$) a($
3define '(a+$) a*$
main()
{
int m;
m)*f(=+'(E+:));
printf(0Bn m is *d0+m);
}
ans: m is 2'
6!. main()
{
char a[!"];
strcpy(a+0B"0);
if (aHW..)
printf(0Ba is null0);
else
printf(0Bn a is not null0);
}
ans: a is not null
6). main()
{
char a[:]0hello0;
printf(0*s0+a);
}
ans: array si0e is small it shoul be '
6=. main()
{
unsi'ned int xO!;
int y;
y X";
if(x y)
printf(0same0);
else
printf(0not same0);
}
ans: same ."1 is store in 2*s complement
form1
6E. char *'xxx()
{
static char xxx[!")E];
return xxx;
}
main()
{
char *'0strin'0;
strcpy('xxx()+');
' 'xxx();
strcpy('+0oldstrin'0);
printf(0Ihe strin' is : *s0+'xxx());
}
ans: Ghe string is : olstring
6:. %oid myalloc(char *x+ int n)
{
x (char *)malloc(n*siCeof(char));
memset(x+1B"1+n*siCeof(char));
}
main()
{
char *'0Utrin'0;
myalloc('+)");
strcpy('+0Vldstrin'0);
printf(0Ihe strin' is *s0+');
}
ans: Ghe string is Nlstring
6L. main()
{
char p[]0Utrin'0;
int x";
if(p0Utrin'0)
{
printf(0Fass !0);
if(p[siCeof(p)O)]1'1)
printf(0Fass )0);
else
printf(0,ail )0);
}
else
{
printf(0,ail !0);
if(p[siCeof(p)O)]1'1)
printf(0Fass )0);
else
printf(0,ail )0);
}
ans: Eail 1Oass 2
67. # code which had some declarations of some data
items. Ihere were a couple of normal data items (char+
int..) and some pointers as well and a malloc call. You
ha%e to find the total memory ta;en up in the stac;
(Mint: Fointers and all are allocated in heap+ not in
stac;+ so donZt count them).#lso in most of
these Kuestions+ they were specifyin' that the VU was
=) $it.
66. # structure was 'i%en and it contained normal data as
well as some $itOwise data. You had to find the total
siCe ta;en up $y the structure
6A. Fointer to a function which returned an array of
char pointers
ans: char (..(x1.1 1 ?@
A". [alue of ) particular %aria$les in R(8#<-HI and some
other constant)
A!. Shat do you need to do to open more than !" files
simultaneously in 8icrosoft Vperatin' Uystem?
ans: change stio.hJchange
KN-E&P.FQFJcompiler epenent
A). main()
{
int i7;
i i((*i((;
printf(0*dBn0+i);
i7;
printf(0*d *dBn0+i +i((*i(();
i);
printf(0*d *dBn0 +i+ i((*((i*i((*i(();
i!;
printf(0*d *d *dBn0+ i+ i((*i((+ i((*i(
(*((i*i(();
i!;
printf(0*d *d *dBn0 +i+ i((*i((+ i((*i(
(*((i*i((*i((*((i);
}
ans: %1
H %'
' 1',
7 3, 32
H %' 112,
A=. main()
{
int d ;
int i!";
d siCeof(((i);
printf(0*d0+d);
}
ans: 2
AE. char *f();
main()
{
char*a+*f();
a(char*)malloc()"*siCeof(char));
af();
printf(0*s0+a);
}
char *f()
{static char n?2,@+
strcpy(n+0Mello Sorld0);
return(n);
}
ans: 5ello Rorl
A:. char *f();
main()
{
char*a+*f();
a(char*)malloc()"*siCeof(char));
af();
printf(0*s0+a);
}
char *f()
{char n?2,@+
strcpy(n+0Mello Sorld0);
return(n);
}
ans: unpreictable output. auto variable
aress shoul not be returne. &t will lose
its scope when it comes out of the bloc2.
AL. char *f()
main()
{
char *a+*f();
af();
printf(0*s0+a);
}
char *f()
{return(0Mello Sorld0);}
ans: 5ello Rorl
A7. what is the error
main()
{int 9!";
switch(9)
{case )":
pritnf.!Sess than 2,!1+
$rea;;
case =":
printf(0.ess than ="0);
$rea;;
default:
printf(0hello0);
}
ans: printf not pritnf an one brace > is
missing
A6. which is %alid :
(i)char arr[!"];
arr0hello0;
(ii) char arr[]0hello0;
ans: secon is correct. &n first lvalue re3uire.
AA. main()
{
char *str;
str(char*)malloc()"*siCeof(char));
strcpy(str+0test0);
strcat(str+1P1);
printf(0*s0+str);
}
ans: strcpy function arguments shoul be
either a character array variable or a string
constant. &nstea of IA* give TAU
!"". Mow many times main is 'et called
main()
{
printf(0\um$oree0);
main();
}
ans: till stac2 overflow
!"!. main()
{
int i;
if(i")
printf(0 Mell 0);
else
printf(0Mea%en0);
}
ans: 5eaven
!"). main()
{
int i+9;
for(i"+9";i4:+94):;i((+9(();
printf(0*d *d0+i+9);
}
ans: 2% 2% A pair of expressions separate
by a comma is evaluate left to right/ an the
type an value of the result are the type an
value of the right operan. 5ere we*ve to
consier :;2% conition.
!"=. !)pointer to a function.
))pointer to structure.
=)static %aria$le and difference $&w(const char *p+char
const *p+const char* const p).
E)pass $y %alue > reference.
:)strin' li$rary functions(syntax).
L)Srite a pro'ram to compare two strin's without
usin' the strcmp() function.
7)Srite a pro'ram to concatenate two strin's.
6)Srite a pro'ram to interchan'e ) %aria$les without
usin' the third one.
A)Srite pro'rams for Utrin' Ge%ersal > Falindrome
chec; .
!")Srite a pro'ram to find the ,actorial of a num$er.
!!)Srite a pro'ram to 'enerate the ,i$inocci Ueries.
!))searchin' and sortin' alo'orithms with
complexities.
!"E. Iheory Kuestion a$out far pointers.
ans: Ear pointers are $ bytes in si0e an local
pointers are 2 bytes in si0e. important: i saw in a
previous 3uestion paper of accenture which is in
the chetana atabase/ some lay wrote that si0e
of an integer in K is 2 bytes an for K66 it is $
bytes. Ghis is absur.Ghe si0e of types is entirely
epenent on the compiler use.for 4NF Gurbo K
si0eof int is 2 an float is $ bytes for winows
borlan K/K66 si0e of int is $ bytes for linux gcc/
si0e of int is 2 bytes. All these epens on the
Nperating system.Olease 2eep this in min.
!":. main()
{
char str[]{0hell0};
int i;
for(i";i4:;i(()
printf(0*c*c*c
*cBn0+str[i]+i[str]+*(str(i)+*(i(str));
}
ans: hhhh
eeee
llll
llll
!"L. inline function does type chec;in' and so it is $etter
than a macro
!"7. main()
{
int i !";
int 9 i 55 !";
printf(0*d0+9);
}
ans: ,
!"6. char *str 0Mello0;
char arr[] 0Mello0;
arr((; && /GGVG..its li;e a pointer constant
*(arr ( !) 1s1;
cout44arr; && o&p: Msllo
!"A. struct Nate
{
int yr;
int day;
int month;
} date!+date);
date!.yr )""E;
date!.day E;
date!.month !);
now how will you initialiCe date) (without
mem$er $y mem$er assi'nment)
ans: ate2 ) ate1+
!!". main()
{
extern int a;
printf(0*d0+a);;
}
int a)";
ans: 2,
!!!. main()
{
int a[:]{)+=};
printf(0Bn *d *d *d0+a[)]+a[=]+a[E]);
}
ans: , , , if there are fewer initiali0ers
uninitiali0e variables are 0ero
!!). main()
{
intiO=+9)+;"+m;
m((i>>((9]]((;;
printf(0Bn *d *d *d *d0+i+9+;+m);
}
ans: "2 3 , 1
!!=. main()
{
int a+$;
asumdi'(!)=);
$sumdi'(!)=);
printf(0*d *d0+a+$);
}
sumdi'(int n)
{
static int s";
int d;
if(nP")
{
dn*!";
n(nOd)&!";
ss(d;
sumdi'(n);
}
else return(s);
}
ans: ' 12
!!E. 3define RW2/(x) (x*x*x)
main()
{
int a+$=;
aRW2/($(();
printf(0Bn *d *d0+a+$);
}
ans: 27 '
!!:. main()
{
const int x'et();
printf(0*d0+x);
}
'et()
{
return()");
}
ans: 2, for auto variables initiali0ers can be
function calls or some expressions. But for
static initiali0ers shoul constants or
constant expressions.
!!L. # function has this prototype %oid f!(int **x)+ Mow will
you call this function?
{a) int **a; ($) int a; (c) int *a; (d) int
a:;
f!(a); f!(>a); f!(>a); f!(>>a);
ans: int (a+ f1.Ba1+
!!7. main()
{
int l!;
for(;;)
{
printf(0*d0+l(();
if(l5!")
$rea;;
}
}
ans: 123$%'7LH1,
!!6. main()
{
char str[:]0fast0;
static char *ptrDtoDarray str;
printf(0*s0+ptrDtoDarray);
}
ans: error. for auto variables initiali0ers can
be function calls or some expressions. But
for static initiali0ers shoul constants or
constant expressions.
!!A. main()
{
char str[:]0fast0;
char *ptrDtoDarray str;
printf(0*s0+ptrDtoDarray);
}
ans: fast. for auto variables initiali0ers can
be function calls or some expressions. But
for static initiali0ers shoul constants or
constant expressions.
!)". main()
{
int i!";
fn(i);
printf(0*d0+i);
}
fn(int i)
{
return ((i;
}
ans: 1,
!)!. main()
{
int i+9;
i!";
9siCeof(((i);
printf(0*d0+i);
}
ans: 1,
!)). main()
{
struct emp
{
char name[)"];
int a'e;
float sal;
};
struct emp e {0ti'er0};
printf(0Bn *d *f0+e.a'e+e.sal);
}
ans: , ,.,,,,,, &f there are fewer
initiali0ers in the list than members of the
structure the trailing members are initiali0e
with 0ero. Ghere may not be more initiali0ers
than members.
!)=. main()
{
char i";
for(;i5";i(() ;
printf(0*dBn0+i);
}
ans: "12L
!)E. typedef enum 'rade{QVVN+2#N+SVGUI+}2#N;
main()
{
2#N '!;
'!!;
printf(0*d0+'!);
}
ans: error.multiple eclaration for BA41
!):. 3define UIY./! char
main()
{
typedef char UIY./);
UIY./! x;
UIY./) y;
x)::;
y)::;
printf(0*d *dBn0+x+y);
}
ans: "1 "1
!)L. 3ifdef IGW/
int -";
3endif
main()
{
int 9";
printf(0*d *dBn0+i+9);
}
ans: error since i is not eclare
!)7. main("
{
char *pNestn+*pUource0- .o%e You Naddy0;
pNestn(char *)malloc(strlen(pUource));
strcpy(pNestn+pUource);
printf(0*s0+pNestn);
free(pNestn);
}
ans: & Sove Qou 4ay
!)6. main()
{
char a[:][:]+fla';
a["]["]1#1;
fla'((a*a)>>(*aa["]));
printf(0*dBn0+fla');
}
ans: 1
!)A. main()
{
int i:+9:+;;
;((i(((9;
printf(0*d0+;);
}
ans: lvalue re3uire .66i661
!=". main()
{
int $!";
int *p>$;
*p((;
printf(0*d0+*p);
}
ans: un2nown value .value at memory
location next to the memory location of b
!=!. main()
{
int i"+9:"
while (i49)
{
if(4some condtn5)
{
4$ody of the loop5
i((
}
elseif(4some condtn5)
{ 4$ody of the loop5
9OO
}
else(4some condtn5)
{4$ody of the loop5
9OO
}
}
Mow many times the $ody of the loopis 'oin' to
$e executed?
Ans: %, times
!=). Mow can you include a li$rary code written in R(( in a
source code written in R?
(Vptions are there)
ans. Fome cross"lin2e platform.compiler1 is
re3uire for this.
!==. main()
{
int a[)"]+i;
for(i";i4)";i(()
{
a[i]i;
}
for(i";i4)";i(()
{
a[i]a[)"Oi];
}
for(i";i4)";i(()
printf(0*d0+a[i]);
}
ans: un2nown value 1H 1L 17 1' 1% 1$
13 12 11 1, 11 12 13 1$ 1% 1' 17 1L 1H
!=E. main()
{
int a[)"]+i;
for(i";i4)";i(()
{
a[i]i;
}
for(i";i4)";i(()
{
a[i]a[)"Oi];
}
for(i";i4)";i(()
printf(0*d0+a[i]);
}
ans: 1H 1L 17 1' 1% 1$ 13 12 11 1, 1,
11 12 13 1$ 1% 1' 17 1L 1H
!=:. %oid a$c(int a[])
{
int ;";int 9:";
while(;49)
{
if(a[i]5a[9])
;((;
else
9OO;
}
Mow many times the loop will occur?
Ans: %, times
!=L. main()
{
int a[]{:+E+=+)+!};
int x+y;
int *p>a[)];
*p((;
x((*p;
y*(p(();
printf(0*d *d0+x+y);
}
ans: 3 3
!=7. int a;
scanf(0*f0+>a); is there any error or warnin' ?

ans. no compile time error but run time error
!=6. main()
{int *p+*K;
p(int *)!""";
K(int *))""";
printf(0*d0+(KOp));
}
ans: %,,
!=A. Shen a 1R1 function call is made+ the order in which
parameters passed to the function are pushed into the
stac; is
ans: right to left
!E". main()
{
extern int a;
a!";
printf(0*d0+a);
}
int a)";
ans: 1,
!E!. siCeof () operator is used for
ans: ata type B veriable
!E). main()
main()
{
int i );
printf(0*d *d *d *d 0+i+ i((+iOO+i(();
}
ans: 3 2 3 2
!E=. main()
{
int i );
printf(0*old *old *old *old 0+i+ i((+iOO+i(();
}
ans: 3l 2l 3l 2l
!EE. Ucope of a 'lo$al %aria$le which is declared as static?
ans: Eile
!E:. main()
{
printf(0 Mello Bo is the world 0);
}
ans: 5ello o is the worl
!EL. Shat is
int *p(char (*s)[])
ans: p is a function which is returning a
pointer to integer
which ta2es arguments as pointer to array of
characters.
!E7. Mow will u print I#I# alone from I#I# FVS/G usin'
strin' copy and concate commands in R?
ans: implement strstr function
!E6. main()
{
int n !;
switch(n)
case !:printf(0R#U/ P0);
case()):printf(0default0);
$rea;;
}
ans: error .case outsie of switch an
misplace brea21
all 2eywors in c shoul start with small
letters
!EA. 3define min((a)+($)) ((a)4($))?(a):($)
main()
{
int i"+a[)"]+*ptr;
ptra;
while(min(ptr((+>a[A])4>a[6])
ii(!;
printf(0i*dBn0+i);
}
ans: i)%
!:". X(X"446)?
ans: Sast L igits are 1's rest are ,'s.
!:!. struct x
{
int -;
char s;
};
union
{
struct x y;
dou$le 9;
}C;
main()
{
printf(0*d0+siCeof (C));
}
ans: L
!:). main()
{
char a[]{1!1+1)1+1=1+"+1!1+1)1+1=1};
printf(0*s0+a);
}
ans: 123
!:=. main()
{
int a[]{1!1+1)1+1=1+"+1!1+1)1+1=1};
printf(0*s0+a);
}
ans: 1
!:E. main()
{
3define x !"
{
printf(0*d0+x);
}
}
ans: 1,
!::. main()
{
3define x !"
{
printf(0*d0+((x);
}
}
ans: lvalue re3uire
!:L. main()
{
char a[]0#2RN/,QM0;
printf(0*d0+siCeof(a));
}
ans: H
!:7. main()
{
int i(int*)"x!""";
printf(0*d0+i);
}
ans: nonportable pointer conversion
!:6. main(int -)
{
printf(0*d0+-);
}
ans: 1 .comman line arguments1
!:A. main()
{
printf(0 *d0+printf(0helloworld0));
}
ans: helloworl 1,
!L". main()
{
int a[)][)][L]
{{)+=+E+:+L+7}
{^^^^^.}}
printf(?*u*u*u*u@+a+*a+**a+***a);
assume $ase address is :L76A:
ans: %'7LH%/ %'7LH%/ %'7LH%/2 .a/ a?,@/
a?,@?,@/ a?,@?,@?,@1
!L!. main()
{
int a[)][)]{{)}+{=}};
printf(0*d 0+a["]["]);
printf(0*d 0+a["][!]);
printf(0*d 0+a[!]["]);
printf(0*d 0+a[!][!]);
}
ans: 2 , 3 ,
!L). char str$uf[]0hello 0;
char *strptr0world 0;
str$uf0world 0;
strptr0hello0;
ans: error .use strcpy function1
!L=. char str![]0hello0;
char str)[]0hello0;
the conditional strin' test (str!str))
returns ,#.U/
ans: use strcmp function
!LE. main()
{
int i;
char *strE0!)=four0;
iatoi(strE);
printf(0*d0+i);
}
ans: 123
!L:. main()
{
char loop;
for(loop1#1;loop41C1;loop(()
printf(0*c0+loop);
}
ans: print characters of ascii value from '% to
112
!LL. main()
{
char s[]{1!1+1)1+1=1+"+1!1+1)1+1=1};
printf(0*s0+s);
}
ans: 123
!L7. main()
{
char *p@Raritor@;
*((p;
printf(?*s@+p);
*((p;
printf(?*s@+*p);
}
ans: aritor ritor
!L6. Mow to print ?*@ sym$ol in printf?

ans: printf.T<=U1+
!LA. Shat is the max no of char in command line
ar'uments?
ans:
!7". arithmetic Vperation canZt $e performed on %oid
pointers.
!7!. main()
{
char str![]0M/..V0;
char str)[]0M/..V0;
if(str!str))
printf(0/_W#.0);
else
printf(0HVI /_W#.0);
}
ans: -NG EVWAS .use strcmp function for
comparing strings1
!7). main()
{
int s:;
printf(0*d0+s+s44)+s55));
}
ans: %
!7=. main()
{
int s:;
printf(0*d *d *d0+s+s44)+s55));
}
ans: % 2, 1
!7E. main()
{
int a[)][)]{)+=};
printf(0*d *d *d *d0+a["]["]+a["][!]+a[!]
["]+a[!][!]);
}
ans: 2 3 , ,
!7:. main()
{
int iO=+9)+;"+m;
m ((9>>((i>>((;;
printf(0*d *d *d *d0+i+9+;+m);
}
ans: "2 3 1 1
!7L. main()
{
const int i7;
printf(0*d0+((i);
}
ans: cannot moify a constant ob:ect
!77. 3define - L
main()
{
printf(0*d0+((-);
}
ans: lvalue re3uire
!76. main()
{
int a[)][=][E]{{!+)+=+E+:+L+7+6+A+!+!+)}+
{)+=+E+7+L+7+6+A+"+"+"+"}};
printf(0*d *d *d *d0+a+*a+**a+***a);
}
ans: 1,,2 1,,2 1,,2 1 .array begins at
aress 1,,21
!7A. main()
{
printf(0*c0+7[0sundaram0]);
}
ans: m .a?i@/ i?a@/ a?2@/ 2?a@1
!6". main()
{
printf(0*c0+0sundaram0[7]);
}
ans: m .a?i@/ i?a@/ a?2@/ 2?a@1
!6!. main(int ar'c + char * ar'%[])
{
int i+9";
for(i";i4ar'c;i(()
99(atoi(ar'%[i]);
printf(0*d0+9);
}
ans: ' .if comman line arguments are
myprog 1 2 31
!6). main()
{
printf(0*d0+O!55E);
}
ans: "1 ."1 is store in 2*s complement form
when it is shifte sign bit is extene1
!6=. struct x
{
int i;
char c;
};
union y{
struct x a;
dou$le d;
};
main()
{
printf(0*d0+siCeof(union y));
}
ans: L .union y is a 2union variable type.
Fi0eof operator ta2es input either a variable
or a ata type1
!6E. struct x{
char c!;
char c);
int i;
short int 9;
};
struct y{
short int 9;
char c!;
char c);
int i;
};
main()
{
printf(0*d *d0+siCeof (struct x)+siCeof (struct y));
}
ans: ' ' .struct x an struct y are structure
variable types. Fi0eof operator ta2es input
either a variable or a ata type1
!6:. main()
{
int ;)+9=+p";
p(;+9+p);
printf(0*dBn0+p);
}
ans: , .comma operator1
!6L. main()
{
int iO!";
for(;i;printf(0*dBn0+i(());
}
ans: prints "1, to "1
!67. main()
{
unsi'ned int iO!;
printf(0*d *uBn0+i+i);
printf(0*uBn0+i*O!);
}
ans: "1 '%%3%
1
!66. main()
{
int **i;
int *9";
i>9;
if (HW.. P i>> HW.. P *i)
{
printf(0- am here0);
}
}
ans: oes not print anything
!6A. main()
{
int *9(int *)"x!""";
printf(0*p0+9);
}
ans: ,,,, : 1,,,
!A". main()
{
int *9"x!""";
printf(0*p0+9);
}
ans: ,,,,:1,,,
!A!. main()
{
int *9(int *)"x!"""; (or) int *9"x!""";
printf(0*d0+9);
}
ans: $,H'
!A). main(int x)
{
printf(0*d0+x);
}
ans: 1 .comman line arguments1
if the name of the executa$le file is a$c and the
command line is
'i%en as
a$c xyC
what is the output
ans: 2
!A=. main()
{
char a[]{1!1+1)1+1=1+"+1!1+1)1+1=1};
printf(a);
}
ans: 123
!AE. 3define const const
%oid main(int ar'c)
{
const int x";
}

ans: runs fine
!A:. main()
{
int a[]{:+L};
printf(0*d0+a[!.L]);
}
ans: '
!AL. struct x
{
int i"; &*line #*&
};
main()
{
struct x y; &*line 2*&
}
ans: error .i is initiali0e in struct boy1
!A7. struct {
int len;
char *str
}*p;
((p O5 len
ans: increments len
!A6. main()
{
char a[]0a$cdef'hi9;lmnopKrstu%wxyC0;
printf(0*d0+siCeof(a));
}
ans: 27 .si0eof operator inclues null
character also/ whereas strlen function
exclues null character1
!AA. main()
{
char a[]0a$cdef'hi9;lmnopKrstu%wxyC0;
char *pa;
printf(0*d 0+strlen(p));
p(!";
printf(0*d0+strlen(a));
}
ans: 2' 2'
)"". main()
{
printf(0*d0+printf(0 hello world 0));
}
ans: hello worl 13 .incluing two spaces1
)"!. what is the output of the followin' code+ assumin' that
the array
$e'ins at location :=LE67:?
main()
{
int a[)][=][E]{
{)+!+E+=+L+:+6+7+"+A+)+)}+
{!+)+=+E+:+L+7+6+A+"+!+)}
};
printf(0*u *u *u *u0+a+*a+**a+***a);
}
ans: %3'$L7%/%3'$L7%/%3'$L7%/2
)"). main()
{
char a "x## ;
int $ ;
$ (int) a ;
$ $ 55 E ;
printf(0*x0+$);
}
ans: fffa
)"=. Shat is the siCe of the array declared as dou$le *
<[:] ?
ans. % ( si0eof . ouble ( 1
)"=. 3define clrscr() !""
main()
{
clrscr();
printf(0*d0+clrscr());
}
ans: 1,,
)"E. main()
{
int a;
printf(0*d0+scanf(0*d0+>a));
}
ans: it will wait for a character from
2eyboar. &f u enter any number
it will print 1.
)":. main()
{
printf(0as0);
printf(0B$hi0);
printf(0isBn0);
}
ans: ahiis .<b is bac2space. Fo s is erase1
)"L. main()
{
unsi'ned short aO!;
unsi'ned char $a;
printf(0*d *d 0+a+$);
}
ans: "1 2%% .= format specifier1
)"7. main()
{
unsi'ned short aO!;
unsi'ned char $a;
printf(0*u*d 0+a+$);
}
ans: '%%3% 2%% .=u format specifier1
)"6. 3define max%al :
main()
{
int i!;
if(iOmax%al)
{
printf(0inside0);
}
else
{
printf(0out0);
}
}
ans: insie
)"A. 3define a =(=
3define $ !!O=
main()
{
printf(0*d0+a*$);
}
ans: 33
)!". main()
{
int *i;
int s(int *)malloc(!"*siCeof(int));
for (i";i4!";i(()
{
printf(0*d0+i*i);
}
}
ans: error .-onportable pointer conversion
an illegal use pointer i(i1
)!!. arrayZs $ase address is !"""....array is a[:][E]..then
wat is de
correct address of a[E][=].../ach element ta;es E $ytes
ans:1,7'
)!). int a[:+L]
how much memory will $e allocated
ans: oubt.if comma operator is consiere
12 bytes will be allocate1
)!=. 3define d !"(!"
main()
{
printf(0*d0+d*d);
}
ans: 12,
)!E. main()
{
int i+9!;
for(i";i4!";i(();
{
99(i;
}
Frintf (0*d *d0+i+9);
}
ans: 1, 11
)!:. static char *i;
imalloc(siCeof(char));
find the error;
ans: malloc returns voi .type casting is
re3uire .char (1 1
)!L. main()
{
int i"xaa;
char *p;
p(char *)i;
pp55E;
printf(0*x0+p);
}
ans: illegal use of pointer p)p##$
)!7. main()
{
enum{sundayO!+monday+wednesday};
printf(0*d *d0+siCeof(wednesday)+wednesday);
}
ans: 2 1
)!6. O5Mow do you write a pro'ram which produces its own
source code as its output?
O5Mow can - find the day of the wee; 'i%en the date?
O5Shy doesn1t R ha%e nested functions?
O5Shat is the most efficient way to count the num$er
of $its which are set in a %alue?
O5Mow can - con%ert inte'ers to $inary or
hexadecimal?
O5Mow can - call a function+ 'i%en its name as a
strin'?
O5Mow do - access commandOline ar'uments?
O5Mow can - return multiple %alues from a function?
O5Mow can - in%o;e another pro'ram from within a R
pro'ram?
O5Mow can - access memory located at a certain
address?
O5Mow can - allocate arrays or structures $i''er than
LET?
O5Mow can - find out how much memory is a%aila$le?
O5Mow can - read a directory in a R pro'ram?
O5Mow can - increase the allowa$le num$er of
simultaneously open files?
O5Shat1s wron' with the call
0fopen(0c:BnewdirBfile.dat0+ 0r0)0?
)!A. %oid main()
{
int d:;
printf(0*f0+d);
}
ans: unefine
))". %oid main()
{
int i;
for(i!;i4E;i(()
switch(i)
{
case !: printf(0*d0+i);$rea;;
{
case ):printf(0*d0+i);$rea;;
case =:printf(0*d0+i);$rea;;
}
}
switch(i) case E:printf(0*d0+i);
}
ans: 123$
))!. %oid main()
{
int i;
for(i!;i4E;i(()
switch(i)
{
case !: printf(0*d0+i);$rea;;
{
case ):printf(0*d0+i);$rea;;
case =:printf(0*d0+i);$rea;;
}
switch(i) case E:printf(0*d0+i);
}
}
ans: 123
))). %oid main()
{
char *s0B!)=E:sBn0;
printf(0*d0+siCeof(s));
}
ans: $ .pointer ta2es $ bytes here1
))=. %oid main()
{
unsi'ned i!; &* unsi'ned char ; O! 5 ;)::;
*&
si'ned 9O!; &* unsi'ned or si'ned int ; O!
5;L::=: *&
if(i49)
printf(0less0);
else
if(i59)
printf(0'reater0);
else
if(i9)
printf(0eKual0);
}
ans: less
))E. Mow do you declare an array of H pointers to functions
returnin' pointers to functions returnin' pointers to
characters?
ans: char (.(.([email protected]+
typedef char *pc; &* pointer to char *&
typedef pc fpc(); &* function returnin' pointer to
char *&
typedef fpc *pfpc; &* pointer to a$o%e *&
typedef pfpc fpfpc(); &* function returnin'... *&
typedef fpfpc *pfpfpc; &* pointer to... *&
pfpfpc a[H]; &* array of... *&
22.int f();
!"i# $ain()
{
f(1);
f(1,2);
f(1,2,3);
}
f(int i,int %,int &)
{
printf("%# %# %# ",i,%,&);
}
ans: 1 garbage garbage 1 2 garabage 1 2 3
))L. %oid main()
{
int count!"+*temp+sum";
temp>count;
*temp)";
temp>sum;
*tempcount;
printf(0*d *d *d 0+count+*temp+sum);
}
ans: 2, 2, 2,
))7. main()
{
static i=;
printf(0*d0+iOO);
return i5" ? main():";
}
ans: 321
))6. char *foo()
{
char result[!""];
strcpy(result+0anythin' is 'ood0);
return(result);
}
%oid main()
{
char *9;
9foo();
printf(0*s0+9);
}
ans: anything is goo .aress of auto
variable shoul not be returne. Fometimes
it will give un2nown results1
))A. %oid main()
{
char *s[]{ 0dharma0+0hewlettO
pac;ard0+0siemens0+0i$m0};
char **p;
ps;
printf(0*s 0+((*p);
printf(0*s 0+*p(();
printf(0*s 0+((*p);
}
ans: harma harma ewlett"pac2ar
)=". main()
{
static int i ";
int C;
if(i((4:)
{
printf(0*d 0+i);
}
else
exit(");
C=;
printf(0*d *d 0+C+main());
}
ans: 1 2 3 $ %
)=!. main()
{
static int i ";
int C;
if(i((5:)
{
printf(0*d 0+i);
exit(");
}
C=;
printf(0*d *d 0+C+main());
}
ans: 7
)=). main()
{
int C=;
printf(0*d *d 0+C+main());
}
ans: infinite loop or till stac2 overflows
)==. main()
{
int i=+9:;
while (iOO+9OO)
{
printf(0*d *d Bn0+i+9);
}
}
ans: 2 $
1 3
, 2
"1 1
"2 ,
% times loop will be execute
)=E. main()
{
int i=+9:;
if(iOO+9OO)
printf(0*d *d Bn0+i+9);
}
ans: 2 $
)=:. main()
{
int i=;
printf(0*d *d *d 0+((i+iOO+i(:);
}
ans: L L L
)=L. main()
{
int times :;
int i=;
int 9E;
int ;=E;
i9(;;
while(times OO)
{
itimes;
9times;
;times;
}
printf(0*d *d *d 0+i+9+;);
}
ans: , , ,
)=7. main()
{
int num =)7L:;
while (num(();
printf(?*d ?+num);
}
ans: 1
)=6. main()
{
float ;=.E!:L;
printf(0*f *f 0+floor(;)+ceil(;));
}
ans: 3.,,,,,, $.,,,,,,
)=A. main()
{
int num$er ):;
char name 1#1;
printf(0Ihe addition of the name and the num$er
is *o 0+name(num$er);
}
ans: Ghe aition of the name an the
number is 132
)E". Ihe followin' function 'i%es some error. Shat chan'es
ha%e to $e made
%oid ( int a+int $)
{
int t; ta; a$; $t;
}
ans: change everywhere a to (a an b to (b
)E!. int main()
{
,-./ *fp;
fpfopen(0test.dat0+0w0);
fprintf(fp+1helloBn0);
fclose(fp);
fpfopen (0test.dat0+0w0);
fprintf (fp+ 0world0);
fclose(fp);
return ";
}
-f text.dat file is already present after compilin' and
execution how many $ytes does the file occupy ?
ans: % bytes
******)E). main()
{
int i;
for(i";i4)";i(()
{
switch(i)
{
case ":i(:;
case !:i();
case ::i(:;
default: i(E;
$rea;;}
printf(0*d+0+i);
}
}
ans: 1'/ 21/
)E=. main()
{
char cOLE;
int iO=);
unsigne int u )"1'+
if(c5i)
{
printf(0pass!+0);
if(c4u)
printf(0pass)0);
else
printf(0,ail)0);
}
else
printf(0,ail!+0);
if(i4u)
printf(0pass)0);
else
printf(0,ail)0);
}
ans: Eail1/ pass2
******)EE. main()
{
char cOLE;
int iO=);
unsigne int u )1'+
if(c5i)
{
printf(0pass!+0);
if(c4u)
printf(0pass)0);
else
printf(0,ail)0);
}
else
printf(0,ail!+0);
if(i4u)
printf(0pass)0);
else
printf(0,ail)0);
}
ans: Eail1/ Eail2 .chec2 with above program1
*****)E:. %oid main()
{
int i;
char a[]0Utrin'0;
char *p0Hew Urin'0;
char *Iemp;
Iempa;
amalloc(strlen(p) ( !);
strcpy(a+p); &&.ine num$er:A&&
p malloc(strlen(Iemp) ( !);
strcpy(p+Iemp);
printf(0(*s+ *s)0+a+p);
free(p);
free(a);
} &*.ine num$er !:*&
ans: lvalue re3uire .at line no. L1
)EL. main()
{
unsi'ned int xO!;
int y;
y X";
if(x y)
printf(0same0);
else
printf(0not same0);
}
ans: same
******)E7. char *'xxx()
{
static char xxx?1,2$@+
return xxx;
}
main()
{
char *'0strin'0;
strcpy('xxx()+');
' 'xxx();
strcpy('+0oldstrin'0);
printf(0Ihe strin' is : *s0+'xxx());
}
ans: Ghe string is olstring
*******)E6. %oid myalloc(char *x+ int n)
{
x (char *)malloc(n*siCeof(char));
memset(x+1B"1+n*siCeof(char));
}
main()
{
char *'0Utrin'0;
myalloc('+)");
strcpy('+0Vldstrin'0);
printf(0Ihe strin' is *s0+');
}
ans: Ghe string is Nlstring
******)EA. main()
{
char p[]0Utrin'0;
int x";
if.p))!Ftring!1
{printf(0Fass !0);
if(p[siCeof(p)O)]1'1)
printf(0Fass )0);
else
printf(0,ail )0);
}
else
{
printf(0,ail !0);
if(p[siCeof(p)O)]1'1)
printf(0Fass )0);
else
printf(0,ail )0);
}
}
ans: Eail 1Oass 2 .aress of array an
aress of string where it is store are
ifferent1
***):". main()
{
char *p0Utrin'0;
int x";
if.p))!Ftring!1
{printf(0Fass !0);
if(p[siCeof(p)O)]1'1)
printf(0Fass )0);
else
printf(0,ail )0);
}
else
{
printf(0,ail !0);
if.p?si0eof.p1"2@))'g'1
printf(0Fass )0);
else
printf(0,ail )0);
}
}
ans: Eail 1Eail2 .aress of array an
aress of string where it is store are
ifferent1
):!. main()
{
printf(0*u0+main);
}
ans: ,
):). main()
{
printf(0*p0+main);
}
ans: starting aress of main function x:y
.segment : offset1. Each time u run starting
aress will change. Eunction name always
gives starting aress of that function.
main()
{
printf(0*u0+main());
}
ans: infinite loop or till stac2 overflows. main
function is calle recursively infinite times or
till stac2 overflows
):=. main()
{
int i!";
printf(0*d *d *d0+i+i((+((i);
}
ans: 12 11 11 .compiler epenent1
):E. main()
{
int *p+*K;
p(int *)!""";
K(int *))""";
printf(0*d0+(KOp));
}
ans: %,,
)::. find(int x+int y)
{return ((x4y)?":(xOy)):}
find(a+find(a+$)) is used for?
ans: fin out minimum of a/ b
):L. find(int x+int y);
main()
{
int x+a6+$L;
xfind(a+find(a+$));
printf(0*d0+x);
}
find(int x+int y)
{ return ((x4y)?":(xOy));}
ans: '
):7. main()
{
int a;
if (a7)
printf(0 a is 7 0);
else
printf(0a is not 70);
}
ans: a is 7
):6. main()
{
int aE+$=+c:;
if (a5$)
if($5c)
printf(0inner0);
else printf(0outer0);
}
ans: outer .else is attache to inner if1
):A. main()
{
int a)+$=+c:;
if (a5$)
if($5c)
printf(0inner0);
else printf(0outer0);
}
ans: no output .else is attache to inner if1
)L". main()
{
inc(); inc(); inc();
}
inc()
{
static int x;
printf(0*d0+ ((x);
}
ans: 123
)L!. main()
{
printf(0*d0+ strlen(00));
}
ans: , .strlen exclues null character. &t is a
null string1
)L). main()
{
printf(0*d0+ siCeof(00));
}
ans: 1 .si0eof inclue null character. &t is a
null string1
)L=. main()
{
int a:+$);
printf(0*d0+ a((($);
}
ans: 7
)LE. main()
{
int %=+ *p%>%;
printf(0 *d *d 0+ %+*p%);
}
ans: 3 3
)L:. main()
{
enum
cities{$ethlehem+9ericho+naCareth!+9erusalem};
printf(0*d *d0+9ericho+naCareth);
}
ans: 1 1
)LL. difference $etween scanf and sscanf function
ans: sscanf.s/...1 is e3uivalent to scanf....1
except that
input charecter are ta2en from string s.
)L7. main()
{
char line[6"];
scanf(0*[JBn]0+line);
printf(0*s0+line);
}
ans: if you type this is manu;enter# output
will be this is manu
scanf normally ta2es a single string but if we
use ?M<n@ it ta2es multiple strings till it
encounters newline .i.e./ enter is presse1
)L6. main()
{
char line[6"];
scanf(0*[Ja]0+line);
printf(0*s0+line);
}
ans: type this is manu;enter# output will be
this is m
)LA. main()
{
char line[6"];
scanf(0*[Ju]0+line);
printf(0*s0+line);
}
ans: type this is manu;enter# output will be
this is man
)7". main()
{
printf(0*f *f0+floor(O).6)+ceil(O).6));
}
ans: "3.,,,,,, "2.,,,,,,
)7!. int x[=][E] {
{!+)+=}+
{E+:+L}+
{7+6+A}
}
ans: values in fourth column are 0ero
)7). main ()
{
int i :;
i (((i)&(i(();
printf( 0*d0 + i);
}
ans: 2
)7=. main()
{
int a+$;
int *p+*K;
a!";$!A;
p)B.a6b1+
3)Bmax+
}
ans: error .must ta2e aress of memory
location1
*****)7E. main()
{
printf(0*u0+ siCeof(func));
}
func()
{
return ";
}
ans: error .si0eof operator operan shoul
not be function name1
)7:. main()
{
printf(0*u0+ siCeof(func()));
}
func()
{
return ";
}
ans: 2 .si0eof operator operan shoul not
be function name but it can be a function
call1
)7L. siCeof operator is runtime operator
)77. #n array whose elements are fn pointers which
inturn returns a character
ans: char .(x?@1 .1+
)76. main()
{
int n+i!;
switch(n)
{
case !:
printf(0!0);
case ):
printf(0)0);
default:
i!";
}
printf(0i*d0+i);
}
ans: 1, .since n is not initiali0e it contains
garbage value hence almost all the times
efault case is run1
)7A. 3define max !"
main()
{
int a+$;
int *p+*K;
a!";$!A;
p)B.a6b1+
3)Bmax+
}
ans: error .must ta2e aress of a memory
location1
*****)6". main()
{
int i;
printf(0*d0+ >i)(!;
scanf(0*d0+ i)O!;
}
ans: aress of memory location i .scanf
function reas value into a garbage location
if it fall in protecte memory it gives error
otherwise value will be rea into that
location1
********)6!. main()
{
int i;
float *pf;
pf (float *)>i;
*pf !""."";
printf(0*d0+ i);
}
ans: runtime error
)6). main()
{
int i "xff;
printf(0*d0+ i44));
}
ans: 1,2,
)6=. 3define U_G(x) x * x
main()
{
printf(0*d0+ )):&U_G(!:));
}

ans: 22%
)6E. union u
{
struct st
{
int i : E;
int 9 : E;
int ; : E;
int l;
}st;
int i;
}u;
main()
{
u.i !"";
printf(0*d+ *d+ *d0+u.i+ u.st.i+ u.st.l);
}
ans: 1,, $ ,
)6:. union x
{
union u
{
int i;
int 9;
}a[!"];
int $[!"];
}u;
main()
{
printf(0*d 0+ siCeof(u));
printf(0*d 0+ siCeof(u.a));
printf(0*d0+ siCeof(u.a["].i));
}
ans: 2, 2, 2 .-ote: when unions or
structures are neste inner an outer
tagnames shoul be ifferent1
******)6L. main()
{
int (*functa$le[)])(char *format+ ...) {printf+ scanf};
int i !"";
(*functa$le["])(0*d 0+ i);
.(functable?1@1.!= !/ i1+
.(functable?1@1.!= !/ i1+
(*functa$le["])(0*d0+ >i);
}
ans: runtime error .B is missing1
***)67. main()
{
int (*functa$le[)])(char *format+ ...) {printf+ scanf};
int i !"";
(*functa$le["])(0*d+ 0+ i);
.(functable?1@1.!=!/ Bi1+
.(functable?1@1.!=!/ Bi1+
(*functa$le["])(0+ *d0+ >i);
}
ans: 1,,/ enter two values for scanf/ i
aress value. &n function pointers all the
functions will have the same return type.
)66. main()
{
int i+ 9+ *p;
i ):;
9 !"";
p >i; &* #ddress of i is assi'ned to pointer p *&
printf(0*f0+ i&(*p)); &* i is di%ided $y pointer p *&
}
ans: runtime error .format specifier =f is not
matche1
)6A. main()
{
char *p 0hello world0;
p["] 1M1;
printf(0*s0+ p);
}
ans: 5ello worl
)A". main()
{
char * str#;
char * str2 0- am VT0;
memcpy( str#+ str2+ L);
}
ans: error .pointer shoul be initiali0e
before using1
)A!. Mow will you print * character?
ans: printf.T<=U1+
printf.T==U1+
printf.T<==U1+
)A). main()
{
printf(0B* 0);
printf(0BB* 0);
printf(0** 0);
printf(0B**0);
}
ans: = <= = =
)A=. main()
{
printf(0B*d 0+ !"");
printf(0BB* 0);
printf(0** 0);
printf(0B**0);
}
ans: 1,, <= = =
)AE. const int perplexed );
3define perplexed =
main()
{
3ifdef perplexed
3undef perplexed
3define perplexe $
3endif
printf(0*d0+perplexe);
}
ans: $ .const int perplexe will not come into
picture bco0 text replacement is one at
preprocessor stage which is first stage in
executable file evelopment stages1
)A:. struct ,oo
{
char *pHame;
};
main()
{
struct ,oo *o$9 malloc(siCeof(struct ,oo));
strcpy(o$9O5p-ame+0Your Hame0);
printf(0*s0+ o$9O5pHame);
}
ans: runtime error .-ote: p-ame shoul be
initiali0e before using1
)AL. struct ,oo
{
char *pHame;
char *p#ddress;
};
main()
{
struct ,oo *o$9 malloc(siCeof(struct ,oo));
o$9O5pHame malloc(!"");
o$9O5p#ddress malloc(!"");
strcpy(o$9O5pHame+0Your Hame0);
strcpy(o$9O5p#ddress+ 0Your #ddress0);
free(o$9);
printf(0*s 0+ o$9O5pHame);
printf(0*s0+ o$9O5p#ddress);
free(o$9O5pHame);
free(o$9O5p#ddress);
}
ans: :Qour -ame Qour Aress
)A7. main()
{
char *a 0Mello 0;
char *$ 0Sorld0;
printf(0*s0+ stract(a+$));
}
ans: stract function shoul be efine or
strcat shoul be use
)A6. main()
{
char *a 0Mello 0;
char *$ 0Sorld0;
printf(0*s0+ strcat(a+$));
}
ans: 5elloRorl
)AA. main()
{
char *a 00;
char *$ 0Sorld0;
printf(0*s0+ strcpy(a+$));
}
ans: Rorl
="". %oid func!(int (*a)[!"])
{
printf(0V; it wor;s 0);
}
%oid func)(int a[][!"])
{
printf(0Sill this wor;?0);
}
main()
{
int a[!"][!"];
func!(a);
func)(a);
}
ans: N2 it wor2s Rill this wor2X
Eormal argument in function efinition
shoul be a pointer to array or ouble
imensional array but not a pointer to
pointer .oble pointer1
="!. main()
{
printf(0*d+ *d0+ siCeof(1c1)+ siCeof(!""));
}
ans: 2/ 2
="). main()
{
int i !"";
printf(0*d0+ siCeof(siCeof(i)));
}
ans: 2
="=. int f();
main()
{
int c :;
printf(0*p *p *d *d0+ f+f()+f+f());
}
int f()
{}
ans: segment:offset segment:offset integer
integer .all are un2nown values. Fegment
an offset values of function aress an
function return value. Yalues of function
aress an function return value1
="E. main()
{
char c;
int i E:L;
c i;
printf(0*d0+ c);
}
ans: "%'
=":. main ()
{
int x !";
printf (0x *d+ y *d0+ x+OOx(();
}
ans: lvalue re3uire
="L. main()
{
int i !"+ 9 )";
printf(0*d+ *d+ 0+ 9OO + OOi);
printf(0*d+ *d0+ 9(( + ((i);
}
ans: 2,/ H/ 1H/ 1,
="7. main()
{
int x:;
for(;x";xOO)
{
printf(0x*dBn0+ xOO);
}
}
ans: no output
="6. main()
{
int x)%+
for(;xP";x"")
{
printf(0x*d 0+ x"");
}
}
ans: infinite loop .becareful here two
ecrements/ an x is o. Fo x)), never
occurs1
="A. main()
{
int x)$+
for(;x";x"")
{
printf(0x*d 0+ x"");
}
}
ans: x)$ x)2
=!". main()
{
int x:;
{
printf(0x*d0+ xOO);
}
}
ans: x)%
=!!. main()
{
unsi'ned int $it):L;
printf(0*d 0+ $it);
{
unsi'ned int $it:!);
printf(0*d0+ $it);
}
}
ans: 2%' %12
=!). main()
{
int i;
for(i";i4:;i(()
{
printf(0*d 0+ !. 44 i);
}
}
ans: 1 2 $ L 1'
=!=. main()
{
si'ned int $it:!)+ i:;
for(;i;iOO)
{
printf(0*d 0+ $it ($it 55 (i O (i O!))));
}
}
ans: 2%' 12L '$ 32 1'
=!E. main()
{
si'ned int $it:!)+ i:;
for(;i;iOO)
{
printf(0*d 0+ $it 55 (i O (i O!)));
}
}
ans: 2%' 2%' 2%' 2%' 2%'
=!:. main()
{
if (P(!>>"))
{
printf(0VT - am done.0);
}
else
{
printf(0VT - am 'one.0);
}
}
ans: NC & am one
=!L. main()
{
if ((!]]") >> ("]]!))
{
printf(0VT - am done.0);
}
else
{
printf(0VT - am 'one.0); }
}
ans: NC & am one
=!7. main()
{
si'ned int $it:!)+ m2it;
{
m2it X$it;
$it $it > X$it ;
printf(0*d *d0+ $it+ m2it);
}
}
ans: , "%13
=!6. Shat is the difference $etween the followin'
a. ii(!;
$. ((i;
ans: 66i is a single instruction while in
i)i61/ first i61 is compute an then
assigne.
=!A. Shat is exception handlin' and how is it different from
error handlin'...... Shy
is exception handlin' used instead of error handlin' in
some cases and %ice %ersa.
=)". /xplanation of VVF principles
ONata #$straction.
ONata /ncapsulation
O-nheritence
OFolymorphism
ONynamic 2indin'.
OGeduction of /rrors.
=)!. main()
{
int d+a:+$=+c(a+$);
d(a+$);
printf(0*d *d0+c+d);
}
ans: 3 3 .from 321 to 32$ thin2 about comma
operator1
=)). main()
{
int a:+$=+ca+d;
d(a+$);
printf(0*d *d0+c+d);
}
ans: % 3
=)=. main()
{
int a:+$=+c(a+$)+d;
d(a+$);
printf(0*d *d0+c+d);
}
ans: 3 3
=)E. main()
{
int a:+$=+c(a+$)+d;
da+$;
printf(0*d *d0+c+d);
}
ans: 3 % .from 321 to 32$ thin2 about comma
operator1
=):. Shich one is ha%in' pro$lem?
int *f!()
{
int n;
return (n)
}
int *f)()
{
int *p;
*p=;
return p;
}
int *f=()
{
int *p;
pmalloc();
return p;
}
int *fE()
{
int n;
return (>n)
}
ans: f$ is having problem as it is returning
aress of auto variable.
=)L. *p(!
*p((
are these two same?
ans: not same .first one increments value
pointe by p an secon one increments
pointer1
=)7. int num[=];
num[=]);
ans: array inex excees array bouns
=)6. main()
{
int 9E;
for(int i";i4:;i(()
{
9((;
((9;
}
printf(0*d0+9);
}
ans: unefine symbol i
=)A. main()
{
int 9E;
for(int i";i4:;i(()
{
9((;
((9;
}
printf(0*d0+9);
}
ans: 1$
==". main()
{
char s![)"]0hello world0;
s1?%@)U<,U+
printf(0*d0+strlen(s!));
}
ans: nonportable pointer conversion
==!. main()
{
char s![)"]0hello world0;
s1?%@)*<,*+
printf(0*d0+strlen(s!));
}
ans: %
==). Shich canZt $e passed to su$routine
ans:preprocessor irective.
===. 3define m 1,
f.1+
main()
{
f(m);
}
f.int :1 or f.:1
{
printf(0=0+9);
}
ans: 1,
==E. 3define m 1,.,
f.float1+
main()
{
f(m);
}
f.float :1
{
printf(0=f0+9);
}
ans: 1,.,,,,,, .careful about macro value
type an procee1
==:. f.1+
main()
{
int x!+y)+C=;
f(x+y+C);
}
f.int p/int 3/int r1
{
printf(0*d *d *d0+p+K+r);
}
ans: 1 2 3 .in prototype we have not given
argument types as they are ints1
==L. f.1+
main()
{
float x!."+y)."+C=.";
f(x+y+C);
}
f.float p/float 3/float r1
{
printf(0*f *f *f0+p+K+r);
}
ans: error .no prototype1
==7. f.float/ float/ float1+
main()
{
float x!."+y)."+C=.";
f(x+y+C);
}
f.float p/float 3/float r1
{
printf(0*f *f *f0+p+K+r);
}
ans: 1.,,,,,, 2.,,,,,, 3.,,,,,,
==6. main()
{
int x";
for(;;x((){
if(xE) $rea;;
continue;
}
printf(0*dBn0+x);
}
ans: $
==A. main()
{
int i!"";
do
{OOi;}while(i5:");
printf(0*dBn0+i);
}
ans: %,
=E". main()
{
int o;
int mO!E;
int nL;
om*((n;
n(m((*o;
printf(0*d*d*d0+m+n+o);
}
ans: ivie by 0ero error
=E!. main()
{
int a!"""+$!"""+c;
(lon')c(lon')a*$;
printf(0*d0+c);
}
ans: error .lvalue re3uire1
=E). Ne$u''in' is the process of findin'
ans : logical an runtime errors
=E=. usin' ternary find out max of a+$+c
ans: .a#b1 X .a#c X a : c1 : .b#c X b : c1
=EE. main()
{
int a+ *$ >a+ **c >$;
aE;
** c :;
printf(0*d0+a);
}
ans: %
=E:. main( )
{
int i !;
if(Pi)
printf(0Gecursi%e calls are real painP0);
else
{
i ";
printf(0Gecursi%e calls are challen'in'Bn0);
main();
}
}
ans: prints Decursive calls are challenging
infinite times or till stac2 overflows.
=EL. main()
{
struct emp{
char n[)"];
int a'e;};
struct emp e!{0da%id0+)=};
struct emp e)e!;
if(e!e))
printf(0structures are eKual0);
}
ans: structures are e3ual .in A-F& K1 but
error in some other compilers. 4irect
assignment an comparisons can*t be one.
=E7. main( )
{
char a[];
a["] 1#1;
printf(0*c0+ a["]);
}
ans: si0e of a is un2nown
=E6. main()
{
printf(0*d *d*d0+siCeof(1=1)+siCeof(0=0)+siCeof(=));
}
ans: 2 2 2
=EA. main()
{
printf(0*c0+0a$cdef'h0[E]);
}
ans: e
=:". main()
{
int a[ ]{!"+)"+="+E"+:"};
char *p;
p(char *)a;
printf(0*d0+*((int *)p(E));
}
ans: %,
=:!. main()
{
int a[]{!"+)"+="+E"+:"};
char *p;
p(char *)a;
printf(0*d *d *d *d0+*p+*(p(!)+*(p())+*(p(=));
}
ans: 1, , 2, ,
=:). main()
{
printf(0*c0+7[0sundaram0]);
}
ans: m
=:=. 3define str(x) 3x
3define <str(x) str(x)
3define oper multiply
main()
{
char *opername<str(oper);
&* Zmultiply i.e.+ TmultiplyU
printf(0*s0+opername);
}
ans: multiply .Z/ stringi0ing operator allows
a formal argument within a macro efinition
to be converte to a string1
=:E. 3define sKr(x) (x*x)
main()
{
int a+$=;
asKr($());
printf(0*d0+a);
}
ans: 11
=::. main()
{
int $;
$f()");
printf(0*d0+$);
}
f(int a)
{
a#2, X return .1,1: return .2,1+
}
ans: error in function efinition
=:L. main()
{
int $;
$f()");
printf(0*d0+$);
}
f(int a)
{
return a#2, X .1,1: .2,1+
}
ans: 2,
=:7. Shat error would the followin' function 'i%e on
compilation.
f(int a+int $)
{
int a;
a)";
return a;
}
ans: reeclaration of a
=:6. main()
{
int i=;
ii((;
printf(0*d0+i);
}
ans: $
=:A. main()
{
static char a[]02om$ay0;
char *$02om$ay0;
printf(0*d *d0+siCeof(a)+siCeof($));
}
ans: 7 $ .here pointer ta2es $ bytes1
=L".
main()
{
int x :;
printf(0*d *d0+ x((+ ((x);
return ";
}
ans: ' '
=L!. main()
{
int C E;
printf(0*d0+ printf(0 *d *d 0+ C+ C));
}
ans: $ $ % .three spaces are there total five
characters will be printe by printf
statement1
=L). main()
{
int C E:;
printf(0*d0+ printf(0 *d *d 0+ C+ C));
}
ans: $% $% 7
=L=. main( )
{
int a[ ] { !"+ )"+ ="+ E"+ :"};
int 9;
for (9 "; 9 4 :; 9(()
{
printf(0*d0+ * a);
a66+
}
}
ans: lvalue re3uire
=LE. main()
{
int n)"+ i ";
while(nOO5");
i i(n;
printf(0*d0+i);
}
ans: "1
=L:. main()
{
int i "; char ch `#Z
do {
printf(?*c@+ ch);
} while (i(( 4:] ] ((ch 4 Z,Z);
}
ans: AAAAAABK4EE
=LL. int count+ sum;
main()
{
for(count E; sum ( OOcount;);
printf(0*d0+ sum);
}
ans: ,
=L7. main( )
{
static float a[ ] { !=.)E+ !.:}
float *9+ *;;
9 a;
; a ( );
9 9 * );
; ;&);
printf(?*f*f @+ *9+ *;);
}
ans: error .pointer multiplication an
ivision is illegal1
=L6. main( )
{
static char s[ ] ?GendeC%ous@;
printf(?*d@+ *(s( strlen(s)));
}
ans: ,
=LA. main()
{
char **p0Mello0;
printf(0*c0+*p);
}
ans: 5
=7". main()
{
char **p0Mello0;
printf(0*s0+p);
}
ans: 5ello
=7!. main()
{
char **p0Mello0;
printf.!=s!/(p1+ J( .or1 printf.T=sU/((p1+
(J
}
ans: error
=7). main()
{
char **p0Mello0;
printf(0*c0+**p);
}
ans: error
=7=. main()
{
char a[]0Mello0;
printf(0*cBn0+*a66);
}
ans: lvalue re3uire
=7E. main()
{
int a=+$)+c!;
static int ; a4$4cO!;
printf(0*d0+;);
}
ans: illegal initiali0ation .for static initiali0er
shoul be constant expression or constant1
=7:. main()
{
int a=+$)+c!;
int ; a4$4cO!;
printf(0*d0+;);
}
ans: ,
=7L. main()
{
char cO=);
int iOLE;
unsi'ned uO)L;
if(c5i)
printf(0F#UU! 0);
if( i 4 c)
printf(0F#UU) 0);
else
printf(0,#-.! 0);
if(i4u)
printf(0F#UU) 0);
else
printf(0,#-.) 0);
}
ans: OAFF1 OAFF2 OAFF2
=77. main()
{
int iE;
switch(i)
{
case !:
printf(0M/llo0);
case default: && 0case0 should not come with
0default0
printf(0****0);
}
}
ans: error .case shoul not be there with
efault1
=76. main()
{
static int i:;
printf(0*d 0+iOO);
if(i)
main();
}
ans: % $ 3 2 1
=7A. main()
{
int a:+c;
int ptr;
ptr)Ba+
c(ptr * a;
printf(0*d+*d0+c+a);
}
ans: error .nonportable pointer conversion
an invali inirection1
=6". main()
{
int x!"+y:+p+K;
px5A;
Kx5=>>yP=;
printf(0p*d K*d0+p+K);
}
ans: p)1 3)1
=6!. main()
{
int x!!+yL+C;
Cx:]]yPE;
printf(0C*d0+C);
}
ans: 0)1
=6). main()
{
int c"+d:+e!"+a;
ac5!?d5!]]e5!?!"":)"":="";
printf(0a*d0+a);
}
ans: a)3,,
=6=. main()
{
int iO:+9O);
9un;(i+>9);
printf(0i*d+9*d0+i+9);
}
9un;(i+9)
int i+*9;
{
ii*i;
*9*9**9;
}
ans: i)"%/:)$
=6E. 3define HV
3define Y/U
main()
{
int i:+9;
if(i5:)
9Y/U;
else
9HV;
printf(0*d0+9);
}
ans: error .-N an QEF are not efine1
=6:. 3define HV "
3define Y/U !
main()
{
int i:+9;
if(i5:)
9Y/U;
else
9HV;
printf(0*d0+9);
}
ans: ,
=6L. main()
{
int a"xff;
if(a44E55!))
printf(0leftist0);
else
printf(0ri'htist0);
}
ans: rightist
=67. main()
{
int i(!;
while(Xi)
printf(0%icious circles0);
}
ans: infinite loop
=66. Shat1s the use of siCeof( ) function... since one can
always directly write num$er of $ytes instead of
callin' the function.
ans: for runtime operations
=6A. main()
{
int p O)"";
char c;
c p;
printf(0*d *d0+ c((+ ((c);
}
ans: %7 %7
=A". int a!;
int a$E;
int main()
{
int $=+a);
printf(0*i*&*i*&**&i0+a+$+a$);
}
ans: 2(J3(J=(Ji
=A!. Shich one of the followin' statements allocates enou'h
space to hold an array of !" inte'ers that are initialiCed
to " ?
ans: int (ptr ) .int (1 calloc.1,/si0eof.int11+
=A). main()
{
int i+9;
9 !";
i 9(( O 9((;
printf(0*d *d0+ i+9);
}
ans: , 12
=A=. main()
{
int 9;
for(9";94=;9(()
foo();
}
foo() {
static int i !";
i(!";
printf(0*d 0+i);
}
ans: 2, 3, $,
=AE. Shat is wron' in the followin' code
main()
{
char *c;
c 0Mello0;
printf(0*sBn0+ c);
}
ans: 5ello .nothing wrong with the coe1
=A:. main()
{
union {
int a;
int $;
int c;
} u+%;
u.a !";
u.$ )";
printf(0*d *d Bn0+u.a+u.$);
}
ans: 2, 2,
=AL. main()
{
char *str 0!)=E:0;
printf(0*c *c *cBn0+ *str+ *(str(()+ *(str(());
}
ans: 3 2 1
=A7. 3define max(a+$) (a$)?a:$
main()
{
int a+$;
a=;
$E;
printf(0*d0+max(a+$));
}
ans: error .unefine symbol ab when it is
replace in printf statement1
=A6. main()
{
int lenE;
char *st0!)=E:L760;
st st Olen;
printf(0*cBn0+*st);
}
ans: some :un2 character is printe
=AA. func();
main()
{
func(!);
}
func(int i)
{
static char (str
)9 !Nne!/!Gwo!/!Ghree!/!Eour!>+
printf(0*sBn0+str[i((]);
return;
}
ans: error in eclaration an efinition.
Oointer shoul be there
E"". main()
{
int i;
for (i!;i4!""; i(()
printf(0*d *,xBn0+i+i);
}
ans: 1 to HH will be printe both in ecimal
an hexaecimal form
E"!. struct {
int x;
int y;
union {
int idDno;
char *name;
}$;
}s+*st;
main()
{
st >s;
stOx!";
stO$.idDno !"!;
printf(0*d *dBn0+s.x+s.$.idDno);
}
ans: error .unefine symbol i an b. i an b
shoul not be use as irect variables. Ghey
shoul be associate with structure variable1
E"). main()
{
int 9+ans;
9 E;
ans count(E);
printf(0*dBn0+ans);
}
int count(int i)
{
if ( i 4 ") return(i);
else
return( count(iO)) ( count(iO!));
}
ans: "1L
E"=. main()
{
int iE;
if(i")
printf(0statement !0);
else
printf(0statement )0);
}
ans: statement 2
E"E. main()
{
char a[)];
*a["]7;
*a[!]:;
printf(0*d0+>a[!]Oa);
}
ans: invali inirection
E":. main()
{
char a[]0hellow0;
char *$0hellow0;
char c?%@)!hellow!+
printf(0*s *s *s 0+a+$+c);
printf(0*d *d *d0+siCeof(a)+siCeof($)+siCeof(c));
}
ans: too many initiali0ers .c array si0e is
less1
E"L. main()
{
char a[]0hellow0;
char *$0hellow0;
char c[7]0hellow0;
printf(0*s *s *s 0+a+$+c);
printf(0*d *d *d0+siCeof(a)+siCeof($)+siCeof(c));
}
ans: hellow hellow hellow 7 $ 7 .here pointer
ta2es $ bytes1
E"7. int num[]{!"+!+:+))+A"};
main()
{
int *p+*K;
int i;
pnum;
Knum();
i*p((;
printf(0*d *d0+i+pOK);
}
ans: 1, "1
E"6. Vne pointer declaration is 'i%en li;e this:
int *(*p[!"])(char *+ char*)
/xplain the %aria$le assi'nment
ans: an array of 1, pointers to functions with
two character pointers as arguments an
returning integer pointer.
E"A. main()
{
char *a[E]{09aya0+0mahe0+0chandra0+0$uchi0};
printf(0*d *d *d0+siCeof(a)+siCeof(char
*)+siCeof(a)&siCeof(char *));
}
ans: 1' $ $ .pointer ta2es $ bytes1
E!". Ihe inte'ers from ! to n are stored in an array in a
random fashion. $ut one inte'er is
missin'. Srite a pro'ram to find the missin' inte'er.
ans: Ghe sum of n natural numbers is )
n.n611J2.
if we subtract the above sum from the
sum of all the
numbers in the array / the result is
nothing but the
missing number.
E!!. Srite a R pro'ram to find whether a stac; is
pro'ressin' in forward or re%erse direction.
E!). Srite a R pro'ram that re%erses the lin;ed list.
E!=. 3define 8#<(x+y) ..x1#.y1X.x1:.y11
main()
{
int x:+y:;
printf(0maximum is *d0+8#<(((x+((y));
}
ans: maximum is 7 .careful about braces not
only in printf but also in macro efinition.
E!E. main()
{
int *p+*K+r;
int %alues[="];
p>%alues["];
K%alues()A;
r((KOp;
printf(0*d0+r);
}
ans: 3,
E!:. static int i :;
main()
{
int sum";
do
{
sum ((!&i);
}while("4iOO);
}
ans: error .ivie by 0ero1
E!L. enum mode {'reen+red+oran'e+$lue +white};
main ()
{
'reen 'reen (!;
printf(0*d+*d0+'reen+red );
}
ans: error .lvalue re3uire since green is a
symbolic constant an ) operator shoul not
be there in enum eclaration1
E!7. int (*(*ptr)(int)) (%oid)
ans: ptr is pointer to function that ta2es an
int value returns a pointer
to a function with a no argument which
returns a integer
E!6. char *c[] {
0,-./0+
0/N-I0+
0U/#GRM0+
0RV8F-./0
};
char **cp[] {c(=+c()+c(!+c};
char ***cpp cp;
main()
{
printf(0*s 0+ **cpp);
printf(0*s0+ *OO*((cpp(=);
printf(0*s0+ *cpp[O)](=);
printf(0*sBn0+cpp[O!][O!](!);
}
ans: KN[O&SE G .last two printfs cause error1
E!A. struct x
{
int 9;
char ;[!""];
unsi'ned i;
};
int *ptr!;
struct < *ptr);
main()
{
printf(0*d *d0+siCeof(ptr!)+siCeof(ptr)));
}
ans: $ $
E)". main()
{
int i:;
printf( 0 *d *d *d0+ ((i+i+i(();
}
ans: 7 ' %
E)!. main()
{
int i+9 ;
for(i";i4!";i(();
for(9";94!";9(();
printf(0i*d+9*dBn0+i+9);
}
ans: i)11/:)11
E)). 3define sKuare(a) (a*a)
main()
{
printf(0*d0+sKuare(E(:));
}
ans: 2H
E)=. main()
{
int p "+ K !;
p K((;
p ((K;
p KOO;
p OOK;
printf(0*d *d0+p+K);
}
ans: 1 1
E)E. main()
{
int a + count;
int func(int);
for (count ! ;count 4:;((count)
{
a func(count);
printf(0*d0+ a);
}
}
int func(int x)
{
int y;
yx*x;
return(y);
}
ans: 1$H1'2%
E):. supposin' that each inte'er occupies E $ytes and each
charactrer ! $yte + what is the
output of the followin' pro'ramme?
main()
{
int a[] { !+)+=+E+:+L+7};
char c[] {1a1+1x1+1h1+1o1+1;1};
printf(0*d *d0+ (>a[=]O>a["])+(>c[=]O >c["]));
}
ans: 3 3
E)L. main()
{
struct s! {int i; };
struct s) {int i; };
struct s! st!;
struct s) st);
st!.i :;
st) st!;
printf(0 *d 0 + st).i);
}
ans: error .ifferent struct variables shoul
not assigne using !)! operator.1
E)7. main()
{
int i+9;
int mat[=][=] {!+)+=+E+:+L+7+6+A};
for (i);i5";iOO)
for (9);95";9OO)
printf(0*d0 + *(*(mat(9)(i));
}
ans: H'3L%27$1
E)6. main()
{
int n!";
fun(n);
}
int fun( int n)
{
int i;
for(i";i4n;i(()
fun(nOi);
printf(0 well done0);
}
howmany times is the printf statement executed
for n!"?
ans: 2efore reachin' to printf statement it will
'oes to infinite loop.
E)A. main()
{
struct emp{
char emp[];
int empno;
float sal;
};
struct emp mem$er { 0I-Q/G0};
printf(0 *d *f0+ mem$er.empno+mem$er.sal);
ans: error.array si0e is not eclare if it is
eclare ans is , ,.,,,,,,1
E=". 3 define infiniteloop while(!)
main()
{
infiniteloop;
printf(0NVH/0);
}
ans: infiniteloop in main ens with !+! . so
loop will not reach en+an the 4N-E also
will not print.
E=!. main()
{
int a)+ $=;
printf(0 *d 0+ a((($);
}
ans: %
E=). 3define prn(a) printf(0*d 0+a)
3define print(a+$+c) prn(a)+ prn($)+ prn(c)
3define max(a+$) (a4$)? $:a
main()
{
int x!+ y);
print(max(x((+y)+x+y);
print(max(x((+y)+x+y);
}
ans: 2 2 2 3 $ 2
E==. 3define FG-HI(int) printf(0int*d 0+int);
main()
{
int x+y+C;
x"=;yO!;C"!;
FG-HI(xJx);
C44=;FG-HI(C);
y55=;FG-HI(y);
}
ans: int), int)L int)"1
E=E. main()
{
int i;
i!;
ii()*i((;
printf(0*d0+i);
}
ans: $
E=:. main()
{
char ch1#1;
while(ch41,1)
{
switch(ch)
{
case1#1:case121:case1R1:case1N1:ch((;continue;
case1/1:case1,1:ch((;
}
putchar(ch);
}
}
ans: EP
E=L. main()
{
int a!+ $)+ c=+ *pointer;
pointer>c;
a)cJ(pointer+
$c;
printf (0a*d $*d0+a+$);
}
ans: error .there shoul be space between J
an ( otherwise it will be starting of
comment1
E=7. 3define 8#H(x+y) (x)5(y)?(x):(y)
main()
{
int i!"+9:+;";
; 8#H(i((+((9);
printf(0*d *d *d *d0+i+9+;);
}
ans: 12 ' 11 garbage value
E=6. main()
{
int a!"+$:+ c=+d=;
if(a4$)>>(cd(()
printf(0*d *d *d *d0 +a+$+c+d);
else printf(0*d *d *d *d0+ a+$+c+d);
}
ans: error .if conition shoul be
parenthesis1
E=A. main(int siCe of ar' +char *ar'[])
{
while(siCe of ar')
printf(0*s0+ar'[OOsiCe of ar']);
}
ans: error .no space between si0eofarg1
EE". main(int siCeofar' +char *ar'[])
{
while(siCeofar')
printf(0*s0+ar'[OOsiCeofar']);
}
ans: f:<progr.exe
EE!. main()
{
int i=;
while(iOO)
{
int i!"";
iOO;
printf(0*d..0+i);
}
}
ans: HH..HH..HH..
EE). main()
{
int rows=+columsE;
int a[rows]
[colums]{!+)+=+E+:+L+7+6+A+!"+!!+!)};
int i+ 9+;; i9;AA;
for(i";i4rows;i(()
for(9";94colums;9(()
if(a[;][9]4;) ;a[i][9];
printf(0*dBn0+;);
}
ans: error .constant expression re3uire in
array imension1
EE=. main()
{
int x!"+y!:;
xx((;
y((y;
printf(0*d *dBn0+x+y);
}
ans: 11 1'
EEE. main()
{
int x)"+y=:;
x y(( ( x((;
y ((y ( ((x;
printf(0*d *dBn0+x+y);
}
ans: %7 H$
EE:. main()
{
char *p!0Hame0;
char *p);
p)(char *)malloc()");
while(*p)((*p!(();
printf(0*sBn0+p));
}
ans: un2nown string will be printe pointer
p2 points to next character to null character.
EEL. main()
{
int x:;
printf(0*d *d *dBn0+x+x44)+x55));
}
ans: % 2, 1
EE7. 3define swap!(a+$) aa($;$aO$;aaO$;
main()
{
int x:+y!";
swap!(x+y);
printf(0*d *dBn0+x+y);
swap)(x+y);
printf(0*d *dBn0+x+y);
}
int swap)(int a+int $)
{
int temp;
tempa;
$a;
atemp;
return;
}
ans: 1, %
1, % .swap2 won*t swap x an y1
EE6. main()
{
char *ptr 0Gamco Uystems0;
(*ptr)((;
printf(0*sBn0+ptr);
ptr((;
printf(0*sBn0+ptr);
}
ans: Famco Fystems
amco Fystems
EEA. main()
{
char s![]0Gamco0;
char s)[]0Uystems0;
s!s);
printf(0*s0+s!);
}
ans: error .lvalue re3uire1
E:". main()
{
char *p!;
char *p);
p!(char *) malloc():);
p)(char *) malloc():);
strcpy(0Gamco0+p!);
strcpy(p)+0Uystems0);
strcat(p!+p));
printf(0*s0+p!);
}
ans: DamcoFystems
E:!. main()
{
char a[)];
*a["]7;
*a[!]:;
printf(0*d0+>a[!]Oa);
}
ans: error .invali inirection1
E:). main()
{
char a[]0hellow0;
char *$0hellow0;
char c[:]0hellow0;
printf(0*s *s *s 0+a+$+c);
printf(0 0+siCeof(a)+siCeof($)+siCeof(c));
}
ans: error .Goo many initiali0ers1
E:=. main()
{
char a[]0hellow0;
char *$0hellow0;
char c[7]0hellow0;
printf(0*s *s *s 0+a+$+c);
printf(0*d *d *d 0+siCeof(a)+siCeof($)+siCeof(c));
}
ans: hellow hellow hellow 7 $ 7 .pointer
ta2es $ bytes1
E:E. int a[!"]{L"+:7+!"+:+E+=+)+6+A};
main()
{
int %arx+%ary+i;
for (i";i4!";i(()
{
if(%arx4a[i])
{
%ary%arx;
%arxa[!];
}
else if (%ary4a[i])
{
%arx%ary;
%arya[i];
}
printf(0*d *d Bn0+%arx+%ary);
}
}
ans: garbage values of varx an vary are
printe 1, times
E::. 3define US#F(x+y) tx;xy;yt;
main()
{
int x:+yL;
if (x5y)
US#F(x+y);
printf(0x*d y*dBn0+x+y);
}
ans: error .unefine symbol t1
E:L. main()
{
int iL;
int 9;
9sum(i);
printf(0*d0+9);
}
sum(int x)
{
int t;
if(x4!) return (!);
tsum(xO=)(sum(xO!);
return (t);
}
ans: H
E:7. main()
{
int a[]{"+)+E+L+6};
int *ptr;
ptra;
printf(0*d0+ *((char *) ptr(E));
}
ans: $
E:6. main()
{
int -=;
while(-OO)
{int -!"";
-OO;
printf(0*d0+ -);
}
}
ans: HHHHHH
E:A. main()
{
char ch;
for(ch1"1;ch4)::;ch(()
printf(0*c0+ ch);
}
ans: infinite loop .signe character varies
from "12L to 1271
EL". x=
function(((x)...%alue E is passed to the function
x=
function(x(()...%alue = is passed to the function
EL!. Shat is runtime locata$le code?
Shat is %olatile+ re'ister definition in R
Shat is compiler and what its output.
EL). which of the followin' is ille'al for the pro'ram?
main()
{
char const *p1p1;
}
!)p(( )) *p(( =)(*p)(( E) all
ans: 3 .(p166 .cannot moify a constant
ob:ect1
EL=.
3define putchar(c) printf(0*c0+c)
main()
{
int c1d1;
putchar(c);
}
ans:
ELE. %oid main (%oid)
{
printf(0*d0+ printf(0#2RBB0));
}
ans: ABK<$
EL:. %oid main(%oid)
{
int a[!"]+ i;
int *$;
$( int*) malloc(!"* siCeof(int)) ;
(b )Ba?3@+
for(i";i4!";i(()
a[i] i(!";
printf(0*d0+$[O!]);
}
ans: error .nonportable pointer conversion1
ELL. %oid main(%oid)
{
int a[!"]+ i;
int *$;
$( int*) malloc(!"* siCeof(int)) ;
b )Ba?3@+
for(i";i4!";i(()
a[i] i(!";
printf(0*d0+$[O!]);
}
ans: 12
EL7. main()
{
int a[!"]{!+)+=+E+:+L+7+6+A+!"};
int *pa;
int *K>a[A];
printf(0*d0+KOp(!);
}
ans: 1,
EL6. main()
{
int iL;
int *p>i;
free(p);
printf(0*d0+i);
}
ans: '
ELA. main()
{
int i:;
iPi5=;
printf(0*d0+i);
}
ans: ,
E7". main()
{
int a[!"];
=[a]!";
printf(0*d0+*(a(=));
}
ans: 1,
E7!. int (*p[!"]) ();
ans: p is array of pointers that each points
to
a function that ta2es no arguments an
returns
an int.
E7). struct emp
{
int a)2%+
char b?2,@)!tg2!+
};
main()
{
emp e+
e.a);
strcpy(e.$+0tellapalli0);
printf(0*d *s0+e.a+e.$);
}
ans: error .structure members shoul not be
initiali0e irectly an struct 2eywor shoul
be there before emp e+1
E7=. main()
{
int a:;
const int *p>a;
*p)"";
printf(0*d0+*p);
}
ans: error .cannot moify a constant ob:ect1
E7E. 3define U_(x) x*x
main()
{
int aU_()(!);
printf(0*d0+a);
}
ans: %
E7:. main()
{
struct t
{
int i;
} a+*p>a;
pO5i!";
printf(0*d0+(*p).i);
}
ans: 1,
E7L. a) for(int i"; i4:" ;i(()
for( int 9"; 94!""; 9(()
a[i][9]!"";
$) for(int i"; i4!"" ;i(()
for( int 9"; 94:"; 9(()
a[9][i]!"";
Shich of the a$o%e ) codes executes Kuic;ly.
ans: a"coe ta2es %,%, comparisons an
%,%, increments an b"coe ta2es %1,,
comparisons an %1,, increments. Fo a"coe
executes 3uic2ly .which is having outer loop
count less1
E77. i) (*ptr)((;
ii) *ptr(!;
iii) *ptr((;
which of the folowin' is same.
ans: i1 an ii1 are same
E76. %oid main()
{
char *s0susan0;
clrscr();
printf(s);
'etch();
}
ans: susan
E7A. %oid main()
{
int a[)"];
clrscr();
*a(int*)malloc(siCeof(a));
printf(0*d0+siCeof(a));
'etch();
}
ans: error .nonportable pointer conversion1
E6". %oid main()
{
%oid fun(int+int);
int i +9;
i)+9=;
fun(i((+9(();
printf(0*d *d0+i+9);
'etch();
}
%oid fun(int i+int 9)
{
i66/:66+
}
ans: 3 $ .no syntax error in function as it is a
comma operator1
E6!. %oid main()
{
int ctr";
clrscr();
switch(ctr)
{
case ":
ctr((;
case !:
ctr((;
default :
ctr((;
};
printf(0*d0+ctr);
'etch();
}
ans: 3
E6). 3define putchar(c) printf(0*c0+c);
main()
{
int cLA;
putchar(c);
}
ans: E
E6=. main()
{
printf(0*d0+printf(0#2R&&0));
}
ans: ABKJJ%
E6E. main()
{
int iL;
printf(0*d0+func(i));
}
int func(int r)
{
int static result;
if(r4") result!;
else
resultfunc(rO=)(func(rO!);
return result;
}
ans: 13
E6:. main()
{
int i=;
while(iOO)
{
int i!"";
iOO;
printf(0*d..0+i);
}
}
ans: HH..HH..HH..
E6L. 3define putchar(c) printf(0*c0+c)
%oid main()
{
char s1c1;
putchar (s);
}
ans: c
E67. Zefine putchar .c1 printf.!=c!/c1
%oid main()
{
char s1c1;
putchar (s);
}
ans: error .gap shoul not be there between
putchar an .c1 1
E66. %oid main()
{
int a[]{A+E+!+7+:};
int *p;
p>a[=];
printf(0*d0+p[O!]);
}
ans: 1
E6A. %oid main()
{
int a[]{!"+)"+="+E"+:"};
int *p;
p (int*)((char *)a ( siCeof(int));
printf(0*d0+*p);
}
ans: 2,
EA". Shich code will run faster
for(i";i4!"";i(()
for(9";94!";9(()
a[i][9]";
VG
for(9";94!";9(()
for(i";i4!"";i(()
a[i][9]";
ans: first coe .11,, increments 11,,
comparisons1
secon coe .1,1, increments 1,1,
comparisons1
secon coe will run faster .which is having
outer loop count less1
:"". main()
{
%oid print(int);
int i:;
print(i);
}
%oid print(int n)
{
if(n5")
{
print(nO!);
printf(0*d0+n);
print(nO!);
}
}
ans: 1213121$1213121%1213121$1213121
:"!. int * f(int a)
{
int i;
ia;
return(>i);
}
ans: we can't return aress of auto variable as it
is allocation is mae in stac2 which is eallocate
when the function returns.
:"). (!)Io find strin' len'th $y usin' recursi%e function.
())Io find fi$onaci series $y usin' recursi%e
function.
(=)Io write code for malloc so that allocation may $e
made fastly.
(E)Srite a fn prototype which return a pointer which
points to an array of !" ints.
ans: int .(f.11?1,@
:"=. %oid main ()
{
int
a[]{!"!+)"!+="!+E"!+:"!+L"!+7"!+6"!+A"!+""!};
int *p; clrscr ();
printf(0*d 0+a);
printf(0arthi 0);
printf(0*d 0+ ((char *)a ( siCeof(int)));
p(int *) ((char *) a (siCeof (int));
printf(0*d0+*p);
}
ans: L'L$ arthi L'L' 2,1 .aress of a )
L'L$1
:"E. %oid main ()
{
int
a[]{!"!+)"!+="!+E"!+:"!+L"!+7"!+6"!+A"!+""!};
int *p; clrscr ();
printf(0*d 0+a);
printf(0arthi 0);
printf(0*d 0+ ((char *)"a ( siCeof(int)));
p(int *) ((char *) a (siCeof (int));
printf(0*d0+*p);
}
ans: error .illegal use of pointer1
:":. main ()
{
int a[!"]{!"+A+6+7+L+:+E+=+)+!};
clrscr();
int (p)a+
int (3)Ba?7@+
printf(0*d *d 0+K+p);
}
ans: error .eclaration is not allowe here
since clrscr.1 function is there. 4eclaration
shoul come before any executable
statement1
:"L. main()
{
printf(0*d0+printf(0MelloUoft0));
}
ans: 5elloFoftH
:"7. main()
{
int i=;
printf(0*d *d *d0+i((+i+((i);
}
ans: $ $ $
:"6. main()
{
int i!";
int 9+;:;
int a[!"];
for(9";94!";9(()
a[9](i(;)((i*;);
}
VptimiCe the a$o%e code.
ans: main.1
9
int i)1,/2)%/:/a?1,@+
for.:),+:;1,+:661
a?:@)'%+
>
:"A. main()
{
int *p"x!"";
int *K"x!"";
int ;p*K;
printf(0*xBn0+;);
}
ans: error .pointer multiplication is not vali1
:!". Rhar* foo(Utr...)
{
char str[E];
strcpy(str+0MelloUoft0);
return str;
}
ans: we can't return aress of auto variable
as it
is allocation is mae in stac2 which is
eallocate
when the function returns.
:!!. int a[!"][)"][="][E"];
int *p
Mow to access an element of a usin' p?
ans: a?i@?:@?2@?l@ (.p6
:!). main()
{
int i!";
if(i5)")
if(i!")
printf(0Mi0);
else
printf(02ye0);
}
ans: no output
:!=. -f a row daminated two dimentional arry in the
followin' which one is ad%anta'e
and why?
a) for(i";i4!""";i(()
for(9";94!""";9(()
temptemp(a[i][9];
$) for(9";94!""";9(()
for(i";i4!""";i(()
temptemp(a[i][9]
ans: a .:ust it is a guess. &n Ia* we are
accessing elements which are in a:acent
locations. &n Ib* we are accessing elements
which are 1,,, locations apart1
:!E. %oid main()
{
printf(0*d0+(float)=&));
}
ans: ,
:!:. %oid main()
{
char *s0Mello Sorld0;
printf(0*c0+s);
}
ans: garbage character
:!L. %oid main()
{
char *s0Mello Sorld0;
printf(0*c0+*s);
}
ans: 5
:!7. fp+fs;
fpfopen(0tc.dat0+0w0);
fsfopen(0tc.dat0+0w0);
putch(1#1+fp);
putch(121+fs); Shat will happen?
ans: A is overwritten by B
:!6. Shat is the eKui%alent of a[i]
ans: (.a6i1
:!A. int .(func1.int/int1 is a pointer to a function with )
inte'ers as parameters and returnin' an inte'er %alue.
:)". int (.(func1.int (/int (1 is a pointer to a function
with ) inte'er pointers as parameters and returnin' a
pointer to an inte'er
:)!. switch(float %alue)
ans: compiler error
:)). main()
{
int a[:]{!+)+=+E+:};
int *pa(!;
int *Ka(:;
int difKOp;
printf(0*d0+ dif);
}
ans: $
:)=. switch(HW..)
ans: case ,: will be execute.
:)E. 3define exp :
main()
{
printf(0*d0+exp(();
}
ans: lvalue re3uire
:):. strcat(str+str);
ans: compilation error .estination string
length shoul accommoate both the strings1
:)L. int.(ptr1?1,@
ans: pointer to array of 1, integers.
:)7. int main()
{
char *str 0Mello+ world0 ;
printf(0*:s0 + str);
}
ans: 5ello/ worl .when the fiel with is
less than the length of the string the entire
string is printe1
:)6. int (ptr?1,@+
ans: eclaration of 1, pointers
:)A. int main()
{
extern int i;
printf(0*d0 + i);
}
ans: lin2er error
:=". %oid temp();
%oid temp(%oid);
int main()
{
temp();
}
%oid temp()
{
printf(0R is excitin'P0);
}
ans: K is excitingA
:=!. %oid temp();
%oid temp(%oid);
int main()
{
temp();
}
%oid temp(%oid)
{
printf(0R is excitin'P0);
}
ans: K is excitingA
:=). %oid temp();
%oid temp(%oid);
int main()
{
temp.voi1+
}
%oid temp()
{
printf(0R is excitin'P0);
}
ans: compiler error .syntax error1
:==. %oid temp(int i)
{
if(i !") return;
i(( ;
temp(i);
printf(0*d 0 + i);
}
int main()
{
temp(!);
}
ans: 1, H L 7 ' % $ 3 2
:=E. some Kuestion on 0strto;0 function
:=:. int main()
{
char *str 0Mello+ world0;
int i ) si0eof.str1+
for( ; i 5 " ; iOO)
printf(0*c0 + str[i]);
}
ans: olle5 .si0eof pointer is $ bytes1
:=L. int main()
{
int a 8#<( E() + =*)) ;
printf(0 *d 0 + a);
}
ans: '
:=7. main()
{
int x;
printf(0Bn*d0+x),/x)2,/x)$,);
}
ans: ,
:=6. main()
{
int a[]{!+)+:+L+A+!"};
int *$>a[E];
printf(0Bn*d0+$[O=]);
}
ans: 2
:=A. main()
{
int x"+y!;
if(xy)
y 7;
else
y);
printf(0*d0+ y);
}
ans: 7
:E". main()
{
int i=A+count";
while( i > !) &&some condition li;e this
{
count((;
ii55!;
}
printf(0*d0+count);
}
ans: 3
:E!. main()
{
int i=A+count";
while( i > !) &&some condition li;e this
{
count((;
i##1+
}
printf(0*d0+count);
}
ans: infinite loop
:E). main()
{
int x!)6;
printf(0Bn*d0+!(x(();
}
ans: 12H
:E=. main()
{
,-./ *f!;
,-./ *f);
f!fopen(0myfile0+0w0);
f)fopen(0myfile0+0w0);
fputc(1#1+f!);
fputc(121+f));
fclose(f!);
fclose(f));
}
what does f! n f) conatins?
ans: B
:EE. if i&p is coe friay monay sunay in commad line
then
main(int ar'c+char *ar'%[])
{
printf(0Bn*c0+**((ar'%);
}
ans:may be f
:E:. 3define max !"
main()
{
printf(0Bn*d0+max(();
}
ans: error .lvalue re3uire1
:EL. main()
{
int a[]{!+)+A+6+L+=+:+7+6+A};
int *pa(!;
int *Ka(L;
printf(0Bn*d0+KOp);
}
ans: %
:E7. main()
{
int i=;
while(iOO){
int i!"";
iOO;
printf(0*d 0+i);
}
}
ans: HH HH HH
:E6. what does (*a)[!"] means?
ans: a is pointer to an array of 1, integers
:EA. Vpen a file 0input0 and print the odd num$er of lines
first on the screen and then
e%en num$er of lines..somethin' li;e that.....
::". main()
{
int x:+ y;
y x*x(( * ((x ;
printf(0*d *d0+x+y);
}
ans: 7 21'
::!. main()
{
int a!"+$:;
while(OO$5" >> ((a)
{
OO$;
((a;
}
printf(0*d *d0+a+$);
}
ans: 1' "2
::). main()
{
char i;
for (i"; i4)::; i(()
{
printf(0*c0+ i);
}
}
ans: infinite loop . signe char range is "12L
to 1271
::=. main()
{
int i";
switch(i)
{
case !: printf(0hi0);
case ": printf(0Cero0);
case ): printf(0world0);
}
}
ans: 0eroworl
::E. struct <<<
{
int a:L;
float b:$+
char s;
}structure;
main()
{
printf(0*d0+siCeof(structure));
}
ans: error .bit fiels must be signe or
unsigne int1
:::. struct <<<
{
int a:L;
&*float $:E;*&
char s;
}structure;
main()
{
printf(0*d0+siCeof(structure));
}
ans: 2
::L. struct <<<
{
int a:'+
&*char s;*&
}structure;
main()
{
printf(0*d0+siCeof(structure));
}
ans: 1
::7. struct <<<
{
int a+
char s;
}structure;
main()
{
printf(0*d0+siCeof(structure));
}
ans: 3
::6. main()
{
char *s;
s0hot 9a%a0;
strcpy(s+0solaris 9a%a0);
printf(0*s0+s);
}
ans: solaris :ava .extra locations will be
overwritten1
::A. main()
{
char (p)'a'+
int (i)1,,J (p+
printf(0*d0+i);
}
ans: error .nonportable pointer conversion1
:L". main()
{
int n:;
printf(0Bnn**d0+n+n);
}
ans: n) % .with specifier =% right
:ustifie1
:L!. Mow lon' the followin' pro'ram will run?
main()
{
printf(0BnUonata Uoftware0);
main();
}
ans: until the stac2 overflows
:L). main()
{
const int x:;
int *ptrx;
ptrx>x;
*ptrx!";
&*x!";*&
printf(0*d0+x);
}
ans: 1, .you can change a constant ob:ect by
using a pointer1
:L=. main()
{
const int x:;
int *ptrx;
ptrx>x;
*ptrx!";
x!:;
printf(0*d0+x);
}
ans: error .cannot moify a constant ob:ect1
:LE. main()
{
const char *fun();
(fun.1)!A!+
}
const char *fun()
{
return 0Mello0;
}
ans: error .cannot moify a constant ob:ect1
fun.1 returns to a !const char! pointer which
cannot be moifie
:L:. Shat error would the followin' function 'i%e on
compilation?
f(int a+ int $)
{
int a;
a)";
return a;
}
ans: error .reeclaration of a1
:LL. Sould the followin' pro'ram compile?
main()
{
int a!"+*9;
%oid *;; 9;>a;
9((;
266+
printf(0Bn*u*u0+9+;);
}
ans: -o/ the arithmetic operation is not
permitte on voi pointers. Fi0e of the type
is un2nown.
:L7. -n the followin' pro'ram how would you print :" usin'
p?
main()
{
int a[]{!"+ )"+ ="+ E"+ :"};
char *p;
p (char*) a;
}
ans: printf.!=!/(..int(1p6$11+ or
printf.!=!/(.p6L11+
:L6. Foint out the error in the followin' pro'ram
main()
{
int a!";
%oid f();
a)f.1+
printf(0Bn*d0+a);
}
%oid f()
{
printf(0BnMi0);
}
ans: error .not an allowe type1. Ghe
program is trying to collect the value of a
!voi! function into an integer variable.
:LA. -f the followin' pro'ram (mypro') is run from the
command line as myprog friay tuesay sunay+
Shat would $e the output?
main(int ar'c+ char *ar'%[])
{
while(siCeof(ar'%))
printf(0*s0+ar'%[OOsiCeof(ar'%)]);
}
ans:
:7". -f the followin' pro'ram (mypro') is run from the
command line as myprog friay tuesay sunay+
Shat would $e the output?
main(int ar'c+ char *ar'%[])
{
printf(0*c0+*((ar'%[!]);
}
ans: r .chec2 it out1
:7!. -f the followin' pro'ram (mypro') is run from the
command line as mypro' friday tuesday sunday+ Shat
would $e the output?
main(int ar'c+ char*ar'%[])
{
printf(0*c0+**((ar'%);
}
ans: f .chec2 it out1
:7). main()
{
char near * near *ptr!;
char near * far *ptr);
char near * hu'e *ptr=;
printf(0*d *d
*d0+siCeof(ptr!)+siCeof(ptr))+siCeof(ptr=));
}
ans: 2 $ $
:7=. Shat is the difference $etween the followin'
declarations?
const char *const s; char const *const s;
ans. -o ifference
:7E. Shat is the difference $etween the followin'
declarations?
const char *s;
char const *s;
ans. -o ifference
:7:. main()
{
int y!)6;
const int x; xy;
printf(0*d0+x);
}
ans: error .cannot moify a constant ob:ect1
:7L. main()
{
int y!)6;
const int xy;
printf(0*d0+x);
}
ans: 12L .when not initiali0e const variable
will have garbage value1
:77. main()
{
const int x;
x!)6;
printf(0*d0+x);
}
ans: error .cannot moify a constant ob:ect.
x shoul have been initiali0e where it is
eclare1
:76. -n the followin' code+ is p) an inte'er or an inte'er
pointer?
typeef int( ptr
ptr p1/p2+
ans. &nteger pointer
:7A. -f the followin' pro'ram (mypro') is run from the
command line as myprog monay tuesay
wenesay thursay+ Shat would $e the output?
main(int ar'c+ char *ar'%[])
{
while(OOar'c 5")
printf(0*s0+*((ar'%);
}
ans: monay tuesay wenesay Ghursay
:6". -f the followin' pro'ram (mypro') is run from the
command line as mypro' ! ) =+ Shat would $e the
output?
main(int ar'c+ char *ar'%[])
{
int i+9";
for(i";i4ar'c;i(()
99( atoi(ar'%[i]);
printf(0*d0+9);
}
ans: chec2 out
:6!. -f the pro'ram (mypro') is run from the command line
as mypro' ! ) = + Shat would $e the output?
main(int ar'c+ char *ar'%[])
{
int i;
for(i";i4ar'c;i(()
printf(0*s0+ar'%[i]);
}
ans: K:<[QODNP.E\E 1 2 3
:6). main()
{
,-./ *fp;
fp fopen(0trial0+0r0);
}
fp points to:
ans: A structure which contains a !char!
pointer which points to the first character in
the file.
:6=. Shat is the type of the %aria$le $ in the followin'
declaration?
3define ,.V#IFIG float*
,.V#IFIG a+$;
ans: float
:6E. Zefine ESNAGOGD float(
main()
{
,.V#IFIG a+$;
$!".";
}
ans: b is a float variable .no error1
:6:. typeef float( ESNAGOGD+
main()
{
,.V#IFIG a+$;
b)1,.,+
}
ans: error .illegal use of floating point. 5ere
b is a floating pointer variable. Nbserve the
ifference between marco an typeef in %L$
an %L% problems1
:6L. 3define U_G(x) (x*x)
main()
{
int a+$=;
a U_G($());
printf(0*d0+a);
}
ans: 11
:67. main()
{
int iE;
switch(i)
{
default:
printf(0Bn # mouse is an elephant $uilt $y the
\apanese0);
case !:
printf(0 2reedin' ra$$its is a hair raisin'
experience0);
$rea;;
case ):
printf(0Bn ,riction is a dra'0);
$rea;;
case =:
printf(0Bn -f practice ma;e perfect+ then no$ody1s
perfect0);
}
}
ans: A mouse is an elephant built by the
]apanese Breeing rabbits is a hair raising
experience
:66. -n the followin' code+ in which order the functions
would $e called?
a f!()=+!E)*f)(!)&E)(f=();
ans: f1/ f2/ f3
:6A. f=()
{
printf(0three 0);
return !;
}
f!(int x+ int y)
{
printf(0one 0);
return(x(y);
}
f)(int x)
{
printf(0two 0);
return x;
}
main()
{
int a;
a f!()=+!E)*f)(!)&E)(f=();
printf(0*d0+a);
}
ans: one two three 112
:A". main()
{
int a!"+$;
a4 : ? $!"" : $)"";
printf(0Bn*d0+$);
}
ans: error .lvalue re3uire. Konitional
operator has highest priority than
assignment operator1
:A!. main()
{
int a!"+$;
a4 : ? $!"" : ($)"");
printf(0Bn*d0+$);
}
ans: 2,,
:A). main()
{
int a!"+$;
a5 : ? $!"" : ($)"");
printf(0Bn*d0+$);
}
ans: 1,,
:A=. main()
{
int i!;
switch(i)
{
case !:
printf(0BnGadioacti%e cats ha%e !6 halfOli%es0);
$rea;;
case !*)(E:
printf(0Bn2ottle for rent OinKuire within0);
$rea;;
}
}
ans: Daioactive cats have 1L half"lives .no
error1
:AE. main()
{
int i);
printf(0-*d i*d0+((i+((i);
}
ans: &)$ i)3
:A:. main()
{
unsi'ned char i"x6";
printf(0i*d0+i44!);
}
ans: i)2%'
:AL. main()
{
unsi'ned char i"x6";
ii44!;
printf(0i*d0+i);
}
ans: i),
:A7. main()
{
int 2"x,,,,;
^B + J( note: not assigne
to B (J
printf(0*d0+2);
}
ans: "1
:A6. main()
{
unsi'ned int 2"x,,,,;
X2 ;
printf.!=!/B1+
}
ans: "1
:AA. main()
{
unsi'ned int 2"x,,,,;
X2 ;
printf.!=u!/B1+
}
ans: '%%3%
L"". ,unc(int a+ int$)
{
int a;
a!";
return a;
}
will there $e any error?
ans: error .reeclaration of a1
L"!. strin' is 'i%en myprog one two three Shere mypro'
is an exe file. Shat will the output of the followin'
pro'ram ?
main(int ar'c+ char *ar'%[])
{
printf(0*c0((**ar'%);
}
ans: n .chec2 it out1
L"). Zefine FVD.b1 b(b+
main()
{
int i=;
printf(0*d0+U_G(i()));
}
ans: error .semicolon in macro efinition will
cause error when it is replace in printf
statement1
L"=. 3define U_G($) $*$
main()
{
int i=;
printf(0*d0+U_G(i()));
}
ans: 11
L"E. main()
{
char c1a1;
printf(0*d *d0+ siCeof(c)+siCeof(1a1));
}
ans: 1 2
L":. main()
{
char c1a1;
Orintf(0*d *d0+ siCeof(c)+siCeof(1a1));
}
ans: lin2er error .unefine symbol_Orintf1
L"L. main()
{
Khar c)'a'+
printf(0*d *d0+ siCeof(c)+siCeof(1a1));
}
ans: error .unefine symbol IKhar* /
unefine symbol Ic* / statement missing + 1
L"7. %oid main(%oid)
{
struct s
{
int x;
float y;
}s!{):+E:.""};
union u
{
int x;
float y;
}u!;
u1).union u1s1+
printf(0*d and *f0+u!.x+u!.y);
}
ans: error .incompatible type conversion1
L"6. int fn(%oid);
%oid print(int+int(*)());
int i!";
%oid main(%oid)
{
int i)";
print(i+fn);
}
%oid print(int i+int (*fn!)())
{
printf(0*dBn0+(*fn!)());
}
int fn(%oid)
{
return(iO:);
}
ans: %
L"A. %oid main(%oid)
{
char num$ers[:]
[L]{0aero0+0Vne0+0Iwo0+0Ihree0+0,our0};
printf(0*s is *c0+>num$ers[E]["]+num$ers["]
["]);
}
ans: Eour is `
L!". %oid main(%oid)
{
int y+C;
int x)y)0)1,+
int fx;
float ans".";
f *x*y;
ansx&=."(y&=;
printf(0*d *.)f0+f+ans);
}
ans: 1,,, '.33
L!!. dou$le d$l)".E:="+dE.:7!"+d$l%ar=;
%oid main(%oid)
{
dou$le d$ln(%oid);
d$l%ar=d$ln();
printf(0*.)fBt*.)fBt*.)fBn0+d$l+d+d$l%ar=);
}
dou$le d$ln(%oid)
{
dou$le d$l%ar=;
d$ld$l%ar=E.:;
return(d$l(d(d$l%ar=);
}
ans: $.%, $.%7 13.%7
L!). %oid main(%oid)
{
int old%ar):+new%arO):;
int swap(int+int);
swap(old%ar+new%ar);
printf(0Hum$ers are *dBt*d0+new%ar+old%ar);
}
int swap(int old%al+int new%al)
{
int temp%alold%al;
old%alnew%al;
new%altemp%al;
}
ans: -umbers are "2% 2%
L!=. %oid main(%oid)
{
int i!""+9)";
i(( 9;
i*9;
printf(0*dBt*dBn0+i+9);
}
ans: error .lvalue re3uire1
L!E. int new%al(int);
%oid main(%oid)
{
int ia[]{!)+)E+E:+"};
int i;
int sum";
for(i";ia[i];i(()
{
sum(new%al(ia[i]);
}
printf(0Uum *d0+sum);
}
int new%al(int x)
{
static int di%!;
return(x&di%(();
}
ans: Fum) 3H
L!:. %oid main(%oid)
{
int %ar!+%ar)+%ar=+minmax;
%ar!:;
%ar):;
%ar=L;
minmax).var1#var21X.var1#var31X
var1:var3:.var2#var31Xvar2:var3+
printf(0*dBn0+minmax);
}
ans: ' .maximum of three numbers1
L!L. static int i:";
int print(int i);
%oid main(%oid)
{
static int i!"";
while(print(i))
{
printf(0*d 0+i);
iOO;
}
}
int print(int x)
{
static int i);
return(iOO);
}
ans: 1,, HH
L!7. %oid main(%oid);
typedef struct HIype
{
int i;
char c;
lon' x;
}HewIype;
%oid main(%oid)
{
HewIype *c;
c(HewIype *)malloc(siCeof(HewIype));
cO5i!"";
cO5c1R1;
(*c).x!"".;
printf(0(*d+*c+*E.d)0+cO5i+cO5c+cO5x);
}
ans: .1,,/K/ 1,,1
L!6. main()
{
char *p!0Hame0;
char *p);
p)(char *)malloc()");
while(*p)((*p!(();
printf(0*sBn0+p));
}
ans: an empty string .no output1
L!A. main()
{
int x)"+y=:;
x y(( ( x((;
y ((y ( ((x;
printf(0*d *dBn0+x+y);
}
ans: %7 H$
L)". main()
{
int x:;
printf(0*d *d *dBn0+x+x44)+x55));
}
ans: % 2, 1
L)!. 3define swap!(a+$) aa($;$aO$;aaO$;
main()
{
int x:+y!";
swap1.x/y1+
printf(0*d *dBn0+x+y);
swap)(x+y);
printf(0*d *dBn0+x+y);
}
int swap)(int a+int $)
{
int temp;
tempa;
$a;
atemp;
return;
}
ans: 1, %
1, %
L)). 3define swap!(a+$) aa($;$aO$;aaO$;
main()
{
int x:+y!";
swap1.x/y1
printf(0*d *dBn0+x+y);
swap)(x+y);
printf(0*d *dBn0+x+y);
}
int swap)(int a+int $)
{
int temp;
tempa;
$a;
atemp;
return;
}
ans: 1, %
1, %
L)=. 3define swap!(a+$) aa($;$aO$;aaO$
main()
{
int x:+y!";
swap1.x/y1
printf(0*d *dBn0+x+y);
swap)(x+y);
printf(0*d *dBn0+x+y);
}
int swap)(int a+int $)
{
int temp;
tempa;
$a;
atemp;
return;
}
ans: error .statement missing +1
L)E. main()
{
char *ptr 0Gamco Uystems0;
(*ptr)((;
printf(0*sBn0+ptr);
ptr((;
printf(0*sBn0+ptr);
}
ans: Famco Fystems
amco Fystems
L):. main()
{
char s![]0Gamco0;
char s)[]0Uystems0;
s!s);
printf(0*s0+s!);
}
ans: error .lvalue re3uire1
L)L. main()
{
char *p!;
char *p);
p!(char *) malloc():);
p)(char *) malloc():);
strcpy(p!+0Gamco0);
strcpy(p)+0Uystems0);
strcat(p!+p));
printf(0*s0+p!);
}
ans: DamcoFystems
L)7. main()
{
int x!"+y!:;
xx((;
y((y;
printf(0*d *dBn0+x+y);
}
ans: 11 1'
L)6. main()
{
int a";
if(a") printf(0Gamco UystemsBn0);
printf(0Gamco UystemsBn0);
}
ans: Damco Fystems
L)A. main()
{
int a";
if(a") printf(0Gamco UystemsBn0);
printf(0Gamco UystemsBn0);
}
ans: Damco Fystems
Damco Fystems
L=". int Uum/lement(int *+int);
%oid main(%oid)
{
int x[!"];
int i!";
for(;i;)
{
iOO;
*(x(i)i;
}
printf(0*d0+Uum/lement(x+!"));
}
int Uum/lement(int array[]+int siCe)
{
int i";
float sum";
for(;i4siCe;i(()
sum(array[i];
return sum;
}
ans: $%
L=!. int printf(const char*+...);
%oid main(%oid)
{
int i!""+9!"+;)";
int sum;
float a%e;
char myformat[]0a%e*.)f0;
sumi(9(;;
a%esum&=.";
printf(myformat+a%e);
}
ans: ave)$3.33
L=). %oid main(%oid)
{
int a[!"];
printf(0*d0+((a(A) ( (a(!)));
}
ans: error .invali pointer aition1
L==. int $a's[:]{)"+:+)"+=+)"};
%oid main(%oid)
{
int pos:+*next();
*next()pos;
printf(0*d *d *d0+pos+*next()+$a's["]);
}
int *next()
{
int i;
for(i";i4:;i(()
if ($a's[i])")
return($a's(i);
printf(0/rrorP0);
exit(");
}
ans: % 2, %
L=E. static int i:;
%oid main(%oid)
{
int sum";
do
{
sum((!&i);
}while("4iOO);
}
ans: error .ivie by 0ero exception1
L=:. %oid main(%oid)
{
%oid pa(int *a+int n);
int arr[:]{:+E+=+)+!};
pa(arr+:);
}
%oid pa(int *a+int n)
{
int i;
for(i";i4n;i(()
printf(0*d 0+*(a(()(i);
}
ans: % % % % %
L=L. const int ;!"";
%oid main(%oid)
{
int a[!""];
int sum";
for(;";;4!"";;(()
*(a(;);;
sum(a[OO;];
printf(0*d0+sum);
}
ans: error .cannot moify a constant ob:ect1
L=7. int ;!"";
%oid main(%oid)
{
int a[!""];
int sum";
for(;";;4!"";;(()
*(a(;);;
sum(a[OO;];
printf(0*d0+sum);
}
ans: HH
L=6. main()
{
printf(0Mello *d0+printf(0_W#GT test? 0));
}
ans: VWADC testX 5ello 12
L=A. main()
{
int i+9+#;
for (# O!;#4!; #(()
printf(0*d 0+PP#);
}
ans: 1 , 1
LE". main()
{
int i)::;
printf.!=<t!/66.i6611+
}
ans: error .lvalue re3uire1
LE!. main()
{
char i 1a1;
printf(0*c *c0+i+(((i));
}
ans: b b
LE). main()
{
int i+9;
printf(0_W#GT *sBn0+main());
}
ans: Ghere is nothing on the screen an prog
waits till the memory lasts an then out of
memory run time error.
LE=. 3define f(x) x*x*x
main()
{
printf(0Bn*d0+f()()));
}
ans: 12
LEE. main()
{
%oid fun!(%oid *);
char a[] 0Kuar;0;
%oid *temp;
temp a;
fun!(temp);}
%oid fun!(%oid *temp! )
{
int t! ";
while(*((char*)temp!( t!(( )P1B"1) {
printf(0*c0+*((char*)temp! ( t!));
}
}
ans: uar2
LE:. %oid main()
{
int x=;
printf(0*d *d0+x55!+ x44=);
}
ans: 1 2$
LEL. %oid main()
{
int *x;
x (int *) !:;
}
ans: Socation 1% in the program space is
assigne to pointer x
LE7. Shich of the followin' functions cannot $e called from
another file?
a. const %oid func(){ ^^..}
$. extern %oid func(){^^^}
c. %oid func(){^^^}
d. static %oid func(){^^^.}
ans. static
LE6. int *func()
{
static int x";
x((; return >x;
}
int main()
{
int * y func();
printf(0*d 0+(*y)(();
func();
printf(0*d0+*y);
return ";
}
ans: 1 3
LEA. %oid main()
{
unsigne int x) "1+
int y ";
if(y4x) printf(0# is trueBn0);
if (y (x O!")) printf(02 is trueBn0);
if ((int) x5y) printf(0R is trueBn0);
}
ans: A is true
L:". %oid main()
{
int x) "1+
int y ";
if(y4x) printf(0# is trueBn0);
if (y (x O!")) printf(02 is trueBn0);
if ((int) x5y) printf(0R is trueBn0);
}
ans: no output
L:!. %oid main()
{
unsi'ned int x O!;
int y ";
printf.!= !/x1+
if(y4x) printf(0# is trueBn0);
if (y (x O!")) printf(02 is trueBn0);
if ((int) x5y) printf(0R is trueBn0);
}
ans: "1 A is true .= signe integer
specifier1
L:). %oid main()
{
unsi'ned int x O!;
int y ";
printf.!=u !/x1+
if(y4x) printf(0# is trueBn0);
if (y (x O!")) printf(02 is trueBn0);
if ((int) x5y) printf(0R is trueBn0);
}
ans: '%%3% A is true .=u unsigne integer
specifier1
L:=. -n the followin' code what is the correct way to
increment the %aria$le ptr to
point to the next mem$er of the array
union intfloat
{
int int#rray[ :];
float float#rray[ :];
};
union intfloat arr[)"];
%oid *ptr arr;
ans: ptr ) .voi(1..union intfloat(1ptr 611+
L:E. 3define FG-HI<Ya(x+y+C) printf (3x 0*dBt0 3C 0
*dBn0+ x+ y)
%oid main()
{
int x+ y+ C;
x"; y!; C);
x ]] ((y ]]((C;
FG-HI<Ya(x+y+C);
((x ]] ((y >> ((C;
FG-HI<Ya(x+y+C);
((x >> ((y ]] ((C;
FG-HI<Ya(x+y+C);
}
ans:
x), 0)2
x)1 0)2
x)2 0)3
L::. main()
{
printf(0*d *d0+ siCeof(HW..)+ siCeof(00));
}
ans: $ 1 .-WSS is a pointer so it ta2es $
bytes. si0eof empty string is 11
L:L. int *chec;(int+int);
%oid main()
{
int c+d;
c ) chec2.11/2H1+
) chec2.2,/3,1+
printf(0Bnc*u0+c);
}
int * chec;(int i+int 9 )
{
int *p+ *K;
p>i;
K>9;
if(i5A:)
return(K);
else
return(p);
}
ans: nonportable pointer conversion
L:7. %oid main()
{
int a[=][)]{ !+6+:+7+L+6};
printf(0*d0+((a(!)O(>a(!)));
}
ans: 82. & haven*t been able to figure this
one out. a is the aress of the 2" array/
here a/ Ba/ (a all give the same value/ i.e./
aress of the array. .a611 gives the aress
of the secon row/ it is the same as a?1@.
(.a611 gives the aress of the first cell of
the secon row. ((.a611 gives the value of
the element store in the first cell in the
secon row. .(.a611611 gives the aress of
the secon cell of the secon row.
(.(.a611611 gives the value of the element
store in the secon cell in the secon row.
L:6. %oid main()
{
int a[=][)]{ !+6+:+7+L+6};
printf(0*d 0+a);
printf(0*d 0+>a);
printf(0*d 0+*a);
}
ans: L'L2 L'L2 L'L2 .all are same1
L:A. main()
{
char str![]0Mello0;
char str)[]0Mello0;
if(str!str) >> (*(str!(L) *(str)(L)) )
printf(0Bn /Kual0);
else
printf(0Bn uneKual0);
}
ans: une3ual
LL". main()
{
int a+ $)::+c!)7;
aX$;
ccJ(Xa > $]");
ccJ(X(X$));
printf(0*dBn0+c);
}
ans: 127
LL!. 3define f(a+$) a($
3define '(x+y) x*y
main()
{
int i;
if(E+'(:+L));
printf(0*d0+i);
}
ans: 3$
LL). main()
{
int i+9AAAA;
char $uff[:];
isprintf($uff+0*d0+9);
printf(0*d *s0+i+$uff);
}
ans: $ HHHH
LL=. main()
{
int i+9AAAAA;
char $uff[:];
isprintf($uff+0*d0+9);
printf(0*d *s0+i+$uff);
}
ans: ' "31,73
LLE. main()
{
int -);
int 9=;
int ;E;
printf(0*d0+(-494;));
}
ans: 1
LL:. 3define macro(a) ((a(() ( (((a) ( (a(())
main()
{
printf(0*d0+macro(!));
}
ans: error .lvalue re3uire1
LLL. int func(int -)
{
static int ;";
;((;
if(;5:)
return !;
else
return func(-O!);
}
int main()
{
printf(0*d0+func(!));
}
ans: 1
LL7. main()
{
char *str0Kuar;0 0media0;
printf(0*s0+str);
}
ans: 3uar2meia
LL6. main()
{
char *str;
str0hello0 0india0;
printf(0*s0+str);
}
ans: helloinia
LLA. main()
{
int i"+C;
CsiCeof.66i 6 i661+
printf(0*d *d0+C+i);
}
ans: 2 , .the operan of a si0eof operator is
either an expression/ which is not evaluate/
or a parenthesi0e type name1
L7". main()
{
int y!";
for (int x),;x4!";x(();
y(x;
printf(0*d0+y);
}
ans: error .x shoul be eclare before for
loop1
L7!. main()
{
int y!"+x;
for (x";x4!";x(();
y(x;
printf(0*d0+y);
}
ans: 21
L7). fun(int a)
{
static int $;
}
what is the stora'e allocation for $oth a and $?
ans: a"stac2/ b"bss .bloc2 starting with
symbol1
L7=. int *fun(int a)
{
return (>a);
}
int *fun(int a)
{
int *$;
$>a;
return($);
}
int *fun(int a )
{
int *$;
$malloc(siCeof(int));
$>a;
return ($);
}
which of the followin' functions are not correct?
ans: 1 B 2 are not correct
L7E. int fun(int a+int y)
{
int x;
xa(y;
return (x);
}
int main()
{
int x+y!+C"+c;
Cfun(y+c);
printf(0 *d 0+x);
}
ans: garbage value
L7:. main()
{
int i;
printf(0*d0+((i(();
}
ans: error .lvalue re3uire1
L7L. main()
{
int a);
printf(0*d *d =0+((a+a(();
}
ans: $ 2 garbage value
L77. struct a$c
{
char a[!"];
int a+$;
};
main()
{
struct a$c a${0main0};
printf(0*d *d0+a$.a+ab.c);
}
ans: error .multiple eclaration of a an
unefine symbol c1
L76. %oid main()
{
printf(0persistent0);
main();
}
ans: till stac2 overflows
L7A. func(char *s!+char * s))
{
char *t;
ts!;
s!s);
s)t;
}
%oid main()
{
char *s!09ac;0+ *s)09ill0;
func(s!+s));
printf(0*s *s0+s!+s));
}
ans: :ac2 :ill
L6". func(char *s!+char * s))
{
char *t;
printf(0*s *s 0+s!+s));
ts!;
s!s);
s)t;
printf(0*s *s 0+s!+s));
}
%oid main()
{
char *s!09ac;0+ *s)09ill0;
func(s!+s));
printf(0*s *s0+s!+s));
}
ans: :ac2 :ill :ill :ac2 :ac2 :ill
L6!. %oid main()
{
int a[:] {!+)+=+E+:}+i+9);
for (i ";i4:;i(( )
func(9+>a[i]);
for (i ";i4:;i(( )
printf(0*d 0+a[i]);
}
func(int 9+int *a)
{
99(!;
aa(9;
}
ans: 1 2 3 $ %
L6). %oid main()
{
int a[:] {!+)+=+E+:}+i+9);
for (i ";i4:;i(( )
func(9+a[i]);
for (i ";i4:;i(( )
printf(0*d 0+a[i]);
}
func(int 9+int *a)
{
99(!;
aa(9;
}
ans: 1 2 3 $ %
L6=. main()
{
for (a!;a4!"";a(()
for($a;$4!"";$(()
foo();
}
foo()
{}
how many times foo will $e called?
ans: %,%,
L6E. int i;
main()
{
int a+$;
for (a!;a4!"";a(()
for($a;$4!"";$(()
foo();
printf(0*d0+i);
}
foo()
{
i((;
}
ans: %,%,
L6:. Vne palindrome pro'ramme was 'i%en in recursion
ans : pal.f66/t""1
L6L. main()
{
int ifoo());
printf(0*d0+i);
}
foo(int s)
{
if(Ps)
return s;
else
{
int i:;
return i;
}
}
ans: %
L67. main()
{
int ;"+i"+9!;
if(P">>.2)21) printf(0*d 0+;);
if(P"]].2),1)
printf(0*d0+;);
}
ans: 2 2
L66. main()
{
int ;"+i"+9!;
if(P">>2)2) printf(0*d 0+;);
if(P"]]2),)
printf(0*d0+;);
}
ans: error .lvalue re3uire1
L6A. main()
{
int i;
for(i";i4=;i(()
switch(i)
{
case !: printf(0*d0+i);
case ) : printf(0*d0+i);
default: printf(0*d0+i);
}
}
ans: ,11122
LA". int (num)91,/1/%/22/H,>+
main()
{
int *p+*K;
int i;
pnum;
Knum();
i*p((;
printf(0*d *d0+i+KOp);
}
ans: error .eclaration error1
LA!. int num?@)91,/1/%/22/H,>+
main()
{
int *p+*K;
int i;
pnum;
Knum();
i*p((;
printf(0*d *d0+i+KOp);
}
ans: 1, 1
LA). int (.(p?1,@1.char (/ char(1
ans: array of pointers to function with two
character pointers as arguments an
returning interger pointer
LA=. main()
{
char *a[E]{09aya0+0mahe0+0chandra0+0$uchi0};
printf(0*d *d *d0+siCeof(a)+siCeof(char
*)+siCeof(a)&siCeof(char *));
}
ans: 1' $ $
LAE. %oid fn(int *a+ int *$)
{
int *t;
ta;
a$;
$t;
}
main()
{int a);
int $=;
fn(>a+>$);
printf(0*d+*d0+ a+$);
}
ans: 2/3
LA:. 3define scanf 0*s is a strin'0
main()
{
printf(scanf+scanf);
}
ans: =s is a string is a string
LAL. main()
{
char *p0a$c0;
char *K0a$c!)=0;
while(*p*K)
printf(0*c*c0+*p+*K);
}
ans: prints a infinite times
LA7. main()
{
printf(0*u0+O!);
}
ans: '%%3%
LA6. 3define %oid int
int i="";
%oid main(voi)
{
int i)"";
{
int i!"";
printf(0*d 0+i);
}
printf(0*d0+i);
}
ans: error .parameter 1 missing name1
LAA. 3define %oid int
int i="";
%oid main(voi argc)
{
int i)"";
{
int i!"";
printf(0*d 0+i);
}
printf(0*d0+i);
}
ans: 1,, 2,,
7"". main()
{
int x);
x44);
printf(0*d 0+x);
}
ans: 2
7"!. main()
{
int x);
xx44);
printf(0*d 0+x);
}
ans: L
7"). main()
{
int a[]{"+"<E+E+A};
int i);
printf(0*d *d0+a[i]+i[a]);
}
ans: $ $
7"=. main()
{
int i)(=+E5=+);
printf(0*d0+i);
}
ans: error
7"E. main()
{
int i()(=+E5=+));
printf(0*d0+i);
}
ans: 2
7":. main()
{
int a"+$";
if(Pa)
{
$Pa;
if($)
aP$;
}
printf(0*d *d0+a+$);
}
ans: , 1
7"L. main()
{
int -!";
--(( ( ((-;
printf(0*d0+-);
}
ans: 23
7"7. swap.int x/y1
{
int temp;
tempx;
xy;
ytemp;
}
main()
{
int x)+y=;
swap(x+y);
printf(?*d *d@+x+y);
}
ans: error .swap function formal arguments
eclaration1
7"6. swap.int x/ int y1
{
int temp;
tempx;
xy;
ytemp;
}
main()
{
int x)+y=;
swap(x+y);
printf(?*d *d@+x+y);
}
ans: 2 3
7"A. struct
{
int x;
int y;
}a$c;
x cannot $e accessed $y the followin'
!)a$cOO5x;
))a$c["]OO5x;
=)a$c.x;
E)(a$c)OO5x;
ans: 1 2 B$
7!". #utomatic %aria$les are destroyed after fn. ends
$ecause
a) Utored in swap
$) Utored in stac; and poped out after fn. returns
c) Utored in data area
d) Utored in dis;
ans: b
7!!. main()
{
int x)+yL+CL;
xyC;
printf(0*d0+x);
}
ans: 1
7!). i ) int *,()
ii) int (*,)()
ans: Ghe first eclaraion is a function
returning a pointer to an integer an the
secon is a pointer to a function returning
int.
7!=. 3define dprintf(expr) printf(3expr 0*dBn0+expr)
main()
{
int x7;
int y=;
dprintf(x&y);
}
ans: xJy)2
7!E. main()
{
int i;
char *p;
i"<6A;
p(char *)i;
p((;
printf(0*x *xBn0+i+p);
}
ans: LH La
7!:. main()
{
int i;
char *p;
i"<6A;
p(char *)i;
p((;
printf(0*x *xBn0+p+i);
}
ans: La ,
7!L. Ihe type of the controllin' expression of a switch
statement cannot $e of the type
a) int $) char c) short d)float e) none
ans: 1float
7!7. main()
{
int <+$;
$7;
< $56 ? $ 44= : $5E ? $55!:$;
printf(0*d0+<);
}
ans: 3
7!6. main()
{
int n);
printf(0*d *dBn0+ ((n+ n*n);
}
ans: 3 $
7!A. int x "xL:;
main()
{
char x;
printf(0*dBn0+x);
}
ans: un2nown
7)". main()
{
int a!";
int $L;
if(a=)
$((;
printf(0*d *dBn0+a+$(();
}
ans: 3 7
7)!. main()
{
enum 8onths {\#H !+,/2+8#G+#FG};
8onths < \#H;
if(<!)
{
printf(0\an is the first month0);
}
}
ans: error
7)). main()
{
enum 8onths {\#H !+,/2+8#G+#FG};
enum 8onths < \#H;
if(<!)
{
printf(0\an is the first month0);
}
}
ans: ]an is the first month
7)=. main()
{
int lL;
switch(l)
{
default : l();
case E: lE;
case :: l((;
$rea;;
}
printf(0*d0+l);
}
ans: %
7)E. main()
{
int x)";
int y!";
swap(x+y);
printf(0*d *d0+y+x());
}
swap(int x+int y)
{
int temp;
temp x;
xy;
ytemp;
}
ans: 1, 22
7):. 3define -HR(<) <((
main()
{
int <E;
printf(0*d0+-HR(<(());
}
ans: error .lvalue re3uire1
7)L. main()
{
char s[]0Mello+ world0;
printf(0*!:.!"s0+s);
}
ans: 5ello/ wor
7)7. main()
{
printf(0*dBn0+f(7));
}
f(x)
{
if(x4E)
return x;
return f(OOx);
}
ans: $
7)6. main()
{
int x" +*p";
x((;p((;
printf(0*d and *dBn0+p);
}
ans: 2 an ,
7)A. main()
{
int i)"+*9>i;
f!(9);
*9(!";
f)(9);
printf(0*d and *d0+i+*9);
}
f!(;)
int *;;
{ *;(!:;}
f)(x)
int *x;
{ int m*x+ *n>m;
*n(!";
}
ans: $% an $%
7=". func(int x)
{
if(x4")
return (!);
return func(xO!)(x;
}
main()
{
printf(0*d0+func(:));
}
ans: 1'
7=!. %oid funca(int *;)
{
*;()";
}
%oid func$(int *;)
{
int m*;+*n>m;
*n(!";
}
main()
{
int %ar):;
int *%arp>%ar;
funca(%arp);
*%arp(!";
func$(%arp);
printf(0*d *d0+%ar+*%arp);
}
ans: %% %%
7=). main()
{
int x"+*p";
x((; p((;
printf (0*d and *dBn0+x+p);
}
ans: 1 an 2
7==. main()
{
int Y!";
if( Y((5A >> Y((P!" >> Y((5!")
printf(0*d0+Y);
else
printf(0........0);
}
ans: 13
7=E.
int i!";
main()
{
int i)"+n;
for(n";n4i;n(()
{
int i!";
i((;
}
printf(0*d0+ i);
}
ans: 2,
7=:. main()
{
int i)"+9+;";
for(9!;94i;9!(E*(i&9))
{
;(94!"?E:=;
}
printf(0*d0+ ;);
}
ans: $
7=L. main()
{
int i!";
printf(0*d *d *d0+i((+i((+iOO);
}
ans: 1, H 1,
7=7. main()
{
int i!";
if(!+i((+((i)
printf(0Ihe %alue for i is *d0+i);
}
ans: Ghe value for i is 12
7=6. main()
{
int a!"+$==;
aaJ$;
$aJ$;
aaJ$;
printf(0*d *d0+ a+$);
}
ans: 33 1,
7=A. main()
{
int *a;
int (*$)();
printf(0*d *d0+siCeof(a)+siCeof($));
}
ans: $ $
7E". main()
{
int i;
char *p;
i"<6A;
p(char *)i;
p((;
printf(0*xBn0+p);
}
ans: La
7E!. main()
{
int x"+*p";
x((; p((;
printf (0*d and *dBn0+x+p);
}
ans: 1 an 2
7E). 3define %al !()
main()
{
printf(0*d *d0+%al&%al+%alJ=);
}
ans: % ,
7E=. Zefine !this! !Z!
Zefine .x/y1 xZZy
main()
{
printf(0this0+0this is0);
}
ans: error .efine irective nees an
ientifier1
7EE. main()
{
int a +$7;
a)b;$Xb;;1:b)$X71:a+
printf(0*d0+a);
}
ans: error .lvalue re3uire1
7E:. main()
{
int a +$7;
a)b;$Xb;;1:.b)$X71:a1+
printf(0*d0+a);
}
ans: 71
7EL. main()
{
int a+$;
a(!".!:);
$!"+!:;
printf(0*d *d0+a+$);
}
ans: 1, 1, .Ia* value is truncate/ no effect of
comma operator/ it is :ust assignment1
7E7. main()
{
int a+$;
a(!".!:);
$(!"+!:);
printf(0*d *d0+a+$);
}
ans: 1, 1% .Ia* value is truncate an effect
of comma operator1
7E6. main()
{
int a+$;
a(!"+!:);
$!"+!:;
printf(0*d *d0+a+$);
}
ans: 1% 1,
7EA. 3define [#.W/ !()
main()
{
printf(0*d and *dBn0+[#.W/&[#.W/+[#.W/*=);
}
ans: % an 7
7:". which of the followin' is not $asic data type
ans: char ( .pointers erive ata types1
7:!. the declaration of the %aria$le does not result in one of
the followin'
ans: allocation of the storage space for the
varable.
7:). ) %aria$les cannot ha%e the same name if they are
ans: in the same bloc2.
7:=. Shich of the followin' is the correct code for strcpy+
that
is used to copy the contents from src to dest?
a) strcpy (char *dst+char *src)
{
while (*src)
*dst(( *src((;
}
$) strcpy (char *dst+char *src)
{
while(*dst(( *src(();
}
c) strcpy (char *dst+char *src)
{
while(*src)
{ *dst *src;
dst((; src((;
}
}
d) strcpy(char *dst+ char *src)
{
while(*((dst *((src);
}
ans: b .Ia*"null character not assigne Ic*"
null character not assigne I*"first
character is s2ippe1
7:E. main()
{
int <+$7;
< $56 ? $ 44= : $5E ? $55!:$;
printf(0*d0+<);
}
ans: 3
7::. main()
{
char *src 0Mello Sorld0;
char *dst;
dst (char *)malloc()");
while(*dst *src){dst((;src((;}
printf(0*s0+dst);
'etch();
}
ans: no output
7:L. main()
{
char *src 0Mello Sorld0;
char *dst;
dst (char *)malloc()");
while(*dst(( *src(();
printf(0*s0+dst);
'etch();
}
ans: garbage characters .st is pointing to
the character next to the null character1
7:7. main()
{
char *src 0Mello Sorld0;
char (st+
while((st66 *src(();
printf(0*s0+dst);
'etch();
}
ans: error .use of st before efinition.
Assign some aress to st1
7:6. main()
{
char *src 0Mello Sorld0;
char st?2,@+
while((st66 *src(();
printf(0*s0+dst);
'etch();
}
ans: error .lvalue re3uire1
7:A. int main()
{
for(;;);
printf(0MelloBn0);
return ";
}
ans: Duns in an infinite loop without printing
anything.
7L". ,WHR (int *p)
{
p (int *)malloc(!"");
printf(0p:*x 0+p);
}
int main()
{
int *ptr;
,WHR(ptr);
printf(0Ftr:*x0+ptr);
return ";
}
ans: Both print ifferent values .p:LL2
Otr:1,H71
7L!. int main()
{
char a[] 0world0;
printf(0*d *dBn0+strlen(a)+siCeof(a));
return ";
}
ans: % '
7L). main()
{
char *s 0Mello0;
printf(0*s0+!(s));
}
ans: error .call of nonfunction1
7L=. main()
{
char *s 0Mello0;
printf(0*s0+![s]);
}
ans: error .it has to print from memory
location Hb i.e. Ie*1
7LE. main()
{
char *s 0Mello0;
printf(0*s0+>![s]);
}
ans: ello
7L:. char . ( . f .1 1 ?@ 1.1
ans: f is a function returning pointer to
array?@ of pointer to function returning char.
7LL. main()
{
int i;
i()+=);
printf(0*d0+i);
}
ans: 3
7L7. main()
{
char str[]0Q/U.0;
printf(0*d *d0+siCeof(str)+strlen(str));
}
ans: % $
7L6. main()
{
int i;
for(i";i((;i4!"")
printf(0hello worldBn0);
}
ans: no output .for loop conition fails1
7LA. main()
{
char i+
for(i!;i((;i4!"")
printf(0hello world *dBn0+i);
}
ans: hello worl 1aa.hello worl 127aa
hello worl "12La..hello worl "1a..hello
worl ,
77". main()
{
int i+
for(i!;i((;i4!"")
printf(0hello world *dBn0+i);
}
ans: hello worl 1aa.hello worl 327'7aa
hello worl "327'L....hello worl "1a..hello
worl ,
77!. main()
{
char c;
scanf(0*s0+c);
}
ans: it as2s for a character when you type a
character it will give error because HH
memory location i.e./ Ic* .which is protecte
memory an not accessible1 is use to store
type character.
77). main()
{
int ;:;
for(((;4: >> ;((&: ]] ((;46);
printf(0*dBn0+;);
}
ans: error .for loop syntax error1
77=. main()
{
int ;:;
if(((;4: >> ;((&: ]] ((;46);
printf(0*dBn0+;);
}
ans: 7
77E. main()
{
int ;:;
if(((;4: >> ;((&: >> ((;46);
printf(0*dBn0+;);
}
ans: '
77:. main()
{
int ;:;
if(((;4: ]] ;((&: >> ((;46);
printf(0*dBn0+;);
}
ans: L
77L. main()
{
int ;:;
if(((;4: ]] ;((&: ]] ((;46);
printf(0*dBn0+;);
}
ans: 7
777. int *func(int a+ int $+ int *c)
{
int x)a6b+
*caO$;
return.Bx1+
}
main()
{
int *ptr!+*ptr);
ptr!(int *)malloc(siCeof(int));
ptr)func()"+!"+ptr!);
printf(0*d *dBn0+*ptr!+*ptr));
}
ans: bug in the coe .we are returning
aress of a auto variable whose scope is
lost after function returns1
776. int *func(int a+ int $+ int *c)
{
static int x)a6b+
*caO$;
return(>x);
}
main()
{
int *ptr!+*ptr);
ptr!(int *)malloc(siCeof(int));
ptr)func()"+!"+ptr!);
printf(0*d *dBn0+*ptr!+*ptr));
}
ans: error .illegal initiali0ation of x. since x is
a static variable it shoul be initiali0e with
constant expression1
77A. int *func(int a+ int $+ int *c)
{
static int x+
x)a6b+
*caO$;
return(>x);
}
main()
{
int *ptr!+*ptr);
ptr!(int *)malloc(siCeof(int));
ptr)func()"+!"+ptr!);
printf(0*d *dBn0+*ptr!+*ptr));
}
ans: 1, 3,
76". int main()
{
int i!"+9;
if((9Xi)4i)
printf ( 0Irue0 ) ;
else
printf ( 0,alse0 ) ;
}
ans: Grue
76!. int main()
{
int i!"+9;
if((9Xi)4i)
printf ( 0Irue0 ) ;
else
printf ( 0,alse0 ) ;
}
ans: Elase
76). int main()
{
unsi'ned int iO!"+9!";
if(94i)
printf ( 0Irue 0 ) ;
else
printf ( 0,alse 0 ) ;
printf(0*d *u0+i+i);
}
ans: Grue "1, '%%2'
76=. main()
{
,-./ *fp;
printf(0*dBn0+siCeof(fp));
}
ans: $ .pointer ta2es $ bytes1
76E. main()
{
int a!"+$)";
aJ$JaJ$;
printf(0*d *dBn0+a+$);
}
ans: 2, 1,
76:. main()
{
int a)1,/2,+
int $;
aJ$JaJ$;
printf(0*d *dBn0+a+$);
}
ans: error .eclaration error1
76L. main()
{
int a+$;
a(!"+!:);
b)1,/1%+
printf(0*d *d0+a+$);
}
ans: 1% 1,
767. main()
{
int i!";
switch(i)
{
case !": printf(0Mello 0);
{
case ! : printf(0Sorld 0);
}
case :: printf(0Mello Sorld 0);
}
}
ans: 5ello Rorl 5ello Rorl
766. main()
{
char str![]0Mello0;
char str)[]0Mello0;
if ( str!str) )
printf(0IrueBn0);
else
printf(0,alseBn0);
}
ans: Ealse
76A. main()
{
3 include 4stdio.h5
int i !" ;
printf(0*dBn0+ i&) );
}
ans: %
7A". 3pra'ma pac;())
struct U-a/
{
int i;
char ch ;
dou$le d$ ;
};
main()
{
printf(0*dBn0+siCeof(struct U-a/));
}
ans: 12 .actually it ta2es 11 bytes since
pac2ing is there it ta2es 12 bytes1
7A!. main()
{
int arr[]{ !+)+=+E };
int *ptr ;;;;
ptr66 ) arr+
printf(0*d+*d0+ptr[)]+arr[)]);
return ";
}
ans: error .lvalue re3uire1
7A). main()
{
char s[!"];
scanf (0*s0+s);
printf(s);
}
what is the output if input is a$cd
ans: abc
7A=. main()
{
char c )::;
printf (0*d0+c);
return ";
}
ans: "1
7AE. main()
{
int i;
for (i7;i4";iOO)
printf (0helloBn0);
}
ans: no output .for loop coition fails on first
iteration1
7A:. main()
{
printf( printf (0world0) );
}
ans: error .printf.%1 gives error. Fince
memory location % is not accessible1
7AL. main()
{
scanf(0*d0);
printf();
}
ans: error .too few parameters in call to
printf1
7A7. main()
{
scanf(0*d0);
printf(0manu0);
}
ans: manu .whatever you type for scanf
output will be manu1
7A6. 3define islower(c) (1a14(c) >> (c)41C1)
3define toupper(c) (islower(c)?(c)O(1a1O1#1):(c))
main()
{
char *p0i am fine0;
while(*p)
printf(0*c0+toupper(*p(());
}
ans: AEE .macro substitution 3 times1
7AA. main()
{
)"";
printf(0tric;y pro$lem0);
}
ans: tric2y problem
6"". which is the null statement?
a) ;
$) {}
c) 1B"1;
d)all of these
ans: a1
6"!. what is the correct prototype of printf function ?
a)printf(char *p+...);
$)printf(const *char *p+...);
c)printf(const char *p+...);
d)printf(const *char p+...);
ans: c1
6"). ,or a lin;ed list implementation which searchin'
techniKue is not
applica$le?
a)linear search
$)none
c)Kuic; sort
d)$inary search
ans: 1
6"=. what is $i'Oendian.
a) 8U2 at lower address .U2 at hi'her address
$) .U2 at lower address 8U2 at hi'her address
c) memory m'mt techniKue
d) none of the a$o%e
ans: a1
6"E. what is .ittleOendian.
a) 8U2 at lower address .U2 at hi'her address
$) .U2 at lower address 8U2 at hi'her address
c) memory m'mt techniKue
d) none of the a$o%e
ans: b1
6":. what is the schedulin' al'orithm used in 'eneral
operatin' systems.
a) ,R,U al'orithm
$) Mi'hest Friority ,irst al'orithm
c) GoundOGo$in al'orithm
d) Hone of the a$o%e
ans: c1
6"L. %oid main()
{
char *mess[]{0Ma%e0+0a0+0nice0+0day0+02ye0};
printf(0*d *d0+siCeof(mess)+siCeof(mess[!]));
}
ans: 2, $ .mess is an array of % pointers an
mess?1@ is pointer. 5ere pointer ta2es $
bytes1
6"7. %oid main()
{
int i+count";
char *p!0a$cdef'hi90;
char *p)0alcmenfoip0;
for(i";i4strlen(p!);i(()
{
if(*p!(( *p)(()
count(:;
else
countO=;
}
printf(0count*dBn0+count);
}
ans: count)'
6"6. what does main return on successful execution?
a. !
$. "
c. O!
d.HonCero
ans: b
6"A. main(int ar'c+char *ar'%[])
{
printf((ar'c 5 ! ? 0*c0 : 0*c0+*((ar'%);
}
-f the i&p strin' is 0Q/U. 2an'alore0.
ans: B .chec2 it out1
6!". Mow do u declare a pointer to an array of pointers to
int?
a. int *a[:];
$. int **a[:];
c. int *(*a)[:];
d. u con not declare
ans: c
6!!. main()
{
int a;
char *p;
a ) si0eof.int1 ( p+
printf(0*dBn0+a);
}
ans: illegal use of pointer .pointer
multiplication is invali1
6!). 3define U-a/ siCeof(int)
main()
{
int iO!;
if( i 4 U-a/ )
printf(0IrueBn0);
else
printf(0,alseBn0);
}
ans: Grue
6!=. int .(fun.11?@
ans: function returning a pointer to an array
of integers
6!E. main()
{
int a6+d;
int *p;
p>a;
)aJ(p+
printf(0*dBn0+d);
}
ans: error .there shoul be space between J
an (1
6!:. main()
{
int a6+d;
int *p;
p>a;
)aJ (p+
printf(0*dBn0+d);
}
ans: 1
6!L. main()
{
char *a0Mello0;
a(( 1h1;
printf(0*sBn0+a);
}
ans: error .lvalue re3uire. Both assignment
an increment is on a1
6!7. main()
{
char *a0Mello0;
*a(( 1h1;
printf(0*sBn0+a);
}
ans: ello .here assignment is to (a an
increment is on a1
6!6. main()
{
char p[]0Mello0;
p["]1h1;
printf(0*sBn0+ p);
}
ans: hello
6!A. 3define mysiCeof(a) (>a(!) O >a
main()
{
float d;
printf(0*d 0+ >d);
printf(0*d 0+ >d(!);
printf(0*d 0+mysiCeof(d));
printf(0*d0+>d(!O>d);
}
ans: H21' H22, 1 1
6)". main()
{
int *p!";
printf(0*dBn0+*p);
}
ans: error .value at memory location 1,
which is not accessible1
6)!. main()
{
int *p!";
printf(0*dBn0+p);
}
ans: 1,
6)). main()
{
int iO!;
i44);
printf(0*dBn0+i);
}
ans: "$
6)=. main()
{
int i "xffffffff;
printf(0*dBn0+i);
}
ans: "1
6)E. main()
{
int #!+2);
if(#2 4 printf(0Mello 0))
printf(0worldBn0);
else
printf(02an'aloreBn0);
}
ans: 5ello worl .; has highest priority than
))1
6):. main()
{
int i;
for(i"; i4 !"; i(()
{
int 9!";
9((;
printf(09 *dBn0+ 9);
}
}
ans: :) 11 will be printe 1, times
6)L. union test
{
int a;
union test *p;
};
main()
{
union test K;
printf(0 a *dBn 0+ K.a);
}
ans: a) garbage value
6)7. re'ister int a+$;
main()
{
for(a" ; a4: ; a(()
$((;
}
ans: error .storage class Iregister* is not
allowe here1
6)6. 3define dprint(expr) printf(0 expr *d Bn 0+ expr)
main()
{
int i!"+9);
dprint(i&9);
}
ans: expr) %
6)A. main()
{
int *p ;
p(int *)malloc(O!");
printf(0*d0+p);
free(p);
}
ans: , .no space is allocate for p. p is a null
pointer1
6=". main()
{
int *p ;
p(int *)malloc(!");
printf(0*d0+p);
free(p);
}
ans: 22'' .starting aress of the allocate
bloc21
6=!. main()
{
for(printf(0a0);printf(0$0);printf(0c0));
}
ans: abcbcbcbcbcbaa. &nfinite loop
6=). fun()
{
return !" ;
}
main()
{
int i !" * fun() ;
printf(0*d0+i);
}
ans: 1,,
6==. fun()
{
return !" ;
}
int i) 1, ( fun.1 +
main()
{
printf(0*d0+i) ;
}
ans: illegal initiali0ation error .static an
global variables shoul be initiali0e with
constant or constant expression1
6=E. main()
{
int i!"" ;
printf(0*d 0+ siCeof(i(());
printf(0*d 0+i) ;
}
ans: 2 1,, .si0eof operator operan will not
be evaluate1
6=:. main()
{
int i!"" ;
printf(0*d 0+ siCeof(((i);
printf(0*d 0+i) ;
}
ans: 2 1,, .si0eof operator operan will not
be evaluate1
6=L. main()
{
int i!"" ;
printf(0*d 0+ siCeof.66i661);
printf(0*d 0+i) ;
}
ans: error .lvalue re3uire an not allowe
type for si0eof operator1
6=7. Shich one of the followin' data structures is $est
suited for searchin' ?
a) #rrays
$) Uin'ly .in;ed .ist
c) Nou$ly .in;ed .ist
d) Mash Ia$le
ans: 1
6=6. Shich of the followin' data structures is $est suited for
Neletion ?
a) #rrays
$) Uin'ly .in;ed .ist
c) Nou$ly .in;ed .ist
d) Mash Ia$le
ans: c1
6=A. Shich one of these is not a schedulin' techniKue in
Vperatin' Uystem?
a) .astORomeO,irstOUer%e Uchedulin'
$) ,irstORomeO,irstOUer%e Uchedulin'
c) Freempti%e Uchedulin'
d) Gound Go$in Uchedulin'
ans: a1
6E". 02an;er1s #l'orithm0 is used for :
a) Neadloc; Netection
$) Neadloc; #%oidance
c) Neadloc; Fre%ention
d) #ll of the a$o%e
ans: b1
6E!. main()
{
int a !;
3define p a
printf(0*d *d 0+a((+p(();
}
ans: 2 1
6E). main()
{
3include4stdio.h5
int a A" ;
printf(0*d0+a) ;
}
ans: H,
6E=. main()
{
main() ;
}
ans: executes until the stac2 overflows
6EE. 3define max 0hello0
main()
{
printf(max);
}
ans: hello
6E:. 3define max main()
main()
{
max;
printf(0hello wolrdBn 0);
}
ans: executes until the stac2 overflows
6EL. typedef int *p ;
main()
{
int a A" ;
p p! ;
p! >a ;
printf(0*d0+*p!) ;
}
ans: H,
6E7. main()
{
int i! ;
printf(i ?0one0 : 0Cero0) ;
}
ans: one
6E6. main()
{
int i!;
printf(0*d0+i ? ! : ") ;
}
ans: 1
6EA. main()
{
int aA"+$!"";
a((;
a(a J $) J (a $ );
$ aJ$Ja ;
OOa ;
printf(0*d *d0+a((+$(() ;
}
ans: H, 1,,
6:". main()
{
int a !" + $ !"" ;
swap(>a + >$) ;
printf(0*d *d0+a+$) ;
}
swap(int *a + int *$)
{
*a *a ( *$ ;
*$ *a O *$ ;
*a *a O *$ ;
swap!(>a + >$) ;
}
swap!(int **a + int **$)
{
**a **a ( **$ ;
**$ **a O **$ ;
**a **a O **$ ;
}
ans: 1, 1,,
6:!. main()
{
%oid *ptr ;
int a !" ;
ptr >a ;
printf(0*d0+*ptr) ;
}
ans: error .inirection operator ( shoul not
be applie on voi pointer. Fince compiler
oes not 2now the si0e of the operan which
voi pointer is pointing to1
6:). main()
{
%oid *ptr ;
int a A" ;
char *ptr! 0hello0 ;
ptr a ;
ptr ptr! ;
}
ans: executes without any error
6:=. main()
{
char *p 0helloo0 ;
char *p! 0strcat0 ;
while((*(p(() *(p!(()) P 1B"1)
{
;
}
}
ans: contents are copie
6:E. int ' !" ;
main()
{
int ' !" ;
printf(0*d0+') ;
}
int ' ;
ans: 1,
6::. int g ) 1, +
main()
{
extern int ';
printf(0*d0+') ;
}
int ' ;
ans: 1,
6:L. &&int ' !" ;
main()
{
extern int ';
printf(0*d0+') ;
}
int g +
ans: ,
6:7. main()
{
int a ! ;
int $ " ;
a a(( ( OO$ * a(( ;
printf(0*d0+a) ;
}
ans: 2
6:6. struct s
{
int si;
union u
{
float uf;
char uc;
>+
};
main()
{
printf(0*d0+siCeof(struct s));
}
ans: eclaration terminate incorrectly
6:A. struct s
{
int si;
union u
{
float uf;
char uc;
>a+
};
main()
{
printf(0*d0+siCeof(struct s));
}
ans: '
6L". struct st
{
int a;
char $;
>
main()
{
}
ans: struct st is return type of main .since
statement termination is not there for struct
template1
6L!. typedef struct info
{
int i;
char $;
}node;
main()
{
struct info node!;
node!.i::;
printf(0*d0+node!.i);
}
ans: %% .noe is ifferent from noe11
6L). struct a
{
int i;
int display()
{
printf(0hello worldBn0);
}
};
main()
{
strcut a %ara;
%ara.display();
}
ans: functions may not be a part of a struct
or union
6L=. struct a
{
int (*ptr)();
};
int display()
{
printf(0Qlo$al /d'eBn0);
}
main()
{
struct a structa;
structa.ptrdisplay;
structa.ptr();
}
ans: Plobal Ege .through function pointers
functions can be implemente in structures1
6LE. typedef int *#2R;
typedef #2R <Ya[!"];
int main()
{
<Ya %ar;
}
!. %ar is an array of inte'er pointers.
). %ar is a pointer to an inte'er array.
ans: only 2 is correct
6L:. union ta'
{
int a;
char x;
char y;
}name;
int main()
{
name.a):6;
printf(0Bn x *d y *d 0+name.x+name.y);
}
ans: x ) 2 y ) 2
6LL. int main()
{
int a[)"];
int *p+*K+%al;
p >a["];
K >a[!"];
%al K O p;
printf(0p *d 0+p);
printf(0K *d 0+K);
printf(0%al *d0+%al);
}
ans: p L'$, 3 L'', val 1,
6L7. struct ;ey
{
char *word[)];
int count;
char c;
}a$c;
int main()
{
printf(0BnsiCe *d0+siCeof(a$c));
}
ans: si0e 11 .pointer ta2es $ bytes1
6L6. main()
{
int a;
fun();
printf(0*d0+a);
a:";
}
fun()
{
int i;
*(>i(E) !"";
}
ans: error .Bi6$ memory location is not
allocate an we are trying to assign a value
to this memory location1
6LA. main()
{
Zefine x %
int $;
$ x;
printf(0*d0+$);
}
ans: %
67". main()
{
int a; Zefine y 1,
ay;
printf(0*d0+a);
}
ans: Zefine .shoul come at the beginning
of the bloc21
67!. 3define s O:"
main()
{
int s+
3ifdef s
printf(0MellBn0);
3else
printf(0Mea%enBn0);
3endif
}
ans: error .eclaration terminate incorrectly
i.e int "%,+1
67). 3define s O:"
main()
{
int a+
3ifdef s
printf(0MellBn0);
3else
printf(0Mea%enBn0);
3endif
}
ans: 5ell
67=. Mow many times can a comment $e nested ?
#)RV88/HIDH/UID.-8-I times
2)RV88/HID.-8-I times
R)VH/ time
N)Hot e%en Vnce
ans: 41
67E. main()
{
int i+9;
i "L;
: ) ,H+
printf (0*d *dBn0+i+9);
}
ans: error .illegal octal igit. H is not there in
octal system1
67:. main()
{
int i+9;
i ) o'+
: ) ,H+
printf (0*d *dBn0+i+9);
}
ans: error .illegal octal igit. H is not there in
octal system. Nctal number starts with ,/0ero not
with letter o1
67L. Z unef __E&SE__
3 define DD,-./DD 0Q.V2#./NQ/0
main()
{
printf(0*sBn0+DD,-./DD);
}
ans: Ba unef irective syntax
677. 3 define .-H/
3 define H#8/ 0Q/U.0
main()
{
printf(0*d *sBn0+.-H/+H#8/);
}
ans: error .S&-E is not efine1
676. 3 define .-H/ !
3 define H#8/ 0Q/U.0
main()
{
printf(0*d *sBn0+.-H/+H#8/);
}
ans: 1 PEFS
67A. main()
{
int i!";
float 9).:;
printf(0*d 0+siCeof(9(((i(());
printf(0*d *f0+i+9);
}
ans: $ 1, 2.%,,,,,
66". int main()
{
int i :;
if(!)
{
static int i;
i((;
printf(0*d 0+ i);
}
printf(0*d0+ i);
}
ans: 1 %
66!. int main()
{
int a[E] {)=+ L7+ A"};
printf(0*d0+ a[=]);
}
ans: , .when there are fewer initiali0ations
remaining elements are 0ero1
66). int main()
{
int i ) 1/ 2+
printf(0*d0+ i);
}
ans: error .eclaration terminate
incorrectly1
66=. int main()
{
int i;
for( i";;i(()
{
i i();
$rea;;
printf(0*d0+ i);
}
}
ans: no output .for loop enters only once an
after i)i62 it brea2s 1
66E. int main()
{
int i;
i !+ );
printf(0*d0+ i);
}
ans: 1
66:. int i )";
int maxlen i;
int main()
{
int 9 i;
printf(0i*d + 9*dBn0+ i + 9);
}
ans: illegal initiali0ation error .static an
global variables shoul be initiali0e with
constants or constant expression1
66L. int main()
{
int i !";
printf(0*d0+ ;);
printf(0*d0+i);
}
int ; )";
ans: error .unefine symbol 21
667. int main()
{
int i !";
extern int ;;
printf(0*d 0+ ;);
printf(0*d0+i);
}
int ; )";
ans: 2, 1,
666. int i )";
int i+9!";
int i;
main()
{
int 9 )";
printf(0i*d + 9*dBn0+ i+ 9);
}
ans: i)2, / :)2,
66A. int main()
{
int ;)+i !";
while(;OO)
{
printf(0*d 0+disp(i));
}
}
disp(int ;)
{
static int i";
return ii(;;
}
ans: 1, 2,
6A". header files usually contains
a)only definitions
$)only declarations
c)$oth
d)compiled code for functions
ans: b1
6A!. int main()
{
int i =;
while(iOO)
{
int i !";
printf(0*d 0+i);
}
}
ans: 1, 1, 1,
6A). int main()
{
char s[] 0hello<, world0;
printf(0*s...*d0+s+strlen(s));
}
ans: helloa%
6A=. int main()
{
printf(0*** s0+0hello0);
}
ans: =hello
6AE. Shat does f'etc return
(a) char
($) int
(c) unsi'ned int
(d) %oid
ans: .b1
6A:. main()
{
int i )E;
printf(0*xd0+i);
}
ans: 1L
6AL. main()
{
int i )E;
printf(0*,xd0+i);
}
ans: 1L
6A7. struct node
{
int i;
};
main()
{
struct node n!;
printf(0*d0+n!.i);
}
ans: garbage value
6A6. struct nodeDta'
{
int i;
struct nodeDta' *pt;
};
main()
{
printf(0*d0+siCeof(noe_tag));
}
ans: error .struct 2eywor is missing1
6AA. struct nodeDta'
{
int i;
struct nodeDta' *pt;
};
main()
{
printf(0*d0+siCeof(struct noe_tag));
}
ans: '
A"". typedef struct nodeDta'
{
int i),+
int 9;
}node;
main()
{
node n!;
printf(0*d0+n!.i);
}
ans: error .i shoul not be initiali0e li2e
that1
A"!. struct
{
int i;
}noe +
main()
{
printf(0*d0+node.i);
}
ans: ,
A"). main()
{
struct
{
int i;
}node ;
printf(0*d0+node.i);
}
ans: 1H12% .garbage value1
A"=. struct ta'
{
int i;
};
main()
{
struct ta' node;
printf(0*d0+node.i);
}
ans: garbage value .1H12%1
A"E. struct nodeDta'
{
int a;
struct nodeDta' *pt;
};
main()
{
struct nodeDta' n!;
n!.pt>n!;
n!.ptO5a:;
printf(0*d0+n!.a);
}
ans: %
A":. main()
{
int n;
scanf(0*d0+n);
}
ans: runtime error .if n value e3uals aress
of inaccessible memory location1
A"L. (%oid *) is called
(a)pointer to %oid
($)pointer to any data type
(c)'eneric pointer
(d)Hone of the a$o%e
ans: .c1
A"7. main()
{
int i:;
ii(( * i((;
printf(0*d0+i);
}
ans: 27
A"6. main()
{
int i:;
printf(0*d0+i(( * i(();
}
ans: 3,
A"A. int main()
{
char *p 0Selcome Io Q/U.Bn0;
*(p(!");
fprintf(stderr+0*s0+p);
return 1c1;
}
ans: Relcome Go PEFS
A!". int main()
{
char *p 0Selcome Io Q/U.Bn0;
*(p(((!");
fprintf(stderr+0*s0+p);
return 1c1;
}
ans: elcome Go PEFS
A!!. int main(%oid)
{
puts(0helloB"world0);
}
ans: hello .<, null character is there after
hello1
A!). union u
{
int i%al;
float f%al;
char *s%al;
}
siCe of u is?
ans: $ bytes
A!=. struct x
{
int i; int 9;int ;;
};
struct x *p;
struct x arr[=];
p >arr["];
p((;
what is p pointin' to?
a) pointin' to i of arr["]
$) pointin' to 9 of arr["]
c) pointin' to ; of arr[!]
d) pointin' to i of arr[!]
ans: 1
A!E. struct a
{
int $;
};
struct $
{
int $;
};
int main()
{
struct a first;
struct $ second;
first.$ !";
second first;
printf(0*d0+second.$);
}
ans: error .secon an first are two ifferent
structure variables1
A!:. struct a
{
int $;
};
int main()
{
struct a first+second;
first.$ !";
second first;
printf(0*d0+second.$);
}
ans: 1, .secon an first variables belong to
same structure1
A!L. struct a
{
int x;
float y;
dou$le C;
struct a $;
};
int main()
{
;
}
ans: error .unefine structure Ia*1
A!7. struct a
{
int x;
float y;
dou$le C;
struct a *$;
};
int main()
{
;
}
ans: no error
A!6. struct a
{
struct $
{
int a;int $;
}c;
int *ptr;
}d;
int main()
{
d.ptr>d.c.a;
}
ans: no error
A!A. int main(%oid)
{
int *intFtr ;
intFtr (char*)malloc(siCeof(!"));
printf(0Bn Ihe startin' address is *d Bn 0+intFtr);
return ";
}
ans: Ghe starting aress is 227$
A)". int main(%oid)
{
int intHum!+intHum)+num !+i;
printf(0Bn/nter first num$er Bn0);
scanf(0*d0+>intHum!);
printf(0Bn/nter second num$er Bn0);
scanf(0*d0+intHum));
for(i ";i4=;i(()
{
num intHum! * intHum) * num;
}
printf(0Bn num *d 0 + num);
return ";
}
ans: error .secon scanf function reas a
value into a memory location which may not
be user accessible some times1
A)!. int main(%oid)
{
int a!+$"+ x;
x a(( >> (($;
printf(0*d *d *d 0+a+$+x );
}
ans: 2 1 1
A)). char *fn();
main()
{
char *s;
s fn();
printf(0*sBn0+s );
}
char *fn()
{ return 0Mello0; }
ans: 5ello
A)=. main()
{
int i;
for( i"; i4!"O!; i() );
i( );
printf(0i *dBn0+ i );
}
ans: i ) 12
A)E. f()
{ return !+)+=; }
main()
{
int i;
i f();
printf(0*d0+i );
}
ans: 3
A):. Shat is the difference $etween ((*ip and *ip(( ?
a) $oth increment %alue
$) ((*ip increment %alue and *ip(( increment
address
c) $oth increment address
d) ((*ip increment address and *ip(( increment
%alue
ans: b1
A)L. int main (%oid)
{
int x E6;
printf(0x *sBn0+ x );
}
ans: error .memory location $L is not user
accessible1
A)7. 3 define VH/ !
3 define ISV )
&&3 define VH/ ISV
&&3 define ISV VH/
int main (%oid)
{
printf(0VH/ *d+ ISV *dBn0+ VH/+ ISV );
}
ans: N-E ) 1/ GRN ) 2
A)6. 3 define VH/ !
3 define ISV )
3 define VH/ ISV
&&3 define ISV VH/
int main (%oid)
{
printf(0VH/ *d+ ISV *dBn0+ VH/+ ISV );
}
ans: N-E ) 2/ GRN ) 2
A)A. 3 define VH/ !
3 define ISV )
3 define VH/ ISV
3 define ISV VH/
int main (%oid)
{
printf.!N-E ) =/ GRN ) =<n!/ N-E/ GRN
1+
}
ans: error .unefine symbol N-E an GRN1
A=". -f the command line ar'uments for the followin'
pro'ram are 4a.out5
and 4Qlo$al/d'eUoftware.td5+ what is the output of
the pro'ram ?
int main(int ar'c+ char **ar'%ar)
{
printf(0output *sBn0+ *ar'%ar[!]);
}
ans: runtime error .chec2 it out1
A=!. %oid fun( int+ int );
int main ( %oid )
{
fun( !)+ ( !=+ ( !E+ !7 ) ) );
return ";
}
%oid fun( int x+ int y )
{
printf(0x *d+ y *dBn0+ x+ y );
}
ans: x ) 12/ y ) 17
A=). main()
{
int i+9;
int arr[E][E]
{!+)+=+E+:+L+7+6+A+!"+!!+!)+!=+!E+!:+!L};
for (i);i4";iOO)
for (9);94";9OO)
printf(0*d0+ arr[i][9]);
}
ans: no output
A==. %oid main()
{
int i+x+sum";
int arr[L]{!+)+=+E+:+L};
for (i";i4E;i(()
sum ( func(arr[i]);
printf(0*d0+ sum);
}
func(int x)
{
int val/x+
%al );
return(x( %al(();
}
ans: error .multiple eclaration of x1
A=E. Shere is a %aria$le defined in a function stores?
ans. Orocess Fwappable Area
A=:. %oid main()
{
int ari[] {!+)+=+E+:};
char arc[] {1a1+1$1+1c1+1d1+1e1};
printf(0*d 0+>ari[E]O>ari[)]);
printf(0*d 0+>arc[=]O>arc["]);
}
ans: 2 3
A=L. %oid main()
{
int i"+9";
int arr[E][E]
{!+)+=+E+:+L+7+6+A+!"+!!+!)+!=+!E+!:+!L};
clrscr();
for (i);i5";iOO)
for(9);95";9OO)
printf(0*d 0+ *(*(arr(9)(i));
'etch();
}
ans: 11 7 3 1, ' 2 H % 1
A=7. %oid main()
{
int a!"+$!!;
printf(0*d 0+a((($);
printf(0*d0+a((($);
}
ans: 21 22
A=6. %oid main()
{
int a;
voi c+
}
ans: error .si0e of c is un2nown1
A=A. %oid main()
{
int a;
voi (c+
}
ans: no error
AE". %oid main()
{
int a+$;
a";
$(a")?):=;
printf(0*d0+$);
}
ans: 3
AE). f!(int c)
{
printf(0*d0+ c);
}
main()
{
int a);
f!(a(();
}
ans: 2
AE=. f(int t)
{
switch(t)
{
int c+
case ): c=;
case =: cE;
case E: c:;
case :: cL;
default: c";
}
printf(0*d0+c);
}
main()
{
f(=);
}
ans: error .unefine symbol Ic*1
AEE. f(int t)
{
int c;
switch.t1+
{
case ): c=;
case =: cE;
case E: c:;
case :: cL;
default: c";
}
printf(0*d0+c);
}
main()
{
f(=);
}
ans: error .case outsie of switch since
switch is terminate by + 1
AE:. f(int t)
{
int c;
switch.t1
{
case ): c=;
case =: cE;
case E: c:;
case :: cL;
default: c";
}
printf(0*d0+c);
}
main()
{
f(=);
}
ans: ,
AEL. Shat is the fallacy in the followin' pro'ram se'ment?
int *f!()
{
int a:;
return >a;
}
f()
int *$f!()
int c*$;
}
ans: we shoul not return aress of a auto
variable as its scope will be lost when
function returns
AE7. Qi%e the R lan'ua'e eKui%alents of the followin'
a),unction returnin' an int pointer
$),unction pointer returnin' an int pointer
c),unction pointer returnin' an array of inte'ers
d)#rray of function pointer returnin' an array of
inte'ers
int (x.1+
int (.(x1.1+
int . .(x1.1 1?@+
int . .([email protected] 1?@+
AE6. 2ootstrap loader pro'ram is a pro'ram $elon'in' to
(a) GV8 startup software
($) GV8 extension software
(c) GV8 2-VU software
(d) GV8 2asic software
ans: .a1
AEA. %oid main()
{
int a=+$E+c:;
a$(c;
ca($;
$a(c;
printf(0*d *d *d 0+a($+$(c+c(a);
a$*c;
ca*$;
printf(0*d *d0+a+c);
}
ans: 31 3% 22 2L' '2H2
A:". %oid main()
{
printf(0Bna$B$cdBref0);
}
ans: ef .<n"new line <b"bac2space <r"
carriage return1
A:!. struct a
{
char $[7];
char *s;
};
struct $
{
char *t;
struct a y;
};
main()
{
struct $ K{0Gaipur0 + 0Tanpur0 + 0\aipur0};
printf(0*s *s 0 + K.t + K.y.s);
printf(0*s *s0 +((K.t + ((K.y.s);
}
ans: Daipur ]aipur aipur aipur
A:). main()
{
int a!+$)+c=;
printf(0*d+*d0+a+$+c);
}
ans: 1/2
A:=. main()
{
int i;
for(i"; i4!";i((+printf(0*d 0+i));
}
ans: 1 2 3 $ % ' 7 L H 1, 11
A:E. main()
{
int a[]{!"+)"+="+E"+:"};
fun(a(!);
}
fun(int *p)
{
for(int i!;i4=;i(()
printf(0*d0+*(p(i));
}
ans: error .i shoul be eclarate before for
loop1
A::. main()
{
int a[]{!"+)"+="+E"+:"};
fun(a(!);
}
fun(int *p)
{
int i;
for( i!;i4=;i(()
printf(0*d0+*(p(i));
}
ans: 3, $, %,
A:L. main()
{
enum day {saturday+
sunday=+
monday+
tuesday
};
printf(0*d *d0+saturday+tuesday);
}
ans: , %
A:7. main()
{
int x;
enum day {
saturday+
sundayO!+
monday+
tuesday
};
xmonday;
printf(0*d0+x);
}
ans: ,
A:6. 3define #NN(<+Y) <(Y
main()
{
3undef #NN(<+Y)
fun();
}
fun()
{
int y)A44.3/21+
printf(0*d0+y);
}
ans: error .lin2er error1
A:A. 3define #NN(<+Y) <(Y
main()
{
JJZunef A44.\/Q1
fun();
}
fun()
{
int y)A44.3/21+
printf(0*d0+y);
}
ans: %
AL". int x;
int *p;
int **p!;
int ***p);
Mow to assi'n each one?
ans: p)Bx+
p1)Bp+
p2)Bp1+
AL!. Shich of the followin' is ille'al
(a)%oid %;
($)%oid *%;
(c)%oid **%;
(d)all are le'al
ans: .a1
AL). 3define int -HI/Q/G&*line!*&
3define -HI/Q/G int&*line )*&
main()
{
&-GEPED p)1,+&*line :*&
printf(0*d0+p);
}
ans: error .unefine symbol &-GEPED an
unefine symbol p1
AL=. main()
{
char str)9'5'/'E'/'S'/'S'/'N'/'<,'>+
printf(0*s&n0+str(!);
}
ans: error
ALE. main()
{
char arr[:]{1a1+1a1+1$1+1c1+1d1+1e1};
printf(0*s0+arr);
}
ans: error .too many initiali0ers1
AL:. main()
{
printf.!<= !1+
printf(0BB* 0);
printf.!== !1+
printf(0****0);
}
ans: = <= = ==
ALL. main()
{
printf(0***** 0);
printf(0****** 0);
printf.!=!1+
}
ans: === === =
AL7. main()
{
int i=;
while(i5")
printf(0*d 0+iOO);
return(");
}
ans: 3 2 1 , .loop is execute $ times1
AL6. main()
{
int i!";
printf(0*d *d *d 0+i+((i+i(();
}
ans: 12 12 1,
ALA. main()
{
int x+y+C;
x);
y:;
Cx(((y;
printf(0*d *d *d0+x+y+C);
}
ans: 3 % 7
A7". %oid xyC(char a[!"])
{
int i;
char $[!"];
isiCeof(a);
printf(0*d0+i);
}
main()
{
char s[!"];
xyC(s);
}
ans: $ .pointer ta2es $ bytes1
A7!. %oid xyC(char a[!"])
{
int i;
char $[!"];
isiCeof($);
printf(0*d0+i);
}
main()
{
char s[!"];
xyC(s);
}
ans: 1,
A7). main()
{
int iL;
printf(0*d0+i((*i(();
}
ans: $2
A7=. main()
{
char str[)"] 0U#H\#Y0;
printf(0*d *d0+siCeof(str)+strlen(str));
}
ans: 2, '
A7E. main()
{
unsi'ned int i=;
while( i 5")
printf( 0*d0+ iOO);
}
ans: infinite loop
A7:. 3 define swap(a+$) tempa; a$; $temp;
main()
{
int i+ 9+ temp;
i:;
9!";
temp";
if( i 5 9)
swap( i+ 9 );
printf( 0*d *d *d0+ i+ 9+ temp);
}
ans: 1, , ,
A7L. func()
{
static int i !";
printf(0*d0+i);
i((;
}
Shat is the %alue of i if the function is called
twice?
ans: 12
A77.
func(int *i+ int*9)
{
*i*i * *i;
*9*9* *9;
}
main()
{
int i :+ 9 );
func(>i+>9);
printf(0*d *d0+ i+ 9);
}
ans: 2% $
A76. %oid f(char *p)
{
p(char *) malloc(L);
strcpy(p+0hello0);
}
%oid main()
{
char *p0$ye0;
f(p);
printf(0*s0+p);
}
ans: bye
A7A. int x(char *a)
{
a(char *) malloc(!"*siCeof(char));
*a0hello0;
}
main()
{
char *a0new0;
x(a);
printf(0*s0+a);
}
ans: error .nonportable pointer conversion1
A6". main()
{
int i !;
switch(i)
{
printf (0first0);
i((;
case ! : printf (0second0);
$rea;;
case ) : printf(00);
$rea;;
default : printf(00);
$rea;;
}
}
ans: secon .first won*t be printe1
A6!. %oid main()
{
char *s[!"]{0welcome0+0to0+0india0};
printf(0*d0+siCeof(s));
}
ans: $,
A6). %oid main()
{
const int i!";
int *p;
p>i;
(*p)((;
printf(0Bn *d0+i);
return;
}
ans: 11 .constant can be moifie through a
poiter1
A6=. %oid main()
{
char c[]0!)=E:L76A0;
int iE;
printf(0*c *c0+ c[i]+ i[c]);
}
ans: % %
A6E. %oid main()
{
int *ptr;
p),+
p((;
printf(0*u0+ p);
}
ans: error .assigning an absolute aress to
a pointer variable is invali1
A6:. %oid main()
{
dou$le i".";
switch(i)
{
case ".":
printf(09'd90);
case !.":
printf(0ptoy0);
$rea;;
default:
printf(0hdf%0);
}
}
ans: error .switch expression shoul be
integer expression or characters an case
values shoul be constants or constat
expression1
A6L. %oid main()
{
int a);
if(a=P=)
printf(0=0);
else
printf(0)0);
return;
}
ans: 2
A67. 3define IGW/ "
main()
{
int i";
while(IGW/)
{
printf(0 *d Bn0+i);
i((;
}
printf(0 *d Bn0+i);
i((;
}
ans: ,
A66. main()
{
int a[E]{!+)+=+E};
int *ptr;
ptra;
*(a(=)*(((ptr)((*ptr(();
printf(0*d0+a[=]);
}
ans: $
A6A. f(char *p)
{
p["]? f(((p):!;
printf(0*d 0+*p);
}
main()
{
f(0a$cde0);
}
ans: , , 1,1 1,, HH HL
AA". f(char *p)
{
p["]? f(((p):!;
printf(0*c 0+*p);
}
main()
{
f(0a$cde0);
}
ans: null null e c b .first two are null
characters1
AA!. f(char *p)
{
p(char *)malloc(siCeof(L));
strcpy(p+0M/..V0);
}
main()
{
char *p02Y/0;
f(p);
printf(0*s0+p);
}
ans: BQE
AA). f.char ((p1
{
(p(char *)malloc(siCeof(L));
strcpy((p+0M/..V0);
}
main()
{
char *p02Y/0;
f(p);
printf(0*s0+p);
}
ans: 5ESSN
AA=. main()
{
char str[:]0hello0;
if(strHW..) printf(0strin' null0);
else printf(0strin' not null0);
}
ans: string not null
AAE. %oid f(int x)
{
int i;
for (i";i4!L;i(()
{
if(x >"x6"""55i) printf(0!0);
else printf(0"0);
}
}
ans: binary representation of x
AA:. %oid f(int *p)
{
static %al!"";
val)Bp+
}
main()
{
int a!";
printf(0*d 0+a);
f(>a);
printf(0*d 0+a);
}
ans: error .nonportable pointer conversion1
AAL. struct a
{
int x;
float y;
char c[!"];
};
union $
{
int x;
float y;
char c[!"];
};
main()
{
printf(0*d *d0+siCeof(a)+siCeof(b));
}
ans: error .here si0eof operator operan
shoul be type name not tag name1
AA7. struct a
{
int x;
float y;
char c[!"];
};
union $
{
int x;
float y;
char c[!"];
};
main()
{
printf(0*d *d0+siCeof(struct a)+siCeof(union b));
}
ans: 1' 1,
AA6. main()
{
char a[!"]0hello0;
strcpy(a+1B"1);
printf(0*s0+a);
}
ans: error ., memory location can*t be
copie to array a1
AAA. main()
{
char a[!"]0hello0;
strcpy(a+@B"@);
printf(0*s0+a);
}
ans: no output
!""". %oid f(int*9)
{
int ;!";
9 >;;
}
main()
{
int i+*9;
i:;
9>i;
printf(0i*d 0+i);
f(9);
printf(0i*d0+i);
}
ans: i)% )%
!""!. main()
{
int *s 0B"0;
if(strcmp(s+HW..) ")
printf(0Bn s is null0);
else
printf(0Bn s is not null0);
}
ans: error
!""). main()
{
int *s 00;
if(strcmp(s+HW..) ")
printf(0Bn s is null0);
else
printf(0Bn s is not null0);
}
ans: error
!""=. int arr[] {!+)+=+E}
int *ptrarr;
*(arr(=) *((ptr ( *ptr((;
,inal contents of arr[]
ans: 1/2/3/$
!""E. func(int *i+ int*9)
{
*i*i * *i;
*9*9* *9;
}
main()
{
int i :+ 9 );
func(>i+>9);
printf(0*d *d0+ i+ 9);
}
ans: 2% $
!"":. int x(char *a)
{
a(char *) malloc(!"*siCeof(char));
*a0hello0;
}
main()
{
char *a0new0;
x(a);
printf(0*s0+a);
}
ans: error .nonportable pointer conversion1
!""L. int x(char *a)
{
char *$;
a(char *) malloc(!"*siCeof(char));
$(char *) malloc(!"*siCeof(char));
a)!hello!+
$a;
}
main()
{
char *a0new0;
x(a);
printf(0*s0+a);
}
ans: new
!""7. int x(char *a)
{
char $[!"];
a(char *) malloc(!"*siCeof(char));
a0hello0;
b)a+
}
main()
{
char *a0new0;
x(a);
printf(0*s0+a);
}
ans: error .lvalue re3uire. strcpy shoul be
use1
!""6. a. for(i";i4num;i(()
$. for(inum;i5";iOO)
#ssumin' no code optimiCation and assume that the
microprocessor
has fla's etc. which one is correct
ans: b .in Ib* 0ero flag is teste but in Ia*
both compare instruction an flag testing will be
there1
!""A. will these two wor; in same manner
3define intp int *
typedef int * inpp;
ans: no
3define intp int *
typedef int * inpp;
main()
{
inpp t!+t);
intp m!+m);
printf(0*d *d *d
*d0+siCeof(t!)+siCeof(t))+siCeof(m!)+siCeof(m)));
}
ans: $ $ $ 2 .t1/t2 an m1 are pointers an
m2 is integer1
!"!". 3define max !"
main()
{
int a+$;
int *p+*K;
a!";$!A;
p)B.a6b1+
3)Bmax+
}
ans: error .B must ta2e aress of a memory
location1
!"!!. main()
{
char U[L] 0M/..V0;
printf(0*s 0+U[L]);
}
ans: error .trying to print from memory
location 0ero1
!"!). unsi'ned char c;
for ( c";cP):L;c(())
printf(0*d0+c);
Ho. of times the loop is executed ?
ans: infinite times
!"!=. main()
{
char *x0strin'0;
char y[]0add0;
char *C;
0).char (1 malloc.si0eof.x16si0eof.y1611+
strcpy.0/y1+
strcat.0/x1+
printf(0*s(*s*s0+y+x+C);
}
ans: a6string)astring
!"!E. char *(*(*a[n]) () )();
ans:an array of n pointers to functions
returning pointers to functins returning
pointers to characters
!"!:. Shat does the followin' piece of code do ?
sprintf(ret$uf+ 0*d0+ n);
(#) Frint the -nte'er %alue of n
(2) Ropy the strin' representation of the inte'er
%aria$le n into the $uffer ret$uf
(R) Frint the ,loat %alue of n.
(N) Frint the strin' representation of the inte'er
%aria$le n.
ans: .B1
!"!L. Shat is wron' with the pro'ram
dou$le d;
scanf(0*f0+ >d);
(#) -nstead of *f + *lf should $e used for formattin'
(2) -nstead of *f + *d should $e used for formattin'
(R) -nstead of *f + *N should $e used for formattin'
(N) -nstead of *f + *n should $e used for formattin'
ans: .A1
!"!7. %oid func()
{
int x ";
static int y ";
x((; y((;
printf( 0*dOO*d 0+ x+ y );
}
int main()
{
func();
func();
return ";
}
ans: 1b1 1b2
!"!6. main()
{
int -+9;
for(-"+ 9-((; 95-; 9((+ -(()
{
printf(0*d *d0+ -+ 9);
}
}
ans: no output
!"!A. %oid main()
{
int C;
int x :;
int y O!";
int a E;
int $ );
C x(( O OOy * $ &a;
printf(0*d0+C);
}
ans: 1,
!")". %oid main()
{
int x[] { !+ E+ 6+ :+ !+ E };
int *ptr+ y;
ptr x ( E;
y ptr O x;
printf(0*d0+y);
}
ans: $
!")!. %oid main()
{
char str[)"] 0/H-Q8#0;
char *p+ *K+ *r;
pstr;
Kp((;
rp(= O (pOK);
printf(0*=s *:s0+ (((p)(=+ r);
}
ans: A P[A
!")). %oid main()
{
char str[)"] 0/H-Q8#0;
char *p+ *K+ *r;
pstr;
Kp((;
rp(= O (KOp);
printf(0*=s *:s0+ (((p)(=+ r);
}
ans: A A
!")=. %oid incDcount(int count)
{
count ((;
}
int main()
{
int count ";
while (count 4 !")
incDcount(count);
return count ;
}
Shat will $e the %alue returned $y the function
main?
ans: infinite loop .control will not come to
return statement1
!")E. Shat is the difference $etween the two declaration
?
3include 4stdio.h5
>
3include ?stdio.h@
(#) Ho Nifference
(2) Ihe )nd declaration will not compile
(R) ,irst case Rompiler loo;s in all default location
and in )nd case only in the wor;in' directory
(N) Nepends on the Rompiler
ans: .K1
!"):. 3define ,-GUIDF#GI 7
3define .#UIDF#GI :
3define #..DF#GIU ,-GUIDF#GI ( .#UIDF#GI
int main()
{
printf (0Ihe UKuare root of all parts is *dBn0 +
#..DF#GIU * #..DF#GIU);
return(");
}
ans: Ghe F3uare root of all parts is $7
!")L. %oid *p;
what operation cannot $e performed on p?
ans : arithmetic operation unless it is
properly typecaste
!")7. main()
{
char **p0Mello0;
printf(0*s 0+p);
printf(0*c0+*p);
&&printf(0*c0+**p);
}
ans: 5ello 5
!")6. main()
{
char **p0Mello0;
printf(0*s 0+p);
printf(0*c0+*p);
printf(0*c0+**p);
}
ans: error .trying to access memory location
72 which may not be accessible1
!")A. main()
{
char str[]0Qeneius0;
print (str);
}
print(char *s)
{
if(*s)
print(((s);
printf(0*c 0+*s);
}
ans: null null s u i e n e .null means null
character1
!"=". main()
{
printf(0Qenius *d0+fun(!)=));
}
fun(int n)
{
return (printf(0*d0+n));
}
ans: 123Penius 3
!"=!. main()
{
int iE;
fun(ii&E);
printf(0*d0+i);
}
fun(int i)
{
return i&);
}
ans: 1
!"=). main()
{
printf(0B0H-IT **UWG#IMT#.** PB00);
}
ans: T-&GC =FWDAG5CAS= AU
!"==. main()
{
printf(0B0H-IT B*UWG#IMT#.B* PB00);
}
ans: T-&GC =FWDAG5CAS= AU
!"=E. main()
{
char str[7]0strin's0;
printf(0*s0+str);
}
ans: stringsaaa..till it encounters null
character. Rhile printing if it accesses
inaccessible memory location error will
come1
!"=:. main()
{
char str[6]0strin's0;
printf(0*s0+str);
}
ans: strings
!"=L. main()
{
char *p 0Vracle -ndia0;
p[:] 1l1 ? printf(0Vrcle0) : printf(0-ndia0);
}
ans: &nia
!"=7. main()
{
int i:;
recursi%e(i);
}
recursi%e(int u)
{
if(u 5 " )
recursi%e(uO!);
printf(0*d 0+ u);
}
ans: , 1 2 3 $ %
!"=6. char *(*(*x() ) [] ) ()
ans: x is a function returnting pointer to
array of pointers to functions returning
character pointers
!"=A. const int 8#<!";
main()
{
enum a {a+$+8#<};
printf(0*d0+8#<);
}
ans: 2
!"E". main()
{
const int 8#<!";
enum a {a+$+8#<};
printf(0*d0+8#<);
}
ans: error .multiple eclaration of [A\1
!"E!. const int 8#<!";
main()
{
enum a {a+$+8#<};
[A\)3+
printf(0*d0+8#<);
}
ans: error .lvalue re3uire1
!"E). !)enum o$9ect is a const which can only $e
assi'ned a %alue at initialiCation or )) a %aria$le which
can $e assi'ned any %alue in the middle of the
pro'ram?
ans: 11 is correct
!"E=. %oid *p;
what operation cannot $e performed on p?
ans : arithmetic operation unless it is
properly typecaste
!"EE. main()
{
int iE;
fun(ii&E);
printf(0*d0+i);
}
fun(int i)
{
return i&);
}
ans: 1
!"E:. main()
{
int a:""+$+c;
if(a5E"")
$=""; c)2""+ printf(0*d *d0+$+c);
}
ans: error .lvalue re3uire1
!"EL. main()
{
char c!1a1+c)1a1;
if (c!1a1or c)1C1)
printf(0welcome0);
}
ans: error .for NDing cc symbol shoul be
use1
!"E7. main()
{
int i;
for(i";i4!";i(();
printf(0*d 0+i);
}
ans: 11
!"E6. main()
{
int x!"+y+C;
yOOx;
CxOO;
printf(0*d *d *d0+x+y+C);
}
ans: L H H
!"EA. main()
{
int i;
int mar;s[]{!""+A"+7:+A"+6"};
for (i";i4E;i(()
disp(>mar;s[i]);
}
disp(int *n)
{
printf(0*d 0+*n);
}
ans: 1,, H, 7% H,
!":". main()
{
int arr[]{!+)+=+E+:+L+7};
int *-+*9;
->arr[!];
9>arr[:];
printf(0*d *d0+*9(*-+*9O*-);
}
ans: L $ .be careful about upper case an
lower case1
!":!. main()
{
int n)+sum:;
switch(n)
{
case ):sumsumO);
case =:sum*:;
$rea;;
default:sum";
}
printf(0*d0+sum);
}
ans: 1%
!":). main()
{
int i";
for(i";i4)";i(()
{
switch(i)
{
case ":
i(:;
case !:
i();
case ::
i(:;
default:
i(E;
$rea;;
}
printf(0*d 0+i);
}
}
ans: 1' 21
!":=. main()
{
int i";
for(i";i4)";i(()
{
switch(i)
{
default:
i(E;
$rea;;
case ":
i(:;
case !:
i();
case ::
i(:;
}
printf(0*d 0+i);
}
}
ans: 12 17 22
!":E. main()
{
int i";
for(i";i4)";i(()
{
switch(i)
{
default:
i(E;
case ":
i(:;
case !:
i();
case ::
i(:;
}
printf(0*d 0+i);
}
}
ans: 12 2H
!"::. func(int i)
{
if(i*)) return ";
else return !;
}
main()
{
int i=;
ifunc(i);
ifunc(i);
printf(0*d0+i);
}
ans: 1
!":L. char*'()
{
static char x[!")E];
return x;
}
main()
{
char*'!0,irst Utrin'0;
strcpy('()+'!);
'!'();
strcpy('!+0Uecond Utrin'0);
printf(0#nswer is:*s0+ '());
}
ans: Answer is:Fecon Ftring
!":7. main()
{
int a[:]{!+=+L+7+"};
int *$;
$>a[)];
printf(0*d0+$[O!]);
}
ans: 3
!":6. Qi%en a piece of code
int x[!"];
int *a$;
a$x;
Io access the Lth element of the array which of the
followin' is incorrect?
(#)*(x(:) (2) x[:] (R) a$[:] (N) *(*a$(:}
ans: .41
!":A. main()
{
int i :;
printf(0*dBn0+ iOO*i(();
}
ans: 2,
!"L". main()
{
int i :;
printf(0*dBn0+ i((*iOO);
}
ans: 3,
!"L!. main()
{
int i :;
printf(0*d *d0+ i+i((*iOO*i(();
}
ans: ' 1%,
!"L). main()
{
char ch1a1;
printf(0*d 0+ch);
printf(0*d0+((int)ch)(();
}
ans: error .lvalue re3uire1
!"L=. int main()
{
int i;
int array![!"]+
array)[!"]{!+)+=+E+:+L+7+6+A+!"};
int *ep+ *ip) >array)["];
int *ip! >array!["];
for(ep >array![A]; ep 5 ip!; epOO)
*ep *ip)(( ;
for(i";i4!";i(()
printf(0*d 0+array![i]);
}
ans: copies array2 to array1 in reverse orer
.1, H L 7 ' % $ 3 2 11
!"LE. int main()
{
char strin'[!""];
char *p;
'ets(strin');
for(p strin'; *p P 1B"1; p(();
printf(0*d0+ p O strin');
}
ans: prints the length of !string!
!"L:. main()
{
int i! ;
for (;;);
{
if(i!)
{
printf(0*d0+i);
exit();
}
}
}
ans: infinite loop .no output1
!"LL. const int n 7;
int a[n];
main()
{
;
}
ans: error .constant expression re3uire for
array si0e1
!"L7. %oid main()
{
char *p ;
p (char*)malloc(!"");
strcpy(p+0Vracle -ndia0);
(p[:] 1l1) ? printf(0Vracle0) : printf(0-ndia0);
}
ans: &nia
!"L6. %oid main()
{
int a:+$+i;
int func(int y);
for(i ";i 4 :;i(()
{
a $ func(a);
printf(0*d 0+$);
}
}
int func(int y)
{
static int x ";
x((;
y y ( x;
return(y);
}
ans: ' L 11 1% 2,
!"LA. %oid main()
{
char i;
for(i";i4):L;i(()
printf(0*d0+i);
}
ans: infinite loop
!"7". %oid main()
{
int ret+- !";
ret func!(-);
printf(0*d0+ret);
}
int func!(int d)
{
int ret!;
ret! func)(OOd);
return(ret!);
}
int func)(int y)
{
return(((y);
}
ans: 1, .replace 8" with "" then answer
will be 111
!"7!. %oid main()
{
char str[)"];
strcpy(str+0Vracle -ndia0);
printf(0*c0+str[!"]);
}
ans: i
!"7). %oid main()
{
int -"+9!;
printf(0*d *d0+OO- +9(();
}
ans: "1 1
!"7=. .3define sK(a) (a*a)
printf (0*d0+sK (=()));
ans: 11
!"7E. 3define max )"
printf (0*d0+ ((max);
ans: lvalue re3uire .error1
!"7:. Shich of the followin' 1return1 statement is
correct?
return+ return;
return.1/ 2/ 31+
return(return E);
(return :+ return L);
ans: return .1/2/31 is correct an 3 will be
returne
!"7L. %oid main()
{
char $uffer[!"] {0Qenesis0};
printf(0 *d 0+ >$uffer[E]O ($uffer));
}
ans: $
!"77. %oid main()
{
struct a
{
char ch[!"];
char *str;
};
struct a s!{0Mydera$ad0+02an'alore0};
printf(0Bn*c*c 0+s!.ch["]+*s!.str);
printf(0*s *s0+s!.ch+s!.str);
'etch();
}
ans: 5B 5yeraba Bangalore
!"76. %oid main()
{
int i+9+;;
for(i";i4=;i(()
;sum(i+i);
printf(0Bn*d0+;);
'etch();
}
sum(s+t)
{
static int m;
m(s(t;
return m;
}
ans: '
!"7A. %oid main()
{
int i;
for(i!;i4L;((i)
switch(i)
{
case !:
case ): printf(0*d+0+i(();$rea;;
case =: continue;
case E: printf(0*d+0+i);
}
printf(0*d0+i);
'etch();
}
ans: 1/$/'
!"6". %oid main()
{
char s[]0oracle is the $est0;
char t[E"];
char *ss+*tt;
while(*tt((*ss(();
printf(0*s0+t);
'etch();
}
ans: core ump .Parbage value1
!"6!. %oid main()
{
int 9[!"]{A+7+:+=+!+)+E+L+A};
int i!;
clrscr();
for(;i4A;i(()
printf(0*d 0+OO9[i((]);
'etch();
}
ans: ' 2 1 %
!"6). %oid main()
{
int i+9+;+n:;
clrscr();
for(i:;i5";iOO)
{
9!4i;
;n>9;
;"?printf(0"0):printf(0!0);
}
'etch();
}
ans: 1111,
!"6=. union
{
int a;
char $;
char c[!"];
}u!;
%oid main()
{
int lsiCeof(u!);
printf(0*d0+l);
'etch();
}
ans: 1,
!"6E. %oid main()
{
struct a
{
int i;
char *st!;
};
typedef struct a UI;
UI *str!;
str!(UI*)malloc(!"");
str!O5i!"";
strcpy(str!O5st!+0Selcome to Vracle0);
printf(0 *d *sBn0+str!O5i+str!O5st!);
'etch();
}
ans: 1,, Relcome to Nracle
!"6:. %oid main()
{
int i+9+;;
i);
9E;
;i((59>);
printf(0*d0+;);
if(((; >> ((i4OO9]] i(()
{
9((;;
}
printf(0 *d *d *d0+i+O9OO+;);
'etch();
}
ans: , "% "2 2
!"6L. Shich of the followin' is not true incase of
Rommand line ar'uments
#.Ihe ar'c parameter is used to hold the num$er
of ar'uments in the
command line and is an inte'er
2. Ihe ar'% parameter is a pointer to an array of
a character
pointer and each one points to command line
ar'uments
R. Ihe ar'%[!] always point to pro'ram name
N. Hone of a$o%e
ans: K
!"67. %oid main()
{
int i+9)";
clrscr();
for(i!;i4=;i(()
{
printf(0*d+0+i);
continue;
printf(0*d0+9);
$rea;;
}
'etch();
}
ans: 1/2/
!"66. %oid fn(int *a+ int *$)
{
int *t;
ta;
a$;
$t;
}
main()
{
int a);
int $=;
fn(>a+>$);
printf(0*d *d0+a+$);
}
ans: 2 3
!"6A. main()
{
char *p0a$c0;
char *K0a$c!)=0;
while(*p*K)
{
printf(0*c *c 0+*p+*K);
'etch();
}
}
ans: a a a a a a a a a a aa..infinite loop1
!"A". 3define %oid int
int i="";
voi main.voi1
{
int i)"";
{
int i!"";
printf(0*d 0+i);
}
printf(0*d0+i);
}
ans: error
!"A!. 3define %oid int
int i="";
voi main.voi argc1
{
int i)"";
{
int i!"";
printf(0*d 0+i);
}
printf(0*d0+i);
}
ans: 1,, 2,,
!"A). main()
{
int #:+x;
int fun(int *+ int);
xfun(>#+#);
printf(0*d0+x);
}
int fun.int (x/ int y1+
{
*x*x(!;
return(*x*y);
}
ans: error .+ in function efinition1
!"A=. main()
{
int #:+x;
int fun(int *+ int);
xfun(>#+#);
printf(0*d0+x);
}
int fun.int (x/ int y1+
ans: lin2er error .unefine symbol fun1
!"AE. main()
{
int #:+x;
int fun(int *+ int);
xfun(>#+#);
printf(0*d0+x);
}
int fun.int (x/ int y1
{
*x*x(!;
return(*x*y);
}
ans: 3,
!"A:. main()
{
int i;
int x[]{"+"+"+"+"};
for(i!;i4E;i(()
x[x[i]]((;
for(i";i4:;i(()
printf(0 *d0+x[i]);
}
ans: $ , , , ,
!"AL. main()
{
int i+9+count;
int a[=][E] { O!+)+=+OE+:+L+7+O6+A+!"+!!+!)};
count";
for(i);i4!;iOO)
{
for(9=;94!;9OO)
{
if(a[i][9]4!)
count(!;
}
}
printf(0*d0+count);
}
ans: ,
!"A7. int sum+count;
%oid main(%oid)
{
for(count:;sum(OOcount;)
printf(0*d 0+sum);
}
ans: $ 7 H 1, 1, H 7 $
!"A6. %oid main(%oid)
{
int i;
for(i);i47;i(()
printf(0*:d0+fno());
}
fno()
{
static int f!!+f)!+f=;
return(f=f!(f)+f!f)+f)f=);
}
ans: 2 3 % L 13 21
!"AA. %oid main (%oid)
{
int x;
x ";
if (x")
printf (0[alue of x is "0);
else
printf (0[alue of x is not "0);
}
ans: Yalue of x is not ,
!!"". int foo(char *);
%oid main (%oid)
{
char arr[!""] {0Selcome to 8istral0};
foo (arr);
}
foo (char *x)
{
printf (0*dBt0+strlen (x));
printf (0*dBt0+siCeof(x));
return ";
}
ans: 1L $
!!"!. display()
{
printf (0 Mello Sorld0);
return ";
}
%oid main (%oid)
{
int (*funcDptr)();
funcDptr display;
(* funcDptr)();
}
ans: 5ello Rorl
!!"). %oid main (%oid)
{
int i";
char ch 1#1;
do
putchar (ch);
while(i(( 4 : ]] ((ch 4 1,1);
printf(0*c 0+ch);
}
ans: AAAAAABK4EEP
!!"=. char *re%();
%oid main(%oid)
{
printf (0*c0+ *re%());
}
char *re% ()
{
char dec[]0a$cde0;
return dec;
}
ans: a .another ans: prints garbage/ aress
of the local variable shoul not returne1
!!"E. %oid main(%oid)
{
int i;
static int ;;
if(;1"1)
printf(0one0);
else if(; E6)
printf(0two0);
else
printf(0three0);
}
ans: three
!!":. %oid main(%oid)
{
enum su${chemistry+ maths+ physics};
struct result
{
char name[="];
enum su$ sc;
};
struct result myDres;
strcpy (myDres.name+0Fatric;0);
myDres.scphysics;
printf(0name: *s 0+myDres.name);
printf(0pass in su$9ect: *dBn0+myDres.sc);
}
ans: name: Oatric2 pass in sub:ect: 2
!!"L. main()
{
char *p 08-UIG#.0;
printf (0*cBt0+ *(((p));
p O!;
printf (0*cBt0+ *(p(());
}
ans: & [
!!"7. Shat does the declaration do?
int (*mist) (%oid *+ %oid *);
ans: eclares mist as a pointer to a function
that has two voi ( arguments an returns
an int.
!!"6. %oid main (%oid)
{
int mat [:][:]+i+9;
int *p;
p > mat ["]["];
for (i";i4:;i(()
for (9";94:;9(()
mat[i][9] i(9;
printf (0*dBt0+ siCeof(mat));
iE;9:;
printf( 0*d0+ *(p(i(9));
}
ans: 1,, %
!!"A. %oid main (%oid)
{
char *p 02an'alore0;
3if "
printf (0*s0+ p);
3endif
}
ans: no output
!!!". %oid main (%oid)
{
char *p 02an'alore0;
3if !
printf (0*s0+ p);
3endif
}
ans: Bangalore
!!!!. main()
{
int x;
float y;
y *(float *)>x;
}
ans: the program containing the expression
compiles an runs without any errors
!!!). int main()
{
char *a 0Ho%ell0;
char *$;
$malloc(!"*siCeof(char));
memset($+"+!");
while(*$((*a(();
printf(0*s0+$);
'etch();
return ";
}
ans: no output
!!!=. int *(*p[!"])(char *)
ans: array of pointers to functions with
character pointer as argument an returning
pointer to integer
!!!E. main()
{
printf(0hello0):
main();
}
ans: hellohelloa..prints recursively till stac2
overflows1
!!!:. 3define scanf 0*s is a strin'0
main()
{
printf(scanf+scanf);
}
ans: =s is a string is a string
!!!L. main()
{
printf(0*u0+O!);
}
ans: '%%3%
!!!7. automatic %aria$les are destroyed after function
ends $ecause
a)stored in swap
$)stored in stac; and poped out after function returns
c)stored in data area
d)stored in dis;
ans: b1
!!!6. main()
{
printf(:(0facsimile0);
}
ans: mile
!!!A. Mow to fine the siCe of the int without usin' siCe of
operator?
ans. store "1 in that location so by two's
complement all ones will be store in that
location. Ceep right shifting it so 0eros will
be appene on the left. Nnce the location is
fille with all 0eros/ the number of shifts
gives you the si0e of that operator.
!!)". main()
{
char a[)];
(a?,@)7+
(a?1@)%+
printf(0*d0+>a[!]Oa);
}
ans: error .invali inirection1
!!)!. main(){
char a[]0hellow0;
char *$0hellow0;
char c?%@)!hellow!+
printf(0*s *s *s 0+a+$+c);
printf(0 0+siCeof(a)+siCeof($)+siCeof(c));
}
ans: error .too many initiali0ers1
!!)). main()
{
float %alue!"."";
printf(0*' *".)' *".E'
*f0+%alue+%alue+%alue+%alue);
}
ans: 1, 1, 1, 1,.,,,,,,
!!)=. Shich one has no .O[alue
[i] a[i]
[ii] i
[iii] )
[i%] *(a(i)
ans. ?iii@
!!)E. main()
{
int i!"+9;
for(9";94!;9(()
{
int i)";
printf(0*d 0+i);
}
printf(0*d0+i);
}
ans: 2, 1,
!!):. main()
{
int i;
printf(0*d0+i);
}
extern int i)";
ans: garbage value
!!)L. main()
{
extern int i+
printf(0*d0+i);
}
int i)2,+
ans: 2,
!!)7. main()
{
int nL;
printf(0*d0+n)
;
}
ans: '
!!)6. main()
{
int arr[:]{)+E};
printf(0*d *d *d Bn0+arr[)]+arr[=]+arr[E]);
}
ans: , , ,
!!)A. main()
{
struct e
{
char name[)"];
int a;
float $;
};
struct e ast{0Mell0};
printf(0*d *f Bn0+ast.a+ast.$);
}
ans: , ,.,,,,,,
!!=". Qi%en an array of siCe H in which e%ery num$er is
$etween ! and H+ determine if there are any duplicates
in it. You are allowed to destroy the array if you li;e.
ans: 11compare all the elements with the
selecte element 21put it in ascening orer
an compare a:acent elements
!!=!. Qi%en an array of characters which form a
sentence of words+ 'i%e an efficient al'orithm to
re%erse the order of the words (not characters) in it.
ans: ta2e an array of pointers an an chage
the aresses of the pointers
!!=). test whether a num$er is a power of ).
ans: first test whether it is even or o an
the bitcount. &f bitcount is one it is a power
of 2.
!!==. Qi%en two strin's U! and U). Nelete from U) all
those characters which occur in U! also and finally
create a clean U) with the rele%ant characters deleted.
!!=E. Ge%erse a lin;ed list.
ans: Oossible answers 8
iterati%e loop
currO5next pre%;
pre% curr;
curr next;
next currO5next
endloop
recursi%e re%erse(ptr)
if (ptrO5next HW..)
return ptr;
temp re%erse(ptrO5next);
tempO5next ptr;
return ptr;
end
!!=:. Qi%en an array t[!""] which contains num$ers
$etween !..AA. Geturn the duplicated %alue. Iry $oth
V(n) and V(nOsKuare).
!!=L. Qi%en an array of characters. Mow would you
re%erse it. ? Mow would you re%erse it without usin'
indexin' in the array.
ans: use pointers
!!=7. Srite+ efficient code for extractin' uniKue
elements from a sorted list of array. e.'. (!+ !+ =+ =+ =+
:+ :+ :+ A+ A+ A+ A) O5 (!+ =+ :+ A).
!!=6. Qi%en an array of inte'ers+ find the conti'uous
su$Oarray with the lar'est sum.
!!=A. #n array of inte'ers. Ihe sum of the array is
;nown not to o%erflow an inte'er. Rompute the sum.
Shat if we ;now that inte'ers are in )1s complement
form?
ans: -f num$ers are in )1s complement+ an ordinary
loo;in' loop li;e
for(itotal";i4 n;total(array[i((]); will do. Ho
need to chec; for o%erflowsP
!!E". Srite a pro'ram to remo%e duplicates from a
sorted array.
ans: int remo%eDduplicates(int * p+ int siCe)
{
int current+ insert !;
for (current!; current 4 siCe; current(()
if (p[current] P p[insertO!])
{
p[insert] p[current];
current((;
insert((;
} else
current((;
return insert;
}
!!E!. Srite an efficient R code for 1tr1 pro'ram. 1tr1 has
two command line ar'uments. Ihey $oth are strin's of
same len'th. tr reads an input file+ replaces each
character in the first strin' with the correspondin'
character in the second strin'. e'. 1tr a$c xyC1 replaces
all 1a1s $y 1x1s+ 1$1s $y 1y1s and so on. #HU.
a) ha%e an array of len'th )L.
put 1x1 in array element corr to 1a1
put 1y1 in array element corr to 1$1
put 1C1 in array element corr to 1c1
put 1d1 in array element corr to 1d1
put 1e1 in array element corr to 1e1
and so on.
the code
while (Peof)
{
c 'etc();
putc(array[c O 1a1]);
}
!!E). Srite a pro'ram to find whether a 'i%en m&c is
$i'Oendian or littleOendianP
!!E=. -f you1re familiar with the ? operator x ? y : C
you want to implement that in a function: int cond(int
x+ int y+ int C); usin' only X+ P+ J+ >+ (+ ]+ 44+ 55 no if
statements+ or loops or anythin' else+ 9ust those
operators+ and the function should correctly return y or
C $ased on the %alue of x. You may use constants+ $ut
only 6 $it constants. You can cast all you want. You1re
not supposed to use extra %aria$les+ $ut in the end+ it
won1t really matter+ usin' %ars 9ust ma;es thin's
cleaner. You should $e a$le to reduce your solution to a
sin'le line in the end thou'h that reKuires no extra
%ars.
!!EE. Wnder what circumstances can one delete an
element from a sin'ly lin;ed list in constant time?
ans: -f the list is circular and there are no references to
the nodes in the list from anywhere elseP \ust copy the
contents of the next node and delete the next node. -f
the list is not circular+ we can delete any $ut the last
node usin' this idea. -n that case+ mar; the last node
as dummyP
!!E:. Qi%en a sin'ly lin;ed list+ determine whether it
contains a loop or not.
ans: (a) Utart re%ersin' the list. -f you reach the head+
'otchaP there is a loopP
2ut this chan'es the list. Uo+ re%erse the list a'ain.
($) 8aintain two pointers+ initially pointin' to the head.
#d%ance one of them one node at a time. #nd the other
one+ two nodes at a time. -f the latter o%erta;es the
former at any time+ there is a loopP
p! p) head;
do {
p! p!O5next;
p) p)O5nextO5next;
} while (p! P p));
!!EL. Qi%en a sin'ly lin;ed list+ print out its contents in
re%erse order. Ran you do it without usin' any extra
space?
ans: Utart re%ersin' the list. No this a'ain+ printin' the
contents.
!!E7. Ge%erse a sin'ly lin;ed list recursi%ely. function
prototype is node * re%erse (node *) ;
ans:
node * re%erse (node * n)
{
node * m ;
if (P (n >> n O5 next))
return n ;
m re%erse (n O5 next) ;
n O5 next O5 next n ;
n O5 next HW.. ;
return m ;
}
!!E6. Qi%en a sin'ly lin;ed list+ find the middle of the
list.
M-HI. Wse the sin'le and dou$le pointer 9umpin'.
8aintain two pointers+ initially pointin' to the head.
#d%ance one of them one node at a time. #nd the other
one+ two nodes at a time. Shen the dou$le reaches the
end+ the sin'le is in the middle. Ihis is not
asymptotically faster $ut seems to ta;e less steps than
'oin' throu'h the list twice.
!!EA. Ge%erse the $its of an unsi'ned inte'er.
ans:
3define re%erse(x) B
(xx55!L]("x""""ffff>x)44!L+
B
x("xff""ff"">x)556]
("x""ff""ff>x)446+ B
x("xf"f"f"f">x)55E]
("x"f"f"f"f>x)44E+ B
x("xcccccccc>x)55)]
("x========>x)44)+ B
x("xaaaaaaaa>x)55!]
("x::::::::>x)44!)
!!:". Rompute the num$er of ones in an unsi'ned
inte'er.
ans:
3define countDones(x) B

(x("xaaaaaaaa>x)55!(("x::::::::>x)+ B
x("xcccccccc>x)55)(("x========>x)+ B
x("xf"f"f"f">x)55E(("x"f"f"f"f>x)+ B
x("xff""ff"">x)556(("x""ff""ff>x)+ B
xx55!L(("x""""ffff>x))
!!:!. Rompute the discrete lo' of an unsi'ned inte'er.
ans:
3define discreteDlo'(h) B
(h(h55!)](h55))+ B
h](h55))+ B
h](h55E)+ B
h](h556)+ B
h](h55!L)+ B
h("xaaaaaaaa>h)55!(("x::::::::>h)+ B
h("xcccccccc>h)55)(("x========>h)+ B
h("xf"f"f"f">h)55E(("x"f"f"f"f>h)+ B
h("xff""ff"">h)556(("x""ff""ff>h)+ B
h(h55!L)(("x""""ffff>h))
-f - understand it ri'ht+ lo')()) !+ lo')(=)!+
lo')(E))..... 2ut this macro does not wor; out lo')(")
which does not existP Mow do you thin; it should $e
handled?
!!:). Mow do we test most simply if an unsi'ned inte'er
is a power of two?
ans: 3define powerDofDtwo(x) B ((x)>>(X(x>(xO
!))))
!!:=. Uet the hi'hest si'nificant $it of an unsi'ned
inte'er to Cero.
ans: Uet the hi'hest si'nificant $it of an unsi'ned
inte'er to Cero
3define CeroDmostDsi'nificant(h) B
(h>(h55!)](h55))+ B
h](h55))+ B
h](h55E)+ B
h](h556)+ B
h](h55!L))
!!:E. You1re 'i%en an array containin' $oth positi%e and
ne'ati%e inte'ers and reKuired to find the su$Oarray
with the lar'est sum (V(H) a la T2.). Srite a routine in
R for the a$o%e.
!!::. Qi%en two strin's U! and U). Nelete from U) all
those characters which occur in U! also and finally
create a clean U) with the rele%ant characters deleted.
!!:L. 2esides communication cost+ what is the other
source of inefficiency in GFR? (answer : context
switches+ excessi%e $uffer copyin'). Mow can you
optimiCe the communication? (ans : communicate
throu'h shared memory on same machine+ $ypassin'
the ;ernel D # Wni%. of Sash. thesis)
!!:7. #n array of characters. Ge%erse the order of words
in it.
ans: Srite a routine to re%erse a character array. How
call it for the 'i%en array and for each word in it.
!!:6. Qi%en a list of num$ers ( fixed list) How 'i%en any
other list+ how can you efficiently find out if there is any
element in the second list that is an element of the first
list (fixed list).
!!:A. Frint an inte'er usin' only putchar. Iry doin' it
without usin' extra stora'e.
!!L". int *a;
char *c;
*(a) )";
*c *a;
printf(0*c0+*c);
what is the output?
2efore usin' pointer they should $e assi'ned some
address
!!L!. to re%erse a strin' usin' a recursi%e function+
without
swappin' or usin' an extra memory.
!!L). Qi%e the outputs of a compiler and assem$ler and
loader and lin;er etc.
!!L=. Iell a$out strto; > strstr functions.
!!LE. 3define int siCeof(int)
main()
{
printf(0*d0+int);
}
ans: 2
!!L:. 3define i siCeof(i)
main()
{
printf(0*d0+i);
}
ans: error .unefine symbol i1

You might also like