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

How is a structure member accessed?

0 Answers  


12344321 123 321 12 21 1 1 how i print this program??

5 Answers   DSR Management, Winit,


What tq means in chat?

0 Answers  


Why the use of alloca() is discouraged?

2 Answers   Oracle,


What is variable and explain rules to declare variable in c?

0 Answers  






What is the difference between #include <header file> and #include “header file”?

0 Answers  


Difference between macros and inline functions? Can a function be forced as inline?

0 Answers   HAL, Honeywell, Zomato,


how to create c progarm without void main()?

1 Answers   NIIT,


write a program to print sum of each row of a 2D array.

4 Answers  


What is the difference between fread and fwrite function?

0 Answers  


What is the size of a union variable?

0 Answers  


what is diff between localstatic and globalstatis variable possible 2 use in another file...?

2 Answers   HCL,


Categories