I wrote a function to reverse an array. The first argument is an iterable object, the second argument is the size of the array element in bytes, and the third argument is the length of the array.void reverse(void *object, int size, int length) {    int i;    int j;     int k;    for(i=0, j=length-1; i < j; i++, j--) {        for(k=0; k<size; k++){            *((char*)object+(i * size)+k) = *((char*)object+(i * size)+k) ^ *((char*)object+(j * size)+k);            *((char*)object+(j * size)+k) = *((char*)object+(i * size)+k) ^ *((char*)object+(j * size)+k);            *((char*)object+(i * size)+k) = *((char*)object+(j * size)+k) ^ *((char*)object+(i * size)+k);        }    }}Could this implementation cause errors? How can I improve it?
Reverse array in C
c;array
Your code works  as far as I can see  correctly. But I would rewriteit a bit to improve the readability (and with it the maintainability) of thecode.The function name reverse() is quite general. That could referto reversing an array, string, or whatever. A better name might bereverseArray(). The repeated cast (char*)object can be avoided by defininga variablechar *ptr = objects;once. Next, the address calculations can be simplified by separatingthe swapping of two objects into a helper function:void reverseArray(void *objects, int size, int length) {    char *ptr = objects;    for (int i = 0, j = length - 1; i < j; i++, j--) {        swapObjects(ptr + size * i, ptr + size * j, size);    }}Note also how i and j are declared locally to the for-loop.Using your method, swapObjects() would be:static inline void swapObjects(char *o1, char *o2, int size) {    for (int k = 0; k < size; k++) {        o1[k] = o1[k] ^ o2[k];        o2[k] = o1[k] ^ o2[k];        o1[k] = o1[k] ^ o2[k];    }}However, I can see no advantage in this magically swap two bytes withouttemporary storage and would rewrite it asstatic inline void swapObjects(char *o1, char *o2, int size) {    for (int k = 0; k < size; k++) {        char tmp = o1[k];        o1[k] = o2[k];        o2[k] = tmp;    }}which is much simpler (no XOR operations and less memory reads andwrites). It is possible to make the swap operation faster by usingint or long as temporary storage, but this requires a carefulcheck of the sizes and memory alignments.Here you can get rid of the subcripts by increasing thepassed pointersstatic inline void swapObjects(char *o1, char *o2, int size) {    for (int k = 0; k < size; k++, o1++, o2++) {        char tmp = *o1;        *o1 = *o2;        *o2 = tmp;    }}but that is a matter of taste. I don't think that it makes a differenceif you compile the code with optimizations switched on.In addition, I would use size_t as type for the size and lengthparameters. size_t is what sizeof returns, and is the correct type to describe the sizeof an object in memory, see for example the declarationsof malloc(), calloc() or strlen().