Possible Duplicate:
length of array in function argument
Hi am doing homework and I am completly stumped. We were suppose to get every order of a list an array of integers so I wrote this piece of code, based off of my teacher’s pseudocode:
void permute(int v[], int curr,char letters[])
{
if(curr >= sizeof(v)/sizeof(int))
{
checkit(v,letters);
}
for(int i = curr; i < sizeof(v)/sizeof(int); i++)
{
swap(i,curr,v);
permute(v,curr + 1,letters);
swap(v[curr],v[i]);
}//for
}//permu
The only thing I am not sure of is if sizeof(v)/sizeof(int) is the right way to go.
sizeof(v)/sizeof(int)is not the way to go. Your function is exactly equivalent to:i.e.
vis not really an array, it’s a pointer. You cannot pass arrays in C or C++.The solution is one of the following (not exhaustive):
std::vector), which you can callsize()on