1.

How To Write A Swap( ) Function Which Swaps The Values Of The Variables Using Bitwise Operators.?

Answer»

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.

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.



Discussion

No Comment Found