sizeof(v)/sizeof(int)
is not the way to go. Your function is exactly equivalent to:
void permute(int *v, int curr, char *letters)
{
...
}
i.e. v
is 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):
- add an extra argument that explicitly describes the length of the array
- add an extra argument that points at the last element of the array
- use a proper container (e.g.
std::vector
), which you can callsize()
on - the template solution that @sehe suggests