I apologize as this is so simple, I was working with my own XOR swap method and wanted for the heck of it compare the speed difference between reference and pointer use (do not spoil it for me!)
My XOR ptr function is as follows:
void xorSwapPtr (int *x, int *y) {
if (x != y && x && y) {
*x ^= *y;
*y ^= *x;
*x ^= *y;
}
}
I copied this to a xorSwapRef function which just uses refs (int &x, etc.) anywho:
I use it like this but I get the error error: invalid conversion from ‘int’ to ‘int*’
int i,x,y = 0;
for(i=0;i<=200000;i++) {
x = rand();
y = rand();
xorSwapPtr(x, y); //error here of course
}
How would I use the pointer function with ints, like the ref one? I just wonder because the example xor function I found in a book uses pointers, hence my wanting to test.