ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
fun(int x)
{
 if(x > 0)
   fun(x/2);
 printf("%d", x);
}

above function is called as:
 fun(10);

what will it print?



}
 Question Submitted By :: Sid08
I also faced this Question!!     Rank Answer Posted By  
 
  Re: fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? }
Answer
# 1
0 1 2 5 10
 
Is This Answer Correct ?    7 Yes 1 No
Guest
 
  Re: fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? }
Answer
# 2
5
 
Is This Answer Correct ?    0 Yes 4 No
Megha
 
 
 
  Re: fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? }
Answer
# 3
0
 
Is This Answer Correct ?    0 Yes 4 No
Divya
 
  Re: fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? }
Answer
# 4
0 1 2 5 10...Please don't post the wrong answer.
 
Is This Answer Correct ?    2 Yes 1 No
Raj
 
  Re: fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? }
Answer
# 5
it will print "0" i.e zero since compiler wont get to the
print statement until the value is zero.
 
Is This Answer Correct ?    0 Yes 1 No
Mortal
 
  Re: fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? }
Answer
# 6
Guest & Raj is correct.......
Please don't post the wrong answer if u r not  clear about this
 
Is This Answer Correct ?    2 Yes 0 No
Code
 
  Re: fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? }
Answer
# 7
0 1 2 5 10 is the answer. But can anybody explain why the
printing order 0 1 2 5 10. Why not 10 5 2 1 0 ? please...

Is it depends on stack allocation??
 
Is This Answer Correct ?    2 Yes 0 No
Gg
 
  Re: fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? }
Answer
# 8
10,5,2,1

after that it terminated.
 
Is This Answer Correct ?    1 Yes 0 No
Vinay
 
  Re: fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? }
Answer
# 9
Only answer 1
     answer 4
     answer 7 are correct others are wrong.. 
If you are confident on your answers please check once then 
write a post.

Correct Answer: 0 1 2 5 10

This will print in reverse order because, This is a 
recursive call, Every time a function is called the values 
are stored in stack/stack is created. when x value reaches 
0 then it will return. So stack is LIFO order, So it will 
print the values in reverse order.
 
Is This Answer Correct ?    2 Yes 0 No
Mahesh Patil
 
  Re: fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? }
Answer
# 10
0
 
Is This Answer Correct ?    0 Yes 1 No
Sri
 
  Re: fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? }
Answer
# 11
0 1 2 5 10
 
Is This Answer Correct ?    2 Yes 0 No
Sridhara Bd
 
  Re: fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? }
Answer
# 12
hi Gg

answer is 0 1 2 5 10

this not stack prlm dear 

here printf is after the function call dear so it is
printing 0 1 2 5 10

if u wnt to see 10 5 2 1 0 as output plz  keep printf
function before function call that is 

fun(int x)
{
 if(x > 0)
     printf("%d\n", x);
   fun(x/2);
 
}

but output will be 10 5 2 1 only on 0 is printed

this above new code will give segmentation error in netbeans 

thank u dear
 
Is This Answer Correct ?    0 Yes 0 No
Ashwin Kumar
 
  Re: fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? }
Answer
# 13
Right answer is 0.
fun(int x)
{
 if(x > 0)
     fun(x/2);
printf("%d\n", x);
}
Here if fun(10)is called the sequence goes as fun(10)->fun
(5)->fun(2.5)->fun(1.25)->fun(0.625) after this itself 
printf will be executed and 0 is printed.

please expalin how answer is 0 1 2 5 10 is right answer???
 
Is This Answer Correct ?    0 Yes 1 No
Shilpa M
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
plz answer....A program that takes 3 variables e.g a,b,c in as seperate parameters and rotates the values stored so that value goes a to b, b to c and c to a .  3
write a function which accept two numbers from main() and interchange them using pointers?  3
Tell us the difference between these two : #include"stdio.h" #include<stdio.h> define in detial.  4
what are the difference between ANSI C and Let Us c and Turbo C LG-Soft1
long int size a) 4 bytes b) 2 bytes c) compiler dependent d) 8 bytes HCL11
What is the most efficient way to count the number of bits which are set in a value?  3
What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1; TCS10
what is c? Tech-Mahindra5
What ios diff. Between %e & %f? Honeywell1
write the function int countchtr(char string[],int ch);which returns the number of timesthe character ch appears in the string. for example the call countchtr("she lives in Newyork",'e') would return 3.  4
what is the difference between #include<stdio.h> and #include"stdio.h" ? TCS5
#include <stdio.h> int main ( int argc, char* argv [ ] ) { int value1 = 10; int value2 = 5; printf ( "\n The sum is :%d", value1 | value2 ); } This is the answer asked by some one to add two numbers with out using arithmetic operator?Yes this answer is write it given out put as 15.But how????? what is need of following line? int main ( int argc, char* argv [ ] ) how it work?what is the meaning for this line? please explain me.Advance thanks Excel4
Identify the correct argument for the function call fflush () in ANSI C: A)stdout B)stdin C)stderr D)All the above Accenture3
write a program to swap bits in a character and return the value prototype of function char fun (char a, charb flag c) where fun returns a char, char a is a the value char b is the bit to be changed and flag c is the bit value for eg: x=fun(45,7,0) since 45 is 0010 0101 and ow x should contain the value 65 (0110 0101) Bosch1
C program to perform stack operation using singly linked list  3
write a program to sort the elements in a given array in c language  2
hi how to convert program from notepad to turboc editor can u please help me  1
What is the output of the following program #include<stdio.h> main() { int i=0; fork(); printf("%d",i++); fork(); printf("%d",i++); fork(); wait(); } ADITI5
pick out the odd one out of the following a.malloc() b.calloc() c.free() d.realloc() TCS1
Can you think of a way when a program crashed before reaching main? If yes how?  2
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com