1. ## Ugly recursion

I think i have a bad function
Code:
```void fill_me(int A[ ], int N)
{
if (N != 0)   /* if N is not equal to zero do*/
{
--N;  /*decrease N*/
A[N] = N;/*  this attempts to put N in A[N] which is wrong.. am I correct*/
fill_me(A,N);
}
}```
does this result in an infinite loop or only with some values of N

2. Originally Posted by matthughes
I think i have a bad function
Code:
```void fill_me(int A[ ], int N)
{
if (N != 0)   /* if N is not equal to zero do*/
{
--N;  /*decrease N*/
A[N] = N;/*  this attempts to put N in A[N] which is wrong.. am I correct*/
fill_me(A,N);
}
}```

does this result in an infinite loop or only with some values of N
Your function could be used to make an index array, where a[n] = n, throughout the array.

There's no reason why you can't assign a[N] to the value of N - perfectly OK.

Let me boot up here and check this out. It's not clear why it would loop indefinitely at first glance.

Works just fine. No, I didn't test it for negative numbers!

N > 0 would be an improvement, and very standard usage, imo.

3. It only results in an infinite loop for some values of N: when N is negative. Well, it wouldn't be an infinite loop, but it would certainly execute for a very long time, trashing your memory in the process.

I would either change your expression from N!=0 to N>0 or pass N as an unsigned int to the function -- which could be awkward unless you make A[] unsigned as well. Best just to change your expression.

4. I get it I am so stupid if negative number is not equal to 0 and the--N just keeps decreasing it keepin it from ever equaling zero wow!