Anda di halaman 1dari 11

First Job. Dream Job. Freshersworld.

com
C,C++ Questions
1. Base class has some virtual method and derived class has a method with the
same name. If we initialize the base class pointer with derived
object,. calling of that virtual method will result in which method being called
a. Base method
b. !erived method..
"ns. b
#. $or the following C program
%define "&'"()*(+.1,-)-)*
main(*
.float r1/0.#1,r#/#.1,a2
a/"&'"(r1*2
printf(34n "rea of the circle is 5f3, a*2
a/"&'"(r#*2
printf(34n "rea of the circle is 5f3, a*2
6
7hat is the output
"ns. "rea of the circle is 1##.010#18
"rea of the circle is 19.0#1888
+. 7hat do the following statements indicate. ')plain.
int(-p*:18;
int-f(*
int(-pf*(*
int-p:18;
&efer to<
== >ernighan ? &itchie page no. 1##
== @chaum series page no. +#+
,.
void main(*
.
int d/12
printf(35f3,d*2
6
"ns< Andefined
Freshersworld.com Resource Center
1
First Job. Dream Job. Freshersworld.com
1.
void main(*
.
int i2
for(i/12iB,,i++*
switch(i*
case 1< printf(35d3,i*2breaC2
.
case #<printf(35d3,i*2breaC2
case +<printf(35d3,i*2breaC2
6
switch(i* case ,<printf(35d3,i*2
6
"ns< 1,#,+,,
0.
void main(*
.
char -s/341#+,1s4n32
printf(35d3,sizeof(s**2
6
"ns< 0
D.
void main(*
.
unsigned i/12 E- unsigned char C/ =1 /F C/#112 -E
signed j/=12 E- char C/ =1 /F C/011+1 -E
E- unsigned or signed int C/ =1 /FC/011+1 -E
if(iBj*
printf(3less3*2
else
if(iFj*
printf(3greater3*2
else
if(i//j*
printf(3eGual3*2
6
"ns< less
H.
Freshersworld.com Resource Center
2
First Job. Dream Job. Freshersworld.com
void main(*
.
float j2
j/1888-18882
printf(35f3,j*2
6
1. 1888888
#. Iverflow
+. 'rror
,. Jone
"ns< ,
9. Kow do Lou declare an arraL of J pointers to functions returning
pointers to functions returning pointers to characters
"ns< Mhe first part of this Guestion can be answered in at least
three waLs<
1. char -(-(-a:J;*(**(*2
#. Build the declaration up incrementallL, using tLpedefs<
tLpedef char -pc2 E- pointer to char -E
tLpedef pc fpc(*2 E- function returning pointer to char -E
tLpedef fpc -pfpc2 E- pointer to above -E
tLpedef pfpc fpfpc(*2 E- function returning... -E
tLpedef fpfpc -pfpfpc2 E- pointer to... -E
pfpfpc a:J;2 E- arraL of... -E
+. Ase the cdecl program, which turns 'nglish into C and vice
versa<
cdeclF declare a as arraL of pointer to function returning
pointer to function returning pointer to char
char -(-(-a:;*(**(*
cdecl can also e)plain complicated declarations, help with
casts, and indicate which set of parentheses the arguments
go in (for complicated function definitions, liCe the one
above*.
"nL good booC on C should e)plain how to read these complicated
C declarations 3inside out3 to understand them (3declaration
mimics use3*.
Mhe pointer=to=function declarations in the e)amples above have
not included parameter tLpe information. 7hen the parameters
have complicated tLpes, declarations can -reallL- get messL.
(Nodern versions of cdecl can help here, too.*
18. " structure pointer is defined of the tLpe time . 7ith + fields min,sec hours
Freshersworld.com Resource Center
3
First Job. Dream Job. Freshersworld.com
having pointers to intergers.
7rite the waL to initialize the #nd element to 18.
11. In the above Guestion an arraL of pointers is declared.
7rite the statement to initialize the +rd element of the # element to 182
1#.
int f(*
void main(*
.
f(1*2
f(1,#*2
f(1,#,+*2
6
f(int i,int j,int C*
.
printf(35d 5d 5d3,i,j,C*2
6
7hat are the number of sLnta) errors in the above
"ns< Jone.
1+.
void main(*
.
int i/D2
printf(35d3,i++-i++*2
6
"ns< 10
1,.
%define one 8
%ifdef one
printf(3one is defined 3*2
%ifndef one
printf(3one is not defined 3*2
"ns< 3one is defined3
11.
void main(*
.
int count/18,-temp,sum/82
Freshersworld.com Resource Center
4
First Job. Dream Job. Freshersworld.com
temp/?count2
-temp/#82
temp/?sum2
-temp/count2
printf(35d 5d 5d 3,count,-temp,sum*2
6
"ns< #8 #8 #8
10. Mhere was Guestion in c worCing onlL on uni) machine with pattern matching.
1,. what is alloca(*
"ns < It allocates and frees memorL after useEafter getting out of scope
1D.
main(*
.
static i/+2
printf(35d3,i==*2
return iF8 main(*<82
6
"ns< +#1
1H.
char -foo(*
.
char result:188;*2
strcpL(result,3anLthing is good3*2
return(result*2
6
void main(*
.
char -j2
j/foo(*
printf(35s3,j*2
6
"ns< anLthing is good.
19.
void main(*
.
char -s:;/. 3dharma3,3hewlett=pacCard3,3siemens3,3ibm362
char --p2
p/s2
printf(35s3,++-p*2
Freshersworld.com Resource Center
5
First Job. Dream Job. Freshersworld.com
printf(35s3,-p++*2
printf(35s3,++-p*2
6
"ns< 3harma3 (p=Fadd(dharma* ?? (-p*=Fharma*
3harma3 (after printing, p=Fadd(hewlett=pacCard* ??(-p*=Fharma*
3ewlett=pacCard3
#8. Iutput of the following program is
main(*
.int i/82
for(i/82iB#82i++*
.switch(i*
case 8<i+/12
case 1<i+/#2
case 1<i+/12
default i+/,2
breaC26
printf(35d,3,i*2
6
6
a* 8,1,9,1+,1D
b* 1,9,1+,1D
c* 1#,1D,##
d* 10,#1
e* @Lnta) error
"ns. (d*
#1. 7hat is the ouptut in the following program
main(*
.char c/=0,2
int i/=+#
unsigned int u /=102
if(cFi*
.printf(3pass1,3*2
if(cBu*
printf(3pass#3*2
else
printf(3$ail#3*2
6
else
printf(3$ail1*2
if(iBu*
printf(3pass#3*2
else
printf(3$ail#3*
6
a* Oass1,Oass#
b* Oass1,$ail#
Freshersworld.com Resource Center
6
First Job. Dream Job. Freshersworld.com
c* $ail1,Oass#
d* $ail1,$ail#
e* Jone of these
"ns. (c*
##. 7hat will the following program do
void main(*
.
int i2
char a:;/3@tring32
char -p/3Jew @ring32
char -Memp2
Memp/a2
a/malloc(strlen(p* + 1*2
strcpL(a,p*2 EEPine number<9EE
p / malloc(strlen(Memp* + 1*2
strcpL(p,Memp*2
printf(3(5s, 5s*3,a,p*2
free(p*2
free(a*2
6 EEPine number 11EE
a* @wap contents of p ? a and print<(Jew string, string*
b* Qenerate compilation error in line number H
c* Qenerate compilation error in line number 1
d* Qenerate compilation error in line number D
e* Qenerate compilation error in line number 1
"ns. (b*
#+. In the following code segment what will be the result of the function,
value of ) , value of L
.unsigned int )/=12
int L2
L / R82
if() // L*
printf(3same3*2
else
printf(3not same3*2
6
a* same, N"SIJM, =1
b* not same, N"SIJM, =N"SIJM
c* same , N"SAJIM, =1
d* same, N"SAJIM, N"SAJIM
e* not same, N"SIJM, N"SAJIM
"ns. (a*
#,. 7hat will be the result of the following program
Freshersworld.com Resource Center
7
First Job. Dream Job. Freshersworld.com
char -g)))(*
.static char ))):18#,;2
return )))2
6
main(*
.char -g/3string32
strcpL(g)))(*,g*2
g / g)))(*2
strcpL(g,3oldstring3*2
printf(3Mhe string is < 5s3,g)))(**2
6
a* Mhe string is < string
b* Mhe string is <Ildstring
c* &un time errorECore dump
d* @Lnta) error during compilation
e* Jone of these
"ns. (b*
#1. $ind the output for the following C program
main(*
.
char -p1/3Jame32
char -p#2
p#/(char -*malloc(#8*2
while(-p#++/-p1++*2
printf(35s4n3,p#*2
6
"ns. "n emptL string
#0. $ind the output for the following C program
main(*
.
int )/#8,L/+12
) / L++ + )++2
L / ++L + ++)2
printf(35d 5d4n3,),L*2
6
"ns. 1D 9,
#D. $ind the output for the following C program
main(*
.
int )/12
printf(35d 5d 5d4n3,),)BB#,)FF#*2
6
"ns. 1 #8 1
Freshersworld.com Resource Center
8
First Job. Dream Job. Freshersworld.com
#H $ind the output for the following C program
%define swap1(a,b* a/a+b2b/a=b2a/a=b2
main(*
.
int )/1,L/182
swap1(),L*2
printf(35d 5d4n3,),L*2
swap#(),L*2
printf(35d 5d4n3,),L*2
6
int swap#(int a,int b*
.
int temp2
temp/a2
b/a2
a/temp2
return2
6
"ns. 18 1
#9 $ind the output for the following C program
main(*
.
char -ptr / 3&amco @Lstems32
(-ptr*++2
printf(35s4n3,ptr*2
ptr++2
printf(35s4n3,ptr*2
6
"ns. @amco @Lstems
+8 $ind the output for the following C program
%includeBstdio.hF
main(*
.
char s1:;/3&amco32
char s#:;/3@Lstems32
s1/s#2
printf(35s3,s1*2
6
"ns. Compilation error giving it cannot be an modifiable TlvalueT
+1 $ind the output for the following C program
%includeBstdio.hF
main(*
Freshersworld.com Resource Center
9
First Job. Dream Job. Freshersworld.com
.
char -p12
char -p#2
p1/(char -* malloc(#1*2
p#/(char -* malloc(#1*2
strcpL(p1,3&amco3*2
strcpL(p#,3@Lstems3*2
strcat(p1,p#*2
printf(35s3,p1*2
6
"ns. &amco@Lstems
+#. $ind the output for the following C program given that
:1;. Mhe following variable is available in file1.c
static int averageUfloat2
"ns. "ll the functions in the file1.c can access the variable
++. $ind the output for the following C program
% define M&A' 8
some code
while(M&A'*
.
some code
6
"ns. Mhis wonTt go into the loop as M&A' is defined as 8
+,. struct list.
int )2
struct list -ne)t2
6-head2
the struct head.) /188
Is the above assignment to pointer is correct or wrong
"ns. 7rong
+1.7hat is the output of the following
int i2
i/12
i/i+#-i++2
printf(5d,i*2
"ns. ,
+0. $IP' -fp1,-fp#2

fp1/fopen(3one3,3w3*
Freshersworld.com Resource Center
10
First Job. Dream Job. Freshersworld.com
fp#/fopen(3one3,3w3*
fputc(T"T,fp1*
fputc(TBT,fp#*
fclose(fp1*
fclose(fp#*
6
$ind the 'rror, If "nL
"ns. no error. But It will over writes on same file.
+D. 7hat are the output(s* for the following
+H. %includeBmalloc.hF
char -f(*
.char -s/malloc(H*2
strcpL(s,3goodbLe3*2
6
main(*
.
char -f(*2
printf(35c3,-f(*/T"T*2 6
+9. %define N"J(),L* ()*F(L*()*<(L*
.int i/182
j/12
C/82
C/N"S(i++,++j*2
printf(5d 5d 5d 5d,i,j,C*2
6
"ns. 18 1 8
,8.
void main(*
.
int i/D2
printf(35d3,i++-i++*2
6
"ns< 10
Freshersworld.com Resource Center
11

Anda mungkin juga menyukai