C: How to write a swap( ) function which swaps the values of the variables using bitwise operators?
How to write a swap( ) function which swaps the values of the variables using bitwise operators?
Here is the swap( ) function:
swap ( int *x, int *y )
{
*x ^= *y ;
*y ^= *x ;
*x ^= *y ;
}The swap( ) function uses the bitwise XOR operator and does not require any temporary variable for swapping.




Comments
Log in or create a user account to comment.