Exforsys

Free Training

What is the Output

This is a discussion on What is the Output within the C and C++ forums, part of the Programming Talk category; I saw a question in a C program as below: void test (int a) { if (a > 0) test(--a); ...

Go Back   Exforsys > Programming Talk > C and C++

Exforsys.com


C and C++ C and C++

Reply

 

LinkBack Thread Tools Search this Thread
  #1 (permalink)  
Old 06-22-2007, 06:17 AM
Member
 
Join Date: Apr 2006
Posts: 98
Angela is on a distinguished road
Question What is the Output

I saw a question in a C program as below:

void test (int a)
{
if (a > 0)
test(--a);
printf("%d, ", a);
}
int main()
{
test(5);
return 0;
}

I want to know how the above program is executed and the output of the above program. Kindly help me know about this.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-22-2007, 09:19 AM
Junior Member
 
Join Date: May 2007
Location: United States
Posts: 4
sasi_jampala is on a distinguished road
Send a message via Yahoo to sasi_jampala
answer to your question

out put is from 0 to 5 it ii print
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-28-2007, 02:25 PM
Senior Member
 
Join Date: Apr 2006
Posts: 153
cyrus is on a distinguished road
The output of the above C program you have given is
0, 0, 1, 2, 3, 4,

This is because the value of test is passed with parameter as 5 which is initial value of 5 in test() function. This value of a gets decremented until the value of a is greater than 0 and so when a reached the value of 0 it gets printed and the logic is proceeded as such till the value reaches the value of 5.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Help in Output ashlee C and C++ 1 06-16-2007 04:52 PM
Different Output cyrus C and C++ 3 06-02-2007 01:04 AM
Puzzled on Output Adrian C and C++ 2 05-24-2007 03:30 PM
To get Output Rahulbatra C and C++ 1 05-10-2007 08:23 AM
C Programming - Managing Input and Output Operations JobHelper Career Advice 0 04-15-2006 07:30 AM


All times are GMT -4. The time now is 08:25 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright 2004 - 2009 Exforsys Inc. All rights reserved.