You are on page 1of 12

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;

<- function returning pointer to integer <- pointer to a function returning to integer

&efer to= >> ?ernighan @ &itchie page no. 1## >> Achaum series page no. +#+ ,. void main(* . int d/12 printf(35f3,d*2 6 "ns= Bndefined

Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com

1. void main(* . int i2 for(i/12iC,,i++* switch(i*. case 1= printf(35d3,i*2breaD2 case #=printf(35d3,i*2breaD2 case +=printf(35d3,i*2breaD2 case ,=printf(35d3,i*2 6 "ns= 1,#,+,, 6

0. void main(* . <<char -s/341#+,1s4n32 char s:;/341#+,1s4n32 printf(35d3,sizeof(s**2 6 "ns= 0

E. void main(* . unsigned i/12 <- unsigned char D/ >1 /F D/#112 -< signed j/>12 <- char D/ >1 /F D/011+1 -< <- unsigned or signed int D/ >1 /FD/011+1 -< if(iCj* printf(3less3*2 else if(iFj* printf(3greater3*2 else if(i//j* printf(3eGual3*2 6 "ns= less

Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com

H. void main(* . float j2 j/1888-18882 printf(35f3,j*2 6 1. #. +. ,. 1888888 Iverflow 'rror Jone

"ns= (,* : 10908.8888 ;

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 <- pointer to char -< tLpedef pc fpc(*2 <- function returning pointer to char -< tLpedef fpc -pfpc2 <- pointer to above -< tLpedef pfpc fpfpc(*2 <- function returning... -< tLpedef fpfpc -pfpfpc2 <- pointer to... -< pfpfpc a:J;2 <- arraL of... -< +. Bse 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, liDe the one above*. "nL good booD on C should e)plain how to read these complicated C declarations 3inside out3 to understand them (3declaration
Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com


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 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(*2 void main(* . f(1*2 f(1,#*2 f(1,#,+*2 6 f(int i,int j,int D* . printf(35d 5d 5d3,i,j,D*2 6 7hat are the number of sLnta) errors in the above "ns= Jone.

1+. void main(* . int i/E2 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

Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com


"ns= 3one is defined3

11. void main(* . int count/18,-temp,sum/82 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 worDing onlL on uni) machine with pattern matching. 1,. what is alloca(* "ns = It allocates and frees memorL after use<after getting out of scope

1E. 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
Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com


6 "ns= anLthing is good.

19. void main(* . char -s:;/. 3dharma3,3hewlett>pacDard3,3siemens3,3ibm362 char --p2 p/s2 printf(35s3,++-p*2 printf(35s3,-p++*2 printf(35s3,++-p*2 6 "ns= 3harma3 (p>Fadd(dharma* @@ (-p*>Fharma* 3harma3 (after printing, p>Fadd(hewlett>pacDard* @@(-p*>Fharma* 3ewlett>pacDard3 #8. Iutput of the following program is main(* .int i/82 for(i/82iC#82i++* .switch(i*. case 8=i+/12 case 1=i+/#2 case 1=i+/12 default i+/,2 breaD26 printf(35d,3,i*2 6 6 a* 8,1,9,1+,1E b* 1,9,1+,1E c* 1#,1E,## d* 10,#1 e* ALnta) 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*
Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com


.printf(3pass1,3*2 if(cCu* printf(3pass#3*2 else printf(3$ail#3*2 6 else printf(3$ail1*2 if(iCu* printf(3pass#3*2 else printf(3$ail#3* 6 a* Oass1,Oass# b* Oass1,$ail# c* $ail1,Oass# d* $ail1,$ail# e* Jone of these "ns. (c* ##. 7hat will the following program do void main(* . int i2 char a:;/3Atring32 char -p/3Jew Aring32 char -Memp2 Memp/a2 a/malloc(strlen(p* + 1*2 strcpL(a,p*2 <<Pine number=9<< 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 <<Pine number 11<< a* Awap 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 E 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
Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com


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"SBJIM, >1 d* same, N"SBJIM, N"SBJIM e* not same, N"SIJM, N"SBJIM "ns. (a* #,. 7hat will be the result of the following program 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 error<Core dump d* ALnta) 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
Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com


#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. 1E 9, #E. $ind the output for the following C program main(* . int )/12 printf(35d 5d 5d4n3,),)CC#,)FF#*2 6 "ns. 1 #8 1 #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 ALstems32 (-ptr*++2
Freshersworld.com Resource Center

First Job. Dream Job. Freshersworld.com


printf(35s4n3,ptr*2 ptr++2 printf(35s4n3,ptr*2 6 "ns. Aamco ALstems

+8 $ind the output for the following C program %includeCstdio.hF main(* . char s1:;/3&amco32 char s#:;/3ALstems32 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 %includeCstdio.hF main(* . char -p12 char -p#2 p1/(char -* malloc(#1*2 p#/(char -* malloc(#1*2 strcpL(p1,3&amco3*2 strcpL(p#,3ALstems3*2 strcat(p1,p#*2 printf(35s3,p1*2 6 "ns. &amcoALstems

+#. $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&B' 8 some code
Freshersworld.com Resource Center

10

First Job. Dream Job. Freshersworld.com


while(M&B'* . some code 6 "ns. Mhis wonTt go into the loop as M&B' 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* 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. +E. 7hat are the output(s* for the following +H. %includeCmalloc.hF char -f(* .char -s/malloc(H*2 strcpL(s,3goodbLe3*2 6 main(* .
Freshersworld.com Resource Center

11

First Job. Dream Job. Freshersworld.com


char -f(*2 printf(35c3,-f(*/T"T*2

+9. %define N"J(),L* ()*F(L* ()*=(L* .int i/182 j/12 D/82 D/N"S(i++,++j*2 printf(5d 5d 5d 5d,i,j,D*2 6 "ns. 18 1 8 ,8. void main(* . int i/E2 printf(35d3,i++-i++*2 6 "ns= 10

Freshersworld.com Resource Center

12