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

1 1 2 1 2 3 1 2 3 4 1 2 3 1 2 1 generate this output using for loop

2 Answers  


main() { printf("hello"); fork(); }

0 Answers   Wilco,


Write a C program that reads a series of strings and prints only those ending in "ed"

2 Answers   Accenture,


write a c program that prints all multiples of 3between 1 and 50.

5 Answers  


Does c have enums?

0 Answers  






What is the use of sizeof () in c?

0 Answers  


What are the commands should be given before weiting C Program i.e, Cd.. like

4 Answers   IBM, Infonet, Satyam, Tech Mahindra,


Write a program to enter the name and age. If age>28 then find salary categories. if age<28 then find that you are gaduate or not.

1 Answers  


Explain what are reserved words?

0 Answers  


What is the difference between if else and switchstatement

0 Answers  


If you know then define #pragma?

0 Answers  


What is an example of structure?

0 Answers  


Categories