Exforsys

Online 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++

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-22-2007, 07: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
  #2 (permalink)  
Old 06-22-2007, 10: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, 03: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

Thread Tools

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 05:52 PM
Different Output cyrus C and C++ 3 06-02-2007 02:04 AM
Puzzled on Output Adrian C and C++ 2 05-24-2007 04:30 PM
To get Output Rahulbatra C and C++ 1 05-10-2007 09:23 AM
C Programming - Managing Input and Output Operations JobHelper Career Advice 0 04-15-2006 08:30 AM


All times are GMT -4. The time now is 04:52 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.