By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,965 Members | 2,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,965 IT Pros & Developers. It's quick & easy.

what purpuse this logic is used

P: 2
1) int foo(int x)
return 0;
return 1+foo(x/10);

a) What is the output of this logic for foo(12345)
b) What purpose this logic is used
c) If we give negative number what output will get. If u future enhance n find a bug, how u change the code to fix the bug n the remain work for negative n positive numbers.
Oct 13 '10 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 100+
P: 931
The purpose of this snippet is to show an example - recursion. Rest you can run the code and get the answers!
Oct 13 '10 #2

Expert 100+
P: 2,398
Walk through the logic with pencil and paper. What do you get for foo(12345)? What do you get for foo(123)?
Oct 13 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.