Hello,
I have a 2D character array:
char nm[MAX1][MAX2] = { "john", "bob", "david" };
I want to swap two of these elements (without std::swap
) by simply writing
swapPointers(nm[0], nm[1]);
where swapPointers
looks like this
void swapPointers(char *&a, char *&b)
{
char *temp = a;
a = b;
b = a;
}
However, this does not compile (and while adding casts makes it compile, the pointers end up pointing to wrong/weird locations).
Can anybody help?
Thanks!