logo CodeStepByStep logo

swap_xor

Write a function named swap_xor that accepts as parameters pointers to two integers a and b and swaps their values, so that after the call, b will store a's value and vice versa. For example, if two variables a and b store 42 and 17 respectively, the call is swap_xor(a, b); should modify them so that they store 17 and 42 respectively.

The challenge in this problem lies in its constraints. You should solve this problem using only the ^ (bitwise XOR) operator. Do not use any other operators, temporary variables, collections, strings to solve the problem.

Function: Write a C function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.