All non-static local variables declared in the body of a function are
unique to that call of the function.

So if you called f(0)

void f(int n)
{
    int array[10] = {0};
    if (n < 10)
    {
        ++array[n];
        f(n+1);
        for(int i = 0; i < 10; ++i)
            printf("%d ", array[i]);
        printf("\n");
    }
}

It will print
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0

Showing that each increment affected the local instance of the array.

Don

On Oct 1, 1:44 pm, rahul sharma <rahul23111...@gmail.com> wrote:
> as we know in recursion new set of variables are created for every
> recurrsive call...if i have array in recursion,then does a new array created
> for every recursive call???

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to