Exforsys
+ Reply to Thread
Results 1 to 3 of 3

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); ...

  1. #1
    Angela is offline Member Array
    Join Date
    Apr 2006
    Answers
    85

    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.


  2. #2
    sasi_jampala is offline Junior Member Array
    Join Date
    May 2007
    Location
    United States
    Answers
    4

    answer to your question

    out put is from 0 to 5 it ii print


  3. #3
    cyrus is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    128
    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



Latest Article

Network Security Risk Assessment and Measurement

Read More...