
- Forum
- Programming Talk
- C and C++
- What is the Output
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); ...
-
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.
-
06-22-2007, 09:19 AM #2
- Join Date
- May 2007
- Location
- United States
- Answers
- 4
answer to your question
out put is from 0 to 5 it ii print
-
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.
-
Sponsored Ads

Reply With Quote





