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); ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
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. |
![]() |
| Thread Tools | |
|
|
|
||||
| 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 |