I am trying to recursively count down from an array. I have done this previously in python, but I am having trouble finding the size of array. My sizeof() function is only returning a length of 2, which is odd since the array size should be 20 bytes/4bytes.
string cdown(int param[])
{
int length = sizeof(param)/sizeof(param[0]);
cout<<"length: "<< length << endl;
string blastoff = "blastoff";
for (int i=0;i<length;i++)
{
if (param[i]==0){return blastoff;}
else
{
cout<<param[i]<< " ";
param[i] = param[i+1];
param[length-1] = 0;
cdown(param);
}
}
}
int main(void)
{
int countdown[] = {5,4,3,2,1,};
cdown(countdown);
return 0;
}
Result
length: 2
5
length: 2
4
length: 2