freelanceprogrammers.org Forum Index » C

C PUZZLE!


View user's profile Post To page top
purplepolka_81 Posted: Tue Jul 29, 2003 11:54 pm


Joined: 29 Jul 2003

Posts: 1
C PUZZLE!
Hi all,
 
how does this pgm work??
 
voidf(char *)main(){f("123");}voidf(char a[]){if(a[1] == ``) return ;f(a+1);f(a+1);printf("%c",a[1]);}
 
cheers,
P
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
Reply with quote
Send private message
View user's profile Post To page top
shantanu_k06 Posted: Wed Jul 30, 2003 10:04 pm


Joined: 19 Jul 2003

Posts: 29
C PUZZLE!
Do a dry-run and you`ll get the answer as well as
understand how it works. It uses recursion, in case
you didn`t know that.

BTW, does it produce an output "22221"? I did a quick
dry-run just now (and used little bit speculation :-).
I might be wrong too.

Regards,
Shantanu

--- polka dot <purplepolka_81@...> wrote:
> Hi all,
>
> how does this pgm work??
>
> voidf(char *)
> main()
> {
> f("123");
> }
> voidf(char a[])
> {
> if(a[1] == ``) return ;
> f(a+1);
> f(a+1);
> printf("%c",a[1]);
> }
>
> cheers,
> P


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help