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

above function is called as:
fun(10);

what will it print?



}

Answers were Sorted based on User's Feedback



fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is call..

Answer / shilpa m

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 ?    1 Yes 1 No

fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is call..

Answer / enigma

Strictly speaking the answer is undefined until someone forces the output text from the console buffer to the screen.
Otherwise it would normally print 012510

Debug it inside MSVC and witness no output. In reality though most implementations will do a final flush to screen....

Is This Answer Correct ?    0 Yes 0 No

fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is call..

Answer / mortal

it will print "0" i.e zero since compiler wont get to the
print statement until the value is zero.

Is This Answer Correct ?    2 Yes 5 No

fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is call..

Answer / vinay

10,5,2,1

after that it terminated.

Is This Answer Correct ?    1 Yes 4 No

fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is call..

Answer / sri

0

Is This Answer Correct ?    1 Yes 6 No

fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is call..

Answer / divya

0

Is This Answer Correct ?    1 Yes 9 No

fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is call..

Answer / megha

5

Is This Answer Correct ?    1 Yes 15 No

Post New Answer

More C Interview Questions

Describe the steps to insert data into a singly linked list.

0 Answers  


what is the difference between NULL('\0') and 0?

14 Answers   Microsoft,


write a program that will read the temperature in Celsius and convert that into Fahrenheit.

1 Answers  


#include<stdio.h> #include<conio.h> void main() {clrscr(); char another='y'; int num; for(;another=='y';) { printf("Enter a number"); scanf("%d",&num); printf("squre of %d is %d",num,num*num); printf("\nwant to enter another number y/n"); scanf("%c",&another); } getch(); } the above code runs only one time.on entering 'y' the screen disappeares.what can i do?

3 Answers  


What is the use of function in c?

0 Answers  






Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors

3 Answers  


Is it acceptable to declare/define a variable in a c header?

0 Answers  


how to capitalise first letter of each word in a given string?

0 Answers  


how to swap 2 numbers in a single statement?

3 Answers  


for(;;) printf("C language") What is out put of above??

2 Answers   Practical Viva Questions,


how to add numbers without using arithmetic operators.

14 Answers   TCS,


How can draw a box in cprogram without using graphics.h header file & using only one printf(); ?

4 Answers   NIIT,


Categories