Sunteți pe pagina 1din 56

Visit http://www.placementpapers.net/ For more downloads!

C Questions
Note : All the programs are tested under Turbo C/C++ compilers.
It is assumed that,
Programs run under DOS environment,
The underling machine is an !"# sstem,
Program is compiled using Turbo C/C++ compiler.
The program output ma depend on the in$ormation based on this assumptions %$or e!ample
si&eo$%int' (( ) ma be assumed'.
Predict the output or error%s' $or the $ollo*ing+
1. void main()
{
int const * p=5;
printf("%d",++(*p));
}
Answer:
Compiler error+ Cannot modi$ a constant value.
Explanation+
p is a pointer to a ,constant integer,. -ut *e tried to change the value o$ the ,constant
integer,.
2. main()
{
char s[ ="man";
int i;
for(i=!;s[ i ;i++)
printf(""n%c%c%c%c",s[ i ,*(s+i),*(i+s),i[s);
}
Answer:
mmmm
aaaa
nnnn
Explanation+
s.i/, 0%i+s', 0%s+i', i.s/ are all di$$erent *as o$ e!pressing the same idea. 1enerall arra
name is the base address $or that arra. 2ere s is the base address. i is the inde! number/displacement $rom
the base address. So, indirecting it *ith 0 is same as s.i/. i.s/ ma be surprising. -ut in the case o$ C it is
same as s.i/.
#. main()
{
f$oat m% = 1.1;
do&'$% (o& = 1.1;
if(m%==(o&)
printf(") $ov% *");
%$s%
printf(") hat% *");
}
Visit http://www.placementpapers.net/ For more downloads! 3
Visit http://www.placementpapers.net/ For more downloads!
Answer:
I hate 4
Explanation+
5or $loating point numbers ($loat, double, long double) the values cannot be predicted
e!actl. Depending on the number o$ btes, the precession *ith o$ the value represented varies. 5loat
ta6es 7 btes and long double ta6es 38 btes. So $loat stores 8.9 *ith less precision than long double.
Rule of Thumb:
:ever compare or at;least be cautious *hen using $loating point numbers *ith relational
operators ((( , <, =, =(, <(,>( ) .
+. main()
{
static int var = 5;
printf("%d ",var,,);
if(var)
main();
}
Answer:
? 7 @ ) 3
Explanation:
Ahen static storage class is given, it is initiali&ed once. The change in the value o$ a static
variable is retained even bet*een the $unction calls. Bain is also treated li6e an other ordinar $unction,
*hich can be called recursivel.
5. main()
{
int c[ ={2.-,#.+,+,../,5};
int 0,*p=c,*1=c;
for(0=!;025;0++) {
printf(" %d ",*c);
++1; }
for(0=!;025;0++){
printf(" %d ",*p);
++p; }
}
Answer:
) ) ) ) ) ) @ 7 # ?
Explanation:
Initiall pointer c is assigned to both p and q. In the $irst loop, since onl q is incremented
and not c , the value ) *ill be printed ? times. In second loop p itsel$ is incremented. So the values ) @ 7 #
? *ill be printed.
.. main()
{
%3t%rn int i;
i=2!;
printf("%d",i);
}
Visit http://www.placementpapers.net/ For more downloads! )
Visit http://www.placementpapers.net/ For more downloads!
Answer:
4in5%r 6rror + 4nde$ined smbol CDiC
Explanation:
e!tern storage class in the $ollo*ing declaration,
extern int i;
speci$ies to the compiler that the memor $or i is allocated in some other program and that address *ill be
given to the current program at the time o$ lin6ing. -ut lin6er $inds that no other variable o$ name i is
available in an other program *ith memor space allocated $or it. 2ence a lin6er error has occurred .
/. main()
{
int i=,1,0=,1,5=!,$=2,m;
m=i++770++775++88$++;
printf("%d %d %d %d %d",i,0,5,$,m);
}
Answer:
8 8 3 @ 3
Explanation :
Eogical operations al*as give a result o$ 1 or 0 . And also the logical A:D %FF' operator
has higher priorit over the logical OG %HH' operator. So the e!pression Ii++ && ++ && !++ is e!ecuted
$irst. The result o$ this e!pression is 8 %;3 FF ;3 FF 8 ( 8'. :o* the e!pression is 8 HH ) *hich evaluates
to 3 %because OG operator al*as gives 3 e!cept $or I8 HH 8J combination; $or *hich it gives 8'. So the
value o$ m is 3. The values o$ other variables are also incremented b 3.
-. main()
{
char *p;
printf("%d %d ",si9%of(*p),si9%of(p));
}
Answer:
3 )
Explanation:
The si&eo$%' operator gives the number o$ btes ta6en b its operand. P is a character
pointer, *hich needs one bte $or storing its value %a character'. 2ence si&eo$%0p' gives a value o$ 3. Since
it needs t*o btes to store the address o$ the character pointer si&eo$%p' gives ).
:. main()
{
int i=#;
s;itch(i)
{
d%fa&$t<printf("9%ro");
cas% 1< printf("on%");
'r%a5;
cas% 2<printf("t;o");
'r%a5;
cas% #< printf("thr%%");
'r%a5;
}
Visit http://www.placementpapers.net/ For more downloads! @
Visit http://www.placementpapers.net/ For more downloads!
}
Answer :
three
Explanation :
The de$ault case can be placed an*here inside the loop. It is e!ecuted onl *hen all other
cases doesnCt match.
1!. main()
{
printf("%3",,122+);
}
Answer:
$$$8
Explanation :
;3 is internall represented as all 3Cs. Ahen le$t shi$ted $our times the least signi$icant 7 bits
are $illed *ith 8Cs.The K! $ormat speci$ier speci$ies that the integer value be printed as a he!adecimal
value.
11. main()
{
char strin=[=">%$$o ?or$d";
disp$a((strin=);
}
void disp$a((char *strin=)
{
printf("%s",strin=);
}
Answer:
@ompi$%r 6rror < Tpe mismatch in redeclaration o$ $unction displa
Explanation :
In third line, *hen the $unction "ispl#$ is encountered, the compiler doesnCt 6no* anthing
about the $unction displa. It assumes the arguments and return tpes to be integers, %*hich is the de$ault
tpe'. Ahen it sees the actual $unction "ispl#$% the arguments and tpe contradicts *ith *hat it has
assumed previousl. 2ence a compile time error occurs.
12. main()
{
int c=, ,2;
printf("c=%d",c);
}
Answer:
c()L
Explanation:
2ere unar minus %or negation' operator is used t*ice. Same maths rules applies, ie. minus
0 minus( plus.
&ote:
2o*ever ou cannot give li6e ;;). -ecause ;; operator can onl be applied to variables as a
"e'rement operator %eg., i;;'. ) is a constant and not a variable.
1#. Ad%fin% int char
Visit http://www.placementpapers.net/ For more downloads! 7
Visit http://www.placementpapers.net/ For more downloads!
main()
{
int i=.5;
printf("si9%of(i)=%d",si9%of(i));
}
Answer:
si&eo$%i'(3
Explanation:
Since the Mde$ine replaces the string int b the macro 'h#r
1+. main()
{
int i=1!;
i=BiC1+;
Drintf ("i=%d",i);
}
Answer:
i(8
Explanation:
In the e!pression (i)1* , :OT %>' operator has more precedence than I <J smbol. ( is a
unar logical operator. >i %>38' is 8 %not o$ true is $alse'. 8<37 is $alse %&ero'.
15. Ainc$&d%2stdio.hC
main()
{
char s[={EaE,E'E,EcE,E"nE,EcE,E"!E};
char *p,*str,*str1;
p=7s[#;
str=p;
str1=s;
printf("%d",++*p + ++*str1,#2);
}
Answer:
NN
Explanation:
p is pointing to character COnC. str3 is pointing to character CaC ++0p. ,p is pointing to COnC and that is
incremented b one., the ASCII value o$ COnC is 38, *hich is then incremented to 33. The value o$ ++0p is
33. ++0str3, str3 is pointing to CaC that is incremented b 3 and it becomes CbC. ASCII value o$ CbC is 9".
:o* per$orming %33 + 9" P @)', *e get NN%,B,'L
So *e get the output NN ++ ,B, %Ascii is NN'.
1.. Ainc$&d%2stdio.hC
main()
{
int a[2[2[2 = { {1!,2,#,+}, {5,.,/,-} };
int *p,*1;
p=7a[2[2[2;
*1=***a;
Visit http://www.placementpapers.net/ For more downloads! ?
Visit http://www.placementpapers.net/ For more downloads!
printf("%d,,,,%d",*p,*1);
}
Answer:
Some1arbageQalue;;;3
Explanation:
p(Fa.)/.)/.)/ ou declare onl t*o )D arras, but ou are tring to access the third
)D%*hich ou are not declared' it *ill print garbage values. 0R(000a starting address o$ a is assigned
integer pointer. :o* R is pointing to starting address o$ a. I$ ou print 0R, it *ill print $irst element o$ @D
arra.
1/. Ainc$&d%2stdio.hC
main()
{
str&ct 33
{
int 3=#;
char nam%[="h%$$o";
};
str&ct 33 *s;
printf("%d",s,C3);
printf("%s",s,Cnam%);
}
Answer:
Compiler Srror
Explanation:
Tou should not initiali&e variables in declaration
1-. Ainc$&d%2stdio.hC
main()
{
str&ct 33
{
int 3;
str&ct ((
{
char s;
str&ct 33 *p;
};
str&ct (( *1;
};
}
Answer:
Compiler Srror
Explanation:
The structure is nested *ithin structure !!. 2ence, the elements are o$ are to be
accessed through the instance o$ structure !!, *hich needs an instance o$ to be 6no*n. I$ the instance is
created a$ter de$ining the structure the compiler *ill not 6no* about the instance relative to !!. 2ence $or
nested structure ou have to declare member.
1:. main()
Visit http://www.placementpapers.net/ For more downloads! #
Visit http://www.placementpapers.net/ For more downloads!
{
printf(""na'");
printf(""'si");
printf(""rha");
}
Answer:
hai
Explanation:
On ; ne*line
Ob ; bac6space
Or ; line$eed
2!. main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i,,,++i,,,i,i);
}
Answer:
7??7?
Explanation:
The arguments in a $unction call are pushed into the stac6 $rom le$t to right. The evaluation
is b popping out $rom the stac6. and the evaluation is $rom right to le$t, hence the result.
21. Ad%fin% s1&ar%(3) 3*3
main()
{
int i;
i = .+Fs1&ar%(+);
printf("%d",i);
}
Answer:
#7
Explanation:
the macro call sRuare%7' *ill substituted b 707 so the e!pression becomes i ( #7/707 .
Since / and 0 has eRual priorit the e!pression *ill be evaluated as %#7/7'07 i.e. 3#07 ( #7

22. main()
{
char *p="hai fri%nds",*p1;
p1=p;
;hi$%(*pB=E"!E) ++*p++;
printf("%s %s",p,p1);
}
Answer:
ibU>gsU$oet
Explanation:
++0p++ *ill be parse in the given order
0p that is value at the location currentl pointed b p *ill be ta6en
++0p the retrieved value *ill be incremented
*hen L is encountered the location *ill be incremented that is p++ *ill be e!ecuted
Visit http://www.placementpapers.net/ For more downloads! N
Visit http://www.placementpapers.net/ For more downloads!
2ence, in the *hile loop initial value pointed b p is IhJ, *hich is changed to IiJ b e!ecuting ++0p and
pointer moves to point, IaJ *hich is similarl changed to IbJ and so on. Similarl blan6 space is converted
to I>J. Thus, *e obtain value in p becomes VibU>gsU$oetW and since p reaches IO8J and p3 points to p thus
p3doesnot print anthing.
2#. Ainc$&d% 2stdio.hC
Ad%fin% a 1!
main()
{
Ad%fin% a 5!
printf("%d",a);
}
Answer:
?8
Explanation:
The preprocessor directives can be rede$ined an*here in the program. So the most recentl
assigned value *ill be ta6en.
2+. Ad%fin% c$rscr() 1!!
main()
{
c$rscr();
printf("%d"n",c$rscr());
}
Answer:
388
Explanation:
Preprocessor e!ecutes as a seperate pass be$ore the e!ecution o$ the compiler. So te!tual
replacement o$ clrscr%' to 388 occurs.The input program to compiler loo6s li6e this +
main%'
X
388L
print$%,KdOn,,388'L
Y
&ote:
388L is an e!ecutable statement but *ith no action. So it doesnCt give an problem
25. main()
{
+1printf("%p",main);
}-Answer:
Some address *ill be printed.
Explanation:
5unction names are Uust addresses %Uust li6e arra names are addresses'.
main%' is also a $unction. So the address o$ $unction main *ill be printed. Kp in print$ speci$ies that the
argument is an address. The are printed as he!adecimal numbers.
)N' main%'
X
clrscr%'L
Visit http://www.placementpapers.net/ For more downloads! "
Visit http://www.placementpapers.net/ For more downloads!
Y
clrscr%'L
Answer:
:o output/error
Explanation:
The $irst clrscr%' occurs inside a $unction. So it becomes a $unction call. In the second
clrscr%'L is a $unction declaration %because it is not inside an $unction'.
)"' enum colors X-EACZ,-E4S,1GSS:Y
main%'
X

print$%,Kd..Kd..Kd,,-EACZ,-E4S,1GSS:'L

return%3'L
Y
Answer:
8..3..)
Explanation:
enum assigns numbers starting $rom 8, i$ not e!plicitl de$ined.
)9' void main%'
X
char $ar 0$arther,0$arthestL

print$%,Kd..Kd,,si&eo$%$arther',si&eo$%$arthest''L

Y
Answer:
7..)
Explanation:
the second pointer is o$ char tpe and not a $ar pointer
@8' main%'
X
int i(788,U(@88L
print$%,Kd..Kd,'L
Y
Answer:
788..@88
Explanation:
print$ ta6es the values o$ the $irst t*o assignments o$ the program. An number o$ print$Cs
ma be given. All o$ them ta6e onl the $irst t*o values. I$ more number o$ assignments
given in the program,then print$ *ill ta6e garbage values.
@3' main%'
X
char 0pL
p(,2ello,L
Visit http://www.placementpapers.net/ For more downloads! 9
Visit http://www.placementpapers.net/ For more downloads!
print$%,KcOn,,0F0p'L
Y
Answer:
2
Explanation:
0 is a dere$erence operator F is a re$erence operator. The can be applied an number o$
times provided it is meaning$ul. 2ere p points to the $irst character in the string ,2ello,. 0p
dere$erences it and so its value is 2. Again F re$erences it to an address and 0 dere$erences
it to the value 2.
@)' main%'
X
int i(3L
*hile %i=(?'
X
print$%,Kd,,i'L
i$ %i<)'
goto hereL
i++L
Y
Y
$un%'
X
here+
print$%,PP,'L
Y
Answer:
Compiler error+ 4nde$ined label ChereC in $unction main
Explanation:
Eabels have $unctions scope, in other *ords the scope o$ the labels is limited to $unctions.
The label ChereC is available in $unction $un%' 2ence it is not visible in $unction main.
@@' main%'
X
static char names.?/.)8/(X,pascal,,,ada,,,cobol,,,$ortran,,,perl,YL
int iL
char 0tL
t(names.@/L
names.@/(names.7/L
names.7/(tL
$or %i(8Li=(7Li++'
print$%,Ks,,names.i/'L
Y
Answer:
Compiler error+ Evalue reRuired in $unction main
Explanation:
Arra names are pointer constants. So it cannot be modi$ied.
@7' void main%'
X
Visit http://www.placementpapers.net/ For more downloads! 38
Visit http://www.placementpapers.net/ For more downloads!
int i(?L
print$%,Kd,,i++ + ++i'L
Y
Answer:
Output Cannot be predicted e!actl.
Explanation:
Side e$$ects are involved in the evaluation o$ i
@?' void main%'
X
int i(?L
print$%,Kd,,i+++++i'L
Y
Answer:
Compiler Srror
Explanation:
The e!pression i+++++i is parsed as i ++ ++ + i *hich is an illegal combination o$
operators.

@#' Minclude=stdio.h<
main%'
X
int i(3,U()L
s*itch%i'
X
case 3+ print$%,1OOD,'L
brea6L
case U+ print$%,-AD,'L
brea6L
Y
Y
Answer:
Compiler Srror+ Constant e!pression reRuired in $unction main.
Explanation:
The case statement can have onl constant e!pressions %this implies that *e cannot use
variable names directl so an error'.
&ote:
Snumerated tpes can be used in case statements.
@N' main%'
X
int iL
print$%,Kd,,scan$%,Kd,,Fi''L // value 38 is given as input here
Y
Answer:
3
Explanation:
Scan$ returns number o$ items success$ull read and not 3/8. 2ere 38 is given as input
*hich should have been scanned success$ull. So number o$ items read is 3.
Visit http://www.placementpapers.net/ For more downloads! 33
Visit http://www.placementpapers.net/ For more downloads!
@"' Mde$ine $%g,g)' gMMg)
main%'
X
int var3)(388L
print$%,Kd,,$%var,3)''L
Y
Answer:
388
@9' main%'
X
int i(8L

$or%Li++Lprint$%,Kd,,i'' L
print$%,Kd,,i'L
Y
Answer:
3
Explanation:
be$ore entering into the $or loop the chec6ing condition is ,evaluated,. 2ere it evaluates to 8
%$alse' and comes out o$ the loop, and i is incremented %note the semicolon a$ter the $or
loop'.
78' Minclude=stdio.h<
main%'
X
char s./(XCaC,CbC,CcC,COnC,CcC,CO8CYL
char 0p,0str,0str3L
p(Fs.@/L
str(pL
str3(sL
print$%,Kd,,++0p + ++0str3;@)'L
Y
Answer:
B
Explanation:
p is pointing to character COnC.str3 is pointing to character CaC ++0p meAns*er+,p is pointing
to COnC and that is incremented b one., the ASCII value o$ COnC is 38. then it is incremented to
33. the value o$ ++0p is 33. ++0str3 meAns*er+,str3 is pointing to CaC that is incremented b
3 and it becomes CbC. ASCII value o$ CbC is 9". both 33 and 9" is added and result is
subtracted $rom @).
i.e. %33+9";@)'(NN%,B,'L
73' Minclude=stdio.h<
main%'
X
struct !!
X
int !(@L
char name./(,hello,L
Visit http://www.placementpapers.net/ For more downloads! 3)
Visit http://www.placementpapers.net/ For more downloads!
YL
struct !! 0s(malloc%si&eo$%struct !!''L
print$%,Kd,,s;<!'L
print$%,Ks,,s;<name'L
Y
Answer:
Compiler Srror
Explanation:
Initiali&ation should not be done $or structure members inside the structure declaration
7)' Minclude=stdio.h<
main%'
X
struct !!
X
int !L
struct
X
char sL
struct !! 0pL
YL
struct 0RL
YL
Y
Answer:
Compiler Srror
Explanation:
in the end o$ nested structure a member have to be declared.
7@' main%'
X
e!tern int iL
i()8L
print$%,Kd,,si&eo$%i''L
Y
Answer:
Ein6er error+ unde$ined smbol CDiC.
Explanation:
e!tern declaration speci$ies that the variable i is de$ined some*here else. The compiler
passes the e!ternal variable to be resolved b the lin6er. So compiler doesnCt $ind an error.
During lin6ing the lin6er searches $or the de$inition o$ i. Since it is not $ound the lin6er
$lags an error.
77' main%'
X
print$%,Kd,, out'L
Y
int out(388L
Answer:
Compiler error+ unde$ined smbol out in $unction main.
Visit http://www.placementpapers.net/ For more downloads! 3@
Visit http://www.placementpapers.net/ For more downloads!
Explanation:
The rule is that a variable is available $or use $rom the point o$ declaration. Sven though a is
a global variable, it is not available $or main. 2ence an error.
7?' main%'
X
e!tern outL
print$%,Kd,, out'L
Y
int out(388L
Answer:
388
Explanation:
This is the correct *a o$ *riting the previous program.

7#' main%'
X
sho*%'L
Y
void sho*%'
X
print$%,ICm the greatest,'L
Y
Answer:
Compier error+ Tpe mismatch in redeclaration o$ sho*.
Explanation:
Ahen the compiler sees the $unction sho* it doesnCt 6no* anthing about it. So the de$ault
return tpe %ie, int' is assumed. -ut *hen compiler sees the actual de$inition o$ sho*
mismatch occurs since it is declared as void. 2ence the error.
The solutions are as $ollo*s+
3. declare void sho*%' in main%' .
). de$ine sho*%' be$ore main%'.
@. declare e!tern void sho*%' be$ore the use o$ sho*%'.

7N' main% '
X
int a.)/.@/.)/ ( XXX),7Y,XN,"Y,X@,7YY,XX),)Y,X),@Y,X@,7YYYL
print$%VKu Ku Ku Kd OnW,a,0a,00a,000a'L
print$%VKu Ku Ku Kd OnW,a+3,0a+3,00a+3,000a+3'L
Y
Answer:
388, 388, 388, )
337, 387, 38), @
Explanation:
The given arra is a @;D one. It can also be vie*ed as a 3;D arra.

) 7 N " @ 7 ) ) ) @ @ 7
388 38) 387 38# 38" 338 33) 337 33# 33" 3)8 3))
Visit http://www.placementpapers.net/ For more downloads! 37
Visit http://www.placementpapers.net/ For more downloads!
thus, $or the $irst print$ statement a, 0a, 00a give address o$ $irst element . since the
indirection 000a gives the value. 2ence, the $irst line o$ the output.
$or the second print$ a+3 increases in the third dimension thus points to value at 337, 0a+3
increments in second dimension thus points to 387, 00a +3 increments the $irst dimension
thus points to 38) and 000a+3 $irst gets the value at $irst location and then increments it b
3. 2ence, the output.
7"' main% '
X
int a. / ( X38,)8,@8,78,?8Y,U,0pL
$or%U(8L U=?L U++'
X
print$%VKdW ,0a'L
a++L
Y
p ( aL
$or%U(8L U=?L U++'
X
print$%VKd W ,0p'L
p++L
Y
Y
Answer:
Compiler error+ lvalue reRuired.
Explanation:
Srror is in line *ith statement a++. The operand must be an lvalue and ma be o$ an o$
scalar tpe $or the an operator, arra name onl *hen subscripted is an lvalue. Simpl
arra name is a non;modi$iable lvalue.
0079' main% '
X
static int a. / ( X8,3,),@,7YL
int 0p. / ( Xa,a+3,a+),a+@,a+7YL
int 00ptr ( pL
ptr++L
print$%VOn Kd Kd KdW, ptr;p, 0ptr;a, 00ptr'L
0ptr++L
print$%VOn Kd Kd KdW, ptr;p, 0ptr;a, 00ptr'L
0++ptrL
print$%VOn Kd Kd KdW, ptr;p, 0ptr;a, 00ptr'L
++0ptrL
print$%VOn Kd Kd KdW, ptr;p, 0ptr;a, 00ptr'L
Y
Answer:
111
222
###
#++
Explanation:
Visit http://www.placementpapers.net/ For more downloads! 3?
Visit http://www.placementpapers.net/ For more downloads!
Eet us consider the arra and the t*o pointers *ith some address
#
8 3 ) @ 7
388 38) 387 38# 38"
p
388 38) 387 38# 38"
3888 388) 3887 388# 388"
ptr
3888
)888
A$ter e!ecution o$ the instruction ptr++ value in ptr becomes 388), i$ scaling $actor $or
integer is ) btes. :o* ptr P p is value in ptr P starting location o$ arra p, %388) P 3888' /
%scaling $actor' ( 3, 0ptr P a ( value at address pointed b ptr P starting value o$ arra a,
388) has a value 38) so the value is %38) P 388'/%scaling $actor' ( 3, 00ptr is the value
stored in the location pointed b the pointer o$ ptr ( value pointed b value pointed b
388) ( value pointed b 38) ( 3. 2ence the output o$ the $irs print$ is 3, 3, 3.
A$ter e!ecution o$ 0ptr++ increments value o$ the value in ptr b scaling $actor, so it
becomes3887. 2ence, the outputs $or the second print$ are ptr P p ( ), 0ptr P a ( ), 00ptr (
).
A$ter e!ecution o$ 0++ptr increments value o$ the value in ptr b scaling $actor, so it
becomes3887. 2ence, the outputs $or the third print$ are ptr P p ( @, 0ptr P a ( @, 00ptr ( @.
A$ter e!ecution o$ ++0ptr value in ptr remains the same, the value pointed b the value is
incremented b the scaling $actor. So the value in arra p at location 388# changes $rom 38#
38 38",. 2ence, the outputs $or the $ourth print$ are ptr P p ( 388# P 3888 ( @, 0ptr P a (
38" P 388 ( 7, 00ptr ( 7.
?8' main% '
X
char 0RL
int UL
$or %U(8L U=@L U++' scan$%VKsW ,%R+U''L
$or %U(8L U=@L U++' print$%VKcW ,0%R+U''L
$or %U(8L U=@L U++' print$%VKsW ,%R+U''L
Y
Explanation:
2ere *e have onl one pointer to tpe char and since *e ta6e input in the same pointer thus
*e 6eep *riting over in the same location, each time shi$ting the pointer value b 3.
Suppose the inputs are BO4SS, TGACZ and QIGT4AE. Then $or the $irst input suppose
the pointer starts at location 388 then the input one is stored as
B O 4 S S O8
Ahen the second input is given the pointer is incremented as U value becomes 3, so the input
is $illed in memor starting $rom 383.
B T G A C Z O8
The third input starts $illing $rom the location 38)
B T Q I G T 4 A E O8
This is the $inal value stored .
The $irst print$ prints the values at the position R, R+3 and R+) ( B T Q
The second print$ prints three strings starting $rom locations R, R+3, R+)
i.e BTQIGT4AE, TQIGT4AE and QIGT4AE.
Visit http://www.placementpapers.net/ For more downloads! 3#
Visit http://www.placementpapers.net/ For more downloads!

?3' main% '
X
void 0vpL
char ch ( IgJ, 0cp ( Vgoo$WL
int U ( )8L
vp ( FchL
print$%VKcW, 0%char 0'vp'L
vp ( FUL
print$%VKdW,0%int 0'vp'L
vp ( cpL
print$%VKsW,%char 0'vp + @'L
Y
Answer:
g)8$
Explanation:
Since a void pointer is used it can be tpe casted to an other tpe pointer. vp ( Fch stores
address o$ char ch and the ne!t statement prints the value stored in vp a$ter tpe casting it to
the proper data tpe pointer. the output is IgJ. Similarl the output $rom second print$ is
I)8J. The third print$ statement tpe casts it to print the string $rom the 7
th
value hence the
output is I$J.
?)' main % '
X
static char 0s. / ( XVblac6W, V*hiteW, Vello*W, VvioletWYL
char 00ptr. / ( Xs+@, s+), s+3, sY, 000pL
p ( ptrL
00++pL
print$%VKsW,0;;0++p + @'L
Y
Answer:
c6
Explanation:
In this problem *e have an arra o$ char pointers pointing to start o$ 7 strings. Then *e
have ptr *hich is a pointer to a pointer o$ tpe char and a variable p *hich is a pointer to a
pointer to a pointer o$ tpe char. p hold the initial value o$ ptr, i.e. p ( s+@. The ne!t
statement increment value in p b 3 , thus no* value o$ p ( s+). In the print$ statement the
e!pression is evaluated 0++p causes gets value s+3 then the pre decrement is e!ecuted and
*e get s+3 P 3 ( s . the indirection operator no* gets the value $rom the arra o$ s and adds
@ to the starting address. The string is printed starting $rom this position. Thus, the output is
Ic6J.
?@' main%'
X
int i, nL
char 0! ( VgirlWL
n ( strlen%!'L
0! ( !.n/L
$or%i(8L i=nL ++i'
X
Visit http://www.placementpapers.net/ For more downloads! 3N
Visit http://www.placementpapers.net/ For more downloads!
print$%VKsOnW,!'L
!++L
Y
Y
Answer:
%blan6 space'
irl
rl
l
Explanation:
2ere a string %a pointer to char' is initiali&ed *ith a value VgirlW. The strlen $unction returns
the length o$ the string, thus n has a value 7. The ne!t statement assigns value at the nth
location %IO8J' to the $irst location. :o* the string becomes VO8irlW . :o* the print$
statement prints the string a$ter each iteration it increments it starting position. Eoop starts
$rom 8 to 7. The $irst time !.8/ ( IO8J hence it prints nothing and pointer value is
incremented. The second time it prints $rom !.3/ i.e VirlW and the third time it prints VrlW and
the last time it prints VlW and the loop terminates.
?7' int i,UL
$or%i(8Li=(38Li++'
X
U+(?L
assert%i=?'L
Y
Answer:
Guntime error+ Abnormal program termination.
assert $ailed %i=?', =$ile name<,=line number<
Explanation:
asserts are used during debugging to ma6e sure that certain conditions are satis$ied. I$
assertion $ails, the program *ill terminate reporting the same. A$ter debugging use,
Munde$ :DS-41
and this *ill disable all the assertions $rom the source code. Assertion
is a good debugging tool to ma6e use o$.

??' main%'
X
int i(;3L
+iL
print$%,i ( Kd, +i ( Kd On,,i,+i'L
Y
Answer:
i ( ;3, +i ( ;3
Explanation:
4nar + is the onl dumm operator in C. Ahere;ever it comes ou can Uust ignore it Uust
because it has no e$$ect in the e!pressions %hence the name dumm operator'.
?#' Ahat are the $iles *hich are automaticall opened *hen a C $ile is e!ecuted[
Answer:
stdin, stdout, stderr %standard input,standard output,standard error'.
Visit http://www.placementpapers.net/ For more downloads! 3"
Visit http://www.placementpapers.net/ For more downloads!
?N' *hat *ill be the position o$ the $ile mar6er[
a+ $see6%ptr,8,SSSZDSST'L
b+ $see6%ptr,8,SSSZDC4G'L
Answer :
a+ The SSSZDSST sets the $ile position mar6er to the starting o$ the $ile.
b+ The SSSZDC4G sets the $ile position mar6er to the current position
o$ the $ile.
?"' main%'
X
char name.38/,s.3)/L
scan$%, O,K.\O,/O,,,s'L
Y
2o* scan$ *ill e!ecute[
Answer:
5irst it chec6s $or the leading *hite space and discards it.Then it matches *ith a Ruotation
mar6 and then it reads all character upto another Ruotation mar6.
?9' Ahat is the problem *ith the $ollo*ing code segment[
*hile %%$gets%receiving arra,?8,$ileDptr'' >( SO5'
L
Answer & Explanation:
$gets returns a pointer. So the correct end o$ $ile chec6 is chec6ing $or >( :4EE.
#8' main%'
X
main%'L
Y
Answer:
Guntime error + Stac6 over$lo*.
Explanation:
main $unction calls itsel$ again and again. Sach time the $unction is called its return address
is stored in the call stac6. Since there is no condition to terminate the $unction call, the call
stac6 over$lo*s at runtime. So it terminates the program and results in an error.
#3' main%'
X
char 0cptr,cL
void 0vptr,vL
c(38L v(8L
cptr(FcL vptr(FvL
print$%,KcKv,,c,v'L
Y
Answer:
Compiler error %at line number 7'+ si&e o$ v is 4n6no*n.
Explanation:
Tou can create a variable o$ tpe void 0 but not o$ tpe void, since void is an empt tpe. In
the second line ou are creating variable vptr o$ tpe void 0 and v o$ tpe void hence an
error.
Visit http://www.placementpapers.net/ For more downloads! 39
Visit http://www.placementpapers.net/ For more downloads!
#)' main%'
X
char 0str3(,abcd,L
char str)./(,abcd,L
print$%,Kd Kd Kd,,si&eo$%str3',si&eo$%str)',si&eo$%,abcd,''L
Y
Answer:
) ? ?
Explanation:
In $irst si&eo$, str3 is a character pointer so it gives ou the si&e o$ the pointer variable. In
second si&eo$ the name str) indicates the name o$ the arra *hose si&e is ? %including the
CO8C termination character'. The third si&eo$ is similar to the second one.
#@' main%'
X
char notL
not(>)L
print$%,Kd,,not'L
Y
Answer:
8
Explanation:
> is a logical operator. In C the value 8 is considered to be the boolean value 5AESS, and
an non;&ero value is considered to be the boolean value TG4S. 2ere ) is a non;&ero value
so TG4S. >TG4S is 5AESS %8' so it prints 8.
#7' Mde$ine 5AESS ;3
Mde$ine TG4S 3
Mde$ine :4EE 8
main%' X
i$%:4EE'
puts%,:4EE,'L
else i$%5AESS'
puts%,TG4S,'L
else
puts%,5AESS,'L
Y
Answer:
TG4S
Explanation+
The input program to the compiler a$ter processing b the preprocessor is,
main%'X
i$%8'
puts%,:4EE,'L
else i$%;3'
puts%,TG4S,'L
else
puts%,5AESS,'L
Y
Visit http://www.placementpapers.net/ For more downloads! )8
Visit http://www.placementpapers.net/ For more downloads!
Preprocessor doesnCt replace the values given inside the double Ruotes. The chec6 b i$
condition is boolean value $alse so it goes to else. In second i$ ;3 is boolean value true hence
,TG4S, is printed.
#?' main%'
X
int 6(3L
print$%,Kd((3 is ,,Ks,,6,6((3[,TG4S,+,5AESS,'L
Y
Answer:
3((3 is TG4S
Explanation:
Ahen t*o strings are placed together %or separated b *hite;space' the are concatenated
%this is called as ,stringi&ation, operation'. So the string is as i$ it is given as ,Kd((3 is
Ks,. The conditional operator% [+ ' evaluates to ,TG4S,.
##' main%'
X
int L
scan$%,Kd,,F'L // input given is )888
i$% %K7((8 FF K388 >( 8' HH K388 (( 8 '
print$%,Kd is a leap ear,'L
else
print$%,Kd is not a leap ear,'L
Y
Answer:
)888 is a leap ear
Explanation:
An ordinar program to chec6 i$ leap ear or not.
#N' Mde$ine ma! ?
Mde$ine int arr3.ma!/
main%'
X
tpede$ char arr).ma!/L
arr3 list(X8,3,),@,7YL
arr) name(,name,L
print$%,Kd Ks,,list.8/,name'L
Y
Answer:
Compiler error %in the line arr3 list ( X8,3,),@,7Y'
Explanation:
arr) is declared o$ tpe arra o$ si&e ? o$ characters. So it can be used to declare the variable
name o$ the tpe arr). -ut it is not the case o$ arr3. 2ence an error.
Rule of Thumb:
Mde$ines are used $or te!tual replacement *hereas tpede$s are used $or declaring ne*
tpes.
#"' int i(38L
main%'
Visit http://www.placementpapers.net/ For more downloads! )3
Visit http://www.placementpapers.net/ For more downloads!
X
e!tern int iL
X
int i()8L
X
const volatile unsigned i(@8L
print$%,Kd,,i'L
Y
print$%,Kd,,i'L
Y
print$%,Kd,,i'L
Y
Answer:
@8,)8,38
Explanation:
CXC introduces ne* bloc6 and thus ne* scope. In the innermost bloc6 i is declared as,
const volatile unsigned
*hich is a valid declaration. i is assumed o$ tpe int. So print$ prints @8. In the ne!t bloc6, i
has value )8 and so print$ prints )8. In the outermost bloc6, i is declared as e!tern, so no
storage space is allocated $or it. A$ter compilation is over the lin6er resolves it to global
variable i %since it is the onl variable visible there'. So it prints iCs value as 38.
#9' main%'
X
int 0UL
X
int i(38L
U(FiL
Y
print$%,Kd,,0U'L
Y
Answer:
38
Explanation+
The variable i is a bloc6 level variable and the visibilit is inside that bloc6 onl. -ut the
li$etime o$ i is li$etime o$ the $unction so it lives upto the e!it o$ main $unction. Since the i
is still allocated space, 0U prints the value stored in i since U points i.
N8' main%'
X
int i(;3L
;iL
print$%,i ( Kd, ;i ( Kd On,,i,;i'L
Y
Answer:
i ( ;3, ;i ( 3
Explanation:
;i is e!ecuted and this e!ecution doesnCt a$$ect the value o$ i. In print$ $irst ou Uust print the
value o$ i. A$ter that the value o$ the e!pression ;i ( ;%;3' is printed.
Visit http://www.placementpapers.net/ For more downloads! ))
Visit http://www.placementpapers.net/ For more downloads!
N3' Minclude=stdio.h<
main%'
X
const int i(7L
$loat UL
U ( ++iL
print$%,Kd K$,, i,++U'L
Y
Answer+
Compiler error
Explanation+
i is a constant. ou cannot change the value o$ constant
N)' Minclude=stdio.h<
main%'
X
int a.)/.)/.)/ ( X X38,),@,7Y, X?,#,N,"Y YL
int 0p,0RL
p(Fa.)/.)/.)/L
0R(000aL
print$%,Kd..Kd,,0p,0R'L
Y
Answer:
garbagevalue..3
Explanation:
p(Fa.)/.)/.)/ ou declare onl t*o )D arras. but ou are tring to access the third
)D%*hich ou are not declared' it *ill print garbage values. 0R(000a starting address o$ a is
assigned integer pointer. no* R is pointing to starting address o$ a.i$ ou print 0R
meAns*er+it *ill print $irst element o$ @D arra.
N@' Minclude=stdio.h<
main%'
X
register i(?L
char U./( ,hello,L
print$%,Ks Kd,,U,i'L
Y
Answer:
hello ?
Explanation+
i$ ou declare i as register compiler *ill treat it as ordinar integer and it *ill ta6e integer
value. i value ma be stored either in register or in memor.
N7' main%'
X
int i(?,U(#,&L
print$%,Kd,,i+++U'L
Y
Answer:
33
Visit http://www.placementpapers.net/ For more downloads! )@
Visit http://www.placementpapers.net/ For more downloads!
Explanation:
the e!pression i+++U is treated as %i++ + U'

N#' struct aaaX
struct aaa 0prevL
int iL
struct aaa 0ne!tL
YL
main%'
X
struct aaa abc,de$,ghi,U6lL
int !(388L
abc.i(8Labc.prev(FU6lL
abc.ne!t(Fde$L
de$.i(3Lde$.prev(FabcLde$.ne!t(FghiL
ghi.i()Lghi.prev(Fde$L
ghi.ne!t(FU6lL
U6l.i(@LU6l.prev(FghiLU6l.ne!t(FabcL
!(abc.ne!t;<ne!t;<prev;<ne!t;<iL
print$%,Kd,,!'L
Y
Answer:
)
Explanation:
above all statements $orm a double circular lin6ed listL
abc.ne!t;<ne!t;<prev;<ne!t;<i
this one points to ,ghi, node the value o$ at particular node is ).
NN' struct point
X
int !L
int L
YL
struct point origin,0ppL
main%'
X
pp(ForiginL
print$%,origin is%KdKd'On,,%0pp'.!,%0pp'.'L
print$%,origin is %KdKd'On,,pp;<!,pp;<'L
Y
Answer:
origin is%8,8'
origin is%8,8'
Explanation+
pp is a pointer to structure. *e can access the elements o$ the structure either *ith arro*
mar6 or *ith indirection operator.
&ote:
Since structure point is globall declared ! F are initiali&ed as &eroes
Visit http://www.placementpapers.net/ For more downloads! )7
Visit http://www.placementpapers.net/ For more downloads!
N"' main%'
X
int i(DlDabc%38'L
print$%,KdOn,,;;i'L
Y
int DlDabc%int i'
X
return%i++'L
Y
Answer:
9
Explanation:
return%i++' it *ill $irst return i and then increments. i.e. 38 *ill be returned.
N9' main%'
X
char 0pL
int 0RL
long 0rL
p(R(r(8L
p++L
R++L
r++L
print$%,Kp...Kp...Kp,,p,R,r'L
Y
Answer:
8883...888)...8887
Explanation:
++ operator *hen applied to pointers increments address according to their corresponding
data;tpes.
"8' main%'
X
char c(C C,!,convert%&'L
getc%c'L
i$%%c<(CaC' FF %c=(C&C''
!(convert%c'L
print$%,Kc,,!'L
Y
convert%&'
X
return &;@)L
Y
Answer:
Compiler error
Explanation:
declaration o$ convert and $ormat o$ getc%' are *rong.
"3' main%int argc, char 00argv'
X
Visit http://www.placementpapers.net/ For more downloads! )?
Visit http://www.placementpapers.net/ For more downloads!
print$%,enter the character,'L
getchar%'L
sum%argv.3/,argv.)/'L
Y
sum%num3,num)'
int num3,num)L
X
return num3+num)L
Y
Answer:
Compiler error.
Explanation:
argv.3/ F argv.)/ are strings. The are passed to the $unction sum *ithout converting it to
integer values.
")' M include =stdio.h<
int oneDd./(X3,),@YL
main%'
X
int 0ptrL
ptr(oneDdL
ptr+(@L
print$%,Kd,,0ptr'L
Y
Answer+
garbage value
Explanation:
ptr pointer is pointing to out o$ the arra range o$ oneDd.
"@' M include=stdio.h<
aaa%' X
print$%,hi,'L
Y
bbb%'X
print$%,hello,'L
Y
ccc%'X
print$%,be,'L
Y
main%'
X
int %0ptr.@/'%'L
ptr.8/(aaaL
ptr.3/(bbbL
ptr.)/(cccL
ptr.)/%'L
Y
Answer+
be
Explanation:
Visit http://www.placementpapers.net/ For more downloads! )#
Visit http://www.placementpapers.net/ For more downloads!
ptr is arra o$ pointers to $unctions o$ return tpe int.ptr.8/ is assigned to address o$ the
$unction aaa. Similarl ptr.3/ and ptr.)/ $or bbb and ccc respectivel. ptr.)/%' is in e$$ect o$
*riting ccc%', since ptr.)/ points to ccc.
"?' Minclude=stdio.h<
main%'
X
5IES 0ptrL
char iL
ptr($open%,&&&.c,,,r,'L
*hile%%i($getch%ptr''>(SO5'
print$%,Kc,,i'L
Y
Answer:
contents o$ &&&.c $ollo*ed b an in$inite loop
Explanation:
The condition is chec6ed against SO5, it should be chec6ed against :4EE.
"#' main%'
X
int i (8LU(8L
i$%i FF U++'
print$%,Kd..Kd,,i++,U'L
print$%,Kd..Kd,i,U'L
Y
Answer:
8..8
Explanation:
The value o$ i is 8. Since this in$ormation is enough to determine the truth value o$ the
boolean e!pression. So the statement $ollo*ing the i$ statement is not e!ecuted. The values
o$ i and U remain unchanged and get printed.

"N' main%'
X
int iL
i ( abc%'L
print$%,Kd,,i'L
Y
abc%'
X
DA] ( 3888L
Y
Answer:
3888
Explanation:
:ormall the return value $rom the $unction is through the in$ormation $rom the
accumulator. 2ere DA2 is the pseudo global variable denoting the accumulator. 2ence, the
value o$ the accumulator is set 3888 so the $unction returns value 3888.
""' int iL
Visit http://www.placementpapers.net/ For more downloads! )N
Visit http://www.placementpapers.net/ For more downloads!
main%'X
int tL
$or % t(7Lscan$%,Kd,,Fi';tLprint$%,KdOn,,i''
print$%,Kd;;,,t;;'L
Y
// I$ the inputs are 8,3,),@ $ind the o/p
Answer:
7;;8
@;;3
);;)
Explanation:
Eet us assume some !( scan$%,Kd,,Fi';t the values during e!ecution
*ill be,
t i !
7 8 ;7
@ 3 ;)
) ) 8

"9' main%'X
int a( 8Lint b ( )8Lchar ! (3Lchar (38L
i$%a,b,!,'
print$%,hello,'L
Y
Answer:
hello
Explanation:
The comma operator has associativit $rom le$t to right. Onl the rightmost value is
returned and the other values are evaluated and ignored. Thus the value o$ last variable is
returned to chec6 in i$. Since it is a non &ero value i$ becomes true so, ,hello, *ill be
printed.
98' main%'X
unsigned int iL
$or%i(3Li<;)Li;;'
print$%,c aptitude,'L
Y
Explanation:
i is an unsigned integer. It is compared *ith a signed value. Since the both tpes doesnCt
match, signed is promoted to unsigned value. The unsigned eRuivalent o$ ;) is a huge value
so condition becomes $alse and control comes out o$ the loop.
93' In the $ollo*ing pgm add a stmt in the $unction $un such that the address o$
CaC gets stored in CUC.
main%'X
int 0 UL
void $un%int 00'L
$un%FU'L
Y
void $un%int 006' X
int a (8L
Visit http://www.placementpapers.net/ For more downloads! )"
Visit http://www.placementpapers.net/ For more downloads!
/0 add a stmt here0/
Y
Answer:
06 ( Fa
Explanation:
The argument o$ the $unction is a pointer to a pointer.

9)' Ahat are the $ollo*ing notations o$ de$ining $unctions 6no*n as[
i. int abc%int a,$loat b'
X
/0 some code 0/
Y
ii. int abc%a,b'
int aL $loat bL
X
/0 some code0/
Y
Answer:
i. A:SI C notation
ii. Zernighan F Gitche notation
9@' main%'
X
char 0pL
p(,KdOn,L
p++L
p++L
print$%p;),@88'L
Y
Answer:
@88
Explanation:
The pointer points to K since it is incremented t*ice and again decremented b ), it points
to CKdOnC and @88 is printed.
97' main%'X
char a.388/L
a.8/(CaCLa.3//(CbCLa.)/(CcCLa.7/(CdCL
abc%a'L
Y
abc%char a./'X
a++L
print$%,Kc,,0a'L
a++L
print$%,Kc,,0a'L
Y
Explanation:
The base address is modi$ied onl in $unction and as a result a points to CbC then a$ter
incrementing to CcC so bc *ill be printed.

Visit http://www.placementpapers.net/ For more downloads! )9
Visit http://www.placementpapers.net/ For more downloads!
9?' $unc%a,b'
int a,bL
X
return% a( %a((b' 'L
Y
main%'
X
int process%',$unc%'L
print$%,The value o$ process is Kd >On ,,process%$unc,@,#''L
Y
process%p$,val3,val)'
int %0p$' %'L
int val3,val)L
X
return%%0p$' %val3,val)''L
Y
Answer:
The value i$ process is 8 >
Explanation:
The $unction CprocessC has @ parameters ; 3, a pointer to another $unction ) and @, integers.
Ahen this $unction is invo6ed $rom main, the $ollo*ing substitutions $or $ormal parameters
ta6e place+ $unc $or p$, @ $or val3 and # $or val). This $unction returns the result o$ the
operation per$ormed b the $unction C$uncC. The $unction $unc has t*o integer parameters.
The $ormal parameters are substituted as @ $or a and # $or b. since @ is not eRual to #, a((b
returns 8. there$ore the $unction returns 8 *hich in turn is returned b the $unction CprocessC.
9#' void main%'
X
static int i(?L
i$%;;i'X
main%'L
print$%,Kd ,,i'L
Y
Y
Answer:
8 8 8 8
Explanation:
The variable ,I, is declared as static, hence memor $or I *ill be allocated $or onl once, as
it encounters the statement. The $unction main%' *ill be called recursivel unless I becomes eRual
to 8, and since main%' is recursivel called, so the value o$ static I ie., 8 *ill be printed ever time
the control is returned.
9N' void main%'
X
int 6(ret%si&eo$%$loat''L
print$%,On here value is Kd,,++6'L
Y
int ret%int ret'
X
ret +( ).?L
Visit http://www.placementpapers.net/ For more downloads! @8
Visit http://www.placementpapers.net/ For more downloads!
return%ret'L
Y
Answer:
2ere value is N
Explanation:
The int ret%int ret', ie., the $unction name and the argument name can be the same.
5irstl, the $unction ret%' is called in *hich the si&eo$%$loat' ie., 7 is passed, a$ter the $irst
e!pression the value in ret *ill be #, as ret is integer hence the value stored in ret *ill have implicit
tpe conversion $rom $loat to int. The ret is returned in main%' it is printed a$ter and preincrement.

9"' void main%'
X
char a./(,3)@7?O8,L
int i(strlen%a'L
print$%,here in @ KdOn,,++i'L
Y
Answer:
here in @ #
Explanation:
The char arra CaC *ill hold the initiali&ed string, *hose length *ill be counted $rom 8 till the
null character. 2ence the CIC *ill hold the value eRual to ?, a$ter the pre;increment in the print$
statement, the # *ill be printed.
99' void main%'
X
unsigned giveit(;3L
int gotitL
print$%,Ku ,,++giveit'L
print$%,Ku On,,gotit(;;giveit'L
Y
Answer:
8 #??@?
Explanation:
388' void main%'
X
int iL
char a./(,O8,L
i$%print$%,KsOn,,a''
print$%,O6 here On,'L
else
print$%,5orget itOn,'L
Y
Answer:
O6 here
Explanation:
Print$ *ill return ho* man characters does it print. 2ence printing a null character
returns 3 *hich ma6es the i$ statement true, thus ,O6 here, is printed.

383' void main%'
Visit http://www.placementpapers.net/ For more downloads! @3
Visit http://www.placementpapers.net/ For more downloads!
X
void 0vL
int integer()L
int 0i(FintegerL
v(iL
print$%,Kd,,%int0'0v'L
Y
Answer:
Compiler Srror. Ae cannot appl indirection on tpe void0.
Explanation:
Qoid pointer is a generic pointer tpe. :o pointer arithmetic can be done on it. Qoid
pointers are normall used $or,
3. Passing generic pointers to $unctions and returning such pointers.
). As a intermediate pointer tpe.
@. 4sed *hen the e!act pointer tpe *ill be 6no*n at a later point o$ time.
38)' void main%'
X
int i(i++,U(U++,6(6++L
print$%VKdKdKdW,i,U,6'L
Y
Answer:
1arbage values.
Explanation:
Gn id%ntifi%r is avai$a'$% to &s% in pro=ram cod% from th% point of its d%c$aration.
So e!pressions such as i ( i++ are valid statements. The i, U and 6 are automatic variables
and so the contain some garbage value. Har'a=% in is =ar'a=% o&t (H)HI).
38@' void main%'
X
static int i(i++, U(U++, 6(6++L
print$%Vi ( Kd U ( Kd 6 ( KdW, i, U, 6'L
Y
Answer:
i ( 3 U ( 3 6 ( 3
Explanation:
Since static variables are initiali&ed to &ero b de$ault.
387' void main%'
X
*hile%3'X
i$%print$%,Kd,,print$%,Kd,'''
brea6L
else
continueL
Y
Y
Answer:
1arbage values
Visit http://www.placementpapers.net/ For more downloads! @)
Visit http://www.placementpapers.net/ For more downloads!
Explanation:
The inner print$ e!ecutes $irst to print some garbage value. The print$ returns no o$
characters printed and this value also cannot be predicted. Still the outer print$ prints
something and so returns a non;&ero value. So it encounters the brea6 statement and comes
out o$ the *hile statement.
387' main%'
X
unsigned int i(38L
*hile%i;;<(8'
print$%,Ku ,,i'L
Y
Answer:
38 9 " N # ? 7 @ ) 3 8 #??@? #??@7^..
Explanation:
Since i is an unsigned integer it can never become negative. So the e!pression i;; <(8 *ill
al*as be true, leading to an in$inite loop.
38?' Minclude=conio.h<
main%'
X
int !,(),&,aL
i$%!(K)' &()L
a()L
print$%,Kd Kd ,,&,!'L
Y
Answer:
1arbage;value 8
Explanation:
The value o$ K) is 8. This value is assigned to !. The condition reduces to i$ %!' or in other
*ords i$%8' and so & goes uninitiali&ed.
Thumb Rule: Chec6 all control paths to *rite bug $ree code.
38#' main%'
X
int a.38/L
print$%,Kd,,0a+3;0a+@'L
Y
Answer:
7
Explanation:
0a and ;0a cancels out. The result is as simple as 3 + @ ( 7 >
38N' Mde$ine prod%a,b' a0b
main%'
X
int !(@,(7L
print$%,Kd,,prod%!+),;3''L
Y
Visit http://www.placementpapers.net/ For more downloads! @@
Visit http://www.placementpapers.net/ For more downloads!
Answer:
38
Explanation:
The macro e!pands and evaluates to as+
!+)0;3 (< !+%)0';3 (< 38
38"' main%'
X
unsigned int i(#?888L
*hile%i++>(8'L
print$%,Kd,,i'L
Y
Answer:
3
Explanation:
:ote the semicolon a$ter the *hile statement. Ahen the value o$ i becomes 8 it comes out o$
*hile loop. Due to post;increment on i the value o$ i *hile printing is 3.

389' main%'
X
int i(8L
*hile%+%+i;;'>(8'
i;(i++L
print$%,Kd,,i'L
Y
Answer:
;3
Explanation:
*nar( + is th% on$( d&mm( op%rator in @. So it has no e$$ect on the e!pression and no* the
*hile loop is, *hile%i;;>(8' *hich is $alse and so brea6s out o$ *hile loop. The value P3 is
printed due to the post;decrement operator.

33@' main%'
X
$loat $(?,g(38L
enumXi(38,U()8,6(?8YL
print$%,KdOn,,++6'L
print$%,K$On,,$==)'L
print$%,Kl$On,,$Kg'L
print$%,Kl$On,,$mod%$,g''L
Y
Answer:
Eine no ?+ Srror+ Evalue reRuired
Eine no #+ Cannot appl le$tshi$t to $loat
Eine no N+ Cannot appl mod to $loat
Explanation:
Snumeration constants cannot be modi$ied, so ou cannot appl ++.
-it;*ise operators and K operators cannot be applied on $loat values.
$mod%' is to $ind the modulus values $or $loats as K operator is $or ints.
Visit http://www.placementpapers.net/ For more downloads! @7
Visit http://www.placementpapers.net/ For more downloads!
338' main%'
X
int i(38L
void pascal $%int,int,int'L
$%i++,i++,i++'L
print$%, Kd,,i'L
Y
void pascal $%integer +i,integer+U,integer +6'
X
*rite%i,U,6'L
Y
Answer:
Compiler error+ un6no*n tpe integer
Compiler error+ undeclared $unction *rite
Explanation:
Pascal 6e*ord doesnJt mean that pascal code can be used. It means that the $unction
$ollo*s Pascal argument passing mechanism in calling the $unctions.
333' void pascal $%int i,int U,int 6'
X
print$%VKd Kd KdW,i, U, 6'L
Y
void cdecl $%int i,int U,int 6'
X
print$%VKd Kd KdW,i, U, 6'L
Y
main%'
X
int i(38L
$%i++,i++,i++'L
print$%, KdOn,,i'L
i(38L
$%i++,i++,i++'L
print$%, Kd,,i'L
Y
Answer:
38 33 3) 3@
3) 33 38 3@
Explanation:
Pascal argument passing mechanism $orces the arguments to be called $rom le$t to right.
cdecl is the normal C argument passing mechanism *here the arguments are passed $rom right to
le$t.

33)'. Ahat is the output o$ the program given belo*
main%'
X
signed char i(8L
$or%Li<(8Li++' L
print$%,KdOn,,i'L
Visit http://www.placementpapers.net/ For more downloads! @?
Visit http://www.placementpapers.net/ For more downloads!
Y
Answer
;3)"
Explanation
:otice the semicolon at the end o$ the $or loop. T2e initial value o$ the i is set to 8.
The inner loop e!ecutes to increment the value $rom 8 to 3)N %the positive range o$
char' and then it rotates to the negative value o$ ;3)". The condition in the $or loop
$ails and so comes out o$ the $or loop. It prints the current value o$ i that is ;3)".

33@' main%'
X
unsigned char i(8L
$or%Li<(8Li++' L
print$%,KdOn,,i'L
Y
Answer
in$inite loop
Explanation
The di$$erence bet*een the previous Ruestion and this one is that the char is declared to be
unsigned. So the i++ can never ield negative value and i<(8 never becomes $alse so that it can
come out o$ the $or loop.
337' main%'
X
char i(8L
$or%Li<(8Li++' L
print$%,KdOn,,i'L

Y
Answer:
-ehavior is implementation dependent.
Explanation:
The detail i$ the char is signed/unsigned b de$ault is implementation dependent. I$
the implementation treats the char to be signed b de$ault the program *ill print P3)" and
terminate. On the other hand i$ it considers char to be unsigned b de$ault, it goes to in$inite
loop.
Rule:
Tou can *rite programs that have implementation dependent behavior. -ut dont
*rite programs that depend on such behavior.
33?' Is the $ollo*ing statement a declaration/de$inition. 5ind *hat does it mean[
int %0!'.38/L
Answer
De$inition.
! is a pointer to arra o$%si&e 38' integers.
Appl cloc6;*ise rule to $ind the meaning o$ this de$inition.
33#'. Ahat is the output $or the program given belo*
Visit http://www.placementpapers.net/ For more downloads! @#
Visit http://www.placementpapers.net/ For more downloads!
tpede$ enum errorTpeX*arning, error, e!ception,YerrorL
main%'
X
error g3L
g3(3L
print$%,Kd,,g3'L
Y
Answer
Compiler error+ Bultiple declaration $or error
Explanation
The name error is used in the t*o meanings. One means that it is a enumerator
constant *ith value 3. The another use is that it is a tpe name %due to tpede$' $or enum
errorTpe. 1iven a situation the compiler cannot distinguish the meaning o$ error to 6no*
in *hat sense the error is used+
error g3L
g3(errorL
// *hich error it re$ers in each case[
Ahen the compiler can distinguish bet*een usages then it *ill not issue error %in
pure technical terms, names can onl be overloaded in di$$erent namespaces'.
Note+ the e!tra comma in the declaration,
enum errorTpeX*arning, error, e!ception,Y
is not an error. An e!tra comma is valid and is provided Uust $or programmerJs convenience.


33N' tpede$ struct errorXint *arning, error, e!ceptionLYerrorL
main%'
X
error g3L
g3.error (3L
print$%,Kd,,g3.error'L
Y
Answer
3
Explanation
The three usages o$ name errors can be distinguishable b the compiler at an instance, so
valid %the are in di$$erent namespaces'.
Tpede$ struct errorXint *arning, error, e!ceptionLYerrorL
This error can be used onl b preceding the error b struct 6a*ord as in+
struct error someSrrorL
tpede$ struct errorXint *arning, error, e!ceptionLYerrorL
This can be used onl a$ter . %dot' or ;< %arro*' operator preceded b the variable name as in +
g3.error (3L
print$%,Kd,,g3.error'L
tpede$ struct errorXint *arning, error, e!ceptionLYerrorL
This can be used to de$ine variables *ithout using the preceding struct 6e*ord as in+
error g3L
Since the compiler can per$ectl distinguish bet*een these three usages, it is per$ectl legal and
valid.
Visit http://www.placementpapers.net/ For more downloads! @N
Visit http://www.placementpapers.net/ For more downloads!
&ote
This code is given here to Uust e!plain the concept behind. In real programming donJt use
such overloading o$ names. It reduces the readabilit o$ the code. Possible doesnJt mean that *e
should use it>

33"' Mi$de$ something
int some(8L
Mendi$
main%'
X
int thing ( 8L
print$%,Kd KdOn,, some ,thing'L
Y
Answer:
Compiler error + unde$ined smbol some
Explanation:
This is a ver simple e!ample $or conditional compilation. The name something is
not alread 6no*n to the compiler ma6ing the declaration
int some ( 8L
e$$ectivel removed $rom the source code.
339' Mi$ something (( 8
int some(8L
Mendi$
main%'
X
int thing ( 8L
print$%,Kd KdOn,, some ,thing'L
Y
Answer
8 8
Explanation
This code is to sho* that preprocessor e!pressions are not the same as the ordinar
e!pressions. I$ a name is not 6no*n the preprocessor treats it to be eRual to &ero.
3)8'. Ahat is the output $or the $ollo*ing program
main%'
X
int arr)D.@/.@/L
print$%,KdOn,, %%arr)D((0 arr)D'FF%0 arr)D (( arr)D.8/'' 'L
Y
Answer
3
Explanation
Visit http://www.placementpapers.net/ For more downloads! @"
Visit http://www.placementpapers.net/ For more downloads!
This is due to the close relation bet*een the arras and pointers. : dimensional
arras are made up o$ %:;3' dimensional arras.
arr)D is made up o$ a @ single arras that contains @ integers each .
The name arr)D re$ers to the beginning o$ all the @ arras. 0arr)D re$ers to the start
o$ the $irst 3D arra %o$ @ integers' that is the same address as arr)D. So the
e!pression %arr)D (( 0arr)D' is true %3'.
Similarl, 0arr)D is nothing but 0%arr)D + 8', adding a &ero doesnJt change the
value/meaning. Again arr)D.8/ is the another *a o$ telling 0%arr)D + 8'. So the
e!pression %0%arr)D + 8' (( arr)D.8/' is true %3'.
Since both parts o$ the e!pression evaluates to true the result is true%3' and the same
is printed.
3)3' void main%'
X
i$%_8 (( %unsigned int';3'
print$%VTou can ans*er this i$ ou 6no* ho* values are represented in memorW'L
Y
Ans*er
Tou can ans*er this i$ ou 6no* ho* values are represented in memor
S!planation
_ %tilde operator or bit;*ise negation operator' operates on 8 to produce all ones to
$ill the space $or an integer. P3 is represented in unsigned value as all 3Js and so both
are eRual.
3))' int s*ap%int 0a,int 0b'
X
0a(0a+0bL0b(0a;0bL0a(0a;0bL
Y
main%'
X
int !(38,()8L
s*ap%F!,F'L
print$%,!( Kd ( KdOn,,!,'L
Y
Ans*er
! ( )8 ( 38
S!planation
This is one *a o$ s*apping t*o values. Simple chec6ing *ill help understand this.
3)@' main%'
X
char 0p ( VaRmWL
Visit http://www.placementpapers.net/ For more downloads! @9
arr)D
arr)D.3/
arr)D.)/
arr)D.@/
Visit http://www.placementpapers.net/ For more downloads!
print$%VKcW,++0%p++''L
Y
Ans*er+
b
3)7' main%'
X
int i(?L
print$%,Kd,,++i++'L
Y
Answer:
Compiler error+ Evalue reRuired in $unction main
Explanation:
++i ields an rvalue. 5or post$i! ++ to operate an lvalue is reRuired.
3)?' main%'
X
char 0p ( VaRmWL
char cL
c ( ++0p++L
print$%VKcW,c'L
Y
Answer:
b
Explanation:
There is no di$$erence bet*een the e!pression ++0%p++' and ++0p++. Parenthesis
Uust *or6s as a visual clue $or the reader to see *hich e!pression is $irst evaluated.
3)#'
int aaa%' Xprint$%V2iW'LY
int bbb%'Xprint$%VhelloW'LY
in ccc%'Xprint$%VbeW'LY
main%'
X
int % 0 ptr.@/' %'L
ptr.8/ ( aaaL
ptr.3/ ( bbbL
ptr.)/ (cccL
ptr.)/%'L
Y
Ans*er+
b$e
S!planation+
int %0 ptr.@/'%' sas that ptr is an arra o$ pointers to $unctions that ta6es no arguments and
returns the tpe int. - the assignment ptr.8/ ( aaaL it means that the $irst $unction pointer in
the arra is initiali&ed *ith the address o$ the $unction aaa. Similarl, the other t*o arra
elements also get initiali&ed *ith the addresses o$ the $unctions bbb and ccc. Since ptr.)/
contains the address o$ the $unction ccc, the call to the $unction ptr.)/%' is same as calling
ccc%'. So it results in printing ,be,.
Visit http://www.placementpapers.net/ For more downloads! 78
Visit http://www.placementpapers.net/ For more downloads!
3)N'
main%'
X
int i(?L
print$%VKdW,i(++i ((#'L
Y
Answer:
1
Explanation:
The e!pression can be treated as i ( %++i((#', because (( is o$ higher precedence than (
operator. In the inner e!pression, ++i is eRual to # ielding true%3'. 2ence the result.
3)"' main%'
X
char p. /(,KdOn,L
p.3/ ( CcCL
print$%p,#?'L
Y
Answer:
A
Explanation:
Due to the assignment p.3/ ( IcJ the string becomes, VKcOnW. Since this string becomes the
$ormat string $or print$ and ASCII value o$ #? is IAJ, the same gets printed.

3)9' void % 0 abc% int, void % 0de$' %' ' ' %'L
Ans*er++
abc is a ptr to a $unction *hich ta6es ) parameters .%a'. an integer variable.%b'. a ptrto
a $untion *hich returns void. the return tpe o$ the $unction is void.
Explanation:
Appl the cloc6;*ise rule to $ind the result.
3@8' main%'
X
*hile %strcmp%VsomeW,WsomeO8W''
print$%VStrings are not eRualOnW'L
Y
Answer:
:o output
Explanation:
Snding the string constant *ith O8 e!plicitl ma6es no di$$erence. So VsomeW and VsomeO8W
are eRuivalent. So, strcmp returns 8 %$alse' hence brea6ing out o$ the *hile loop.
3@3' main%'
X
char str3./ ( XIsJ,JoJ,JmJ,JeJYL
char str)./ ( XIsJ,JoJ,JmJ,JeJ,JO8JYL
Visit http://www.placementpapers.net/ For more downloads! 73
Visit http://www.placementpapers.net/ For more downloads!
*hile %strcmp%str3,str)''
print$%VStrings are not eRualOnW'L
Y
Answer:
VStrings are not eRualW
VStrings are not eRualW
^.
Explanation:
I$ a string constant is initiali&ed e!plicitl *ith characters, IO8J is not appended
automaticall to the string. Since str3 doesnJt have null termination, it treats *hatever the
values that are in the $ollo*ing positions as part o$ the string until it randoml reaches a
IO8J. So str3 and str) are not the same, hence the result.

3@)' main%'
X
int i ( @L
$or %Li++(8L' print$%VKdW,i'L
Y
Answer:
Compiler Srror+ Evalue reRuired.
Explanation:
As *e 6no* that increment operators return rvalues and hence it cannot appear on
the le$t hand side o$ an assignment operation.

3@@' void main%'
X
int 0mptr, 0cptrL
mptr ( %int0'malloc%si&eo$%int''L
print$%VKdW,0mptr'L
int 0cptr ( %int0'calloc%si&eo$%int',3'L
print$%VKdW,0cptr'L
Y
Answer:
garbage;value 8
Explanation:
The memor space allocated b malloc is uninitiali&ed, *hereas calloc returns the allocated
memor space initiali&ed to &eros.
3@7' void main%'
X
static int iL
*hile%i=(38'
%i<)'[i+++i;;L
print$%VKdW, i'L
Y
Answer:
@)N#N
Explanation:
Visit http://www.placementpapers.net/ For more downloads! 7)
Visit http://www.placementpapers.net/ For more downloads!
Since i is static it is initiali&ed to 8. Inside the *hile loop the conditional operator evaluates
to $alse, e!ecuting i;;. This continues till the integer value rotates to positive value %@)N#N'.
The *hile condition becomes $alse and hence, comes out o$ the *hile loop, printing the i
value.
3@?' main%'
X
int i(38,U()8L
U ( i, U[%i,U'[i+U+UL
print$%,Kd Kd,,i,U'L
Y
Answer:
38 38
Explanation:
The Ternar operator % [ + ' is eRuivalent $or i$;then;else statement. So the Ruestion can be
*ritten as+
i$%i,U'
X
i$%i,U'
U ( iL
else
U ( UL
Y
else
U ( UL
3@#' 3. const char 0aL
). char0 const aL
@. char const 0aL
;Di$$erentiate the above declarations.
Answer:
3. CconstC applies to char 0 rather than CaC % pointer to a constant char '
0a(C5C + illegal
a(,2i, + legal
). CconstC applies to CaC rather than to the value o$ a %constant pointer to char '
0a(C5C + legal
a(,2i, + illegal
@. Same as 3.
3@N' main%'
X
int i(?,U(38L
i(iF(UFF38L
print$%,Kd Kd,,i,U'L
Y
Visit http://www.placementpapers.net/ For more downloads! 7@
Visit http://www.placementpapers.net/ For more downloads!
Answer:
3 38
Explanation:
The e!pression can be *ritten as i(%iF(%UFF38''L The inner e!pression %UFF38' evaluates
to 3 because U((38. i is ?. i ( ?F3 is 3. 2ence the result.
3@"' main%'
X
int i(7,U(NL
U ( U HH i++ FF print$%,TO4 CA:,'L
print$%,Kd Kd,, i, U'L
Y
Answer:
7 3
Explanation:
Jh% 'oo$%an %3pr%ssion n%%ds to '% %va$&at%d on$( ti$$ th% tr&th va$&% of th% %3pr%ssion is
not 5no;n. U is not eRual to &ero itsel$ means that the e!pressionJs truth value is 3. -ecause
it is $ollo*ed b HH and tr&% 88 (an(thin=) =C tr&% ;h%r% (an(thin=) ;i$$ not '% %va$&at%d. So
the remaining e!pression is not evaluated and so the value o$ i remains the same.
Similarl *hen FF operator is involved in an e!pression, *hen an o$ the operands
become $alse, the *hole e!pressionJs truth value becomes $alse and hence the remaining
e!pression *ill not be evaluated.
fa$s% 77 (an(thin=) =C fa$s% ;h%r% (an(thin=) ;i$$ not '% %va$&at%d.
3@9' main%'
X
register int a()L
print$%,Address o$ a ( Kd,,Fa'L
print$%,Qalue o$ a ( Kd,,a'L
Y
Answer:
Compier Srror+ CFC on register variable
Rule to Remember:
& (address of ) operator cannot be applied on register variables
378' main%'
X
$loat i(3.?L
s*itch%i'
X
case 3+ print$%,3,'L
case )+ print$%,),'L
de$ault + print$%,8,'L
Y
Y
Answer:
Compiler Srror+ s*itch e!pression not integral
Explanation:
Visit http://www.placementpapers.net/ For more downloads! 77
Visit http://www.placementpapers.net/ For more downloads!
K;itch stat%m%nts can '% app$i%d on$( to int%=ra$ t(p%s.
373' main%'
X
e!tern iL
print$%,KdOn,,i'L
X
int i()8L
print$%,KdOn,,i'L
Y
Y
Answer:
Ein6er Srror + 4nresolved e!ternal smbol i
Explanation:
The identi$ier i is available in the inner bloc6 and so using e!tern has no use in resolving it.
37)' main%'
X
int a(),0$3,0$)L
$3($)(FaL
0$)+(0$)+(a+().?L
print$%,OnKd Kd Kd,,a,0$3,0$)'L
Y
Answer:
3# 3# 3#
Explanation:
$3 and $) both re$er to the same memor location a. So changes through $3 and $) ultimatel
a$$ects onl the value o$ a.
37@' main%'
X
char 0p(,1OOD,L
char a. /(,1OOD,L
print$%,On si&eo$%p' ( Kd, si&eo$%0p' ( Kd, strlen%p' ( Kd,, si&eo$%p', si&eo$%0p', strlen%p''L
print$%,On si&eo$%a' ( Kd, strlen%a' ( Kd,, si&eo$%a', strlen%a''L
Y
Answer:
si&eo$%p' ( ), si&eo$%0p' ( 3, strlen%p' ( 7
si&eo$%a' ( ?, strlen%a' ( 7
Explanation:
si&eo$%p' (< si&eo$%char0' (< )
si&eo$%0p' (< si&eo$%char' (< 3
Similarl,
si&eo$%a' (< si&e o$ the character arra (< ?
?h%n si9%of op%rator is app$i%d to an arra( it r%t&rns th% si9%of th% arra( and it is not the
same as the si&eo$ the pointer variable. 2ere the si&eo$%a' *here a is the character arra and
the si&e o$ the arra is ? because the space necessar $or the terminating :4EE character
should also be ta6en into account.
377' Mde$ine DIB% arra, tpe' si&eo$%arra'/si&eo$%tpe'
Visit http://www.placementpapers.net/ For more downloads! 7?
Visit http://www.placementpapers.net/ For more downloads!
main%'
X
int arr.38/L
print$%VThe dimension o$ the arra is KdW, DIB%arr, int''L
Y
Answer:
38
Explanation:
The si&e o$ integer arra o$ 38 elements is 38 0 si&eo$%int'. The macro e!pands to
si&eo$%arr'/si&eo$%int' (< 38 0 si&eo$%int' / si&eo$%int' (< 38.
37?' int DIB%int arra./'
X
return si&eo$%arra'/si&eo$%int 'L
Y
main%'
X
int arr.38/L
print$%VThe dimension o$ the arra is KdW, DIB%arr''L
Y
Answer:
3
Explanation:
Grra(s cannot '% pass%d to f&nctions as ar=&m%nts and on$( th% point%rs can '% pass%d. So
the argument is eRuivalent to int 0 arra %this is one o$ the ver $e* places *here ./ and 0
usage are eRuivalent'. The return statement becomes, si&eo$%int 0'/ si&eo$%int' that happens
to be eRual in this case.
37#' main%'
X
static int a.@/.@/(X3,),@,7,?,#,N,",9YL
int i,UL
static 0p./(Xa,a+3,a+)YL
$or%i(8Li=@Li++'
X
$or%U(8LU=@LU++'
print$%,KdOtKdOtKdOtKdOn,,0%0%p+i'+U',
0%0%U+p'+i',0%0%i+p'+U',0%0%p+U'+i''L
Y
Y
Answer:
3 3 3 3
) 7 ) 7
@ N @ N
7 ) 7 )
? ? ? ?
# " # "
N @ N @
" # " #
9 9 9 9
Visit http://www.placementpapers.net/ For more downloads! 7#
Visit http://www.placementpapers.net/ For more downloads!
Explanation:
0%0%p+i'+U' is eRuivalent to p.i/.U/.
37N' main%'
X
void s*ap%'L
int !(38,("L
s*ap%F!,F'L
print$%,!(Kd (Kd,,!,'L
Y
void s*ap%int 0a, int 0b'
X
0a \( 0b, 0b \( 0a, 0a \( 0bL
Y
Answer:
!(38 ("
Explanation:
4sing \ li6e this is a *a to s*ap t*o variables *ithout using a temporar variable and that
too in a single statement.
Inside main%', void s*ap%'L means that s*ap is a $unction that ma ta6e an number o$
arguments %not no arguments' and returns nothing. So this doesnJt issue a compiler error b
the call s*ap%F!,F'L that has t*o arguments.
This convention is historicall due to pre;A:SI stle %re$erred to as Zernighan and Gitchie
stle' stle o$ $unction declaration. In that stle, the s*ap $unction *ill be de$ined as
$ollo*s,
void s*ap%'
int 0a, int 0b
X
0a \( 0b, 0b \( 0a, 0a \( 0bL
Y
*here the arguments $ollo* the %'. So naturall the declaration $or s*ap *ill loo6 li6e, void
s*ap%' *hich means the s*ap can ta6e an number o$ arguments.
37"' main%'
X
int i ( )?NL
int 0iPtr ( FiL
print$%,Kd Kd,, 0%%char0'iPtr', 0%%char0'iPtr+3' 'L
Y
Answer:
3 3
Explanation:
The integer value )?N is stored in the memor as, 88888883 88888883, so the individual
btes are ta6en b casting it to char 0 and get printed.
379' main%'
X
int i ( )?"L
int 0iPtr ( FiL
print$%,Kd Kd,, 0%%char0'iPtr', 0%%char0'iPtr+3' 'L
Visit http://www.placementpapers.net/ For more downloads! 7N
Visit http://www.placementpapers.net/ For more downloads!
Y
Answer:
) 3
Explanation:
The integer value )?N can be represented in binar as, 88888883 88888883. Gemember that
the I:TSE machines are Ismall;endianJ machines. Kma$$,%ndian m%ans that th% $o;%r ord%r
'(t%s ar% stor%d in th% hi=h%r m%mor( addr%ss%s and th% hi=h%r ord%r '(t%s ar% stor%d in
$o;%r addr%ss%s. The integer value )?" is stored in memor as+ 88888883 88888838.
3?8' main%'
X
int i(@88L
char 0ptr ( FiL
0++ptr()L
print$%,Kd,,i'L
Y
Answer:
??#
Explanation:
The integer value @88 in binar notation is+ 88888883 88383388. It is stored in memor
%small;endian' as+ 88383388 88888883. Gesult o$ the e!pression 0++ptr ( ) ma6es the
memor representation as+ 88383388 88888838. So the integer corresponding to it is
88888838 88383388 (< ??#.
3?3' Minclude =stdio.h<
main%'
X
char 0 str ( ,hello,L
char 0 ptr ( strL
char least ( 3)NL
*hile %0ptr++'
least ( %0ptr=least ' [0ptr +leastL
print$%,Kd,,least'L
Y
Answer:
8
Explanation:
A$ter IptrJ reaches the end o$ the string the value pointed b IstrJ is IO8J. So the value o$ IstrJ
is less than that o$ IleastJ. So the value o$ IleastJ $inall is 8.
3?)' Declare an arra o$ : pointers to $unctions returning pointers to $unctions returning pointers to
characters[
Answer:
%char0%0'% '' %0ptr.:/'% 'L
3?@' main%'
X
struct student
X
char name.@8/L
Visit http://www.placementpapers.net/ For more downloads! 7"
Visit http://www.placementpapers.net/ For more downloads!
struct date dobL
YstudL
struct date
X
int da,month,earL
YL
scan$%,KsKdKdKd,, stud.rollno, Fstudent.dob.da, Fstudent.dob.month,
Fstudent.dob.ear'L
Y
Answer:
Compiler Srror+ 4nde$ined structure date
Explanation:
Inside the struct de$inition o$ IstudentJ the member o$ tpe struct date is given. The
compiler doesnJt have the de$inition o$ date structure %$or*ard re$erence is not allo*ed in
C in this case' so it issues an error.
3?7' main%'
X
struct dateL
struct student
X
char name.@8/L
struct date dobL
YstudL
struct date
X
int da,month,earL
YL
scan$%,KsKdKdKd,, stud.rollno, Fstudent.dob.da, Fstudent.dob.month,
Fstudent.dob.ear'L
Y
Answer:
Compiler Srror+ 4nde$ined structure date
Explanation:
Onl declaration o$ struct date is available inside the structure de$inition o$ IstudentJ but to
have a variable o$ tpe struct date the de$inition o$ the structure is reRuired.
3??' There *ere 38 records stored in Vsome$ile.datW but the $ollo*ing program printed 33 names. Ahat
*ent *rong[
void main%'
X
struct student
X
char name.@8/, rollno.#/L
YstudL
5IES 0$p ( $open%Vsome$ile.datW,WrW'L
*hile%>$eo$%$p''
X
$read%Fstud, si&eo$%stud', 3 , $p'L
puts%stud.name'L
Visit http://www.placementpapers.net/ For more downloads! 79
Visit http://www.placementpapers.net/ For more downloads!
Y
Y
Explanation:
$read reads 38 records and prints the names success$ull. It *ill return SO5 onl
*hen $read tries to read another record and $ails reading SO5 %and returning SO5'.
So it prints the last record again. A$ter this onl the condition $eo$%$p' becomes
$alse, hence comes out o$ the *hile loop.
3?#' Is there an di$$erence bet*een the t*o declarations,
3. int $oo%int 0arr./' and
). int $oo%int 0arr.)/'
Answer:
:o
Explanation:
5unctions can onl pass pointers and not arras. The numbers that are allo*ed inside the ./
is Uust $or more readabilit. So there is no di$$erence bet*een the t*o declarations.
3?N' Ahat is the subtle error in the $ollo*ing code segment[
void $un%int n, int arr./'
X
int 0p(8L
int i(8L
*hile%i++=n'
p ( Farr.i/L
0p ( 8L
Y
Answer & Explanation:
I$ the bod o$ the loop never e!ecutes p is assigned no address. So p remains :4EE
*here 0p (8 ma result in problem %ma rise to runtime error V:4EE pointer
assignmentW and terminate the program'.
3?"' Ahat is *rong *ith the $ollo*ing code[
int 0$oo%'
X
int 0s ( malloc%si&eo$%int'388'L
assert%s >( :4EE'L
return sL
Y
Answer & Explanation:
assert macro should be used $or debugging and $inding out bugs. The chec6 s >( :4EE is
$or error/e!ception handling and $or that assert shouldnJt be used. A plain i$ and the
corresponding remed statement has to be given.
3?9' Ahat is the hidden bug *ith the $ollo*ing statement[
assert%val++ >( 8'L
Answer & Explanation:
Assert macro is used $or debugging and removed in release version. In assert, the e!perssion
involves side;e$$ects. So the behavior o$ the code becomes di$$erent in case o$ debug
version and the release version thus leading to a subtle bug.
Visit http://www.placementpapers.net/ For more downloads! ?8
Visit http://www.placementpapers.net/ For more downloads!
Rule to Remember:
LonMt &s% %3pr%ssions that hav% sid%,%ff%cts in ass%rt stat%m%nts.
3#8' void main%'
X
int 0i ( 8!788L // i points to the address 788
0i ( 8L // set the value o$ memor location pointed b iL
Y
Answer:
4nde$ined behavior
Explanation:
The second statement results in unde$ined behavior because it points to some location
*hose value ma not be available $or modi$ication. Jhis t(p% of point%r in ;hich th% non,
avai$a'i$it( of th% imp$%m%ntation of th% r%f%r%nc%d $ocation is 5no;n as Eincomp$%t% t(p%E.
3#3' Mde$ine assert%cond' i$%>%cond'' O
%$print$%stderr, ,assertion $ailed+ Ks, $ile Ks, line Kd On,,Mcond,O
DD5IESDD,DDEI:SDD', abort%''
void main%'
X
int i ( 38L
i$%i((8'
assert%i = 388'L
else
print$%,This statement becomes else $or i$ in assert macro,'L
Y
Ans*er+
:o output
Explanation:
The else part in *hich the print$ is there becomes the else $or i$ in the assert macro. 2ence nothing
is printed.
The solution is to use conditional operator instead o$ i$ statement,
Mde$ine assert%cond' %%cond'[%8'+ %$print$ %stderr, ,assertion $ailed+ O Ks, $ile Ks, line Kd On,,Mcond,
DD5IESDD,DDEI:SDD', abort%'''
:ote+
2o*ever this problem o$ Vmatching *ith nearest elseW cannot be solved b the usual
method o$ placing the i$ statement inside a bloc6 li6e this,
Mde$ine assert%cond' X O
i$%>%cond'' O
%$print$%stderr, ,assertion $ailed+ Ks, $ile Ks, line Kd On,,Mcond,O
DD5IESDD,DDEI:SDD', abort%'' O
Y
3#)' Is the $ollo*ing code legal[
struct a
X
int !L
struct a bL
Visit http://www.placementpapers.net/ For more downloads! ?3
Visit http://www.placementpapers.net/ For more downloads!
Y
Ans*er+
:o
Explanation:
Is it not legal $or a structure to contain a member that is o$ the same
tpe as in this case. -ecause this *ill cause the structure declaration to be recursive *ithout
end.
3#@' Is the $ollo*ing code legal[
struct a
X
int !L
struct a 0bL
Y
Answer:
Tes.
Explanation:
0b is a pointer to tpe struct a and so is legal. The compiler 6no*s, the si&e o$ the pointer to
a structure even be$ore the si&e o$ the structure
is determined%as ou 6no* the pointer to an tpe is o$ same si&e'. This tpe o$ structures is
6no*n as Isel$;re$erencingJ structure.
3#7' Is the $ollo*ing code legal[
tpede$ struct a
X
int !L
aTpe 0bL
YaTpe
Answer:
:o
Explanation:
The tpename aTpe is not 6no*n at the point o$ declaring the structure %$or*ard re$erences
are not made $or tpede$s'.
3#?' Is the $ollo*ing code legal[
tpede$ struct a aTpeL
struct a
X
int !L
aTpe 0bL
YL
Answer:
Tes
Explanation:
The tpename aTpe is 6no*n at the point o$ declaring the structure, because it is alread
tpede$ined.
3##' Is the $ollo*ing code legal[
void main%'
X
Visit http://www.placementpapers.net/ For more downloads! ?)
Visit http://www.placementpapers.net/ For more downloads!
tpede$ struct a aTpeL
aTpe someQariableL
struct a
X
int !L
aTpe 0bL
YL
Y
Answer:
:o
Explanation:
Ahen the declaration,
tpede$ struct a aTpeL
is encountered bod o$ struct a is not 6no*n. This is 6no*n as Iincomplete tpesJ.

3#N' void main%'
X
print$%Vsi&eo$ %void 0' ( Kd OnV, si&eo$% void 0''L
print$%Vsi&eo$ %int 0' ( Kd OnW, si&eo$%int 0''L
print$%Vsi&eo$ %double 0' ( Kd OnW, si&eo$%double 0''L
print$%Vsi&eo$%struct un6no*n 0' ( Kd OnW, si&eo$%struct un6no*n 0''L
Y
Answer :
si&eo$ %void 0' ( )
si&eo$ %int 0' ( )
si&eo$ %double 0' ( )
si&eo$%struct un6no*n 0' ( )
Explanation:
The pointer to an tpe is o$ same si&e.
3#"' char inputString.388/ ( X8YL
To get string input $rom the 6eboard *hich one o$ the $ollo*ing is better[
3' gets%inputString'
)' $gets%inputString, si&eo$%inputString', $p'
Answer & Explanation:
The second one is better because gets%inputString' doesnCt 6no* the si&e o$ the string passed
and so, i$ a ver big input %here, more than 388 chars' the charactes *ill be *ritten past the
input string. Ahen $gets is used *ith stdin per$orms the same operation as gets but is sa$e.
3#9' Ahich version do ou pre$er o$ the $ollo*ing t*o,
3' print$%VKsW,str'L // or the more curt one
)' print$%str'L
Answer & Explanation:
Pre$er the $irst one. I$ the str contains an $ormat characters li6e Kd then it *ill result in a
subtle bug.
3N8' void main%'
X
int i(38, U()L
int 0ip( Fi, 0Up ( FUL
Visit http://www.placementpapers.net/ For more downloads! ?@
Visit http://www.placementpapers.net/ For more downloads!
int 6 ( 0ip/0UpL
print$%VKdW,6'L
Y
Answer:
Compiler Srror+ V4ne!pected end o$ $ile in comment started in line ?W.
Explanation:
The programmer intended to divide t*o integers, but b the Vma!imum munchW
rule, the compiler treats the operator seRuence / and 0 as /0 *hich happens to be the
starting o$ comment. To $orce *hat is intended b the programmer,
int 6 ( 0ip/ 0UpL
// give space e!plicit separating / and 0
//or
int 6 ( 0ip/%0Up'L
// put braces to $orce the intention
*ill solve the problem.
3N3' void main%'
X
char chL
$or%ch(8Lch=(3)NLch++'
print$%VKc Kd OnV, ch, ch'L
Y
Answer:
Implementaion dependent
Explanation:
The char tpe ma be signed or unsigned b de$ault. I$ it is signed then ch++ is e!ecuted
a$ter ch reaches 3)N and rotates bac6 to ;3)". Thus ch is al*as smaller than 3)N.
3N)' Is this code legal[
int 0ptrL
ptr ( %int 0' 8!788L
Answer:
Tes
Explanation:
The pointer ptr *ill point at the integer in the memor location 8!788.
3N@' main%'
X
char a.7/(,2SEEO,L
print$%,Ks,,a'L
Y
Answer:
Compiler error+ Too man initiali&ers
Explanation:
The arra a is o$ si&e 7 but the string constant reRuires # btes to get stored.
3N7' main%'
X
char a.7/(,2SEE,L
print$%,Ks,,a'L
Visit http://www.placementpapers.net/ For more downloads! ?7
Visit http://www.placementpapers.net/ For more downloads!
Y
Answer:
2SEEK`>_`>`[[[`__>
Explanation:
The character arra has the memor Uust enough to hold the string V2SEEW and doesnt have
enough space to store the terminating null character. So it prints the 2SEE correctl and
continues to print garbage values till it accidentall comes across a :4EE character.
3N?' main%'
X
int a(38,0UL
void 06L
U(6(FaL
U++L
6++L
print$%,On Ku Ku ,,U,6'L
Y
Answer:
Compiler error+ Cannot increment a void pointer
Explanation:
Qoid pointers are generic pointers and the can be used onl *hen the tpe is not 6no*n
and as an intermediate address storage tpe. :o pointer arithmetic can be done on it and ou
cannot appl indirection operator %0' on void pointers.
3N#' main%'
X
e!tern int iL
X int i()8L
X
const volatile unsigned i(@8L print$%,Kd,,i'L
Y
print$%,Kd,,i'L
Y
print$%,Kd,,i'L
Y
int iL
3NN' Print$ can be implemented b using DDDDDDDDDD list.
Answer:
Qariable length argument lists
3N"' char 0some5un%'
X
char 0temp ( Vstring constant,L
return tempL
Y
int main%'
X
puts%some5un%''L
Y
Ans*er+
Visit http://www.placementpapers.net/ For more downloads! ??
Visit http://www.placementpapers.net/ For more downloads!
string constant
Explanation+
The program su$$ers no problem and gives the output correctl because the character constants are
stored in code/data area and not allocated in stac6, so this doesnJt lead to dangling pointers.
3N9' char 0some5un3%'
X
char temp. / ( Vstring,L
return tempL
Y
char 0some5un)%'
X
char temp. / ( XIsJ, ItJ,JrJ,JiJ,JnJ,JgJYL
return tempL
Y
int main%'
X
puts%some5un3%''L
puts%some5un)%''L
Y
Ans*er+
1arbage values.
Explanation+
-oth the $unctions su$$er $rom the problem o$ dangling pointers. In some5un3%' temp is a character
arra and so the space $or it is allocated in heap and is initiali&ed *ith character string VstringW. This is
created dnamicall as the $unction is called, so is also deleted dnamicall on e!iting the $unction so the
string data is not available in the calling $unction main%' leading to print some garbage values. The
$unction some5un)%' also su$$ers $rom the same problem but the problem can be easil identi$ied in this
case.
Visit http://www.placementpapers.net/ For more downloads! ?#

S-ar putea să vă placă și