samedi 25 mars 2017

Control Flow of if statement and function calls

I am getting the output ' 0,1,2,0'. Please someone help me how this function call is working. I have this doubt that after decrementing n, if statement will not execute as it will not be greater than 0. Thus there will be no output. But the result is something else.

#include <stdio.h>
void fun(int);
int main(void) 

{
int a=3;
fun(a);
return 0;
}
void fun(int n)
{
if(n > 0)
{
    fun(--n);
    printf("%d,", n);
    fun(--n);
}
}

Aucun commentaire:

Enregistrer un commentaire