I have this mysterious code...
What the heck does this do?Code:void swap(void *v[], int i, int j) { void *temp; temp = v[i]; v[i] = v[j]; v[j] = temp; }
I was suprised it even compiled.
The function suggests something is swapped.
If I use my logical sense, I would say this swaps what is in v[i] and v[j].
But what I don't get is:
how can something like this be legal:
when v is a void* pointer.Code:temp = v[i];
I mean..isnt it impossible to find exactly where in memory to find element nr i, when we don't know the size of the thing we're storing in our array?
and secondly, exactly what does this do in practice?
The book im reading suggests it "exchanges two pointers"...but this just doesent make sense to me.
Would anyone be so kind as to try to explain it to me?