Write a function that receives two pointers, and swaps the values between them.
Utilisateur anonyme
This also looked like a simple question, and was from the same interviewer as the previous one. This one is tricky, but I was already familiar with a bitwise solution to swap variables using XOR. This is exactly what he expected. He also asked me whether something could be improved, so I added the address checking after some thought. void swap (int *a, int *b) { // If addresses are equal and XOR swap is done, // both *a and *b get zeroed out as it is the same value if(a != b) { *a = *a ^ *b; *b = *a ^ *b; *a = *a ^ *b; } }