i need to write a function
void reverse(void *base, int nel, int width)
{
// ...
}
where base is the pointer to the start of the array, nel – number of elements in the array, and width is the size of each element in bytes.
For example, how can I swap first two elements of the array?
You can simply use
memcpy(since it is a builtin on many compilers), with the help ofwidthvalue. You also need a temporary variable.