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..

0 1 2 5 10

 Is This Answer Correct ? 23 Yes 3 No

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

answer 7 are correct others are wrong..
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 ? 9 Yes 0 No

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

 Is This Answer Correct ? 10 Yes 2 No

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

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 ? 5 Yes 0 No

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

Guest & Raj is correct.......

 Is This Answer Correct ? 4 Yes 1 No

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

0 1 2 5 10

 Is This Answer Correct ? 3 Yes 0 No

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

All are incorrect. Please try it on a machine and see...
The answer is 012510. Please not that it is 0 1 2 5 10 but
without spaces.

 Is This Answer Correct ? 1 Yes 0 No

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

Hi all,

since the code is calling the same function with different
values,it's not at all possible to move to printf statement
until x becomes < 0

so only when the compiler gets the value of x as 0 the loop
will be stopped.

 Is This Answer Correct ? 1 Yes 0 No

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

5,2,1

 Is This Answer Correct ? 1 Yes 0 No

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

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

More C Interview Questions

An array name contains base address of the array. Can we change the base address of the array?

What's a "sequence point"?

Difference between Shallow copy and Deep copy?

Write code for atoi(x) where x is hexadecimal string.

what is the coding of display the factorial of a number using array and function?

Output for following program using for loop only * * * * * * * * * * * * * * *

Display names and numbers of employees who have 5 years or more experience and salary less than Rs.15000 using array of structures (name, number, experience and salary)

A float occupies 4 bytes in memory. How many bits are used to store exponent part? since we can have up to 38 number for exponent so 2 ki power 6 6, 6 bits will be used. If 6 bits are used why do not we have up to 64 numbers in exponent?

what is pointer

how many header file is in C language ?

Convert a distance from miles to kilometers .there are 5280 feets per mile,12 inches per foot .2.54 centimeters per inch and 100000centimeters per kilometer

Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 1. Print only the alphabets . If in upper case print in lower case vice versa. 2. Enter alphanumeric characters and form 2 array alphaets and digits.Also print the count of each array. 3. Find the count of a certain character. 4. Print the positions where a certain character occured. 5. Print the characters between successive array elements. 6. Find the largest and smallest charcter. How many times it each one occured. 7. Enter a certain range. Print out the array elements which occured between these range. 8. Reverse a character array without using another array. 9. Reverse an array region. 10. Replace a the array elements with it next character . Use a after z. 11. Code the array element with certain character as first alphabet. 12. Duplicate all the vowels in a character array. What is the new count. 13. Delete the vowels in a character array. What is the new array count. 14. Print the count of all characters in the array. 15. Enter n alphabets and store a upto tht charcter in array.What is the array count? 16. Sort a character array. 17. Merge 2 character arrays largearray,smallarray. 18. Find the pair with largest number of characters in between. 19. Find the numerical value of a charcter array. 20. Store n numeral characters in an arrray. Insert another numeral character in a certain position. 21. Insert a character in a sorted array. 22. Merge 2 sorted arrays in sorted fashion. 23. Duplicate the least occuring character. 24. Write a menu driven program to circular right/left shift an array of n elements. 25. Is the character array palindrome? if not make it palindrome. 26. Concatenate the first n charaters to the end of the string. 27. Print all n group of chracters which are palindrome. 28. Concatneate the reverse of last n characters to the array.

Categories