I've been doing a recursive function for exercise and there's a part which really confuses me. Here's what the entire code looks like:
void RekFunkcija(int * pok, int max)
{
if (max != 0)
{
cout << pok[max - 1] << endl;
RekFunkcija(pok + 1, max - 1);
}
}
void main()
{
const int max = 5;
int niz[] = { max, 63, max, 126, 252 };
RekFunkcija(niz, max);
}
So the output here is:
What's been confusing me is this part of the recursive function: cout << pok[max - 1] << endl;
I don't understand why does it output always the last member of the array(252)? While the index number(max-1) is decrementing by 1? Shouldn't the output be: 252,126,5,63,5? Does it have anything to do with the pok+1
argument?
Thank you in advance.