fun(int x)
if(x > 0)
printf("%d", x);

above function is called as:

what will it print?


Answers were Sorted based on User's Feedback

Answer / guest

0 1 2 5 10

Is This Answer Correct ?    23 Yes 3 No

Answer / mahesh patil

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

Answer / raj

0 1 2 5 10...Please don't post the wrong answer.

Is This Answer Correct ?    10 Yes 2 No

Answer / gg

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

Answer / code

Guest & Raj is correct.......
Please don't post the wrong answer if u r not clear about this

Is This Answer Correct ?    4 Yes 1 No

Answer / sridhara bd

0 1 2 5 10

Is This Answer Correct ?    3 Yes 0 No

Answer / amit

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

Answer / hemavathiarun

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

Answer / sunil v r


Is This Answer Correct ?    1 Yes 0 No

Answer / ashwin kumar

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);


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

Post New Answer

More C Interview Questions

Write a program to print this triangle: * ** * **** * ****** * ******** * ********** Don't use printf statements;use two nested loops instead. you will have to use braces around the body of the outer loop if it contains multiple statements.

6 Answers   Wipro,

Can we write a program without main() function?

9 Answers  

write a program to sum of its digit with using control structure or with out using loop. for ex: let the number is 25634 then answer will be=2+5+6+3+4=20

4 Answers  

could u able to tell about suresoft technical session

1 Answers  

to convert a string without using decrement operater and string functions

1 Answers  

Write a function stroverlap that takes (at least) two strings, and concatenates them, but does not duplicate any overlap. You only need to worry about overlaps between the end of the first string and the beginning of the second string. Examples: batman, manonthemoon = batmanonthemoon batmmamaman, mamamanonthemoon = batmmamamanonthemoon bat, man = batman batman, batman = batman batman, menonthemoon = batmanmenonthemoon

0 Answers   HCL,

Given a single Linked list with lakhs of nodes and length unknown how do you optimally delete the nth element from the list?

1 Answers   Oracle,

Write a program that takes a 5 digit number and calculates 2 power that number and prints it

7 Answers  

is it possible to change the default calling convention in c ?

1 Answers   Aptech,

we have to use realloc only after malloc or calloc ? or we can use initially with out depending on whether we are using malloc or calloc in our program ?

2 Answers  

what is c language?

2 Answers  

i want to switch my career from quailty assurance engineering to development kindly guide me from which programming language its better for me to start plz refer some courses or certifications too i have an experience of 1.5 yrs in QA field.Kindly guide me

0 Answers   Microsoft,